[antlr-interest] Help debugging ANTLR code

Edson Tirelli tirelli at post.com
Fri Aug 27 10:14:01 PDT 2010


    Jim,

    I know java shortcuts || on true, but on false, those predicates become
**really** expensive... not to mention the size of the code that right now
is causing javac to raise stackoverflow when trying to compile the generated
class...

    I can keep, with trial&error, tweaking my grammar, but the inefficient
code will still be there... doesn't look it should be too difficult to fix
this on code generation, as it is the same predicate generated over and over
with an || in between?! My first choice would be to fix code generation and
hopefully get rid of both the "stack-overflow" and the "code too large"
errors.

    Thanks,

    Edson


2010/8/27 Jim Idle <jimi at temporal-wave.com>

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
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>



-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com



-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com


More information about the antlr-interest mailing list