Try input.mark() and input.release() instead? Jim
> -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Christian Pontesegger > Sent: Thursday, February 18, 2010 8:18 AM > To: [email protected] > Subject: [antlr-interest] Tree Grammar for loops > > Hi there, > > I hope this list is intendend to ask for support. > > I am desperately trying to write a tree grammar for a do-while loop. I > got the following so far: > > The source for the loop: > ---------------------------- > > int $loop = 0 > do { > $loop = $loop + 1 > foo() > } while ($loop < 3) > > > for such a loop my parser gives me: > --------------------------------------- > > (= int ($ loop) 0) (do { (= ($ loop) (+ ($ loop) 1)) foo } (< ($ > loop) 3)) > > > TreeGrammar.g: > ----------------------- > > doWhileStatement > : > ^( > head='do' '{' { int loopHead = > ((CommonTree) head).getTokenStartIndex(); } > statementList > '}' e=expression { if (e.isTrue()) { > > input.seek(loopHead); > > doWhileStatement(); > } > } > ) > ; > > the TreeGrammar is able to recognize the loop, but I am not able to run > the loop a second time. as calling doWhileStatement() runs into an > exception. How can I traverse parts of my tree again? > > I was looking for tutorials and found: > http://www.antlr.org/wiki/display/CS652/Tree-based+interpreters > > ... but it seems a bit out of date. > > any help is appreciated > regards > Christian > > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your- > email-address List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
