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

John D. Mitchell johnm-antlr at non.net
Fri Mar 11 08:53:36 PST 2005


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

> yes. That is the intention.  A program in an expr, so are namespaces,
> classes etc. etc.

Interesting.

Well, if you're going that far, why not go whole hog to e.g., Lisp or even
a pure functional language?  You'll get a much cleaner, more consistent,
and (mostly likely) a more powerful solution.


[...]
>>> Secondly, and importantly, expr won't match:

>>> "{if {a>0} then {f();g();} x();}", will it? (or am I going blind?)

>> Of course it will:

>> expr will match exprList.

>> exprList will match expr will match if followed by an expr matching an
>> exprList followed by then followed by an expr matching an exprList
>> containing two exprs matching a list of function call expressions;
>> followed by a function call expression.

> I still don't get it.  It looks like your exprListOrStmt *requires* a ';'
> to follow an expr.  So, if the above entire expression is an exprList
> containing two exprs (first is 'if'... and second is x();), why isn't a
> ';' required to follow the 'if' expr?

You're (mis-)reading the wrong part.  The *FIRST* alternative in
exprListOrStmt matches the *nested* exprList's.  That's the whole point
(and why that's the first alternative and the statement is the second
alternative -- remember that ANTLR does top-down (aka predictive) parsers).

I suggest that you write a small, simple grammar that has this and turn on
the tracing and run it over some input to see it in action.

Take care,
	John


More information about the antlr-interest mailing list