[antlr-interest] repeating the parsing of a subtree

Claude Moulin claude.moulin at hds.utc.fr
Thu Nov 5 11:22:05 PST 2009


Hello Jim,

Thank you very much.

I did not know how to deal with these methods.

Following your advice my rule is now:

 

repeat 

@init{  int mark_before; }

:              

   ^(REPEAT a = atom  {mark_before = input.mark();}  list = .  ) 

         {     for (int i = 0; i < $a.r ; i++)  {

                   input.rewind(mark_before);

                   list_instructions();

              } 

             input.rewind(input.index() + 1);

             // need to skip one node to reach the right position

          }                    

   ;

 

Claude

------------------------------

 

Message: 33

Date: Thu, 05 Nov 2009 08:36:05 -0800

From: "Jim Idle" <jimi at temporal-wave.com>

Subject: Re: [antlr-interest] repeating the parsing of a subtree

To: "antlr-interest at antlr.org" <antlr-interest at antlr.org>

Message-ID: <2230d40e6d2bac41bad38daa03de7e9a at temporal-wave.com>

Content-Type: text/plain;    charset="us-ascii"

 

Should you not be using the push(index) and pop() of the
CommonTreeNodeStream or mark() and rewind()? The index() method will
give you the current location when you hit the node that you want to
repeat.

 

Jim

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091105/ab822871/attachment.html 


More information about the antlr-interest mailing list