[antlr-interest] Keywords not context-free

Clifford Heath clifford.heath at gmail.com
Wed Oct 17 15:21:23 PDT 2007


Johannes Luber wrote:
> How about using always IDENTIFIER tokens except for the context-free
> keywords and test at the appropriate places, if the IDENTIFIER contains
> the correct string?
> contextual_keyword[string identifier]
> 	:	 { input.LT(1).Text() == $identifier }? IDENTIFIER
> 	;
> should work. Then use contextual_keyword["keyword"] instead KEYWORD.

Cunning, and a good trick to know, thanks.

Part of my problem arises because I have key phrases, like "is known by",
where the problem is that "is" and "by" can occur elsewhere. A recent
thread in this list shows someone with whitespace in their tokens, and
if that can be made to work for them, maybe it would work in this case
also. It doesn't completely fix the problem, but it might alleviate it.

Clifford Heath.



More information about the antlr-interest mailing list