> On Fri, Jan 29, 2010 at 6:37 PM, Jim Idle <[email protected]> wrote:
> Yes, you need to follow the method in the example - what you are trying to do
> will not work until you left factor it.
OK, I've attempted to merge the INT, DOT and FLOAT rules together and
manually set the token types at various branch points in the rules.
I'm still not having much luck with it, I'm afraid, but here's my
grammar to date:
grammar test;
fragment INT:;
fragment DOT:;
top: expr EOF;
expr: (INT | FLOAT | ID | '(' expr ')') (DOT ID)*;
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
FLOAT
: ('0'..'9')+ (
{input.LA(2) >= '0' && input.LA(2) <= '9'}?=>
'.' ('0'..'9')+ EXPONENT? {$type = FLOAT;}
| {$type = INT;} (
'.' {$type = DOT;}
)
)
| '.' {$type = DOT;}
;
WS : ( ' '
| '\t'
| '\r'
| '\n'
) {$channel=HIDDEN;}
;
fragment
EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
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.