Наследование: OperatorExpression
Пример #1
0
 public abstract void Visit(UnaryExpression expression);
Пример #2
0
        private Expression ParseUnary()
        {
            if (_current == null)
            {
                throw new EvaluatorException(_scanner.Column, "Expected unary operator, literal or open bracket.");
            }

            if (_current.Type == TokenType.Literal)
            {
                var literal = ParseLiteral();
                Consume();
                return literal;
            }

            var unary = new UnaryExpression();
            if (_current.Type == TokenType.Minus)
            {
                unary.Operator = OperatorType.UnaryMinus;
                Expect(MiddleGroupUnary);
            }
            else if (_current.Type == TokenType.Plus)
            {
                unary.Operator = OperatorType.UnaryPlus;
                Expect(MiddleGroupUnary);
            }

            if (_current.Type == TokenType.Literal)
            {
                unary.Value = ParseLiteral();
                //if (_scanner.PeekToken() != null && _scanner.PeekToken().Type == TokenType.Literal)
                //{
                //    throw new EvaluatorException(_scanner.Column, "Expected expression.");
                //}
            }
            else if (_current.Type == TokenType.LeftParenthesis)
            {
                unary.Value = ParseExpression();
            }
            else if (_current.Type == TokenType.Identifier)
            {
                unary.Value = ParseIdentifier();
            }
            else
            {
                throw new EvaluatorException(_scanner.Column, "Expected literal or open bracket.");
            }
            Consume();
            return unary;
        }