[antlr-interest] Help debugging ANTLR code
Edson Tirelli
tirelli at post.com
Fri Aug 27 09:56:40 PDT 2010
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
More information about the antlr-interest
mailing list