[antlr-interest] Non-disjoint tokens

Steve Bennett stevagewp at gmail.com
Mon Nov 26 04:44:43 PST 2007


On 11/26/07, Gavin Lambert <antlr at mirality.co.nz> wrote:
> I prefer this sort of approach over using semantic predicates; I
> try to use those as little as possible.  (Mainly because I think
> they're ugly, but also because they're target-specific.)

Thanks for the tip. I'm new to Antlr, but so far I'm finding a bit of
a preference the other way, actually: I find syntactic predicates
rather clunky and inexpressive, and since they're simply semantic
predicates in disguise, they don't seem elegant to me. Most of the
time they seem to end up in chains like this:

foo:
  (bar) => bar
| (dar) => dar
| (lar) => lar
| (rar) => rar
;

When all I really want to say is: "match the first expression that
fits, and for god's sake don't give me any warnings about it!"

There also seems not to be an easy way to say "in this context, don't
try matching X, it won't work and you'll get stuck". Or for that
matter a way of incorporating previously matched tokens: "If you have
matched A and B, and the next token is D, then now would be a good
time to match a C."

Both semantic and syntactic predicates seem like very powerful tools,
but they seem a bit immature at the moment, and just need a bit more
bedding down.

Steve


More information about the antlr-interest mailing list