Esempio n. 1
0
        public void ExitFactor(QueryParser.FactorContext context)
        {
            BaseValue constantValue = null;

            // parse INT
            var constantToken = context.INT();

            if (constantToken != null)
            {
                var value = int.Parse(constantToken.Symbol.Text, CultureInfo.InvariantCulture);
                constantValue = new IntValue(value);
            }
            else if (context.REAL() != null) // parse REAL
            {
                constantToken = context.REAL();
                var value = double.Parse(constantToken.Symbol.Text, CultureInfo.InvariantCulture);
                constantValue = new RealValue(value);
            }
            else if (context.STRING() != null) // parse STRING
            {
                constantToken = context.STRING();
                constantValue = new StringValue(ParseStringValue(constantToken.Symbol));
            }

            // if this is a constant
            if (constantValue != null)
            {
                _expressions.Push(new ConstantExpression(
                                      constantToken.Symbol.Line,
                                      constantToken.Symbol.Column,
                                      constantValue));
                return;
            }

            // parse ID
            string identifier      = null;
            var    identifierToken = context.ID();

            if (identifierToken != null)
            {
                identifier = identifierToken.Symbol.Text;
            }
            else if (context.COMPLEX_ID() != null) // parse COMPLEX_ID
            {
                identifierToken = context.COMPLEX_ID();
                identifier      = ParseComplexIdentifier(identifierToken.Symbol);
            }

            // this is an ID or a function call
            if (identifierToken != null)
            {
                if (context.LPAREN() == null) // attribute access
                {
                    _expressions.Push(new AttributeAccessExpression(
                                          identifierToken.Symbol.Line,
                                          identifierToken.Symbol.Column,
                                          identifier));
                }
                else // function call
                {
                    var stackTop   = _expressionsFrameStart.Pop();
                    var parameters = new List <ValueExpression>();
                    while (_expressions.Count > stackTop)
                    {
                        parameters.Add(_expressions.Pop());
                    }

                    parameters.Reverse();
                    _expressions.Push(new FunctionCallExpression(
                                          identifierToken.Symbol.Line,
                                          identifierToken.Symbol.Column,
                                          identifier,
                                          parameters));
                }

                return;
            }

            // if this is a unary minus
            var unaryOperator = context.ADD_SUB();

            if (unaryOperator != null)
            {
                if (unaryOperator.Symbol.Text == "-")
                {
                    var parameter = _expressions.Pop();
                    _expressions.Push(new UnaryMinusExpression(
                                          unaryOperator.Symbol.Line,
                                          unaryOperator.Symbol.Column,
                                          parameter));
                }
            }

            // otherwise, this is a subexpression => it is already on the stack
        }
Esempio n. 2
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="QueryParser.factor"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitFactor([NotNull] QueryParser.FactorContext context)
 {
 }
Esempio n. 3
0
 public void EnterFactor(QueryParser.FactorContext context)
 {
 }