On Sunday 17 May 2009 11:01:36 Jesper Larsson wrote:
> > If you want the longest match, then left factor everything and let it
> > do that:
> >
> > A ( B (C|) |) ;
> >
> > And set the token type at the appropriate points.
>
> Not always so easy, however. My original example was, even more
> simplified, something like this:
>
> FOO:    'foo';
> BAR:    'bar';
> FOOZ:   'foo'* 'z';
>

that works with the method mentioned earlier:

start   :       ( FOO { System.out.println("foo, ");} 
                | FOOZ { System.out.println("FOOZ, ");} )* EOF;

WS      :       (' ' | '\t' | '\n')+ { skip(); };

fragment FOO    : ;

fragment FOOZ: ;
        
FOO_OR_FOOZ
        :       (
                        'foo' { $type = FOO; }
                        ('foo'* 'z' { $type = FOOZ;} )? 
                ) 
                | 'z' { $type = FOOZ;};
                

 Michael


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to