[antlr-interest] Lexer predicates...why don't they work for me?
Diehl, Matthew J
matthew.j.diehl at intel.com
Sat Aug 25 14:13:05 PDT 2007
Hi,
The lexer is the part of ANTLR that I do not understand at all. I think
I understand what it's doing, but obviously I don't. It always feels
like it is a LL(1) lexer. For instance if I have the following rules:
Apostrophe : '\''
CharacterLiteral : Apostrophe (.) Apostrophe ;
Given an input of:
foo = '0'; --works fine (token = CharacterLiteral)
Foo = signalA'RANGE --doesn't work. It throws a lexer error saying that
'A' is not an apostrophe (''')
In this case I would like it to just return ''' as Apostrophe.
I tried using predicates:
CharacterLiteral : (Apostrophe (.) Apostrophe)=> Apostrophe (.)
Apostrophe ;
And also:
CharacterLiteral : Apostrophe (.) Apostrophe
| Apostrophe {$type=Apostrophe;} ;
/*same error as above*/
CharacterLiteral : {input.LA(3)==Apostrophe}? Apostrophe (.) Apostrophe
;
/*threw a 'did not pass predicate' error */
But none of it's working. What am I doing wrong? Thanks for your time
and consideration.
Matt
More information about the antlr-interest
mailing list