antlr4cs icon indicating copy to clipboard operation
antlr4cs copied to clipboard

Infinite Loop

Open jcculli opened this issue 4 years ago • 1 comments

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;
}

jcculli avatar Mar 09 '21 16:03 jcculli

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

lextm avatar Sep 09 '23 23:09 lextm