0
votes

I defined a grammar rule

variable : ID ;

where ID is defined in the lexer grammar as

ID : VALID_ID_START VALID_ID_CHAR* ;
fragment VALID_ID_START : ('a' .. 'z') | ('A' .. 'Z') | '_' ;
fragment VALID_ID_CHAR : VALID_ID_START | ('0' .. '9') ;

However in my test, the literal word "detector" is not recognized as a token of variable. It works as expected as soon as I remove any character from the word. Is "detector" a reserved word in ANTLR4? If yes, how can I get around that since this word is a common variable in my work.

1
Which input string did you use to test this grammar? - Anderson Green
Just the word "detector" without the quote. - Fedrick Kenan
If it's not recognized as an ID token, what is it recognized as? - sepp2k
It couldn't recognize that as anything, but just reported an error: ChdHotspotQueryLanguage::variable:1:0: mismatched input 'detector' expecting ID - Fedrick Kenan
I tested with many other words and some random string of characters which just worked fine. - Fedrick Kenan

1 Answers

0
votes

I found the cause of the problem. Somewhere in my lexer rules, the word "detector" is used to define a different token. Thanks to @sepp2k for his comments that guided me to right direction of solving the problem.