John B. Brodie <[EMAIL PROTECTED]> wrote:
> > In the grammar below NAMES has been made a fragment. But still it produces
> > the same output as before that doesn't contain a NAMES token:
> actually I believe the prefered way is to specify this and any other Virtural
> Token in a tokens {} section - should appear after the options {} and before
> your @header {} section.
I agree.

> > Token:  IDENT( 0) >GoTo<
> > Token:  WHITE(99) > <
> here is, i believe the problem, see comments near your IDENT rule below.
You were right.

> > IDENT
> >     : (ID (WS ID)+)=> ID (WS ID)+ {$type = NAMES;}
> recall that ANTLR lexer constructs greedily consume the longest possible 
> string, and that,
> further, once commited to a particular looping construct no other alternative 
> is recognized.
> so your predicate wants a list of WS ID pairs. fine. good. gotcha. but your 
> input has some
> WS ID pairs and then a WS LB pair - that does not match a (WS ID)+ and the 
> predicate fails.
> remove the blank before the { in your test data and see what I mean. so try 
> this ident
> rule instead:
> IDENT
>     : ID ( ((WS ID)=>(WS ID))+ {$type = NAMES;} )?
>     ;
Obviously I didn't understand how predicates work. I thought they would
match as much as possible. I did not understand that the complete predicate
fails when the common WS prefix was recognized. Coming from lex/JFlex
this will probably be a pitfall for quite some time.

Thank you very much John. You brought me a big step further in understanding
how ANTLR works.

Regards,
Nukiti


      

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/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