예제 #1
0
파일: Stmt.cs 프로젝트: djangbahevans/CsLox
 public If(Expr condition, Stmt thenBranch, Stmt elseBranch)
 {
     this.Condition  = condition;
     this.ThenBranch = thenBranch;
     this.ElseBranch = elseBranch;
 }
예제 #2
0
파일: Stmt.cs 프로젝트: djangbahevans/CsLox
 public While(Expr condition, Stmt body)
 {
     this.Condition = condition;
     this.Body      = body;
 }
예제 #3
0
 public While(Expr condition, Stmt body)
 {
     Condition = condition;
     Body      = body;
 }
예제 #4
0
 private void Execute(Stmt stmt)
 {
     stmt.Accept(this);
 }
예제 #5
0
파일: Parser.cs 프로젝트: sirgru/CsLox
        private Stmt ForStatement()
        {
            Expect(TokenType.LeftParen, ErrorType.ExpectedOpenParen);

            Stmt initializer;

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

            Expr condition = null;

            if (!CheckCurrentToken(TokenType.Semicolon))
            {
                condition = Expression();
            }
            Expect(TokenType.Semicolon, ErrorType.ExpectedSemicolon);

            Expr increment = null;

            if (!CheckCurrentToken(TokenType.RightParen))
            {
                increment = Expression();
            }
            Expect(TokenType.RightParen, ErrorType.ExpectedClosedParen);

            Stmt body = Statement();

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

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

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

            return(body);
        }
예제 #6
0
 public If(Expr condition, Stmt thenBranch, Stmt elseBranch)
 {
     Condition  = condition;
     ThenBranch = thenBranch;
     ElseBranch = elseBranch;
 }
예제 #7
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(SEMICOLON))
            {
                increment = Expression();
            }
            Consume(RIGHT_PAREN, "Expect ';' after for clauses");

            Stmt body = Statement();

            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 (initializer != null)
            {
                body = new Stmt.Block(new List <Stmt>()
                {
                    initializer, body
                });
            }

            return(body);
        }
예제 #8
0
 void Resolve(Stmt stmt)
 {
     stmt.Accept(this);
 }
예제 #9
0
파일: Gen_Stmt.cs 프로젝트: sirgru/CsLox
 public IfStmt(Expr condition, Stmt thenBranch, Stmt elseBranch)
 {
     this.condition  = condition;
     this.thenBranch = thenBranch;
     this.elseBranch = elseBranch;
 }
예제 #10
0
파일: Gen_Stmt.cs 프로젝트: sirgru/CsLox
 public WhileStmt(Expr condition, Stmt body)
 {
     this.condition = condition;
     this.body      = body;
 }
예제 #11
0
파일: AST_Printer.cs 프로젝트: sirgru/CsLox
 public String Print(Stmt stmt)
 {
     return(stmt.Accept(this));
 }