0

is there a way to controll the reduction operation of a token with ANTLR at runtime. For example, I've an ANTLR grammar that looks like:

s: ( a | b);
a: WORD;
b: WORD;
WORD: ('a'..'z')+

Where the exact possible values related to both 'a' and 'b' are known at runtime, i.e. I want to decide at runtime whether to reduce a WORD to 'a' or 'b'.

bachr
  • 5,780
  • 12
  • 57
  • 92
  • Sorry, but this grammar wouldn't work. Can you explain more specifically, what really you want to achive? May be some example... – Andremoniy Oct 25 '12 at 09:35
  • I know that there is a reduce-reduce conflit but I'm looking for a way to solve this conflit in runtime. I've a table of words that can be reduced to 'a' to 'b' but this time is filled at runtime. – bachr Oct 28 '12 at 09:42

1 Answers1

1

Use a semantic predicate. Unless you plan on adding actions to rules a and b, this example won't be particularly useful.

s:
   {someBoolFunction();}? a
 | b
;
a: WORD;
b: WORD;
WORD: ('a'..'z')+
  • Hey, it is [Disambiguating Semantic Predicates](http://stackoverflow.com/questions/3056441/what-is-a-semantic-predicate-in-antlr3) what I was looking for. thanks – bachr Oct 31 '12 at 15:51