private ExpressionContext expression(int _p) { ParserRuleContext _parentctx = _ctx; int _parentState = State; ExpressionContext _localctx = new ExpressionContext(_ctx, _parentState); ExpressionContext _prevctx = _localctx; int _startState = 2; EnterRecursionRule(_localctx, 2, RULE_expression, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 21; _errHandler.Sync(this); switch (_input.La(1)) { case LPAREN: { _localctx = new ParenthesizedExprContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 8; Match(LPAREN); State = 9; expression(0); State = 10; Match(RPAREN); } break; case MIN: case MAX: { _localctx = new MinMaxExprContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 12; ((MinMaxExprContext)_localctx).operatorToken = _input.Lt(1); _la = _input.La(1); if (!(_la == MIN || _la == MAX)) { ((MinMaxExprContext)_localctx).operatorToken = _errHandler.RecoverInline(this); } else { if (_input.La(1) == TokenConstants.Eof) { matchedEOF = true; } _errHandler.ReportMatch(this); Consume(); } State = 13; Match(LPAREN); State = 14; expression(0); State = 15; Match(DESP); State = 16; expression(0); State = 17; Match(RPAREN); } break; case NUMBER: { _localctx = new NumberExprContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 19; Match(NUMBER); } break; case IDENTIFIER: { _localctx = new IdentifierExprContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 20; Match(IDENTIFIER); } break; default: throw new NoViableAltException(this); } _ctx.stop = _input.Lt(-1); State = 34; _errHandler.Sync(this); _alt = Interpreter.AdaptivePredict(_input, 2, _ctx); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber) { if (_alt == 1) { if (_parseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { State = 32; _errHandler.Sync(this); switch (Interpreter.AdaptivePredict(_input, 1, _ctx)) { case 1: { _localctx = new MultiplicativeExprContext(new ExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expression); State = 23; if (!(Precpred(_ctx, 5))) { throw new FailedPredicateException(this, "Precpred(_ctx, 5)"); } State = 24; ((MultiplicativeExprContext)_localctx).operatorToken = _input.Lt(1); _la = _input.La(1); if (!(_la == MULTIPLY || _la == DIVIDE)) { ((MultiplicativeExprContext)_localctx).operatorToken = _errHandler.RecoverInline(this); } else { if (_input.La(1) == TokenConstants.Eof) { matchedEOF = true; } _errHandler.ReportMatch(this); Consume(); } State = 25; expression(6); } break; case 2: { _localctx = new ModDivContext(new ExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expression); State = 26; if (!(Precpred(_ctx, 4))) { throw new FailedPredicateException(this, "Precpred(_ctx, 4)"); } State = 27; ((ModDivContext)_localctx).operatorToken = _input.Lt(1); _la = _input.La(1); if (!(_la == MOD || _la == DIV)) { ((ModDivContext)_localctx).operatorToken = _errHandler.RecoverInline(this); } else { if (_input.La(1) == TokenConstants.Eof) { matchedEOF = true; } _errHandler.ReportMatch(this); Consume(); } State = 28; expression(5); } break; case 3: { _localctx = new AdditiveExprContext(new ExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expression); State = 29; if (!(Precpred(_ctx, 3))) { throw new FailedPredicateException(this, "Precpred(_ctx, 3)"); } State = 30; ((AdditiveExprContext)_localctx).operatorToken = _input.Lt(1); _la = _input.La(1); if (!(_la == SUBTRACT || _la == ADD)) { ((AdditiveExprContext)_localctx).operatorToken = _errHandler.RecoverInline(this); } else { if (_input.La(1) == TokenConstants.Eof) { matchedEOF = true; } _errHandler.ReportMatch(this); Consume(); } State = 31; expression(4); } break; } } } State = 36; _errHandler.Sync(this); _alt = Interpreter.AdaptivePredict(_input, 2, _ctx); } } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.ReportError(this, re); _errHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return(_localctx); }
private ExpressionContext expression(int _p) { ParserRuleContext _parentctx = _ctx; int _parentState = State; ExpressionContext _localctx = new ExpressionContext(_ctx, _parentState); ExpressionContext _prevctx = _localctx; int _startState = 2; EnterRecursionRule(_localctx, 2, RULE_expression, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 13; switch (_input.La(1)) { case LPAREN: { _localctx = new ParenthesizedExprContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 8; Match(LPAREN); State = 9; expression(0); State = 10; Match(RPAREN); } break; case NUMBER: { _localctx = new NumberExprContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 12; Match(NUMBER); } break; default: throw new NoViableAltException(this); } _ctx.stop = _input.Lt(-1); State = 26; _errHandler.Sync(this); _alt = Interpreter.AdaptivePredict(_input, 2, _ctx); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber) { if (_alt == 1) { if (_parseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { State = 24; switch (Interpreter.AdaptivePredict(_input, 1, _ctx)) { case 1: { _localctx = new ExponentialExprContext(new ExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expression); State = 15; if (!(Precpred(_ctx, 4))) { throw new FailedPredicateException(this, "Precpred(_ctx, 4)"); } State = 16; Match(EXPONENT); State = 17; expression(5); } break; case 2: { _localctx = new MultiplicativeExprContext(new ExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expression); State = 18; if (!(Precpred(_ctx, 3))) { throw new FailedPredicateException(this, "Precpred(_ctx, 3)"); } State = 19; ((MultiplicativeExprContext)_localctx).operatorToken = _input.Lt(1); _la = _input.La(1); if (!(_la == MULTIPLY || _la == DIVIDE)) { ((MultiplicativeExprContext)_localctx).operatorToken = _errHandler.RecoverInline(this); } Consume(); State = 20; expression(4); } break; case 3: { _localctx = new AdditiveExprContext(new ExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expression); State = 21; if (!(Precpred(_ctx, 2))) { throw new FailedPredicateException(this, "Precpred(_ctx, 2)"); } State = 22; ((AdditiveExprContext)_localctx).operatorToken = _input.Lt(1); _la = _input.La(1); if (!(_la == SUBTRACT || _la == ADD)) { ((AdditiveExprContext)_localctx).operatorToken = _errHandler.RecoverInline(this); } Consume(); State = 23; expression(3); } break; } } } State = 28; _errHandler.Sync(this); _alt = Interpreter.AdaptivePredict(_input, 2, _ctx); } } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.ReportError(this, re); _errHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return(_localctx); }