문제

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