[antlr-interest] Re: tree parser generating templates
duboimat at iro.umontreal.ca
duboimat at iro.umontreal.ca
Thu Dec 15 10:24:34 PST 2005
>
> On Dec 15, 2005, at 2:39 AM, Bryan Ewbank wrote:
>
>> Sohail,
>>
>> Can you please elaborate? I don't think I understand what you mean;
>> if I do, I don't see how it would be done.
>>
>> How would you use a TreeParser to /generate/ a StringTemplate?
>
> In v2, you just manually request a template for, say, assignment and
> stuff it with values. Either return or spit out that template's
> output. In v3, it's a bit easier but the same process:
>
> tree grammar T;
> options { output=template; }
> ...
> assign : ID '=' expr -> assigntemplate(lhs={$ID.text}, rhs=
> {$expr.template}) ;
>
> In this case, assign returns a template. [actually, the $ID.text is
> broken in the tree parser for v3 at the moment, but that is my
> intention]. The assigntemplate is defined somewhere in a group file.
>
> Ter
>
In v2, i have tried to manually request a template like
program : #( PROGRAM( block )+
{
program_st.setAttribute("header","My header");
...
block : #( BLOCK( thread )+
{
StringTemplate t= printmodele("module");
program_st.setAttribute("module",t);
thread_st.reset();
}
and I have a init function
class LangWalker extends TreeParser;
{
StringTemplateGroup group; TextReader str;
StringTemplate program_st,header_st,block_st,thread_st,
assign_st,plus_st,moins_st,div_st,star_st;
StringTemplate code;
public void init()
{
str = new StreamReader("program.st");
group= new StringTemplateGroup(str);
...
To build the program I have to put a template into another one.
if i build lines I have to regroup it to build a block .
It work only when i use st for a subset of the program . I can't regroup all
subset to built a program without having repetition from another subset with a
new value. May be a need to reset the template with its value.
Is there another to do a manually request in v2?
mat
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
More information about the antlr-interest
mailing list