[antlr-interest] Re: TokenStreamRewriteEngine class and samples of its usage

kumarsriram sriram.kumar at nomissolutions.com
Thu May 27 15:24:51 PDT 2004


Terrence,

It worked. Thanks a lot. Your example does 
have "lexer.setTokenObjectClass("TokenWithIndex"); 

Regards,
Sriram



--- In antlr-interest at yahoogroups.com, Terence Parr <parrt at c...> 
wrote:
> 
> On May 27, 2004, at 2:59 PM, kumarsriram wrote:
> 
> >>> Hi. You need to set the token object to be TokenWithIndex as
> > well :)
> >
> > Thanks a lot for the quick response. But I'm not sure I 
understand.
> > How do I SET the token object? In my code, I'm GETTING the token
> > object from the TokenStreamRewriteEngine instance.
> >
> > I tried the following code as well:
> >
> > Mylexer = new MyLexer(new StringReader(inputStr));
> 
> 
> Add
> 
> MyLexer.setTokenObjectClass("antlr.TokenWithIndex");
> 
> and it should work.  I use a special token with the rewrite 
engine.  
> The lexer must create the special objects.  Doesn't the example 
usage 
> show this?  I'll have to fix it.
> 
> Terence
> 
> > System.out.println("Input string is " + inputStr);
> > TokenStreamRewriteEngine writer = new TokenStreamRewriteEngine
> > (lexer);
> > CommonToken dollarInput = new CommonToken(12, "$input"); //12 is 
the
> > index of the toke "$input" in the lexer
> > writer.replace(dollarInput, "get");
> >
> > When I execute, I get the following exception:
> >
> > java.lang.ClassCastException
> > 	at antlr.TokenStreamRewriteEngine.replace
> > (TokenStreamRewriteEngine.java:269)
> > 	at antlr.TokenStreamRewriteEngine.replace
> > (TokenStreamRewriteEngine.java:257)
> > 	at NomisParserTest.main(NomisParserTest.java:32)
> > exception: java.lang.ClassCastException
> >
> >
> > Help appreciated. Thanks.
> >
> > Sriram
> >
> >
> >
> >
> > --- In antlr-interest at yahoogroups.com, Terence Parr <parrt at c...>
> > wrote:
> >>
> >> On May 26, 2004, at 7:04 PM, kumarsriram wrote:
> >>
> >>> Hi,
> >>>
> >>> I'm a novice to ANTLR. I'm trying to write an expression parser
> >>> (extension to the one that is provided in the ANTLR examples). 
I
> >>> have a case where I need to replace some input characters
> >>> ("$input.xyz" should be replaced with "getXYZ()"). I figured 
out
> >>> that I could use TokenStreamRewriteEngine to do that. But when 
I
> > use
> >>> it in my program, I end up with ClassCastExceptions whenever I
> >>> invoke nextToken() method on the engine instance. Has anyone 
used
> >>> TokenStreamRewriteEngine before? BTW, am I taking the correct
> >>> approach?
> >>>
> >>> I have tested my Lexer and Parser and they seem to be work 
fine.
> >>>
> >>> Have enclosed my test code.
> >>>
> >>> MyLexer lexer = new MyLexer(new StringBufferInputStream
> > (inputStr));
> >>> System.out.println("Input string is " + inputStr);
> >>> TokenStreamRewriteEngine writer = new TokenStreamRewriteEngine
> >>> (lexer);
> >>> Token t = writer.nextToken; //here's the problematic code
> >>
> >> Hi. You need to set the token object to be TokenWithIndex as
> > well :)
> >>
> >> Terence
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> --
> Professor Comp. Sci., University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
> Cofounder, http://www.knowspam.net enjoy email again!
> Cofounder, http://www.peerscope.com pure link sharing



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list