[antlr-interest] Help debugging ANTLR code

Jim Idle jimi at temporal-wave.com
Fri Aug 27 10:05:10 PDT 2010


It's not a bug as the way the DFA has fallen out from your expression of the
grammar. It could be tidier in the code generation of course.
Try changing the parameters for code generation such as increasing the size
of switches and increasing the conversion timeout. See if you can get rid of
any of those predicates too.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Edson Tirelli
> Sent: Friday, August 27, 2010 9:57 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Help debugging ANTLR code
> 
>     Hi all,
> 
>     Continuing on the work on Drools grammar, I've split the grammar in 4
> smaller grammars as suggested by Jim the other day, but I am still getting
the
> "code too large" error. I looked throughout the code antlr generated and
the
> problem happens on DFAs. It generates a method called
> 
>         public int specialStateTransition(int s, IntStream _input) throws
> NoViableAltException {
> 
>     Inside that method, there is a switch case with nested "if"s. In my
case, it is
> generating things like the bellow for the "if" alternatives:
> 
>  else if ( (LA4_1==STRING) &&
>      ( ( (evalPredicate(helper.validateLT(1,
> DroolsSoftKeywords.QUERY),"helper.validateLT(1,
> DroolsSoftKeywords.QUERY)") &&
> 
> 
> evalPredicate((helper.validateIdentifierKey(DroolsSoftKeywords.QUERY)),"(
> helper.validateIdentifierKey(DroolsSoftKeywords.QUERY))"))
>        ||(evalPredicate(helper.validateLT(1,
> DroolsSoftKeywords.QUERY),"helper.validateLT(1,
> DroolsSoftKeywords.QUERY)") &&
> 
> 
> evalPredicate((helper.validateIdentifierKey(DroolsSoftKeywords.QUERY)),"(
> helper.validateIdentifierKey(DroolsSoftKeywords.QUERY))"))
>        ||(evalPredicate(helper.validateLT(1,
> DroolsSoftKeywords.QUERY),"helper.validateLT(1,
> DroolsSoftKeywords.QUERY)") &&
> 
> 
> evalPredicate((helper.validateIdentifierKey(DroolsSoftKeywords.QUERY)),"(
> helper.validateIdentifierKey(DroolsSoftKeywords.QUERY))"))
> 
>           ...repeats that hundreds of times...
> 
>        ||(evalPredicate(helper.validateLT(1,
> DroolsSoftKeywords.QUERY),"helper.validateLT(1,
> DroolsSoftKeywords.QUERY)") &&
> 
> 
> evalPredicate((helper.validateIdentifierKey(DroolsSoftKeywords.QUERY)),"(
> helper.validateIdentifierKey(DroolsSoftKeywords.QUERY))")))))
> {s = 5;}
> 
> 
>     This is obviously a code generation bug, as the same condition is
repeated
> over and over. Since I need to move on with this, I will try to find the
problem
> myself, but I appreciate if anyone can point me to the right direction,
i.e.,
> which classes/templates in ANTLR take care of the code generation for
DFAs.
> 
>     The rule that triggers the problem above is like this:
> 
> statement
> options { k=2; } :
>         // some alternatives
> | {helper.validateLT(1, DroolsSoftKeywords.QUERY)}?=>    query
>         // more alternatives
>         ;
> 
>      The problem happens on all alternatives, BTW. The above is just a
snippet
> to show the problem.
> 
>      The problem happens both when running with and without -debug, but
> obviously the above snippet includes the debug info.
> 
>      Thanks,
> 
>      Edson
> 
> --
>   Edson Tirelli
>   JBoss Drools Core Development
>   JBoss by Red Hat @ www.jboss.com
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address



More information about the antlr-interest mailing list