private ExprContext expr(int _p) { ParserRuleContext _parentctx = Context; int _parentState = State; ExprContext _localctx = new ExprContext(Context, _parentState); ExprContext _prevctx = _localctx; int _startState = 2; EnterRecursionRule(_localctx, 2, RULE_expr, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 30; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case UINT: { _localctx = new Expr_noneContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 12; num(); } break; case TEXT: { _localctx = new Expr_textContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 13; Match(TEXT); } break; case OPEN_PAREN: { _localctx = new Expr_noneContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 14; paren_expr(); } break; case PLUS: case MINUS: { _localctx = new Expr_unaryContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 15; ((Expr_unaryContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == PLUS || _la == MINUS)) { ((Expr_unaryContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 16; expr(6); } break; case IDENTIFIER: { _localctx = new Expr_funccallContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 17; ((Expr_funccallContext)_localctx).funcname = Match(IDENTIFIER); State = 18; Match(OPEN_PAREN); State = 27; ErrorHandler.Sync(this); _la = TokenStream.LA(1); if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << PLUS) | (1L << MINUS) | (1L << OPEN_PAREN) | (1L << UINT) | (1L << TEXT) | (1L << IDENTIFIER))) != 0)) { { State = 19; ((Expr_funccallContext)_localctx)._expr = expr(0); ((Expr_funccallContext)_localctx)._args.Add(((Expr_funccallContext)_localctx)._expr); State = 24; ErrorHandler.Sync(this); _la = TokenStream.LA(1); while (_la == COMMA) { { { State = 20; Match(COMMA); State = 21; ((Expr_funccallContext)_localctx)._expr = expr(0); ((Expr_funccallContext)_localctx)._args.Add(((Expr_funccallContext)_localctx)._expr); } } State = 26; ErrorHandler.Sync(this); _la = TokenStream.LA(1); } } } State = 29; Match(CLOSE_PAREN); } break; default: throw new NoViableAltException(this); } Context.Stop = TokenStream.LT(-1); State = 45; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 4, Context); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER) { if (_alt == 1) { if (ParseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { State = 43; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 3, Context)) { case 1: { _localctx = new Expr_powerContext(new ExprContext(_parentctx, _parentState)); ((Expr_powerContext)_localctx).lhs = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 32; if (!(Precpred(Context, 5))) { throw new FailedPredicateException(this, "Precpred(Context, 5)"); } State = 33; Match(HAT); State = 34; ((Expr_powerContext)_localctx).rhs = expr(5); } break; case 2: { _localctx = new Expr_multipricativeContext(new ExprContext(_parentctx, _parentState)); ((Expr_multipricativeContext)_localctx).lhs = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 35; if (!(Precpred(Context, 4))) { throw new FailedPredicateException(this, "Precpred(Context, 4)"); } State = 36; ((Expr_multipricativeContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == ASTERISK || _la == SLASH)) { ((Expr_multipricativeContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 37; ((Expr_multipricativeContext)_localctx).rhs = expr(5); } break; case 3: { _localctx = new Expr_additiveContext(new ExprContext(_parentctx, _parentState)); ((Expr_additiveContext)_localctx).lhs = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 38; if (!(Precpred(Context, 2))) { throw new FailedPredicateException(this, "Precpred(Context, 2)"); } State = 39; ((Expr_additiveContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == PLUS || _la == MINUS)) { ((Expr_additiveContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 40; ((Expr_additiveContext)_localctx).rhs = expr(3); } break; case 4: { _localctx = new Expr_multipricativeContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 41; if (!(Precpred(Context, 3))) { throw new FailedPredicateException(this, "Precpred(Context, 3)"); } State = 42; paren_expr(); } break; } } } State = 47; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 4, 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 = 2; EnterRecursionRule(_localctx, 2, RULE_expr, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 24; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 0, Context)) { case 1: { _localctx = new Expr_noneContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 14; num(); } break; case 2: { _localctx = new Expr_defineContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 15; define(); } break; case 3: { _localctx = new Expr_stringContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 16; @string(); } break; case 4: { _localctx = new Expr_unaryContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 17; ((Expr_unaryContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == PLUS || _la == MINUS)) { ((Expr_unaryContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 18; expr(4); } break; case 5: { _localctx = new Expr_funccallContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 19; ((Expr_funccallContext)_localctx).funcname = Match(IDENTIFIER); State = 20; Match(OPEN_PAREN); State = 21; ((Expr_funccallContext)_localctx)._expr = expr(0); ((Expr_funccallContext)_localctx)._args.Add(((Expr_funccallContext)_localctx)._expr); State = 22; Match(CLOSE_PAREN); } break; } Context.Stop = TokenStream.LT(-1); State = 34; 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 = 32; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 1, Context)) { case 1: { _localctx = new Expr_additiveContext(new ExprContext(_parentctx, _parentState)); ((Expr_additiveContext)_localctx).lhs = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 26; if (!(Precpred(Context, 3))) { throw new FailedPredicateException(this, "Precpred(Context, 3)"); } State = 27; ((Expr_additiveContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == PLUS || _la == MINUS)) { ((Expr_additiveContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 28; ((Expr_additiveContext)_localctx).rhs = expr(4); } break; case 2: { _localctx = new Expr_multipricativeContext(new ExprContext(_parentctx, _parentState)); ((Expr_multipricativeContext)_localctx).lhs = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 29; if (!(Precpred(Context, 2))) { throw new FailedPredicateException(this, "Precpred(Context, 2)"); } State = 30; ((Expr_multipricativeContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == ASTERISK || _la == SLASH)) { ((Expr_multipricativeContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 31; ((Expr_multipricativeContext)_localctx).rhs = expr(3); } break; } } } State = 36; 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); }