[antlr-interest] Re: Antlr grammar to parse Java classfile?
lgcraymer
lgc at mail1.jpl.nasa.gov
Thu Dec 6 16:57:59 PST 2001
Actually, I would argue that semantic predicates are the way to go; as
Monty pointed out
( { n > 0 }? foo { n--; } )*
will parse at most n iterations and you can add a sem pred as a
termination check, as Ter suggested. Recursive definitions also work:
loop
{ int n = N; }
:
{ n > 0 }? foo { n--; } loop
| { n == 0}?
;
will parse exactly n copies of foo or throw an exception.
Unfortunately, syntactic predicates don't behave the same in loops as
they do in recursive definitions--the recursive solution works as
ANTLR is currently implemented. (Maybe I could get the syn preds to
work with the non-greedy #pragma--I haven't tried that.) It would be
nice if this were fixed--the loop expression is rather less verbose,
and the recursive definition can be inconvenient for tree structuring.
The real advantages of sem preds over a new counter syntax is that
they support a full range of exit conditions. Why add a new syntactic
element which does less than the current machinery?
--Loring Craymer
--- In antlr-interest at y..., Terence Parr <parrt at j...> wrote:
>
> On Wednesday, December 5, 2001, at 04:01 PM, John D. Mitchell
wrote:
>
> > [...]
> >> Let's see. Well, it's close, but it wouldn't give you an error
if you
> >> have less than blockCount. You need that "did I get enough"
check at
> >> the
> >> end of the loop. Could do with a simple "validating" sem pred
after
> >> loop.
> >
> > Hmm... How is that going to be safe in the face of hoisting?
>
> Hmm...not sure if it's an issue or not. I just realized though that
the
> code gen is easy but the analysis might not be so easy to enhance.
> There is no concept of repeated grammatical item in my internal data
> structure.
>
> Ter
> --
> Chief Scientist & Co-founder, http://www.jguru.com
> Creator, ANTLR Parser Generator: http://www.antlr.org
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list