On Sunday 17 May 2009 13:22:37 Jesper Larsson wrote:
> On Sun, 2009-05-17 at 12:48 +0200, Micha wrote:
> > On Sunday 17 May 2009 11:01:36 Jesper Larsson wrote:
> > > 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:
>
> Hm, as far as I can tell your variant has exactly the same problems as
> mine. The following grammar, incorporating the trick from yours, can
> match "foobar" as FOO BAR but fails on "foofoobar":

*Argh*  you need the synpred again:


> ============================================
> grammar Y;
> options { output=AST; }

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

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

fragment
FOO     :       ;

BAR     :       'bar';

fragment FOOZ
        :       ;
        
fragment FOOZ_LA
        :       'foo'* 'z';     
        
FOO_OR_FOOZ
        :       (
                        'foo' { $type = FOO; }
                        ((FOOZ_LA) => FOOZ_LA { $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 il-antlr-interest@googlegroups.com
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to