[antlr-interest] Re: [stringtemplate-interest] Re: cminus.g

eric nelson wirecracker at gmail.com
Sat Oct 22 06:04:18 PDT 2005


The way I've started to think about it is just that it doesn't make sense to
have a template for the "declaration" rule in cminus.g. A declaration is
either a function or a variable, but we just let the respective
"function(type,name,args,locals,stats)"
and "variable(type,name)" templates (via the p determine the output grammar
depending on which is applicable.

"declaration" and "block" seem to serve only as helpers, so mabye it would
have been more clear if they had been prefixed with "protected" (isn't that
the convention with ANTLR?).
 Yes, mabye the example was just supposed to show the different approaches.
 At first I thought it would also be ok to do something like this (assuming
the templates were modified accordingly):

program returns [StringTemplate code=template("program")]

: (code.setAttribute(declaration))+

;

 declaration returns [StringTemplate code = template("declaration")]

{StringTemplate f=null,v=null;}

: v=variable {code.setAttribute("globals", v);}

| f=function {code.setAttribute("functions", f);}

;
EXCEPT that the attributes "globals" and "functions" are in the program
template. It seems the appropriate place. In other words it would be out of
place to have "globals" and "functions" be attributes of "declaration"
because any single declaration matches to EITHER a global or a function.
Does that seem logical? Anyone want to confirm or disconfirm? I have been
racking my head for 2 or 3 days over this ... by now mabye my brain is just
willing to accept ANY logic ;)
 Thanks for the response Laurent!
  - e

 On 10/22/05, Laurent Vaucher <blo.b at infonie.fr> wrote:
>
> Well, the way I understand the difference between program, which
> returns a value, and declaration, which takes a stringtemplate as a
> parameter is the same as between a 'purely functional' function and a
> 'side-effect' one. The second is used to 'fill' an already existing
> object with additional data.
> It might be possible to convert the whole thing to a 'purely
> functional' style, but I think one point of the article was to show
> all the possible approaches with the library. The other possible
> explanation is 'purely pragmatic': do the simplest thing that might
> possibly work ((c) Ward Cunningham). If one style is simpler to use
> in some cases, just use it.
>
>
> Laurent.
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20051022/8495fde8/attachment.html


More information about the antlr-interest mailing list