Пример #1
0
        private ConditionalExpression Consume_ConditionalExpression()
        {
            Token token = currentToken;

            switch (token.Type)
            {
            case TokenType.CONDITION:
                Consume(TokenType.CONDITION);
                return(ExpressionFactory.CreateConditionalExpression(Consume_ConditionBlock(), Consume_ConditionalExpression(), currentToken));

            case TokenType.ELSEIF:
                Consume(TokenType.ELSEIF);
                ConditionBlock block = Consume_ConditionBlock();

                if (currentToken.Type == TokenType.END)
                {
                    Consume(TokenType.END);
                    return(ExpressionFactory.CreateConditionalExpression(block, null, currentToken));
                }
                else
                {
                    return(ExpressionFactory.CreateConditionalExpression(block, Consume_ConditionalExpression(), currentToken));
                }

            case TokenType.ELSE:
                Consume(TokenType.ELSE);
                ConditionBlock        elseBlock = ExpressionFactory.CreateConditionalBlock(2, new TRUE_Expression(), Consume_BlockStatement(), currentToken);
                ConditionalExpression expr      = ExpressionFactory.CreateConditionalExpression(elseBlock, null, currentToken);
                Consume(TokenType.END);
                return(expr);
            }
            throw RaiseError(ScriptErrorCode.UNEXPECTED_TOKEN, token);
        }
Пример #2
0
        private ConditionBlock Consume_ConditionBlock()
        {
            IExpression    expr      = Consume_Expression();
            BlockStatement blockStmt = new BlockStatement();

            Consume(TokenType.THEN);

            while (currentToken.Type != TokenType.ELSEIF && currentToken.Type != TokenType.ELSE)
            {
                blockStmt.Append(Consume_Statement());
            }

            return(ExpressionFactory.CreateConditionalBlock(0, expr, blockStmt, currentToken));
        }