상속: NameExpression
예제 #1
0
 public abstract void Visit(VariableExpression expression);
예제 #2
0
        private Expression ParseIdentifier()
        {
            if (_current == null)
            {
                throw new EvaluatorException(_scanner.Column, "Expected function or expression.");
            }

            if (_current.Type != TokenType.Identifier)
            {
                return ParseUnary();
            }

            if (_scanner.PeekToken() == null || (_scanner.PeekToken() != null &&
                _scanner.PeekToken().Type != TokenType.LeftParenthesis))
            {
                // variable
                var varExpr = new VariableExpression(_current.Text);
                if (_scanner.PeekToken() != null)
                {
                    Expect(MiddleGroupIdentifier);
                }
                else
                {
                    Consume(); // Reach eof
                }
                return varExpr;
            }

            var expr = new FunctionCallExpression(_current.Text);
            Expect(TokenType.LeftParenthesis);
            while (!_scanner.IsEof())
            {
                Consume();
                expr.Arguments.Add(ParseExpression(true));
                if (_current == null)
                {
                    break;
                }
                if (_current.Type == TokenType.Comma)
                {
                    continue;
                }
                else if (_current.Type == TokenType.RightParenthesis)
                {
                    Consume();
                    break;
                }
                else
                {
                    throw new EvaluatorException(_scanner.Column, "Expected comma or close bracket.");
                }
            }
            return expr;
        }