Exemplo n.º 1
0
        public void VisitForLoop(ForLoopNode fln)
        {
            fln.Assignment.Visit(this);
            string           op         = CreateOperatorToForLoopCondition(fln);
            UnaryOperandNode cond       = fln.Condition.Visit(this);
            UnaryOperandNode assignment = new UnaryOperandNode(
                this.symbolTable.GetEntry(cond.Token.Value).Value,
                SymbolType.IntegerValue,
                cond.Token
                );

            this.symbolTable.LockVariable(cond.Token.Value);
            while (cond.Type == SymbolType.Boolean && cond.Value == "true")
            {
                this.symbolTable.PushBlock();
                VisitStatements(fln);
                this.symbolTable.PopBlock();

                // Left value of BinaryExpression needs to be incremented by one (Has to be Identifier)
                assignment = HandleIntegerOperation(
                    assignment,
                    new UnaryOperandNode("1", SymbolType.IntegerValue, assignment.Token),
                    op
                    );
                this.symbolTable.ForceModifyEntry(cond.Token.Value, assignment.Value);
                cond = fln.Condition.Visit(this);
            }
            this.symbolTable.ReleaseVariable(cond.Token.Value);
        }
Exemplo n.º 2
0
        public void VisitForLoop(ForLoopNode fln)
        {
            int    temp    = this.depth;
            string spaces1 = IncreaseDepth();
            string spaces2 = IncreaseDepth();

            this.io.WriteLine($"{spaces1}ForLoop: (\n{spaces2}Assignment: (");
            fln.Assignment.Visit(this);
            this.io.WriteLine($"{spaces2}),\n{spaces2}Condition: (");
            fln.Condition.Visit(this);
            this.io.WriteLine($"{spaces2}),\n{spaces2}Statements: [");
            VisitStatements(fln);

            /*string spaces3 = IncreaseDepth();
             * foreach (Statement stmt in fln.Statements)
             * {
             * this.io.WriteLine($"{spaces3}(");
             * stmt.Visit(this);
             * this.io.WriteLine($"{spaces3}),");
             * }*/
            this.io.WriteLine($"{spaces2}]\n{spaces1})");
            this.depth = temp;
        }