[antlr-interest] disambiguating sempred in a closure?
Terence Parr
parrt at cs.usfca.edu
Fri Dec 21 15:13:55 PST 2007
On Dec 21, 2007, at 2:58 PM, J Chapman Flack wrote:
> Ok, here is the simplified grammar that really does
> demonstrate my dilemma. The predicates can't do what
> I need because of the grouping parentheses added to
> factor out the common something_else suffix.
>
> I can get the code I want if I leave off the grouping
> parens and duplicate the something_else suffix on
> each branch. Is that the best I can do? I hate to
> duplicate the something_else (which is followed by
> a nontrivial action).
Hi Chap! long time no chat ;)
Heh, so the code gen is not right in v2? I can't remember how it
works :(
> Is the story the same in ANTLR 3?
> class CelebParser extends Parser;
>
> prod : something
> ( options { greedy=true; }
> : ( { muppet }? ( KERMIT | FOZZIE )
> | { turtle }? ( LEONARDO | DONATELLO )
> )
> something_else
> )*
> ;
v3 is way better at this stuff. You use a gated semantic pred, which
always get hoisted into decision:
prod : something
( ( { muppet }?=> ( KERMIT | FOZZIE )
| { turtle }?=> ( LEONARDO | DONATELLO )
)
something_else
)*
;
results in DFA predictor:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Celeb.dec-2.pdf
Type: application/pdf
Size: 16459 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20071221/ee983471/attachment-0001.pdf
-------------- next part --------------
The preds are hoisted out of the subrule inside (...)* and used to
control exit. 3rd alt (exit) is implicit.
Ter
More information about the antlr-interest
mailing list