If-Else branching
Inheritance: Statement
Esempio n. 1
0
 public virtual void Visit(If node)
 {
 }
        void IfStmt(out Statement ifStmt)
        {
            StatementSequence ifBranch = null;
            StatementSequence elseBranch = null;
            Statement tmpStmt = null;
            Expression exp = null;
            ifStmt = null;

            Expect(18);
            int sl = t.line; int sc = t.col; Token tok = t;
            Expr(out exp);
            if (!ExpectBool(exp, tok, true)) {
                                     return;
                                 }
            Expect(19);
            int el = t.line; int ec = t.col+t.val.Length;
            if (Options.BookVersion) {
            Stmt(out tmpStmt);
            ifBranch = ToStatementSequence(tmpStmt);
            if (la.kind == 20) {
                Get();
                Stmt(out tmpStmt);
                elseBranch = ToStatementSequence(tmpStmt);
            }
            } else if (StartOf(1)) {
            StmtSeq(out ifBranch);
            if (la.kind == 20) {
                Get();
                StmtSeq(out elseBranch);
            }
            Expect(21);
            ifBranch.AddSequencePoint(t);
            if (elseBranch != null) {
                elseBranch.AddSequencePoint(t);
            }

            } else SynErr(53);
            ifStmt = new If((TypedExpression<bool>)exp, ifBranch, elseBranch);
            ifStmt.AddSequencePoint(sl,sc,el,ec);
        }