[antlr-interest] Lexer predicates...why don't they work for me?

向秦贤 fyaoxy at gmail.com
Sat Aug 25 17:08:53 PDT 2007


Hi,
Your example, you can goto antlr site, click document link to go that,
search
greedy
you will see documents which give samples like this: T
(options{greedy=false;}:.)* T
and you can search maillist check out some subject about lexer and parser
and difference between those.

and you can search filter about usage.

2007/8/26, Diehl, Matthew J <matthew.j.diehl at intel.com>:
>
> 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
>



-- 
致敬
向秦贤
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070826/0de90f93/attachment.html 


More information about the antlr-interest mailing list