예제 #1
0
        private StmtIf ParseStmtElif()
        {
            StmtBlock elseObj  = null;
            var       branches = new List <Branch>();

            branches.Add(ParseStmtIf());
            while (Accept(TokenType.Else) != null)
            {
                List <IStatement> stmtBlock;
                if (Accept(TokenType.If) != null)
                {
                    var expression = ParseExprParen();
                    stmtBlock = ParseStmtBlock();
                    branches.Add(new Branch(expression, new StmtBlock(stmtBlock)));
                }
                else
                {
                    stmtBlock = ParseStmtBlock();
                    elseObj   = new StmtBlock(stmtBlock);

                    break;
                }
            }

            return(new StmtIf(branches, elseObj));
        }
예제 #2
0
        public Branch(IExpression condition, StmtBlock body)
        {
            AddChildren(condition, body);
            Condition = condition;
            Body      = body;

            EndLabel = new Label();
        }
예제 #3
0
        public StmtWhile(IExpression condition, StmtBlock body)
        {
            AddChildren(condition, body);
            this.condition = condition;
            this.body      = body;

            startLabel = new Label();
            endLabel   = new Label();
        }
예제 #4
0
        public StmtIf(List <Branch> branches, StmtBlock elseBody)
        {
            /*var temp = new Node[branches.Count + 1];
             * temp[branches.Count] = elseBody;*/

            AddChildren(branches.ToArray());
            AddChildren(elseBody);
            this.Branches = branches;
            this.ElseBody = elseBody;

            ElseLabel      = new Label();
            AfterElseLabel = new Label();
        }