Example #1
0
    private ExpressionContext expression(int _p)
    {
        ParserRuleContext _parentctx = Context;
        int _parentState             = State;
        ExpressionContext _localctx  = new ExpressionContext(Context, _parentState);
        ExpressionContext _prevctx   = _localctx;
        int _startState = 0;

        EnterRecursionRule(_localctx, 0, RULE_expression, _p);
        int _la;

        try {
            int _alt;
            EnterOuterAlt(_localctx, 1);
            {
                State = 14;
                ErrorHandler.Sync(this);
                switch (TokenStream.LA(1))
                {
                case T__0:
                {
                    _localctx = new ParenthesisExpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;

                    State = 3; Match(T__0);
                    State = 4; expression(0);
                    State = 5; Match(T__1);
                }
                break;

                case NAME:
                {
                    _localctx = new FunctionExpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 7; Match(NAME);
                    State     = 8; Match(T__0);
                    State     = 9; expression(0);
                    State     = 10; Match(T__1);
                }
                break;

                case NUMBER:
                {
                    _localctx = new NumericAtomExpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 12; Match(NUMBER);
                }
                break;

                case ID:
                {
                    _localctx = new IdAtomExpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 13; Match(ID);
                }
                break;

                default:
                    throw new NoViableAltException(this);
                }
                Context.Stop = TokenStream.LT(-1);
                State        = 27;
                ErrorHandler.Sync(this);
                _alt = Interpreter.AdaptivePredict(TokenStream, 2, Context);
                while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                {
                    if (_alt == 1)
                    {
                        if (ParseListeners != null)
                        {
                            TriggerExitRuleEvent();
                        }
                        _prevctx = _localctx;
                        {
                            State = 25;
                            ErrorHandler.Sync(this);
                            switch (Interpreter.AdaptivePredict(TokenStream, 1, Context))
                            {
                            case 1:
                            {
                                _localctx = new MulDivExpContext(new ExpressionContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expression);
                                State = 16;
                                if (!(Precpred(Context, 6)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 6)");
                                }
                                State = 17;
                                _la   = TokenStream.LA(1);
                                if (!(_la == ASTERISK || _la == SLASH))
                                {
                                    ErrorHandler.RecoverInline(this);
                                }
                                else
                                {
                                    ErrorHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 18; expression(7);
                            }
                            break;

                            case 2:
                            {
                                _localctx = new AddSubExpContext(new ExpressionContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expression);
                                State = 19;
                                if (!(Precpred(Context, 5)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 5)");
                                }
                                State = 20;
                                _la   = TokenStream.LA(1);
                                if (!(_la == PLUS || _la == MINUS))
                                {
                                    ErrorHandler.RecoverInline(this);
                                }
                                else
                                {
                                    ErrorHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 21; expression(6);
                            }
                            break;

                            case 3:
                            {
                                _localctx = new PowerExpContext(new ExpressionContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expression);
                                State = 22;
                                if (!(Precpred(Context, 4)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 4)");
                                }
                                State = 23; Match(T__2);
                                State = 24; expression(4);
                            }
                            break;
                            }
                        }
                    }
                    State = 29;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 2, Context);
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            UnrollRecursionContexts(_parentctx);
        }
        return(_localctx);
    }
    private ExprContext expr(int _p)
    {
        ParserRuleContext _parentctx = Context;
        int         _parentState     = State;
        ExprContext _localctx        = new ExprContext(Context, _parentState);
        ExprContext _prevctx         = _localctx;
        int         _startState      = 0;

        EnterRecursionRule(_localctx, 0, RULE_expr, _p);
        try {
            int _alt;
            EnterOuterAlt(_localctx, 1);
            {
                State = 17;
                ErrorHandler.Sync(this);
                switch (Interpreter.AdaptivePredict(TokenStream, 0, Context))
                {
                case 1:
                {
                    _localctx = new ParenthesisExpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;

                    State = 9; Match(T__0);
                    State = 10; expr(0);
                    State = 11; Match(T__1);
                }
                break;

                case 2:
                {
                    _localctx = new NotExpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 13; Match(T__2);
                    State     = 14; expr(5);
                }
                break;

                case 3:
                {
                    _localctx = new AttrCompExpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 15; attr_comp();
                }
                break;

                case 4:
                {
                    _localctx = new AttrPrExpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 16; attr_pr();
                }
                break;
                }
                Context.Stop = TokenStream.LT(-1);
                State        = 27;
                ErrorHandler.Sync(this);
                _alt = Interpreter.AdaptivePredict(TokenStream, 2, Context);
                while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                {
                    if (_alt == 1)
                    {
                        if (ParseListeners != null)
                        {
                            TriggerExitRuleEvent();
                        }
                        _prevctx = _localctx;
                        {
                            State = 25;
                            ErrorHandler.Sync(this);
                            switch (Interpreter.AdaptivePredict(TokenStream, 1, Context))
                            {
                            case 1:
                            {
                                _localctx = new AndExpContext(new ExprContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 19;
                                if (!(Precpred(Context, 4)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 4)");
                                }
                                State = 20; Match(T__3);
                                State = 21; expr(5);
                            }
                            break;

                            case 2:
                            {
                                _localctx = new OrExpContext(new ExprContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 22;
                                if (!(Precpred(Context, 3)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 3)");
                                }
                                State = 23; Match(T__4);
                                State = 24; expr(4);
                            }
                            break;
                            }
                        }
                    }
                    State = 29;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 2, Context);
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            UnrollRecursionContexts(_parentctx);
        }
        return(_localctx);
    }
Example #3
0
        private MainExprContext mainExpr(int _p)
        {
            ParserRuleContext _parentctx = Context;
            int             _parentState = State;
            MainExprContext _localctx    = new MainExprContext(Context, _parentState);
            MainExprContext _prevctx     = _localctx;
            int             _startState  = 2;

            EnterRecursionRule(_localctx, 2, RULE_mainExpr, _p);
            try {
                int _alt;
                EnterOuterAlt(_localctx, 1);
                {
                    State = 21;
                    ErrorHandler.Sync(this);
                    switch (Interpreter.AdaptivePredict(TokenStream, 1, Context))
                    {
                    case 1:
                    {
                        _localctx = new ParenthesisExpContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;

                        State = 11; Match(T__0);
                        State = 12; mainExpr(0);
                        State = 13; Match(T__1);
                    }
                    break;

                    case 2:
                    {
                        _localctx = new CompareNumberExpContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 15; Match(PROPERTY);
                        State     = 16; Match(OPERATOR);
                        State     = 17; Match(NUMBER);
                    }
                    break;

                    case 3:
                    {
                        _localctx = new CompareStringExpContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 18; Match(PROPERTY);
                        State     = 19; Match(OPERATOR);
                        State     = 20; Match(ESCAPEDSTRING);
                    }
                    break;
                    }
                    Context.Stop = TokenStream.LT(-1);
                    State        = 31;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 3, Context);
                    while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                    {
                        if (_alt == 1)
                        {
                            if (ParseListeners != null)
                            {
                                TriggerExitRuleEvent();
                            }
                            _prevctx = _localctx;
                            {
                                State = 29;
                                ErrorHandler.Sync(this);
                                switch (Interpreter.AdaptivePredict(TokenStream, 2, Context))
                                {
                                case 1:
                                {
                                    _localctx = new AndExpContext(new MainExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_mainExpr);
                                    State = 23;
                                    if (!(Precpred(Context, 4)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 4)");
                                    }
                                    State = 24; Match(AND);
                                    State = 25; mainExpr(5);
                                }
                                break;

                                case 2:
                                {
                                    _localctx = new OrExpContext(new MainExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_mainExpr);
                                    State = 26;
                                    if (!(Precpred(Context, 3)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 3)");
                                    }
                                    State = 27; Match(OR);
                                    State = 28; mainExpr(4);
                                }
                                break;
                                }
                            }
                        }
                        State = 33;
                        ErrorHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(TokenStream, 3, Context);
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                ErrorHandler.ReportError(this, re);
                ErrorHandler.Recover(this, re);
            }
            finally {
                UnrollRecursionContexts(_parentctx);
            }
            return(_localctx);
        }