コード例 #1
0
ファイル: Interpreter.cs プロジェクト: mikebrasher/LoxSharp
 // Stmt Visitors
 public void Visit(Stmt.Block stmt)
 {
     ExecuteBlock(stmt.statements, new Environment(environment));
 }
コード例 #2
0
 // Stmt Visitors
 public void Visit(Stmt.Block block)
 {
     // do nothing
 }
コード例 #3
0
        private Stmt ForStatement()
        {
            Consume(TokenType.LeftParen, "Expect '(' after 'for'");

            // initializer
            Stmt initializer = null;

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

            // condition
            Expr condition = null;

            if (!Check(TokenType.Semicolon))
            {
                condition = Expression();
            }
            Consume(TokenType.Semicolon, "Expect ';' after loop condition.");

            // increment
            Expr increment = null;

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

            // body
            Stmt body = Statement();

            // desugar
            if (increment != null)
            {
                List <Stmt> statements = new List <Stmt>();
                statements.Add(body);
                statements.Add(new Stmt.Expression(increment));

                body = new Stmt.Block(statements);
            }

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

            if (initializer != null)
            {
                List <Stmt> statements = new List <Stmt>();
                statements.Add(initializer);
                statements.Add(body);

                body = new Stmt.Block(statements);
            }

            return(body);
        }
コード例 #4
0
ファイル: Resolver.cs プロジェクト: mikebrasher/LoxSharp
 // Stmt Visitors
 public void Visit(Stmt.Block stmt)
 {
     BeginScope();
     Resolve(stmt.statements);
     EndScope();
 }