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

        EnterRule(_localctx, 12, RULE_parens);
        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 55;
                Match(LP);
                State = 56;
                sum(0);
                State = 57;
                Match(RP);
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
コード例 #2
0
 object Visit(ParensContext context)
 {
     return(Visit(context.midexp));
 }
コード例 #3
0
 public ParentsExpression(ParensContext ctx) : base(ctx)
 {
 }
コード例 #4
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 = 15;
                    _errHandler.Sync(this);
                    switch (_input.La(1))
                    {
                    case INT:
                    {
                        _localctx = new IntContext(_localctx);
                        _ctx      = _localctx;
                        _prevctx  = _localctx;

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

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

                    default:
                        throw new NoViableAltException(this);
                    }
                    _ctx.stop = _input.Lt(-1);
                    State     = 25;
                    _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 = 23;
                                _errHandler.Sync(this);
                                switch (Interpreter.AdaptivePredict(_input, 2, _ctx))
                                {
                                case 1:
                                {
                                    _localctx = new MulDivContext(new ExprContext(_parentctx, _parentState));
                                    ((MulDivContext)_localctx).left = _prevctx;
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 17;
                                    if (!(Precpred(_ctx, 4)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(_ctx, 4)");
                                    }
                                    State = 18;
                                    ((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 = 19; ((MulDivContext)_localctx).right = expr(5);
                                }
                                break;

                                case 2:
                                {
                                    _localctx = new AddSubContext(new ExprContext(_parentctx, _parentState));
                                    ((AddSubContext)_localctx).left = _prevctx;
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 20;
                                    if (!(Precpred(_ctx, 3)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(_ctx, 3)");
                                    }
                                    State = 21;
                                    ((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 = 22; ((AddSubContext)_localctx).right = expr(4);
                                }
                                break;
                                }
                            }
                        }
                        State = 27;
                        _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);
        }
 // TODO
 public override ASTN VisitParens([NotNull] ParensContext context)
 {
     return(VisitExpr(context.midexp));
 }
コード例 #6
0
    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 = 15;
                ErrorHandler.Sync(this);
                switch (TokenStream.LA(1))
                {
                case INT:
                {
                    _localctx = new IntContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;

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

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

                default:
                    throw new NoViableAltException(this);
                }
                Context.Stop = TokenStream.LT(-1);
                State        = 25;
                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 = 23;
                            ErrorHandler.Sync(this);
                            switch (Interpreter.AdaptivePredict(TokenStream, 2, Context))
                            {
                            case 1:
                            {
                                _localctx = new MulDivContext(new ExprContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 17;
                                if (!(Precpred(Context, 4)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 4)");
                                }
                                State = 18;
                                ((MulDivContext)_localctx).op = TokenStream.LT(1);
                                _la = TokenStream.LA(1);
                                if (!(_la == MUL || _la == DIV))
                                {
                                    ((MulDivContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                }
                                else
                                {
                                    ErrorHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 19; expr(5);
                            }
                            break;

                            case 2:
                            {
                                _localctx = new AddSubContext(new ExprContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 20;
                                if (!(Precpred(Context, 3)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 3)");
                                }
                                State = 21;
                                ((AddSubContext)_localctx).op = TokenStream.LT(1);
                                _la = TokenStream.LA(1);
                                if (!(_la == ADD || _la == SUB))
                                {
                                    ((AddSubContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                }
                                else
                                {
                                    ErrorHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 22; expr(4);
                            }
                            break;
                            }
                        }
                    }
                    State = 27;
                    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);
    }
コード例 #7
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;
                    switch (_input.La(1))
                    {
                    case INT:
                    {
                        _localctx = new IntContext(_localctx);
                        _ctx      = _localctx;
                        _prevctx  = _localctx;

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

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

                    case 2:
                    {
                        _localctx = new ParensContext(_localctx);
                        _ctx      = _localctx;
                        _prevctx  = _localctx;
                        State     = 25; Match(2);
                        State     = 26; expr(0);
                        State     = 27; Match(1);
                    }
                    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 != ATN.InvalidAltNumber)
                    {
                        if (_alt == 1)
                        {
                            if (_parseListeners != null)
                            {
                                TriggerExitRuleEvent();
                            }
                            _prevctx = _localctx;
                            {
                                State = 37;
                                switch (Interpreter.AdaptivePredict(_input, 3, _ctx))
                                {
                                case 1:
                                {
                                    _localctx = new MulDivContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 31;
                                    if (!(Precpred(_ctx, 5)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(_ctx, 5)");
                                    }
                                    State = 32;
                                    _la   = _input.La(1);
                                    if (!(_la == MUL || _la == DIV))
                                    {
                                        _errHandler.RecoverInline(this);
                                    }
                                    Consume();
                                    State = 33; expr(6);
                                }
                                break;

                                case 2:
                                {
                                    _localctx = new AddSubContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 34;
                                    if (!(Precpred(_ctx, 4)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(_ctx, 4)");
                                    }
                                    State = 35;
                                    _la   = _input.La(1);
                                    if (!(_la == ADD || _la == SUB))
                                    {
                                        _errHandler.RecoverInline(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);
        }
コード例 #8
0
    public PolynomialContext polynomial()
    {
        PolynomialContext _localctx = new PolynomialContext(Context, State);

        EnterRule(_localctx, 4, RULE_polynomial);
        int _la;

        try {
            State = 43;
            ErrorHandler.Sync(this);
            switch (Interpreter.AdaptivePredict(TokenStream, 6, Context))
            {
            case 1:
                _localctx = new ParensContext(_localctx);
                EnterOuterAlt(_localctx, 1);
                {
                    State = 32;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    if (_la == SIGN)
                    {
                        {
                            State = 31; Match(SIGN);
                        }
                    }

                    State = 34; Match(T__0);
                    State = 38;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << INT) | (1L << DEC) | (1L << VAR) | (1L << SIGN))) != 0))
                    {
                        {
                            {
                                State = 35; polynomial();
                            }
                        }
                        State = 40;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                    }
                    State = 41; Match(T__1);
                }
                break;

            case 2:
                _localctx = new MonomContext(_localctx);
                EnterOuterAlt(_localctx, 2);
                {
                    State = 42; monomial();
                }
                break;
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
コード例 #9
0
    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 = 29;
                ErrorHandler.Sync(this);
                switch (Interpreter.AdaptivePredict(TokenStream, 1, Context))
                {
                case 1:
                {
                    _localctx = new StringOpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;

                    State = 10; Match(ID);
                    State = 11;
                    ((StringOpContext)_localctx).op = TokenStream.LT(1);
                    _la = TokenStream.LA(1);
                    if (!(_la == EQ || _la == NE))
                    {
                        ((StringOpContext)_localctx).op = ErrorHandler.RecoverInline(this);
                    }
                    else
                    {
                        ErrorHandler.ReportMatch(this);
                        Consume();
                    }
                    State = 12;
                    _la   = TokenStream.LA(1);
                    if (!(_la == STRING || _la == EMPTY))
                    {
                        ErrorHandler.RecoverInline(this);
                    }
                    else
                    {
                        ErrorHandler.ReportMatch(this);
                        Consume();
                    }
                }
                break;

                case 2:
                {
                    _localctx = new IsNullContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 13; Match(ID);
                    State     = 14;
                    ((IsNullContext)_localctx).op = TokenStream.LT(1);
                    _la = TokenStream.LA(1);
                    if (!(_la == EQ || _la == NE))
                    {
                        ((IsNullContext)_localctx).op = ErrorHandler.RecoverInline(this);
                    }
                    else
                    {
                        ErrorHandler.ReportMatch(this);
                        Consume();
                    }
                    State = 15; Match(T__0);
                }
                break;

                case 3:
                {
                    _localctx = new IntOpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 16; Match(ID);
                    State     = 17;
                    ((IntOpContext)_localctx).op = TokenStream.LT(1);
                    _la = TokenStream.LA(1);
                    if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << EQ) | (1L << NE) | (1L << GT) | (1L << GE) | (1L << LT) | (1L << LE))) != 0)))
                    {
                        ((IntOpContext)_localctx).op = ErrorHandler.RecoverInline(this);
                    }
                    else
                    {
                        ErrorHandler.ReportMatch(this);
                        Consume();
                    }
                    State = 18; Match(INT);
                }
                break;

                case 4:
                {
                    _localctx = new FuncOpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 19;
                    ((FuncOpContext)_localctx).func = TokenStream.LT(1);
                    _la = TokenStream.LA(1);
                    if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << ENDSWITH) | (1L << STARTSWITH) | (1L << SUBSTRINGOF))) != 0)))
                    {
                        ((FuncOpContext)_localctx).func = ErrorHandler.RecoverInline(this);
                    }
                    else
                    {
                        ErrorHandler.ReportMatch(this);
                        Consume();
                    }
                    State = 20; Match(T__1);
                    State = 21; Match(ID);
                    State = 22; Match(T__2);
                    State = 23; Match(STRING);
                    State = 24; Match(T__3);
                }
                break;

                case 5:
                {
                    _localctx = new ParensContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 25; Match(T__1);
                    State     = 26; expr(0);
                    State     = 27; Match(T__3);
                }
                break;
                }
                Context.Stop = TokenStream.LT(-1);
                State        = 39;
                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 = 37;
                            ErrorHandler.Sync(this);
                            switch (Interpreter.AdaptivePredict(TokenStream, 2, Context))
                            {
                            case 1:
                            {
                                _localctx = new AndContext(new ExprContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 31;
                                if (!(Precpred(Context, 7)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 7)");
                                }
                                State = 32; ((AndContext)_localctx).op = Match(AND);
                                State = 33; expr(8);
                            }
                            break;

                            case 2:
                            {
                                _localctx = new OrContext(new ExprContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 34;
                                if (!(Precpred(Context, 6)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 6)");
                                }
                                State = 35; ((OrContext)_localctx).op = Match(OR);
                                State = 36; expr(7);
                            }
                            break;
                            }
                        }
                    }
                    State = 41;
                    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);
    }
コード例 #10
0
    public PrimaryContext primary()
    {
        PrimaryContext _localctx = new PrimaryContext(Context, State);

        EnterRule(_localctx, 8, RULE_primary);
        int _la;

        try {
            State = 68;
            ErrorHandler.Sync(this);
            switch (TokenStream.LA(1))
            {
            case NUM:
                _localctx = new NumContext(_localctx);
                EnterOuterAlt(_localctx, 1);
                {
                    State = 58; Match(NUM);
                }
                break;

            case ID:
                _localctx = new IdContext(_localctx);
                EnterOuterAlt(_localctx, 2);
                {
                    State = 59; Match(ID);
                }
                break;

            case LL:
                _localctx = new ParensContext(_localctx);
                EnterOuterAlt(_localctx, 3);
                {
                    State = 60; Match(LL);
                    State = 62;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    do
                    {
                        {
                            {
                                State = 61; expr(0);
                            }
                        }
                        State = 64;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                    } while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << T__1) | (1L << SIN) | (1L << COS) | (1L << TAN) | (1L << LN) | (1L << LOG) | (1L << SQRT) | (1L << LL) | (1L << ID) | (1L << NUM))) != 0));
                    State = 66; Match(RL);
                }
                break;

            default:
                throw new NoViableAltException(this);
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }