[antlr-interest] Matching ellipsis

Terence Parr parrt at cs.usfca.edu
Tue Nov 28 17:59:56 PST 2006


Hi Julian,

just call emit() multiple times within a lexer rule :)

Ter
On Nov 24, 2006, at 2:12 AM, Julian Santander wrote:

> Folks,
>
>     I'd be very grateful if someone could provide me some guidance  
> on a problem I'm having. This is actually my first attempt at a  
> parser using ANTLR. I'm using ANTLR beta 5 with Java generation (on  
> a Windows XP machine and Java 1.5 if that matters).
>
>     At the lexical level I need to match tokens like '.' (dot)  
> '..'  (ellipsis), integers and floating point numbers. (Actually I  
> don't need sign nor exponential formats)....
>
>     So far one of my many attempts has been:
> T_INTEGER_LITERAL: DIGIT+; DOT: ('.' (('.')=>{false}? | ))=>  
> '.' ; // This one is copied from http://www.antlr.org/blog/antlr3/ 
> lookahead.tml May 2006 post. T_ELLIPSIS: '.' '.'+ ;  
> T_FLOAT_LITERAL: DIGIT+ DOT DIGIT* | DOT DIGIT+ ;
> But so far I'm unable to parse "1..2" into T_INTEGER_LITERAL,  
> T_ELLIPSIS, T_INTEGER_LITERAL.
>
> for example: "... .. 1..2 3...4 5.0 .6 7." renders: TOKEN:  
> T_ELLIPSIS[@-1,0:2='...',<180>,1:0] TOKEN: WS[@-1,3:3='  
> ',<168>,channel=99,1:3] TOKEN: T_ELLIPSIS[@-1,4:5='..',<180>,1:4]  
> TOKEN: WS[@-1,6:6=' ',<168>,channel=99,1:6] TOKEN: T_FLOAT_LITERAL 
> [@-1,7:8='1.',<181>,1:7] TOKEN: T_FLOAT_LITERAL[@-1,9:10='.2',<181>, 
> 1:9] TOKEN: WS[@-1,11:11=' ',<168>,channel=99,1:11] TOKEN:  
> T_FLOAT_LITERAL[@-1,12:13='3.',<181>,1:12] TOKEN: T_ELLIPSIS 
> [@-1,14:15='..',<180>,1:14] TOKEN: T_INTEGER_LITERAL 
> [@-1,16:16='4',<175>,1:16] TOKEN: WS[@-1,17:17='  
> ',<168>,channel=99,1:17] TOKEN: T_FLOAT_LITERAL 
> [@-1,18:20='5.0',<181>,1:18] TOKEN: WS[@-1,21:21='  
> ',<168>,channel=99,1:21] TOKEN: T_FLOAT_LITERAL[@-1,22:23='. 
> 6',<181>,1:22] TOKEN: WS[@-1,24:24=' ',<168>,channel=99,1:24]  
> TOKEN: T_FLOAT_LITERAL[@-1,25:26='7.',<181>,1:25] TOKEN: WS 
> [@-1,27:27='\n',<168>,channel=99,1:27]
> I've tried other things (I've seen a post on emitting multiple  
> tokens for the same rule, but was apparently not yet supported in  
> v3, I've seen also the pascal examples for v2, but somehow I  
> couldn't get them to work??)
>
> Thanks very much in advance and best regards
>
>     Julian
>
>
>
>



More information about the antlr-interest mailing list