示例#1
0
 public object visitBlockStmt(Stmt.Block stmt)
 {
     beginScope();
     resolve(stmt.statements);
     endScope();
     return(null);
 }
示例#2
0
        private Stmt forStatement()
        {
            consume(LEFT_PAREN, "Expect '(' after 'for'.");

            Stmt initializer;

            if (match(SEMICOLON))
            {
                initializer = null;
            }
            else if (match(VAR))
            {
                initializer = varDeclaration();
            }
            else
            {
                initializer = expressionStatement();
            }

            Expr condition = null;

            if (!check(SEMICOLON))
            {
                condition = expression();
            }
            consume(SEMICOLON, "Expect ';' after loop condition.");

            Expr increment = null;

            if (!check(RIGHT_PAREN))
            {
                increment = expression();
            }
            consume(RIGHT_PAREN, "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 Expr.Literal(true);
            }
            body = new Stmt.While(condition, body);

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

            return(body);
        }
示例#3
0
 public object visitBlockStmt(Stmt.Block stmt)
 {
     executeBlock(stmt.statements, new RosellaEnvironment(environment));
     return(null);
 }