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

John D. Mitchell johnm-antlr at non.net
Thu Mar 10 11:11:32 PST 2005

>>>>> "David" == David Jung <jungdl at ornl.gov> writes:
>>>>>> John D. Mitchell said:
>>>>>>> "David" == David Jung <jungdl at ornl.gov> writes:

>> Add the handling of the recursive exprList directly into
>> exprList. E.g.:

>> exprList : '{' ( exprListOrStmt )* '}' ;

>> exprListOrStmt : exprList | expr ';' ;

> Perhaps I'm confused.  Here as you have expr ';', that means that an
> expression that ends with an exprList (but isn't one directly), like the
> 'if' case, can have a ';' following it - which is exactly what I'm trying
> to avoid requiring.

Read my grammar fragment again. The first alternative of exprListOrStmt is
a recursive call to exprList.  That will match the nested exprLists.

What I didn't do was make the semi-colon optional: no semi after exprList
blocks but a semi is require after an expr.

> That is "if (a) {f();g();h();}" is a valid expr, but isn't an exprList,

The entire if expression isn't an exprList but the block is an expr which
will resolve to an exprList all by itself.

Check out e.g., the C or Java grammars for examples of how the various
parts of an expr hang together.

Take care,

More information about the antlr-interest mailing list