示例#1
0
 object Stmt.IVisitor <object> .VisitBlockStmt(Stmt.Block stmt)
 {
     BeginScope();
     Resolve(stmt.statements);
     EndScope();
     return(null);
 }
示例#2
0
 public Unit VisitBlockStmt(Stmt.Block stmt)
 {
     BeginScope();
     Resolve(stmt.Statements);
     EndScope();
     return(Unit.Default);
 }
示例#3
0
        public object VisitBlockStmt(Stmt.Block stmt)
        {
            BeginScope();
            Resolve(stmt.Statements);
            EndScope();

            return(null);
        }
示例#4
0
文件: Resolver.cs 项目: leddt/cslox
        public Void Visit(Stmt.Block stmt)
        {
            BeginScope();
            Resolve(stmt.Statements);
            EndScope();

            return(Void.Instance);
        }
示例#5
0
文件: Parser.cs 项目: andrewl33/cslox
        private Stmt ForStatement()
        {
            Consume(TokenType.LEFT_PAREN, "Expect '(' after 'for'.");

            Stmt initializer;

            if (Match(TokenType.SEMICOLON))
            {
                initializer = null;
            }
            else if (Match(TokenType.VAR))
            {
                initializer = VarDeclaration();
            }
            else
            {
                initializer = ExpressionStatement();
            }

            Expr condition = null;

            if (!Check(TokenType.SEMICOLON))
            {
                condition = Expression();
            }

            Consume(TokenType.SEMICOLON, "Expect ';' after loop condition.");

            Expr increment = null;

            if (!Check(TokenType.RIGHT_PAREN))
            {
                increment = Expression();
            }
            Consume(TokenType.RIGHT_PAREN, "Expect ')' after for clauses");

            Stmt body = Statement();

            if (increment != null)
            {
                body = new Stmt.Block(new List <Stmt>(new[] { body, new Stmt.Expression(increment) }));
            }

            if (condition == null)
            {
                condition = new Expr.Literal(true);
            }
            body = new Stmt.While(condition, body);

            if (initializer != null)
            {
                body = new Stmt.Block(new List <Stmt>(new[] { initializer, body }));
            }

            return(body);
        }
示例#6
0
        private Stmt ForStatement()
        {
            Consume(LeftParen, "Expect '(' after 'for'.");

            Stmt initializer;

            if (Match(Semicolon))
            {
                initializer = null;
            }
            else if (Match(Var))
            {
                initializer = VarDeclaration();
            }
            else
            {
                initializer = ExpressionStatement();
            }

            var condition = Check(Semicolon) ? null : Expression();

            Consume(Semicolon, "Expect ';' after loop condition.");

            var increment = Check(RightParen) ? null : Expression();

            Consume(RightParen, "Expect ')' after for clauses.");

            var body = Statement();

            if (increment != null)
            {
                body = new Stmt.Block(new[] {
                    body,
                    new Stmt.Expression(increment)
                });
            }

            if (condition == null)
            {
                condition = new Literal(true);
            }
            body = new Stmt.While(condition, body);

            if (initializer != null)
            {
                body = new Stmt.Block(new[] {
                    initializer,
                    body
                });
            }

            return(body);
        }
示例#7
0
        public string VisitBlockStmt(Stmt.Block stmt)
        {
            var builder = new StringBuilder();

            builder.Append("(block ");

            foreach (var s in stmt.Statements)
            {
                builder.Append(s.Accept(this));
            }

            builder.Append(")");
            return(builder.ToString());
        }
示例#8
0
 public object VisitBlockStmt(Stmt.Block stmt)
 {
     ExecuteBlock(stmt.Statements, new Environment(environment));
     return(null);
 }
示例#9
0
        // forStmt :: "for" "(" ( varDecl | exprStmt | "; ")
        //                      expression? ";"
        //                      expression? ")" statement ;
        private Stmt ForStatement()
        {
            Consume(TokenType.LeftParen, "Expect '(' after 'for'");

            // Get the initializer.
            Stmt init;

            if (MatchAny(TokenType.Semicolon))
            {
                init = null;
            }
            else if (MatchAny(TokenType.Var))
            {
                init = VarDeclaration();
            }
            else
            {
                init = ExpressionStatement();
            }

            // Get the condition.
            Expr condition = null;

            if (!Check(TokenType.Semicolon))
            {
                condition = Expression();
            }

            Consume(TokenType.Semicolon, "Expect ';' after loop condition");

            // Get the increment.
            Expr increment = null;

            if (!Check(TokenType.RightParen))
            {
                increment = Expression();
            }

            Consume(TokenType.RightParen, "Expect ')' after for clauses");

            var body = Statement();

            // Desugar by creating a while loop instead.
            if (increment != null)
            {
                body = new Stmt.Block(
                    new List <Stmt> {
                    body,
                    new Stmt.Expression(increment)
                });
            }

            if (condition == null)
            {
                condition = new Expr.Literal(true);
            }

            body = new Stmt.While(condition, body);

            if (init != null)
            {
                body = new Stmt.Block(
                    new List <Stmt> {
                    init,
                    body
                });
            }

            return(body);
        }
示例#10
0
 object Stmt.IVisitor <object> .VisitBlockStmt(Stmt.Block stmt)
 {
     ExecuteBlock(stmt.statements, new Environment(environment));
     return(null);
 }
示例#11
0
 public Unit VisitBlockStmt(Stmt.Block stmt)
 {
     ExecuteBlock(stmt.Statements, new Environment(_environment));
     return(Unit.Default);
 }
示例#12
0
        public Void Visit(Stmt.Block stmt)
        {
            ExecuteBlock(stmt.Statements, new Environment(environment));

            return(Void.Instance);
        }