Esempio n. 1
0
        public RelationalExpressionContext relationalExpression()
        {
            RelationalExpressionContext _localctx = new RelationalExpressionContext(_ctx, State);

            EnterRule(_localctx, 10, RULE_relationalExpression);
            int _la;

            try {
                EnterOuterAlt(_localctx, 1);
                {
                    State = 65; literal();
                    State = 66;
                    _la   = _input.La(1);
                    if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << GT) | (1L << GT_ET) | (1L << LT) | (1L << LT_ET) | (1L << EQ) | (1L << NE))) != 0)))
                    {
                        _errHandler.RecoverInline(this);
                    }
                    else
                    {
                        Consume();
                    }
                    State = 67; literal();
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                _errHandler.ReportError(this, re);
                _errHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
Esempio n. 2
0
        internal static IExpression Create(ExpressionContext context)
        {
            if (context.children.Count == 1)
            {
                ITerminalNode first = context.children[0] as ITerminalNode;

                if (first != null && first.Symbol.Type == KScriptLexer.TRUE)
                {
                    return(new BooleanLiteralExpression(true));
                }
                else if (first != null && first.Symbol.Type == KScriptLexer.FALSE)
                {
                    return(new BooleanLiteralExpression(false));
                }
                else if (context.children[0] is BetweenExpressionContext)
                {
                    BetweenExpressionContext btContext = context.children[0] as BetweenExpressionContext;

                    Literal a = LiteralFactory.Create(btContext.literal(0));
                    Literal b = LiteralFactory.Create(btContext.literal(1));
                    Literal c = LiteralFactory.Create(btContext.literal(2));

                    return(new AndExpression(
                               new RelationalExpression(a, b, KScriptLexer.GT_ET),
                               new RelationalExpression(a, c, KScriptLexer.LT)));
                }
                else if (context.children[0] is InExpressionContext)
                {
                    InExpressionContext inContext = context.children[0] as InExpressionContext;

                    Literal literal = LiteralFactory.Create(inContext.literal());

                    IReadOnlyCollection <Literal> list = inContext.list().literal().Select(LiteralFactory.Create).ToList();

                    return(new InExpression(literal, list));
                }
                else if (context.children[0] is RelationalExpressionContext)
                {
                    RelationalExpressionContext relContext = context.children[0] as RelationalExpressionContext;

                    Literal a             = LiteralFactory.Create(relContext.literal(0));
                    IToken  operatorToken = (relContext.children[1] as ITerminalNode).Symbol;
                    Literal b             = LiteralFactory.Create(relContext.literal(1));

                    return(new RelationalExpression(a, b, operatorToken.Type));
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            if (context.children.Count == 2)
            {
                ITerminalNode first = context.children[0] as ITerminalNode;
                ITerminalNode last  = context.children[1] as ITerminalNode;

                if (first.Symbol.Type == KScriptLexer.NOT)
                {
                    return(new NotExpression(Create(context.expression()[0])));
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            else if (context.children.Count == 3)
            {
                ITerminalNode first  = context.children[0] as ITerminalNode;
                ITerminalNode middle = context.children[1] as ITerminalNode;
                ITerminalNode last   = context.children[2] as ITerminalNode;

                if (middle != null && middle.Symbol.Type == KScriptLexer.AND)
                {
                    IExpression a = Create(context.children[0] as ExpressionContext);
                    IExpression b = Create(context.children[2] as ExpressionContext);
                    return(new AndExpression(a, b));
                }
                else if (middle != null && middle.Symbol.Type == KScriptLexer.OR)
                {
                    IExpression a = Create(context.children[0] as ExpressionContext);
                    IExpression b = Create(context.children[2] as ExpressionContext);
                    return(new OrExpression(a, b));
                }
                else if (first != null && last != null && first.Symbol.Type == KScriptLexer.OPEN_PAREN && last.Symbol.Type == KScriptLexer.CLOSE_PAREN)
                {
                    return(Create(context.children[1] as ExpressionContext));
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            else
            {
                throw new InvalidOperationException();
            }

            throw new NotImplementedException();
        }
Esempio n. 3
0
	private bool relationalExpression_sempred(RelationalExpressionContext _localctx, int predIndex) {
		switch (predIndex) {
		case 14: return Precpred(Context, 4);
		case 15: return Precpred(Context, 3);
		case 16: return Precpred(Context, 2);
		case 17: return Precpred(Context, 1);
		}
		return true;
	}
Esempio n. 4
0
	private RelationalExpressionContext relationalExpression(int _p) {
		ParserRuleContext _parentctx = Context;
		int _parentState = State;
		RelationalExpressionContext _localctx = new RelationalExpressionContext(Context, _parentState);
		RelationalExpressionContext _prevctx = _localctx;
		int _startState = 30;
		EnterRecursionRule(_localctx, 30, RULE_relationalExpression, _p);
		try {
			int _alt;
			EnterOuterAlt(_localctx, 1);
			{
			{
			State = 219; shiftExpression(0);
			}
			Context.Stop = TokenStream.Lt(-1);
			State = 235;
			ErrorHandler.Sync(this);
			_alt = Interpreter.AdaptivePredict(TokenStream,21,Context);
			while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) {
				if ( _alt==1 ) {
					if ( ParseListeners!=null )
						TriggerExitRuleEvent();
					_prevctx = _localctx;
					{
					State = 233;
					switch ( Interpreter.AdaptivePredict(TokenStream,20,Context) ) {
					case 1:
						{
						_localctx = new RelationalExpressionContext(_parentctx, _parentState);
						PushNewRecursionContext(_localctx, _startState, RULE_relationalExpression);
						State = 221;
						if (!(Precpred(Context, 4))) throw new FailedPredicateException(this, "Precpred(Context, 4)");
						State = 222; Match(Less);
						State = 223; shiftExpression(0);
						}
						break;
					case 2:
						{
						_localctx = new RelationalExpressionContext(_parentctx, _parentState);
						PushNewRecursionContext(_localctx, _startState, RULE_relationalExpression);
						State = 224;
						if (!(Precpred(Context, 3))) throw new FailedPredicateException(this, "Precpred(Context, 3)");
						State = 225; Match(Greater);
						State = 226; shiftExpression(0);
						}
						break;
					case 3:
						{
						_localctx = new RelationalExpressionContext(_parentctx, _parentState);
						PushNewRecursionContext(_localctx, _startState, RULE_relationalExpression);
						State = 227;
						if (!(Precpred(Context, 2))) throw new FailedPredicateException(this, "Precpred(Context, 2)");
						State = 228; Match(LessEqual);
						State = 229; shiftExpression(0);
						}
						break;
					case 4:
						{
						_localctx = new RelationalExpressionContext(_parentctx, _parentState);
						PushNewRecursionContext(_localctx, _startState, RULE_relationalExpression);
						State = 230;
						if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)");
						State = 231; Match(GreaterEqual);
						State = 232; shiftExpression(0);
						}
						break;
					}
					} 
				}
				State = 237;
				ErrorHandler.Sync(this);
				_alt = Interpreter.AdaptivePredict(TokenStream,21,Context);
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			UnrollRecursionContexts(_parentctx);
		}
		return _localctx;
	}