[antlr-interest] Tree Grammar for loops
Jim Idle
jimi at temporal-wave.com
Thu Feb 18 08:37:38 PST 2010
Try input.mark() and input.release() instead?
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Christian Pontesegger
> Sent: Thursday, February 18, 2010 8:18 AM
> To: antlr-interest at antlr.org
> 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
More information about the antlr-interest
mailing list