[antlr-interest] Re: Semantic predicates that aren't & hoisting

David Jung jungdl at ornl.gov
Mon Mar 14 10:15:31 PST 2005


John D. Mitchell said:
>>>>>> "David" == David Jung <jungdl at ornl.gov> writes:
> [...]
>
>>> Here's a sample input: {if (a() < 0) then {b; c(); {;} dd();} e; f();}
>>> g();
>
>> Notice how you've corrupted my input "{if {a>0;} then {f();g();} x();}"
>> so that you only accept an expression, but not a statement as the if
>> conditional.  More importantly, statements are not primary in your
>> grammar.  Having the primaryExpr rule include statement would make it
>> closer.
>
> Here's my last take on this for free.  If you want more, contact me
> directly and we can work out a consulting agreement.

John,
  Don't waste any more of your time.  You've failed to
grasp the fundamental problem.  Your grammar, like Java/C++,
breaks the orthogonality rule of language design; in that
your statements/blocks are not primary.
That's why it can't parse the input I provided in my last post:
"{if ({a();}++ < 0) then {b; c(); {;}+1 dd();} e; f();}*2"
(notice the "++", "+1" and "*2")

That could be fixed by putting statementList in primaryExpr, but
would introduce ambiguity.  Doing that would give something very
similar to the solution I proposed in my original post in this
thread.  However, my original question was if there was a better
way; one that avoids the ambiguity.  Now I know the answer is no.
Perhaps ANTLR 3 will support the hoisting I need.

Thanks for your time,
-David.



More information about the antlr-interest mailing list