[antlr-interest] Big grammar => static initializer/method size is exceeding the 65535 bytes limit

Alex Marin alex.marin at amiq.ro
Fri Oct 30 14:16:55 PDT 2009


Hello,

While trying to migrate a parser grammar file from ANTLR v2 to ANTLR v3
I came across the following errors in the generated Parser.java:

   1. The code for the static initializer is exceeding the 65535 bytes
limit

and:

   2. The code of method specialStateTransition(int, IntStream) is
exceeding the 65535 bytes limit.

One solution to work around problem #1 seems to be spreading the static
initializations from the Parser.java file across more compilation units,
but it is definitely cumbersome and not scalable.

Regarding problem #2, I came across several mail threads, but none
provided a clear & scalable solution.

I have to mention that the grammar worked well in ANTLR v2 (the
generated parser was ~40 000 lines of code as opposed to the one
generated with ANTLR v3 which counts ~300 000 loc). I also have to point
out that the grammar is very large ( ~600 rule definitions and ~5000
loc).

My questions are:

Are there any known solutions/workarounds for these problems?
Is there a known approach for fixing such issues related to big
grammars? (N.B. Generation takes a few minutes and even opening the
generated parser with a basic text editor is quite sluggish)

Thank you,
    Alex Marin



More information about the antlr-interest mailing list