Though you specify x and y as return, there is also still a $st. You can either build the $dst in the b rule or use the results of the b rule in a caller to build a template, but b won't build you anything by default because you changed the return pattern. So use the bs return, create a template using x and u, add that template to a list of template, pass that list to the template constructor and not the raw $bs.
Jim > -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Sanchay Harneja > Sent: Wednesday, April 20, 2011 5:48 AM > To: [email protected] > Subject: [antlr-interest] How to communicate between rules in a tree > grammar > > Hi, > > I am new to ANTLR, using it to create a DSL. So far I've been able to > write a parser grammar, a tree grammar & string template file. Its all > working as I expect. > > But I have a niggling feeling that I may not be using the tree grammar > & stg in an idiomatic manner. I'll ask my question using an example, > suppose the tree grammar has rules a, b, c: > > options { > ... > output=template; > } > > a : > // ... > -> template( .. ) > > b : returns [ int x, int y ] > // only return no string template > > c : b (as+=a)+ > -> c(x={$b.x}, y={$b.y}, as={$as}) > > This works fine, but is it an "correct" way? In the generated code the > type of $b is b_return while the type of $as is List(containing > StringTemplate objects). > > Now suppose I have a rule like: > > d : a (bs+=b)+ > -> d(a={$a}, bs={$bs}) > > This doesn't work, as the type of $bs is List containing StringTemplate > objects, but not b_return objects. Since I haven't defined a > StringTemplate for b, this doesn't work. > > Maybe this is the right thing to do, i.e., in rule c type of $b is > b_return, whereas in rule d type of $bs is List(containing > StringTemplates as opposed to b_returns). But then how I communicate > the structure of b (i.e. x, y) to d ? One way is maintaining a global > memory for this. Is there any other way? > How would you guys tackle this issue. > > Thanks! > Sanchay > > 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.
