[antlr-interest] Dynamic token generation

Johannes Luber jaluber at gmx.de
Mon Jan 28 14:37:25 PST 2008


Jan van der Ven schrieb:
> Dear Antlr Community,
> ...
> Quantum uses a JDBC driver to connect to the specific database. Most 
> drivers report a list of keywords and functions. I would like these to 
> appear as tokens in the grammar. This means that a rule would refer to a 
> token as a KEYWORD, but the KEYWORD should be defined at runtime. Is 
> this possible?

At minimum, you have to know what keyword is allowed when. I suppose 
that is somewhere defined already. You can then use a generic token in 
place of the keywords and check dynamically, if the token text equals 
the required keyword. A possible implementation is (for C#):

contextual_keyword[string identifier]
	:	{ input.LT(1).Text == $identifier }? IDENTIFIER
	;

Johannes


More information about the antlr-interest mailing list