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

David Jung jungdl at ornl.gov
Mon Mar 14 16:30:51 PST 2005


John D. Mitchell said:
>>>>>> "David" == David Jung <jungdl at ornl.gov> writes:
>> John D. Mitchell said:
>>>>>>>> "David" == David Jung <jungdl at ornl.gov> writes:
> [...]
>
>> 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.
>
> As the man once said, "You're deluded, Mr. Bond."
Really? :)

>
> (A) As I've shown from the beginning, you can get around the lack of
> hoisting by making your grammar a bit [or a lot depending on how ambiguous
> your language is] more complicated so as to drive the decision more
> directly.  This is what we had to do in the C grammar because Antlr v2
> doesn't support automatic predicate hoisting.
Yes.  In this case it will be a lot.  Hence my post for suggestions
of a solution that doesn't involve whole-sale re-organization of the
grammar.

>
> (B) Your language looks pretty ambiguous.  One way or another you still
> have to resolve the ambiguity by forcing the choice of how the parser will
> actually act when it comes to those decision points.  There's no magic
> wand
> to take that responsibility off of your hands as the language
> designer/implementor.

There is a simple syntactic predicate that can make the decision (as
previously indicated).
Unfortunately, in ANTLR v2 it must be expressed as a,
so called, semantic predicate, which additionally it isn't hoised,
hence ANTLR thinks the grammar is highly ambiguous when it actually
isn't.
As you say, I can avoid the need for the predicate by
re-orgnizing the grammar, but that would make it highly unnatural.

>
> (C) Yes, Antlr v3 does/will do automatic predicate hoisting.  This allows
> for more naturally structured grammars.

Indeed, I think I've settled on using ANTLR v3 to implement
the solution.  Perhaps I will brave the pre-release.

Cheers,
-David.


More information about the antlr-interest mailing list