[antlr-interest] REAL or int or Range

Alexander Gängel alexander at gaengel.de
Tue Jan 22 01:32:14 PST 2008


Thank you Jim,

Ok so it works, but shouldn't LL(*)  distinguish between '.' and '..'

I also think that AntlrWorks at least give the Error message:
line 1:2 required (...)+ loop did not match anything at character '.'

like the real code when debugging in AntlrWorks.

Alexander

Jim Idle schrieb:
>
> This should help (here it uses parser rules, but you could use the 
> same predicate stuff to match range in the lexer too:
>
>  
>
> // Return decimal numeric as one token but 888..888 as NUMBER RANGE 
> NUMBER
>
> // Also shows that '.' can still be recognized on its own, just for 
> kicks.
>
> // Try the input 999.88 . . 666..667
>
> //
>
> grammar harry;
>
>  
>
> start
>
>      :    (number_range)+
>
>      ;
>
>     
>
> number_range
>
>      : NUMBER ( RANGE NUMBER)?
>
>      | DOT
>
>      ;
>
>     
>
> NUMBER
>
>      : ('0'..'9')+
>
>            (
>
>                  ('.' '0'..'9')=> ('.' ('0'..'9')+)
>
>                 |// Just an integer
>
>            )
>
>      ;
>
>  
>
> RANGE
>
>      :    '..'
>
>      ;
>
>     
>
> DOT
>
>      : '.'
>
>      ;
>
>     
>
> OTHER
>
>      : . {$channel = HIDDEN; }
>
>      ;
>
>  
>
> Jim
>
>  
>
> *From:* Alexander Gängel [mailto:alexander at gaengel.de]
> *Sent:* Friday, January 18, 2008 2:00 AM
> *To:* antlr-interest at antlr.org
> *Subject:* Re: [antlr-interest] REAL or int or Range
>
>  
>
> I searched the Archive but till now I did not find anything, but I 
> will keep looking.
>
> I now also tried with actual code an not with AntlrWorks debugger an 
> now I get the message:
> line 1:2 required (...)+ loop did not match anything at character '.'
> when I try to  parse 0..9
>
> the 0.. is still missing in the output (I now create an Ast to test 
> and it has only the node 9)
>
> so I think AntlrWorks should at least also give the errormessage.
>
> Alexander
>
> Jim Idle schrieb:
>
> The interpreter won't be able to deal with your specification I think, 
>   
> whereas the real generated code does. I gave out code for int vs float 
>   
> vs range some time back if you check the archives - that should do what 
>   
> you want.
>   
>  
>   
> Jim
>   
>  
>   
>   
>   
>
>     -----Original Message-----
>         
>
>     From: shmuel siegel [mailto:antlr at shmuelhome.mine.nu]
>         
>
>     Sent: Wednesday, January 09, 2008 6:14 PM
>         
>
>     To: Antlr Interest
>         
>
>     Subject: Re: [antlr-interest] REAL or int or Range
>         
>
>      
>         
>
>     Alexander Gängel wrote:
>         
>
>         
>         
>
>         What I think is odd is that it works for Fırat Küçük.
>               
>
>          
>               
>
>               
>               
>
>     Maybe not so strange. In the debugger, I get the same as you but in 
>         
>
>         
>         
>
> the
>   
>   
>   
>
>     interpreter I get the attached png.
>         
>
>      
>         
>
>      
>         
>
>      
>         
>
>     No virus found in this incoming message.
>         
>
>     Checked by AVG Free Edition.
>         
>
>     Version: 7.5.516 / Virus Database: 269.19.0/1216 - Release Date: 
>         
>
>         
>         
>
> 1/9/2008
>   
>   
>   
>
>     10:16 AM
>         
>
>      
>         
>
>      
>         
>
>         
>         
>
>  
>   
>  
>   
>   
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080122/a8765429/attachment-0001.html 


More information about the antlr-interest mailing list