[antlr-interest] question on simple grammar for tick format to decimal conversion

Nagesh, Harsha harsha.nagesh at csfb.com
Wed Nov 30 17:07:32 PST 2005


Hi,

    I am trying to implement a very simple parser for converting strings to
decimal numbers. The strings are bond prices given in tick format such as
"101-12(5+)" or "103-1+", etc. I am sure antlr is an overkill, but I am doing 
it for fun and I am kind of stuck with this error that I need some help. 

my parser rules looks like this (this is just trying to match a number like
"102-3" or "1345-1")

parse returns [decimal result]
{result = -1.0;}
   :  Number (MINUS DigitsA)? EOF

Number: (DigitsA | DigitsB | DigitsC)+
   ;

My lexer has the following literals
 
MINUS: "-";

DigitsA: '0'..'3';
DigitsB: '4'..'8';
DigitsA: '9';

I need to group the digits into these tree groups as the number after the MINUS
can only be from 0 to 32. and further in some places I need to restrict the 
number from 0 to 8.

But antlr is complaining that "Lexical rule Number defined outside of lexer.
Exiting due to errors"

Can somebody explain what is wrong here ?

Thanks,
Harsha

ps: I am quite familiar with antlr and I have done some serious syntax directed
translation using it recently, but I am stuck with this problem.

==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer: 

http://www.csfb.com/legal_terms/disclaimer_external_email.shtml

==============================================================================



More information about the antlr-interest mailing list