コード例 #1
0
 public While(Expr condition, Stmt body)
 {
     Condition = condition;
     Body      = body;
 }
コード例 #2
0
ファイル: Stmt.cs プロジェクト: Terrabalt/CsLox
 public StmtIf(Expr _condition, Stmt _thenBranch, Stmt _elseBranch)
 {
     condition  = _condition;
     thenBranch = _thenBranch;
     elseBranch = _elseBranch;
 }
コード例 #3
0
 void execute(Stmt s)
 {
     s.accept(this);
 }
コード例 #4
0
ファイル: Interpreter.cs プロジェクト: andrewl33/cslox
 private void Execute(Stmt stmt)
 {
     stmt.Accept(this);
 }
コード例 #5
0
ファイル: Stmt.cs プロジェクト: Terrabalt/CsLox
 public StmtWhile(Expr _condition, Stmt _body)
 {
     condition = _condition;
     body      = _body;
 }
コード例 #6
0
ファイル: Stmt.cs プロジェクト: andrewl33/cslox
 public If(Expr condition, Stmt thenBranch, Stmt elseBranch)
 {
     this.condition  = condition;
     this.thenBranch = thenBranch;
     this.elseBranch = elseBranch;
 }
コード例 #7
0
        private Stmt ForStatement()
        {
            //forStmt         → "for" "(" ( varDecl | exprStmt | ";" ) expression? ";" expression? ")" statement ;
            if (!TryParse(LEFT_PAREN))
            {
                throw new ParserError(Current, "'(' expected after 'for'.");
            }

            //initializer is optional
            Stmt initializer = null;

            if (!TryParse(SEMICOLON)) //initializer skipped?
            {
                if (TryParse(VAR))
                {
                    initializer = VarDeclaration();
                }
                else
                {
                    initializer = ExpressionStatement();
                }
            }

            //condition is optional
            Expr condition = null;

            if (!TryParse(SEMICOLON)) //condition skipped?
            {
                condition = Expression();
            }
            if (!TryParse(SEMICOLON))
            {
                throw new ParserError(Current, "';' expected after 'for' loop condition.");
            }

            //increment is also optional
            Expr increment = null;

            if (!TryParse(RIGHT_PAREN)) //increment skipped?
            {
                increment = Expression();
            }
            if (!TryParse(RIGHT_PAREN))
            {
                throw new ParserError(Current, "')' expected after 'for' clauses.");
            }

            //For is represented as Syntax-Tree build from primitives
            //{
            //    var i = 0;
            //    while (i < 10)
            //    {
            //        print i;
            //        i = i + 1;
            //    }
            //}

            Stmt body = Statement();

            //combine body and increment in the inner block
            if (increment != null)
            {
                body = new Block(new List <Stmt>
                {
                    body,
                    new ExpressionStatement(increment)
                });
            }

            //wrap body in while loop with condition
            if (condition != null)
            {
                body = new WhileStatement(condition, body);
            }

            //if there's an initializer combine it with body to form the outer block
            if (initializer != null)
            {
                body = new Block(new List <Stmt>
                {
                    initializer,
                    body
                });
            }

            return(body);
        }
コード例 #8
0
 void Resolve(Stmt stmt)
 {
     stmt.Accept(this);
 }
コード例 #9
0
ファイル: Stmt.cs プロジェクト: andrewl33/cslox
 public While(Expr condition, Stmt body)
 {
     this.condition = condition;
     this.body      = body;
 }
コード例 #10
0
ファイル: Stmt.cs プロジェクト: EldoranDev/cslox
 public If(Expr Condition, Stmt ThenBranch, Stmt ElseBranch)
 {
     this.Condition  = Condition;
     this.ThenBranch = ThenBranch;
     this.ElseBranch = ElseBranch;
 }
コード例 #11
0
ファイル: Stmt.cs プロジェクト: EldoranDev/cslox
 public While(Expr Condition, Stmt Body)
 {
     this.Condition = Condition;
     this.Body      = Body;
 }
コード例 #12
0
 public IfStatement(Expr condition, Stmt thenBranch, Stmt elseBranch)
 {
     Condition  = condition;
     ThenBranch = thenBranch;
     ElseBranch = elseBranch;
 }
コード例 #13
0
 public WhileStatement(Expr condition, Stmt body)
 {
     Condition = condition;
     Body      = body;
 }
コード例 #14
0
 private void Resolve(Stmt statement)
 {
     statement.Accept(this);
 }