سؤال

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

هل كانت مفيدة؟

المحلول

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')+
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top