コード例 #1
0
    public UnaryMinusContext unaryMinus()
    {
        UnaryMinusContext _localctx = new UnaryMinusContext(Context, State);

        EnterRule(_localctx, 10, RULE_unaryMinus);
        try {
            State = 66;
            ErrorHandler.Sync(this);
            switch (TokenStream.LA(1))
            {
            case MINUS:
                _localctx = new ChangeSignContext(_localctx);
                EnterOuterAlt(_localctx, 1);
                {
                    State = 63; Match(MINUS);
                    State = 64; unaryMinus();
                }
                break;

            case INT:
            case DOUBLE:
            case PI:
            case E:
            case ID:
            case LPAR:
                _localctx = new ToAtomContext(_localctx);
                EnterOuterAlt(_localctx, 2);
                {
                    State = 65; atom();
                }
                break;

            default:
                throw new NoViableAltException(this);
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
コード例 #2
0
        private ExprContext expr(int _p)
        {
            ParserRuleContext _parentctx = _ctx;
            int         _parentState     = State;
            ExprContext _localctx        = new ExprContext(_ctx, _parentState);
            ExprContext _prevctx         = _localctx;
            int         _startState      = 2;

            EnterRecursionRule(_localctx, 2, 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 = 10; Match(INT);
                    }
                    break;

                    case FLOAT:
                    {
                        _localctx = new FloatContext(_localctx);
                        _ctx      = _localctx;
                        _prevctx  = _localctx;
                        State     = 11; Match(FLOAT);
                    }
                    break;

                    case T__0:
                    {
                        _localctx = new ParensContext(_localctx);
                        _ctx      = _localctx;
                        _prevctx  = _localctx;
                        State     = 12; Match(T__0);
                        State     = 13; expr(0);
                        State     = 14; Match(T__1);
                    }
                    break;

                    case SUB:
                    {
                        _localctx = new UnaryMinusContext(_localctx);
                        _ctx      = _localctx;
                        _prevctx  = _localctx;
                        State     = 16; Match(SUB);
                        State     = 17; expr(2);
                    }
                    break;

                    case GAUSS:
                    {
                        _localctx = new GaussContext(_localctx);
                        _ctx      = _localctx;
                        _prevctx  = _localctx;
                        State     = 18; Match(GAUSS);
                        State     = 19; Match(T__0);
                        State     = 20; expr(0);
                        State     = 21; Match(T__2);
                        State     = 22; expr(0);
                        State     = 23; Match(T__2);
                        State     = 24; expr(0);
                        State     = 25; Match(T__2);
                        State     = 26; expr(0);
                        State     = 27; Match(T__1);
                    }
                    break;

                    default:
                        throw new NoViableAltException(this);
                    }
                    _ctx.stop = _input.Lt(-1);
                    State     = 39;
                    _errHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(_input, 3, _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, 2, _ctx))
                                {
                                case 1:
                                {
                                    _localctx = new MulDivContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 31;
                                    if (!(Precpred(_ctx, 7)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(_ctx, 7)");
                                    }
                                    State = 32;
                                    ((MulDivContext)_localctx).op = _input.Lt(1);
                                    _la = _input.La(1);
                                    if (!(_la == MUL || _la == DIV))
                                    {
                                        ((MulDivContext)_localctx).op = _errHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        if (_input.La(1) == TokenConstants.Eof)
                                        {
                                            matchedEOF = true;
                                        }

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

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

                                        _errHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 36; expr(7);
                                }
                                break;
                                }
                            }
                        }
                        State = 41;
                        _errHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(_input, 3, _ctx);
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                _errHandler.ReportError(this, re);
                _errHandler.Recover(this, re);
            }
            finally {
                UnrollRecursionContexts(_parentctx);
            }
            return(_localctx);
        }
コード例 #3
0
 public ChangeSignContext(UnaryMinusContext context)
 {
     CopyFrom(context);
 }
コード例 #4
0
 public ToAtomContext(UnaryMinusContext context)
 {
     CopyFrom(context);
 }
コード例 #5
0
 public virtual void CopyFrom(UnaryMinusContext context)
 {
     base.CopyFrom(context);
 }