[antlr-interest] ANTLR Optional statements
Terence Parr
parrt at jguru.com
Thu Apr 11 11:15:20 PDT 2002
On Wednesday, April 10, 2002, at 03:30 PM, Tom Moog wrote:
>
> Part 1:
>
> The extra EOF in the follow set is a general problem.
> When antlr2 or pccts analyzes a grammar and finds an
> orphan rule they assume that it is a start rule. Since
> every start rule should have EOF in the follow-set they
> add one. They should probably warn the user, but they
> don't.
Well, you might have a grammar with lots of start rules...should one
really get a warning for that? Certainly it would be nice to be able to
get a list of these suckers. Not sure a warning is proper since every
single grammar will get a warning then ;)
> There is a warning about this in the "Notes For New Users
> of pccts" and why pccts has a "-info o" option which
> lists all orphan rules.
Ah...you've beaten me to the punch :) Thanks for all your hard work on
PCCTS!
> Part 2
>
> If antlr2 doesn't see class_head, then obviously it will
> compute the follow set improperly. Sounds like a bug
It sees class_head in the predicate but not in the list of rule
references apparently. Therefore a standard FOLLOW will not compute it
properly. I think I remember saying that a predicate is not part of the
grammar and is merely there to show a minimum lookahead language that
predicts an alternative. It should not be included in FOLLOW
computations. HOWEVER, it needs to compute FIRST sets properly. If the
lookahead can see past class_head it must include what follows that
specific reference since it knws the context of the FOLLOW.
> to me. My hypothesis is that it is skipping the block
> following the syntax predicate in computing first and follow
> sets. This is correct for first sets, but incorrect for
> follow sets.
ANTLR computes standard static k lookahead to determine if the backtrack
is necessary even if you specify one. I should be computing this on the
alternative not the predicate.
Tom: is this similar to the error you pointed out in PCCTS that you
fixed regarding syn preds?
Ter
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list