示例#1
0
 public object visitBlockStatement(Statement.Block blockStmt)
 {
     beginScope();
     resolve(blockStmt.statements);
     endScope();
     return(null);
 }
示例#2
0
        private Statement forStatement()
        {
            consume(TokenType.LEFT_PAREN, "Expect '(' after 'for'.");
            Statement 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.");
            parsingLoop = true;
            Statement body = statement();

            parsingLoop = false;
            if (increment != null)
            {
                body = new Statement.Block(new List <Statement> {
                    body, new Statement.Expression(increment)
                });
            }

            if (condition == null)
            {
                condition = new Expr.Literal(true, previous());
            }
            body = new Statement.whileStmt(condition, body, false);

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

            return(body);
        }
示例#3
0
 public object visitBlockStatement(Statement.Block blockStmt)
 {
     executeBlock(blockStmt.statements, new Environment(environment));
     return(null);
 }