Exemplo n.º 1
0
Arquivo: Expr.cs Projeto: mamidon/nlox
 public WhileStmt(Expr Condition, Stmt BodyStatement)
 {
     this.Condition     = Condition;
     this.BodyStatement = BodyStatement;
 }
Exemplo n.º 2
0
 public void Execute(Stmt stmt)
 {
     stmt.Accept(this);
 }
Exemplo n.º 3
0
Arquivo: Expr.cs Projeto: mamidon/nlox
 public IfStmt(Expr Condition, Stmt ThenStatement, Stmt ElseStatement)
 {
     this.Condition     = Condition;
     this.ThenStatement = ThenStatement;
     this.ElseStatement = ElseStatement;
 }
Exemplo n.º 4
0
        Stmt ForStatement()
        {
            Consume(TokenType.LeftParen, "Expected opening '('.");

            Stmt initializer = null;

            if (MatchNext(TokenType.Var))
            {
                initializer = VarDeclaration();
            }
            else if (MatchNext(TokenType.SemiColon))
            {
                initializer = null;
            }
            else
            {
                initializer = ExpressionStatement();
            }

            Expr conditional = null;

            if (!MatchNext(TokenType.SemiColon))
            {
                conditional = Expression();
                Consume(TokenType.SemiColon, "Expecting ';' in for loop");
            }


            Expr incrementer = null;

            if (!MatchNext(TokenType.RightParen))
            {
                incrementer = Expression();
                Consume(TokenType.RightParen, "Expected closing ')' in for loop");
            }

            var body = Statement();

            if (incrementer != null)
            {
                body = new BlockStmt(new List <Stmt> {
                    body,
                    new ExpressionStmt(incrementer)
                });
            }

            if (conditional == null)
            {
                conditional = new LiteralExpr(true);
            }
            body = new WhileStmt(conditional, body);

            if (initializer != null)
            {
                body = new BlockStmt(new List <Stmt> {
                    initializer,
                    body
                });
            }

            return(body);
        }