[antlr-interest] ANTLR generating invalid Java

Oren Ben-Kiki oren at ben-kiki.org
Thu Aug 7 12:37:54 PDT 2008


On Thu, Aug 7, 2008 at 11:17 AM, Terence Parr <parrt at cs.usfca.edu> wrote:
> On Aug 6, 2008, at 3:23 PM, Oren Ben-Kiki wrote:
>> See for example line 1758 - where is the "n" rule parameter variable
>> supposed to come from? Could it be that back-tracking and rule
>> parameters don't mix?
>
> yep.  youHave to be careful; some discussions about this in the archives or
> in the book.
> Ter

I didn't see this warning in the book... Now that I am aware of it, I
can avoid the problem by turning of auto-backtracking and manually
adding syntactic predicates. Thanks!

There's still the question of the huge redundant "if" statements. It
seems like some sort of exponential explosion of combinations of
semantic predicates... that is, (T1 || T2 || ..) where each T<i> is
(S1 && S2 && ...) for some semantic predicates S<i>.

The resulting "if" statement is *huge*. There are 1916 T<i> tests in
this "if", but they are all repetitions of only 6 unique tests. And of
these six, two are redundant, where T<i> == (T<j> && <more stuff>).
Also all the T<i> tests contain the same last S<j> test, which could
have been factored out. So we are talking 84K bytes of source code to
perform 4 simple tests that could be coded in 130 bytes. Yikes! In
theory the optimizer/JIT should be able to make this go away, but
given one of the semantic tests is a function call... well...

Is this also a "known" problem? Is there anything I can do to avoid
this explosion?

Thanks,

   Oren Ben-Kiki


More information about the antlr-interest mailing list