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

David Jung jungdl at ornl.gov
Thu Mar 10 09:19:14 PST 2005


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.

John,

I'm not exactly sure how that would work.
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

expr: 'if' cond 'then' expr

so I'd like to be able to write (where f() is func call):
{
  if (c) then {f();g();h()}
  i();
  j();
}

Here the outer expressionList consists of three expressions, none
of which are an expressionList (but the first is an 'if' that
contains an expressionList as its last part)

>
> I'm not sure why you don't require the semi-colon after the last item in
> the exprList but changing that would make the grammar cleaner.

Actually I was trying to simplify my description.  I'd like
to have an optional semi-colon after the last expression.
This is so that users coming from java/C++ could write 'naturally'
both:

{
  f();
  g();
  h();
}

and

a = {f();g();h()};

I think requiring either

{
  f();
  g();
  h()
}

or

a = {f();g();h();}

is confusing and 'un-natural'.


Thanks very much for your reply, btw.
Cheers,
-David.




More information about the antlr-interest mailing list