[antlr-interest] Bytes Limit

David-Sarah Hopwood david-sarah at jacaranda.org
Tue Oct 20 16:24:04 PDT 2009


Marcelo Nichele wrote:
> Hi,
> 
> I'm getting started in ANTLR and my grammar generated the
> specialStateTransition method too big.
> 
> The error message is *The code of method specialStateTransition(int,
> IntStream) is exceeding the 65535 bytes limit.*
> 
> The method assignature is:
> *public int specialStateTransition(int s, IntStream _input) throws
> NoViableAltException*

Workaround:

Look at the code for that method in the generated parser source
(note that there may be multiple DFA inner classes each with a
specialStateTransition method; the full error message should say which
one, or just look at the largest such methods).
Probably the code for specialStateTransition will include code copied
from predicates in your grammar, duplicated many times. Try to simplify
the code that is being duplicated.

For example, you could declare a boolean variable in the parser class
using @parser::members, set it to the predicate condition in an @init
block of the relevant rule(s), and reference that variable in place of
the original condition. (Be careful that you aren't changing the behaviour
of the rule by moving the predicate evaluation to the @init block.)


Suggested longer-term improvement:

The size of the generated specialStateTransition methods would be
considerably reduced if ANTLR were to automatically create temporary
variables for predicate conditions, rather than duplicating their code.
Since the DFA object is an instance of an inner class of the parser,
the workaround above requires the Java compiler to generate references
to outer class variables, which is more code than would be needed if
ANTLR were to create such temporaries as local variables of
specialStateTransition. Since there is no guarantee as to how often
predicates are evaluated, that change would not affect correctness.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the antlr-interest mailing list