antlr4cs icon indicating copy to clipboard operation
antlr4cs copied to clipboard

ANTLR hangs in this deep parse tree

Open masonwheeler opened this issue 1 year ago • 2 comments

Grammar file: https://github.com/uwol/proleap-vb6-parser/blob/master/src/main/antlr4/io/proleap/vb6/VisualBasic6.g4 Source file: https://github.com/smbx/smbx-legacy-source/blob/master/modNPC.bas

Attempting to parse this file with a C# parser generated off this grammar causes ANTLR to hang in what appears to be an infinite loop. The debugger says there's some very deep recursion going on deep within the bowels of ParserATNSimulator.AdaptivePredict. Memory usage remains constant during the hang.

It looks like the source file includes some extremely deep parse trees, such as the code following line 2400. This might be part of what's giving the parser trouble. Are there any known workaround for dealing with such issues?

masonwheeler avatar Jul 25 '22 00:07 masonwheeler

After further investigation, this isn't an infinite loop afterall; it completed parsing the file in question after approximately four and a half minutes. (Where similar-sized files are usually finished in a matter of seconds.)

Any idea what's causing the parser's performance to degenerate so severely on this file?

masonwheeler avatar Jul 25 '22 18:07 masonwheeler

I had a similar issue with the PostgreSQL parser from the official grammars repo: https://github.com/antlr/grammars-v4/tree/master/sql/postgresql

I left this building for over a day on my M1 Pro MacBook Pro and it never finished. I plan on attempting to use the original C# target soon to see if it finishes in a reasonable amount of time.

paulirwin avatar Dec 25 '22 21:12 paulirwin