tunnelvisionlabs / antlr4cs

The original, highly-optimized C# Target for ANTLR 4
Other
450 stars 103 forks source link

Infinite Loop #365

Open jcculli opened 3 years ago

jcculli commented 3 years ago

I'm running into an issue after upgrading from 4.3.0 to any newer version of Antlr4 where a function within the auto-generated parser is running in an infinite loop and memory usage increases rapidly. I'm not very familiar with Antlr4 and didn't create the original grammar files, but my guess is there's an issue with my grammar file and the newer versions of Antlr4. Here's the section of code that is causing me problems (it never makes it out of the while loop due to _alt always having a value of 1):

    [RuleVersion(0)]
public GenadminContext genadmin() {
    GenadminContext _localctx = new GenadminContext(_ctx, State);
    EnterRule(_localctx, 66, RULE_genadmin);
    try {
        int _alt;
        EnterOuterAlt(_localctx, 1);
        {
        State = 692;
        _errHandler.Sync(this);
        _alt = Interpreter.AdaptivePredict(_input,43,_ctx);
        while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) {
            if ( _alt==1 ) {
                {
                {
                State = 689; genadmin_line();
                }
                } 
            }
            State = 694;
            _errHandler.Sync(this);
            _alt = Interpreter.AdaptivePredict(_input,43,_ctx);
        }
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.ReportError(this, re);
        _errHandler.Recover(this, re);
    }
    finally {
        ExitRule();
    }
    return _localctx;
}
lextm commented 1 year ago

You might upgrade to ANTLR 4.7 and above (#381) and then see if this issue remains.

Note that all new issues should be reported to https://github.com/antlr/antlr4/issues