[antlr-interest] Keyword Vs Identifiers

Alessandro Feriani alessandro.feriani at gmail.com
Thu Jul 19 02:21:18 PDT 2007


Hi All
i am developing a parser geenrator for a particular language using AntLR
2.7.7
I have to parse lines like

repeat 1 > 1 0    1111   010    X     HL
where 6 is an integer and after ">" every single char is a keyword.
I created a token set in this way
tokens
{
   DRIVE_LOW = "0";
   DRIVE_HIGH = "1";
   EXPECT_X = "X";
   EXPECT_L = "L";
    EXPECT_H = "H";
}

INT options{testLiterals=true;}: (DIGIT)+;
WORD options{testLiterals=true;}: LETTER (LETTER|DIGIT)*; where DIGIT and
LETTER are protected identifiers

Now the problem appear due to the ambiguity in bewteen INT and
DRIVE_LOW....( the same for EXPECT_L and WORD )
Ho can I do to distinguish in between them depending on the context?
Setting testLiterals=true, the lexer will always try to math the hash table
and I can also not apply testLiterals=true on parser.
How to fix this ambiguity?

Please help me
Thanks a lot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070719/ca41d691/attachment.html 


More information about the antlr-interest mailing list