[antlr-interest] (no subject)

Daniels, Troy (US SSA) troy.daniels at baesystems.com
Fri Nov 30 09:15:23 PST 2007


I'm using antlr 2.7.6 and I'm trying to write a parser rule of the form

rule: rule1 rule2* rule3?

With two levels of look ahead, there's ambiguity between rule2 and
rule3. The third token would remove the ambiguity. Is there a way to
increase the look ahead for just one rule? (Setting k only appears to be
valid in the grammar file options, not in rule options).

I tried using a syntactic predicate.

rule: rule1 ((TOK1 TOK2 TOK3)=> rule2*) rule3?

but antlr ignored it, since it doesn't consider (...)* to be multiple
options. Adding a blank alternative seems hackish:

rule: rule1 ((TOK1 TOK2 TOK3)=> rule2*|/* */) rule3?

Is there a good way to handle this sort of problem?

Troy


P.S.  I also posted this on Jguru, but there doesn't seem to be much
action in the Antlr forum there.  Is this a better place for such
questions?


More information about the antlr-interest mailing list