Exemplo n.º 1
0
        public override Node VisitFor(DeltinScriptParser.ForContext context)
        {
            BlockNode block = (BlockNode)VisitBlock(context.block());

            VarSetNode varSet = null;

            if (context.varset() != null)
            {
                varSet = (VarSetNode)VisitVarset(context.varset());
            }

            DefineNode defineNode = null;

            if (context.define() != null)
            {
                defineNode = (DefineNode)VisitDefine(context.define());
            }

            Node expression = null;

            if (context.expr() != null)
            {
                expression = VisitExpr(context.expr());
            }

            VarSetNode statement = null;

            if (context.forEndStatement() != null)
            {
                statement = (VarSetNode)VisitVarset(context.forEndStatement().varset());
            }

            return(new ForNode(varSet, defineNode, expression, statement, block, new Location(file, Range.GetRange(context))));
        }
Exemplo n.º 2
0
 public ForNode(VarSetNode varSetNode, ScopedDefineNode defineNode, IExpressionNode expression, IStatementNode statement, BlockNode block, Range range) : base(range)
 {
     VarSetNode = varSetNode;
     DefineNode = defineNode;
     Expression = expression;
     Statement  = statement;
     Block      = block;
 }
Exemplo n.º 3
0
 public ForNode(VarSetNode varSetNode, DefineNode defineNode, Node expression, VarSetNode statement, BlockNode block, Location location) : base(location)
 {
     VarSetNode = varSetNode;
     DefineNode = defineNode;
     Expression = expression;
     Statement  = statement;
     Block      = block;
 }
Exemplo n.º 4
0
        void ParseVarset(ScopeGroup scope, VarSetNode varSetNode)
        {
            DefinedVar variable = scope.GetVar(varSetNode.Variable, varSetNode.Range, Diagnostics);

            Element target = null;

            if (varSetNode.Target != null)
            {
                target = ParseExpression(scope, varSetNode.Target);
            }

            Element value = ParseExpression(scope, varSetNode.Value);

            Element initialVar = variable.GetVariable(target);

            Element index = null;

            if (varSetNode.Index != null)
            {
                index      = ParseExpression(scope, varSetNode.Index);
                initialVar = Element.Part <V_ValueInArray>(initialVar, index);
            }


            switch (varSetNode.Operation)
            {
            case "+=":
                value = Element.Part <V_Add>(initialVar, value);
                break;

            case "-=":
                value = Element.Part <V_Subtract>(initialVar, value);
                break;

            case "*=":
                value = Element.Part <V_Multiply>(initialVar, value);
                break;

            case "/=":
                value = Element.Part <V_Divide>(initialVar, value);
                break;

            case "^=":
                value = Element.Part <V_RaiseToPower>(initialVar, value);
                break;

            case "%=":
                value = Element.Part <V_Modulo>(initialVar, value);
                break;
            }

            Actions.Add(variable.SetVariable(value, target, index));
        }
Exemplo n.º 5
0
        public override Node VisitFor(DeltinScriptParser.ForContext context)
        {
            Node      node;
            BlockNode block = (BlockNode)VisitBlock(context.block());

            if (context.IN() != null)
            {
                IExpressionNode array    = (IExpressionNode)Visit(context.expr());
                string          variable = context.PART().GetText();

                node = new ForEachNode(variable, array, block, Range.GetRange(context));
            }
            else
            {
                VarSetNode varSet = null;
                if (context.varset() != null)
                {
                    varSet = (VarSetNode)VisitVarset(context.varset());
                }

                ScopedDefineNode defineNode = null;
                if (context.define() != null)
                {
                    defineNode = (ScopedDefineNode)VisitDefine(context.define());
                }

                IExpressionNode expression = null;
                if (context.expr() != null)
                {
                    expression = (IExpressionNode)VisitExpr(context.expr());
                }

                IStatementNode statement = null;
                if (context.statement() != null)
                {
                    statement = (IStatementNode)VisitStatement(context.statement());
                }

                node = new ForNode(varSet, defineNode, expression, statement, block, Range.GetRange(context));
            }

            CheckRange(node);
            return(node);
        }
Exemplo n.º 6
0
        public override Node VisitVarset(DeltinScriptParser.VarsetContext context)
        {
            IExpressionNode target   = context.expr().Length == 2 ? (IExpressionNode)Visit(context.expr()[0]) : null;
            string          variable = context.PART().GetText();

            IExpressionNode index = null;

            if (context.array() != null)
            {
                index = (IExpressionNode)Visit(context.array().expr());
            }

            string          operation = context.statement_operation().GetText();
            IExpressionNode value     = (IExpressionNode)Visit(context.expr().Last());

            Node node = new VarSetNode(target, variable, index, operation, value, Range.GetRange(context));

            CheckRange(node);
            return(node);
        }
        void ParseVarset(ScopeGroup getter, ScopeGroup scope, VarSetNode varSetNode)
        {
            var varSetData = new ParseExpressionTree(this, getter, scope, varSetNode.Variable);

            if (!(varSetData.ResultingVariable is IndexedVar))
            {
                throw SyntaxErrorException.VariableIsReadonly(varSetData.ResultingVariable.Name, varSetNode.Location);
            }

            IndexedVar variable = (IndexedVar)varSetData.ResultingVariable;

            Element[] index = varSetData.VariableIndex;

            Element value = null;

            if (varSetNode.Value != null)
            {
                value = ParseExpression(getter, scope, varSetNode.Value);
            }

            Element initialVar = variable.GetVariable(varSetData.Target);

            Operation?operation = null;

            switch (varSetNode.Operation)
            {
            case "+=":
                operation = Operation.Add;
                break;

            case "-=":
                operation = Operation.Subtract;
                break;

            case "*=":
                operation = Operation.Multiply;
                break;

            case "/=":
                operation = Operation.Divide;
                break;

            case "^=":
                operation = Operation.RaiseToPower;
                break;

            case "%=":
                operation = Operation.Modulo;
                break;

            case "++":
                operation = Operation.Add;
                value     = 1;
                break;

            case "--":
                operation = Operation.Subtract;
                value     = 1;
                break;
            }

            if (operation == null)
            {
                Actions.AddRange(variable.SetVariable(value, varSetData.Target, index));
            }
            else
            {
                Actions.AddRange(variable.ModifyVariable((Operation)operation, value, varSetData.Target, index));
            }
        }