Ejemplo n.º 1
0
 public virtual void Visit(IfElseStatement statement)
 {
     VisitSubNodes(statement);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Parser for If(Else)Statement
        /// </summary>
        /// <returns>Parsed If(Else)Statement</returns>
        public Statement ParseIfStatement()
        {
            Statement statement = null;

            //Skip if keyword
            NextToken("if", "if ( Predicate ) Statement else Statement", "if");

            //Skip ( token
            NextToken("(", "if ( Predicate ) Statement else Statement", '(');

            //Parse predicate
            Predicate predicate = predicateParser.ParsePredicate();

            //Skip ) token
            NextToken(")", "if ( Predicate ) Statement else Statement", ')');

            //Parse if part of statement
            Statement ifStatementPart = ParseStatement();

            if (TokenStream.HasNext() && TokenStream.Peek(1).GetValue().ToString() == "else")
            {   //Else part detected
                //Skip else token
                NextToken("else", "if ( Predicate ) Statement else Statement", "else");

                //Parse else statement part
                Statement elseStatementPart = ParseStatement();

                IfElseStatement ifElseStatement = new IfElseStatement();
                ifElseStatement.SetPredicate(predicate);
                ifElseStatement.SetTrueStatement(ifStatementPart);
                ifElseStatement.SetFalseStatement(elseStatementPart);
                statement = ifElseStatement;
            }
            else
            {   //If statement
                IfStatement ifStatement = new IfStatement();
                ifStatement.SetPredicate(predicate);
                ifStatement.SetTrueStatement(ifStatementPart);
                statement = ifStatement;
            }

            return statement;
        }