[antlr-interest] Help with a tree grammar: losing a list of statements

Pauba, Kevin L KLPauba at west.com
Tue Dec 1 10:06:05 PST 2009


Thanks for the helpful hints, Jim.

Using the debugging method you described makes me think the statement rule's st isn't right - I'll have to do some more reading/learning since the only st that was used was in the "while" rule.

Kevin

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
Sent: Tuesday, December 01, 2009 11:49 AM
To: antlr-interest
Subject: Re: [antlr-interest] Help with a tree grammar: losing a list of statements

$s is the correct reference, but it is a collection of whatever the statement rule returns, so you may need to use an iterator in your string template. , or it might just be that your statement rule isn't setting up its st properly.

stats={$s}

then

..., stats) ::= <<
...
<stats:{<it>}; separator="\n">

Your reference to $text is the text for the whole node, and so you get the while keyword too. So, check your  statement rule generates a good st, then use $s=statement and just pass in  $s.st to check that just one statement works, then go to s+= and see if that works, then add an iterator in the template and see if that works. Use small incremental changes to see where your problem lies, rather than just stabbing in the dark ;-)

Also do not forget that you do not HAVE to use rewrite rules, you can create the template in an action, then repeatedly set the stats attribute in your loop, which will create a collection of StringTemplate.

Jim

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


More information about the antlr-interest mailing list