[antlr-interest] uh oh...trouble in meaning of (..)=> pred!!!
Gavin Lambert
antlr at mirality.co.nz
Thu Mar 15 00:32:45 PDT 2007
At 12:27 15/03/2007, Loring Craymer wrote:
>As a first step, predicates should not specify more
>tokens that the alternative being selected. That
>would rule out the example grammar.
They're often required for disambiguation, though -- I have a few
rules of similar form in my own grammars (which do appear to work
so far, although I do recall having to work around some nastyness
at one point [which IIRC I did by changing the language to make it
easier to parse, since it was a custom one]).
Regarding the original problem, I think predicates of that form
will always require backtracking by their very nature, unless you
have sufficient lookahead cached up already (which may be
impossible for even fairly simple grammars).
Although it would be nicer if there was a simpler way to express
them -- since this sort of predicate will usually be of the form
"(a b c d) => a b" (ie. the matching portion is a strict prefix to
the predicate), maybe this could be rewritten as something like "a
b <c d>" (symbols just a suggestion; go with whatever makes more
sense) to indicate that the tokens/rules at the end need to match
but not be removed from the input stream and not be part of the
production. But that's mostly syntactic sugar, so can probably
wait.
More information about the antlr-interest
mailing list