[antlr-interest] Re: tree parser generating templates

duboimat at iro.umontreal.ca duboimat at iro.umontreal.ca
Thu Dec 15 11:01:27 PST 2005


>
> On Dec 15, 2005, at 10:24 AM, duboimat at iro.umontreal.ca wrote:
>> 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);
>
> Ok, first thing:use a group file format and StringTemplateGroup.  See 
>  the article I have up on using ANTLR+ST.
>
>>        ...
>>
>> 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.
>
> I have that functionality but I've never once used it...
>
>> Is there another to do a manually request in v2?
>
> see the article :)
>
> Ter
>
I have seen this article
Language Translation Using ANTLR and StringTemplate
I have begun my project with this article

my group file is included in program.st file.
In my program.st

group sim;
program(header,block) ::=<< Created by $header$   Program: $block$ >>
header()::=<<header>>
block(thread) ::=<< Block: $thread$ >>
thread(statement) ::= <<Thread : >>
...
assign(lhs,rhs) ::= << $lhs$ = $rhs$; >>
plus(lhs,rhs) ::= << $lhs$ + $rhs$ >>
moins(lhs,rhs) ::= << $lhs$ - $rhs$ >>
div(lhs,rhs) ::= << $lhs$ / $rhs$ >>
star(lhs,rhs) ::= << $lhs$ * $rhs$ >>

In my example , the program is composed of block, the block is composed of
thread , the thread is composed of statement ...

The article doesn't show how to use antlr + st with tree.
if I call template from tree parser class
like
        code = template("variable");        }
        code.setAttribute("type", t);
        code.setAttribute("name", d);

String template will not regroup all template together with its value to get a
final code.

mat




----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



More information about the antlr-interest mailing list