Esempio n. 1
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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

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

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

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

                return(exp);
            }
            throw new InvalidSyntaxException("Invalid expression");
        }
Esempio n. 2
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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

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

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

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

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