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); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 9; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case OP: { _localctx = new ParenExpContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 3; Match(OP); State = 4; expr(0); State = 5; Match(CP); } break; case VAR: { _localctx = new VarContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 7; Match(VAR); } break; case NUM: { _localctx = new ConstContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 8; Match(NUM); } break; default: throw new NoViableAltException(this); } Context.Stop = TokenStream.LT(-1); State = 24; 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 = 22; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 2, Context)) { case 1: { _localctx = new PowerContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 11; if (!(Precpred(Context, 5))) { throw new FailedPredicateException(this, "Precpred(Context, 5)"); } State = 12; Match(POWER); State = 13; expr(5); } break; case 2: { _localctx = new ProdContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 14; if (!(Precpred(Context, 4))) { throw new FailedPredicateException(this, "Precpred(Context, 4)"); } State = 16; ErrorHandler.Sync(this); _la = TokenStream.LA(1); if (_la == PROD) { { State = 15; Match(PROD); } } State = 18; expr(5); } break; case 3: { _localctx = new PlusminusContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 19; if (!(Precpred(Context, 3))) { throw new FailedPredicateException(this, "Precpred(Context, 3)"); } State = 20; _la = TokenStream.LA(1); if (!(_la == PLUS || _la == MINUS)) { ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 21; expr(4); } break; } } } State = 26; 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); }
private ExprContext expr(int _p) { ParserRuleContext _parentctx = Context; int _parentState = State; ExprContext _localctx = new ExprContext(Context, _parentState); ExprContext _prevctx = _localctx; int _startState = 6; EnterRecursionRule(_localctx, 6, RULE_expr, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 44; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case T__0: { _localctx = new ParenExpContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 36; Match(T__0); State = 37; expr(0); State = 38; Match(T__1); } break; case R_VAR: { _localctx = new RefExpContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 40; referenceExp(); } break; case IF: { _localctx = new IteExpContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 41; ite_defi(); } break; case INT: { _localctx = new IntVarContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 42; Match(INT); } break; case BOOL: { _localctx = new BoolVarContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 43; Match(BOOL); } break; default: throw new NoViableAltException(this); } Context.Stop = TokenStream.LT(-1); State = 57; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 6, Context); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER) { if (_alt == 1) { if (ParseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { State = 55; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 5, Context)) { case 1: { _localctx = new MultExpContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 46; if (!(Precpred(Context, 5))) { throw new FailedPredicateException(this, "Precpred(Context, 5)"); } State = 47; _la = TokenStream.LA(1); if (!(_la == T__2 || _la == T__3)) { ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 48; expr(6); } break; case 2: { _localctx = new AddExpContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 49; if (!(Precpred(Context, 4))) { throw new FailedPredicateException(this, "Precpred(Context, 4)"); } State = 50; _la = TokenStream.LA(1); if (!(_la == T__4 || _la == T__5)) { ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 51; expr(5); } break; case 3: { _localctx = new CompExpContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 52; if (!(Precpred(Context, 3))) { throw new FailedPredicateException(this, "Precpred(Context, 3)"); } State = 53; _la = TokenStream.LA(1); if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__6) | (1L << T__7) | (1L << T__8) | (1L << T__9) | (1L << T__10) | (1L << T__11))) != 0))) { ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 54; expr(4); } break; } } } State = 59; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 6, Context); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return(_localctx); }