Controlling token reduction

67 views Asked by At

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'.

1

There are 1 answers

1
AudioBubble On BEST ANSWER

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')+