[antlr-interest] Lexer token type problem

Sriram Durbha cintyram at yahoo.com
Mon Nov 25 12:00:00 PST 2002


hi monty,
 earlier my code was wrong,
 now i corrected it but still i have a strange error;
please see 

http://www.geocities.com/cintyram/antlr/errors/error.html

it works fine when the rule has to return char or int, but not when
string;
also i have included the library #include <string> in teh headers
section along with  iostream.. so no problem due to that ;
please advise,
cheers
ram

--- mzukowski at yci.com wrote:
> returns is fine for parsers and lexers.  What are the errors?
> 
> Monty
> 
> -----Original Message-----
> From: Sriram Durbha [mailto:cintyram at yahoo.com]
> Sent: Monday, November 25, 2002 9:25 AM
> To: antlr-interest at yahoogroups.com
> Subject: RE: [antlr-interest] Lexer token type problem
> 
> 
> hi ,
>  i am writing a function that REALizes all numbers in a string and
> returns teh putput as a string ,
>  ie. if input is :       a = 2 , b =.345 ;
>  out put is      :       a = 2.0 , b = 0.345 ;
> 
> all other characters should be unmodified;
> 
> when i write the grammar like this , i get errors,
> 
> 
> file [returns string s] {s = "something" ; }: ( ( (design_unit )+ ) ?
> )
>  EOF ;
> 
> ... more lines.. 
> 
> the code generated is ..  : in TopLevelPArser.hpp
> 
> public: void file(
> 		returns string s
>   );
> 
>  ..
> PLease advise what i have to do, is the returns feature only for tree
> grammars??
> 
> cheers
> ram
> 
>  
> 
> --- mzukowski at yci.com wrote:
> > The lexer always assigns the token type as the type of the rule. 
> > That way
> > Numbers don't come out as DIGITs, etc.  Simply $setType() as an
> > action after
> > PARAGRAPH and CRNL.  It's a little trickier if you need to test for
> > literals
> > too.  An example of that is in the ID rule of the GCC parser.
> > http://www.codetransform.com/gcc.html.
> > 
> > Monty
> > 
> > -----Original Message-----
> > From: Matthew Ford [mailto:Matthew.Ford at forward.com.au]
> > Sent: Friday, November 22, 2002 4:23 PM
> > To: antlr-interest at yahoogroups.com
> > Subject: [antlr-interest] Lexer token type problem
> > 
> > 
> > Hi all,
> > I have a lexer with the following rules (and others)
> > 
> > CRNL_PARAGRAPH
> >  : ('\r' '\n' 'T')=>PARAGRAPH
> >  | ('\r' '\n' ~('T')) => CRNL ;
> > 
> > protected 
> > CRNL 
> >  : '\r' '\n'  
> >   ;
> >  
> >  
> > protected 
> > PARAGRAPH
> >  : "\r\nT" 
> >  ;
> > 
> > 
> > I expected to get token types  PARAGRAPH and CRNL returned but only
> > got
> > CRNL_PARAGRAPH even though the rules PARAGRAPH and CRNL were
> called.
> > 
> > changing  CRNL_PARAGRAPH to
> > 
> > CRNL_PARAGRAPH
> >  : ('\r' '\n' 'T')=>PARAGRAPH {$setType(PARAGRAPH);}
> >  | ('\r' '\n' ~('T')) => CRNL {$setType(CRNL);}
> >  ;
> > 
> > fixed the problem but I am still not clear why the original version
> > is not
> > valid.
> > 
> > Any comments?
> > 
> > matthew
> > 
> > Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service. 
> > 
> >  
> > 
> > Your use of Yahoo! Groups is subject to
> > http://docs.yahoo.com/info/terms/ 
> > 
> > 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> 
>  
> 
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/ 
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/ 
> 
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list