[antlr-interest] Re: Semantic predicates that aren't & hoisting
John D. Mitchell
johnm-antlr at non.net
Sat Mar 12 18:40:01 PST 2005
>>>>> "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.
Change the following in the grammar that I gave previously:
statement
: SEMI
| block
| expression ( SEMI ) ?
| "if" exprOrBlock "then" statement
( options { warnWhenFollowAmbig = false; } : "else" statement )?
;
And add this:
exprOrBlock
: block
| expression
;
Now your wacky "{if {a>0;} then {f();g();} x();}" works just fine.
Geez,
John
More information about the antlr-interest
mailing list