[antlr-interest] Newbie Help
Gavin Lambert
antlr at mirality.co.nz
Wed Jan 14 11:17:21 PST 2009
At 04:43 15/01/2009, Mike Gering wrote:
>Thanks for the suggestion, but no value of k will work because
>the grammar accepts an optional list of tokens between (STAR
>simple_name)* and "b". For example:
> x*x*x*y/y/y*z
>should be accepted. The series of slash terms can be arbitrarily
>long or absent.
The slashes shouldn't be a factor.
The way your rules are written, as soon as it sees a single slash
term it's no longer possible for it to match the star terms as
part of "a" -- any star appearing after it must be a "b".
In other words, "x*x*x*y/y/y*z" is simply illegal; "x*x*x*y/y/y*2"
should be interpreted as three STAR terms (from a) followed by two
SLASH terms (from a) and finally one STAR term (from b). There
shouldn't be any ambiguity there.
Where you *will* get ambiguity with k=1 is for the input "x*x*2"
-- on seeing the "*" following the "x"s, ANTLR needs to look ahead
one more character (k=2) to discover that it can't satisfy the
STAR block in "a", but must instead fall out and go process it as
a "b" instead.
So k=2 really should be all you need, given the rules you've
posted thus far.
More information about the antlr-interest
mailing list