Exemple #1
0
        public override void ContextVerify(IContext context)
        {
            var repeatContext = new LoopBlockContext();

            repeatContext.ClassContext  = context.ClassContext;
            repeatContext.ParentContext = context;

            this.Block.Symbol.ContextVerify(repeatContext);

            var conditionExpValue = this.Exp.Symbol.GetExpressions(context.ClassContext.Packages, context);

            if (conditionExpValue.Length > 1)
            {
                throw new SyntaxException("Cannot use multi-value in condition expression.", this.Lparen.Line, this.Lparen.Column);
            }
            if (conditionExpValue.Length == 0)
            {
                throw new SyntaxException("Cannot use non-value in condition expression.", this.Lparen.Line, this.Lparen.Column);
            }
            var tlValue = conditionExpValue[0];

            if (tlValue.Classify != ExpressionType.Value)
            {
                throw new SyntaxException("Condition expression is not a value.", this.Lparen.Line, this.Lparen.Column);
            }
            this.Exp.Symbol.ContextVerify(context);
        }
        public override void ContextVerify(IContext context)
        {
            //Öظ´±äÁ¿¼ì²é
            var v1 = context.GetElement(this.Identifier.Symbol, context);

            if (v1 != null)
            {
                throw new SyntaxException("Variable with same name is already exist", this.Identifier.Line, this.Identifier.Column);
            }

            var expValueList1 = this.Exp.Symbol.GetExpressions(context.ClassContext.Packages, context);

            if (expValueList1.Length != 1)
            {
                throw new SyntaxException("Expression mismatch.", this.Eq.Line, this.Eq.Column);
            }
            var expValue1 = expValueList1[0];

            if (expValue1.Classify != ExpressionType.Value || expValue1.Type != Type.Number)
            {
                throw new SyntaxException("The expression must be a number.", this.Eq.Line, this.Eq.Column);
            }
            this.Exp.Symbol.ContextVerify(context);

            if (this.Exp_2 != null)
            {
                var expValueList2 = this.Exp_2.Symbol.GetExpressions(context.ClassContext.Packages, context);
                if (expValueList2.Length != 1)
                {
                    throw new SyntaxException("Expression mismatch.", this.Comma.Line, this.Comma.Column);
                }
                var expValue2 = expValueList2[0];
                if (expValue2.Classify != ExpressionType.Value || expValue2.Type != Type.Number)
                {
                    throw new SyntaxException("The expression must be a number.", this.Eq.Line, this.Eq.Column);
                }
                this.Exp_2.Symbol.ContextVerify(context);
            }

            var forContext = new LoopBlockContext();

            forContext.ParentContext = context;
            forContext.ClassContext  = context.ClassContext;
            forContext.AddElement(new Variable(this.Identifier.Symbol)
            {
                Type = Type.Number
            });

            this.Forstepstatement.Symbol.ContextVerify(forContext);
            this.Block.Symbol.ContextVerify(forContext);
        }
Exemple #3
0
        public override void ContextVerify(IContext context)
        {
            //Öظ´±äÁ¿¼ì²é
            var v1 = context.GetElement(this.Identifier.Symbol, context);

            if (v1 != null)
            {
                throw new SyntaxException("Variable with same name is already exist", this.Identifier.Line, this.Identifier.Column);
            }
            var v2 = context.GetElement(this.Identifier_2.Symbol, context);

            if (v2 != null)
            {
                throw new SyntaxException("Variable with same name is already exist", this.Identifier_2.Line, this.Identifier_2.Column);
            }

            var expValueList = this.Exp.Symbol.GetExpressions(context.ClassContext.Packages, context);

            if (expValueList.Length != 1)
            {
                throw new SyntaxException("Expression mismatch.", this.In.Line, this.In.Column);
            }
            var expValue = expValueList[0];

            if (expValue.Classify != ExpressionType.Value)
            {
                throw new SyntaxException("Expression mismatch.", this.In.Line, this.In.Column);
            }
            this.Exp.Symbol.ContextVerify(context);

            var forContext = new LoopBlockContext();

            forContext.ParentContext = context;
            forContext.ClassContext  = context.ClassContext;

            if (expValue.Type == Type.Table || expValue.Type == Type.Any)
            {
                forContext.AddElement(new Variable(this.Identifier.Symbol)
                {
                    Type = Type.Any
                });
                forContext.AddElement(new Variable(this.Identifier_2.Symbol)
                {
                    Type = Type.Any
                });
            }
            else if (expValue.Type.Name == Type.ListTable.Name && expValue.Type.PackageName == Type.ListTable.PackageName)
            {
                var tlGenericityType = expValue.Type as GenericityType;
                forContext.AddElement(new Variable(this.Identifier.Symbol)
                {
                    Type = Type.Number
                });
                forContext.AddElement(new Variable(this.Identifier_2.Symbol)
                {
                    Type = tlGenericityType.FirstGroupGenericTypeArguments[0]
                });
            }
            else if (expValue.Type.Name == Type.HashTable.Name && expValue.Type.PackageName == Type.HashTable.PackageName)
            {
                var tlGenericityType = expValue.Type as GenericityType;
                forContext.AddElement(new Variable(this.Identifier.Symbol)
                {
                    Type = tlGenericityType.FirstGroupGenericTypeArguments[0]
                });
                forContext.AddElement(new Variable(this.Identifier_2.Symbol)
                {
                    Type = tlGenericityType.FirstGroupGenericTypeArguments[1]
                });
            }
            else
            {
                throw new SyntaxException("Expression mismatch.", this.In.Line, this.In.Column);
            }
            this.Block.Symbol.ContextVerify(forContext);
        }