[antlr-interest] Re: Semantic predicates that aren't & hoisting
John D. Mitchell
johnm-antlr at non.net
Thu Mar 10 09:38:36 PST 2005
>>>>> "David" == David Jung <jungdl at ornl.gov> writes:
> John D. Mitchell said:
>>>>>>> "David" == David Jung <jungdl at ornl.gov> writes:
[...]
>>> expressionList : '{' expr ( ';' expr )* '}' ;
>>> The important rule for this discussion being expressionList. So, a
>>> valid expr can be "5" or "{5; 7; 8}" or "{ { 2; 3; }; <-- notice this
>>> ';' 5; } "
>> Make the exprList rule a bit more complicated and have it explicitly
>> understand the recursive nesting of the exprLists.
> I'm not exactly sure how that would work.
Add the handling of the recursive exprList directly into exprList. E.g.:
exprList
: '{' ( exprListOrStmt )* '}'
;
exprListOrStmt
: exprList
| expr ';'
;
> Note that a semi-colon following an expr that was an expressionList isn't
> the only case where I want it optional, but immediately after *any*
> expressionList (which could be nested down). e.g. another valid expr
> rule option is
[...]
Ah, the old separator vs. terminator argument. Well, there are certainly
plenty of examples of that idea floating around. :-)
Since you seem to have some control over the language, I strongly suggest
implementing your grammar with semi-colons as terminators first and then go
back after you have that well debugged and tweak it to be a separator.
Hope this helps,
John
More information about the antlr-interest
mailing list