public AddExprContext addExpr()
        {
            AddExprContext _localctx = new AddExprContext(_ctx, State);

            EnterRule(_localctx, 12, RULE_addExpr);
            int _la;

            try {
                EnterOuterAlt(_localctx, 1);
                {
                    State = 76; multExpr();
                    State = 81;
                    _errHandler.Sync(this);
                    _la = _input.La(1);
                    while (_la == PLUS || _la == MINUS)
                    {
                        {
                            {
                                State = 77;
                                _la   = _input.La(1);
                                if (!(_la == PLUS || _la == MINUS))
                                {
                                    _errHandler.RecoverInline(this);
                                }
                                else
                                {
                                    if (_input.La(1) == TokenConstants.Eof)
                                    {
                                        matchedEOF = true;
                                    }

                                    _errHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 78; multExpr();
                            }
                        }
                        State = 83;
                        _errHandler.Sync(this);
                        _la = _input.La(1);
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                _errHandler.ReportError(this, re);
                _errHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
        public AddExprContext addExpr()
        {
            AddExprContext _localctx = new AddExprContext(Context, State);

            EnterRule(_localctx, 12, RULE_addExpr);
            int _la;

            try {
                EnterOuterAlt(_localctx, 1);
                {
                    State = 76; multExpr();
                    State = 81;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    while (_la == PLUS || _la == MINUS)
                    {
                        {
                            {
                                State = 77;
                                _la   = TokenStream.LA(1);
                                if (!(_la == PLUS || _la == MINUS))
                                {
                                    ErrorHandler.RecoverInline(this);
                                }
                                else
                                {
                                    ErrorHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 78; multExpr();
                            }
                        }
                        State = 83;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                ErrorHandler.ReportError(this, re);
                ErrorHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
Пример #3
0
	private AddExprContext addExpr(int _p) {
		ParserRuleContext _parentctx = _ctx;
		int _parentState = State;
		AddExprContext _localctx = new AddExprContext(_ctx, _parentState);
		AddExprContext _prevctx = _localctx;
		int _startState = 20;
		EnterRecursionRule(_localctx, 20, RULE_addExpr, _p);
		try {
			int _alt;
			EnterOuterAlt(_localctx, 1);
			{
			{
			State = 186; _localctx._multExpr = multExpr(0);
			 _localctx.retValue =  _localctx._multExpr.retValue;
			}
			_ctx.stop = _input.Lt(-1);
			State = 201;
			_errHandler.Sync(this);
			_alt = Interpreter.AdaptivePredict(_input,13,_ctx);
			while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) {
				if ( _alt==1 ) {
					if ( _parseListeners!=null ) TriggerExitRuleEvent();
					_prevctx = _localctx;
					{
					State = 199;
					switch ( Interpreter.AdaptivePredict(_input,12,_ctx) ) {
					case 1:
						{
						_localctx = new AddExprContext(_parentctx, _parentState);
						_localctx.first = _prevctx;
						PushNewRecursionContext(_localctx, _startState, RULE_addExpr);
						State = 189;
						if (!(Precpred(_ctx, 3))) throw new FailedPredicateException(this, "Precpred(_ctx, 3)");
						State = 190; Match(T__2);
						State = 191; _localctx._multExpr = multExpr(0);
						 _localctx.retValue =  new BinaryExpression(BinaryExpressionType.Plus, _localctx.first.retValue, _localctx._multExpr.retValue);
						}
						break;

					case 2:
						{
						_localctx = new AddExprContext(_parentctx, _parentState);
						_localctx.first = _prevctx;
						PushNewRecursionContext(_localctx, _startState, RULE_addExpr);
						State = 194;
						if (!(Precpred(_ctx, 2))) throw new FailedPredicateException(this, "Precpred(_ctx, 2)");
						State = 195; Match(T__0);
						State = 196; _localctx._multExpr = multExpr(0);
						 _localctx.retValue =  new BinaryExpression(BinaryExpressionType.Minus, _localctx.first.retValue, _localctx._multExpr.retValue);
						}
						break;
					}
					} 
				}
				State = 203;
				_errHandler.Sync(this);
				_alt = Interpreter.AdaptivePredict(_input,13,_ctx);
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.ReportError(this, re);
			_errHandler.Recover(this, re);
		}
		finally {
			UnrollRecursionContexts(_parentctx);
		}
		return _localctx;
	}
Пример #4
0
	private bool addExpr_sempred(AddExprContext _localctx, int predIndex) {
		switch (predIndex) {
		case 13: return Precpred(_ctx, 3);

		case 14: return Precpred(_ctx, 2);
		}
		return true;
	}
Пример #5
0
        private ExprContext expr(int _p)
        {
            ParserRuleContext _parentctx = _ctx;
            int         _parentState     = State;
            ExprContext _localctx        = new ExprContext(_ctx, _parentState);
            ExprContext _prevctx         = _localctx;
            int         _startState      = 4;

            EnterRecursionRule(_localctx, 4, RULE_expr, _p);
            int _la;

            try {
                int _alt;
                EnterOuterAlt(_localctx, 1);
                {
                    State = 29;
                    _errHandler.Sync(this);
                    switch (_input.La(1))
                    {
                    case INT:
                    {
                        _localctx = new IntContext(_localctx);
                        _ctx      = _localctx;
                        _prevctx  = _localctx;

                        State = 23; Match(INT);
                    }
                    break;

                    case ID:
                    {
                        _localctx = new IdentContext(_localctx);
                        _ctx      = _localctx;
                        _prevctx  = _localctx;
                        State     = 24; Match(ID);
                    }
                    break;

                    case T__2:
                    {
                        _localctx = new ParensContext(_localctx);
                        _ctx      = _localctx;
                        _prevctx  = _localctx;
                        State     = 25; Match(T__2);
                        State     = 26; expr(0);
                        State     = 27; Match(T__3);
                    }
                    break;

                    default:
                        throw new NoViableAltException(this);
                    }
                    _ctx.stop = _input.Lt(-1);
                    State     = 39;
                    _errHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(_input, 4, _ctx);
                    while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber)
                    {
                        if (_alt == 1)
                        {
                            if (_parseListeners != null)
                            {
                                TriggerExitRuleEvent();
                            }
                            _prevctx = _localctx;
                            {
                                State = 37;
                                _errHandler.Sync(this);
                                switch (Interpreter.AdaptivePredict(_input, 3, _ctx))
                                {
                                case 1:
                                {
                                    _localctx = new MultExprContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 31;
                                    if (!(Precpred(_ctx, 5)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(_ctx, 5)");
                                    }
                                    State = 32;
                                    ((MultExprContext)_localctx).op = _input.Lt(1);
                                    _la = _input.La(1);
                                    if (!(_la == MUL || _la == DIV))
                                    {
                                        ((MultExprContext)_localctx).op = _errHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        if (_input.La(1) == TokenConstants.Eof)
                                        {
                                            matchedEOF = true;
                                        }

                                        _errHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 33; expr(6);
                                }
                                break;

                                case 2:
                                {
                                    _localctx = new AddExprContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 34;
                                    if (!(Precpred(_ctx, 4)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(_ctx, 4)");
                                    }
                                    State = 35;
                                    ((AddExprContext)_localctx).op = _input.Lt(1);
                                    _la = _input.La(1);
                                    if (!(_la == ADD || _la == SUB))
                                    {
                                        ((AddExprContext)_localctx).op = _errHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        if (_input.La(1) == TokenConstants.Eof)
                                        {
                                            matchedEOF = true;
                                        }

                                        _errHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 36; expr(5);
                                }
                                break;
                                }
                            }
                        }
                        State = 41;
                        _errHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(_input, 4, _ctx);
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                _errHandler.ReportError(this, re);
                _errHandler.Recover(this, re);
            }
            finally {
                UnrollRecursionContexts(_parentctx);
            }
            return(_localctx);
        }