Пример #1
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        private static IExpression  ParseExpExpression()
        {
            if (Check(FirstUnaryExp))
            {
                IExpression exp = ParseUnaryExpression();

                if (Check(new TokenSet(TokenType.Exponent)))
                {
                    TokenType opType = CurrentToken.type;
                    Eat(opType);
                    if (!Check(FirstUnaryExp))
                    {
                        throw new InvalidSyntaxException("Expected an expression after ^ operator");
                    }
                    IExpression right = ParseUnaryExpression();

                    switch (opType)
                    {
                    case TokenType.Exponent:
                        exp = new ExpExpression(exp, right);
                        break;

                    default:
                        throw new UnexpectedBehaviorException("Expected exponent, got: " + opType);
                    }
                }

                return(exp);
            }
            else
            {
                throw new InvalidSyntaxException("Invalid expression");
            }
        }
Пример #2
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        private static IExpression ParseExpExpression()
        {
            if ( Check( FirstUnaryExp ) )
            {
                IExpression exp = ParseUnaryExpression();

                if ( Check( new TokenSet( TokenType.Exponent ) ) )
                {
                    TokenType opType = CurrentToken.type;
                    Eat( opType );
                    if ( !Check( FirstUnaryExp ) )
                    {
                        throw new InvalidSyntaxException( "Expected an expression after ^ operator" );
                    }
                    IExpression right = ParseUnaryExpression();

                    switch ( opType )
                    {
                    case TokenType.Exponent:
                        exp = new ExpExpression( exp, right );
                        break;

                    default:
                        throw new UnexpectedBehaviorException( "Expected exponent, got: " + opType );
                    }
                }

                return exp;
            }
            else
            {
                throw new InvalidSyntaxException( "Invalid expression" );
            }
        }