public override void VisitAssignmentStatement(BoundAssignmentStatement node)
 {
     node.Left.Accept(this);
     _writer.WritePunctuation(" = ");
     node.Right.Accept(this);
     _writer.WriteLine();
 }
Exemple #2
0
        private async Task <Either <RuntimeErrors, Success> > Execute(BoundAssignmentStatement boundAssignmentStatement)
        {
            var evaluation = await Evaluate(boundAssignmentStatement.Expression);

            evaluation.WhenRight(o => variables[boundAssignmentStatement.Variable] = o);
            return(evaluation.MapRight(o => new Success()));
        }
Exemple #3
0
            public override void VisitRepeatStatement(RepeatStatement node)
            {
                // reduce REPEAT statement to a WHILE statement

                /* REPEAT n i
                 *    block
                 * ENDREPEAT
                 *
                 * i = 0
                 * WHILE i < n
                 *    block
                 *    i = i + 1
                 * ENDWHILE
                 */

                var boundLimit   = Bind(node.Limit) !;
                var boundCounter = Bind(node.Counter) !;

                // i = 0
                var zeroCounter = new BoundAssignmentStatement(boundCounter, new BoundIntLiteralExpression(0));

                stmts !.Add(zeroCounter);

                // WHILE i < n
                var condition  = new BoundBinaryExpression(boundCounter, boundLimit, BinaryOperator.Less);
                var boundWhile = new BoundWhileStatement(condition);

                stmts !.Add(boundWhile);

                VisitScope(node.Block, boundWhile.Block);

                // i = i + 1
                var add    = new BoundBinaryExpression(boundCounter, new BoundIntLiteralExpression(1), BinaryOperator.Add);
                var assign = new BoundAssignmentStatement(boundCounter, add);

                boundWhile.Block.Add(assign);
            }
Exemple #4
0
 public void Visit(BoundAssignmentStatement a)
 {
     sa.TabPrint(a.Variable + " = ");
     a.Expression.Accept(this);
     sa.Print(";");
 }
Exemple #5
0
 public virtual void VisitAssignmentStatement(BoundAssignmentStatement node) =>
 this.DefaultVisit(node);