On Friday 05 December 2008 07:46:10 Kenny Leung wrote:
> Hi All.
>
> One of the interesting things I found was that this is legal:
>
>      NUMBER : '0'..'9';

that's a lexer rule

> but this is not:
>
>      number : '0'..'9';

that's a parser rule, the ".." syntax is only allowed in lexer rules.

> Is there a way I can say, "use tokenizer rule A after the "{", but use
> tokenizer rule B after the "=".

for context switching the lexer,  I have two ideas (which both may be wrong 
:-) ) :

let the lexer allways return charaters as token and  combine them in parser 
rules like (examples):

id: LETTER (LETTER | DIGIT )*
type_id:  I | D | S | CARET | V
type_encoding = LEFT_BRACE id EQUAl type_id+ RIGHT_BRACE


or try a syntactic predicate in the lexer like:

fragment ID: LETTER (LETTER | DIGIT)*

NAME: ;
TYPE: ;
EQUAL:;
V:;

NAME_or_TYPE: 
          (ID '=') => ID { type = NAME; }
        | '=' { type = EQUAL; }
        | 'v'  { type = V;}
        ...

but I don't know if this works  in nested cases.


 Michael


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 il-antlr-interest@googlegroups.com
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