[antlr-interest] Can TokenRewriteStream be applied to rules?

YINGAnnie yimm8369 at hotmail.com
Tue Mar 24 20:55:01 PDT 2009


 

 

Finally, it works.

 

Thanks a million for your explaination and patience!!!!!!

 

 

Annie
 


Date: Wed, 25 Mar 2009 09:16:00 +0530
From: indhu.b at s7software.com
To: yimm8369 at hotmail.com
CC: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Can TokenRewriteStream be applied to rules?

Are you sure 'tokens' is the TokenRewriteStream? Generally in the generated code the member variable 'input' is the token stream. Maybe you have to write 'input.replace($m.start, $m.stop, "something else");' unless you have done something to change the name of the token stream.

Also note that 'input' will be of type Interface TokenStream and it wont be of type TokenRewriteStream. So you might have to say ' ((TokenRewriteStream)input).replace(....)'. Else in the member variable section, you can write 'TokenRewriteStream rewriteStream = (TokenRewriteStream)input' and then use 'rewriteStream.replace(...)' in your code.

- Indhu


YINGAnnie wrote: 


 
It is not null.
 
I use the following:
 
 
variableStatement
    :     VAR? m=variableDeclaration ( COMMA variableDeclaration )* semic    {System.out.print("Start"+$m.start+"stop"+$m.stop);tokens.replace($m.start, $m.stop, "something else");}  
 ;
 
And the input is:
 
var int:a=2;
 
Then I got the output:
 
Start[@68,219:221='int',<250>,8:12]     stop[@72,225:225='2',<248>,8:18]
 
That means variableDeclaration  match  int:a=2. However, the java.lang.NullPointerException   is still there.
 
 
Here is the error line in the parser file:
 
 if ( state.backtracking==0 ) {
              System.out.print("Start"+(m!=null?((Token)m.start):null)+"stop"+(m!=null?((Token)m.stop):null));tokens.replace((m!=null?((Token)m.start):null), (m!=null?((Token)m.stop):null), "something else");
            }
 
 
I really dont know why?
 
Thanks,
 
 
Annie
 


Date: Wed, 25 Mar 2009 08:53:17 +0530
From: indhu.b at s7software.com
To: yimm8369 at hotmail.com
CC: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Can TokenRewriteStream be applied to rules?

Maybe 'm=variableDeclaration' didn't match anything in the input...


YINGAnnie wrote: 


 
 
Sorry ,I forgot to mention, I corrected $m.end.
 
Now, I am using {tokens.replace($m.start, $m.stop, "something else");}
 
but I got java.lang.NullPointerException  error.
 
It seems $m is null.
 
 
Annie
 

 


Date: Wed, 25 Mar 2009 08:40:46 +0530
From: indhu.b at s7software.com
To: yimm8369 at hotmail.com
CC: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Can TokenRewriteStream be applied to rules?

There was a typo in my mail. It is $m.stop and not $m.end. Sorry :-)

And here is the documentation: http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1_parser_rule_return_scope.html

:-)

YINGAnnie wrote: 


 
 
Well, I tried it ,but this time the error is : java.lang.NullPointerException.
 
Did I do something wrong?
 
Thanks,
 
 
Annie
 

 

 
> Date: Wed, 25 Mar 2009 08:22:04 +0530
> From: indhu.b at s7software.com
> To: yimm8369 at hotmail.com
> CC: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Can TokenRewriteStream be applied to rules?
> 
> This will work:
> 
> variableStatement
> : VAR? variableDeclaration ( COMMA m=variableDeclaration )* semic
> {tokens.replace($m.start, $m.end, "something else");} &n bsp;
> ;
> 
> $m will be of type variableDeclar ation_ret urn which will be subclass of
> 'ParserRuleReturnScope'. $m is not Token.
> 
> 
> - Indhu
> 
> 
> YINGAnnie wrote:
> > Hi again,
> >
> > TokenRewriteStream can only replace the declared token, not the rule.
> > right?
> >
> > for example,If I want to replace VAR, it works fine, But if I want to
> > replace variableDeclaration , the error said $a can no t be resolved.
> >
> > variableStatement
> > : m= VAR? variableDeclaration ( COMMA variableDeclaration )* semic
> > {tokens.replace($m, "something else");}
> > ;
> >
> >
> > variableStatement
> > : VAR? variableDeclaration ( COMMA m=variableDeclaration )* semic
> > {tokens.replace($m, "something else");} &n bsp;
> > ;
> >
> > So how can I replace variableDeclaration ?
> >
> > T hanks in a dvance.
> >
> > Annie
> > ------------------------------------------------------------------------
> > 更多热辣资讯尽在新版MSN首页! 立刻访问! <http://cn.msn.com/>
> > ------------------------------------------------------------------------
> >
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr- interest/your-email-address
> > 
> 



微软地图实时路况,为您节省的不仅仅是时间! 立即查看!



更多热辣资讯尽在新版MSN首页! 立刻访问!



更多热辣资讯尽在新版MSN首页! 立刻访问!

_________________________________________________________________
MSN 表情魔法书,改变你的对话时代!
http://im.live.cn/emoticons/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090325/7ce026a9/attachment.html 


More information about the antlr-interest mailing list