[antlr-interest] template generation for dumb rules

Grzegorz Cieslewski cieslewski at hcs.ufl.edu
Tue Mar 25 10:14:18 PDT 2008


I think that the concatenating two templates would be an optimal
solution.  I have many rules that consist of 2 or more sub-rules.  If
the user does not like the default rule he can overwrite it with his
own,  which in my opinion is better than adding many simple templates
just to get a token to print that is nested 20 rules down.  Also, this
would make it similar in behavior to the AST rewriting approach where
you don't have to specify a rewrite rule to get a tree back.

Since that would change the default behavior of the ANTLR, I think
that adding another option like "use_default_template=true" or
something would make life easier.

Just my 2 cents,

Greg

On Tue, Mar 25, 2008 at 10:59 AM, Terence Parr <parrt at cs.usfca.edu> wrote:
> try
>
>  a : b -> {$b.st} | c -> {$c.st} ;
>
>  I'm waiting to see more of these patterns before I alter the behavior
>  or add a shorthand.  That case is obvious but what about:
>
>  a : b c ;
>
>  now what to return?  The "cat"?
>
>  Ter
>
>
>
>  On Mar 25, 2008, at 6:01 AM, Grzegorz Cieslewski wrote:
>
>  > I am in the similar situation.  In my grammar I have about 100 rules
>  > like that.  I have saved some time by defining all templates in
>  > separate file and creating template  simple(a)::="<a>" and then
>  > invoking it multiple times whenever I have a "dumb" rule.  If any one
>  > knows a better way of doing this I am all ears.
>  >
>  > Greg
>  >
>  > On Wed, Mar 19, 2008 at 10:28 AM, Philippe Faes
>  > <ph_reader at faes.net> wrote:
>  >> Dear ANTLR-gang,
>  >>
>  >> I'm writing an ANTLR stringtemplate generator, which translates a
>  >> tree to a
>  >> string template. My grammar has many rules like this:
>  >> a : b | c;
>  >> The generation rule that I want for these rules looks something like:
>  >>  a: b -> template(b={$b.st}) "<b>"
>  >>   | c -> template(c={$c.st}) "<c>";
>  >> In fact the stringtemplate just repeats whatever the underlying
>  >> rule would
>  >> return as stringtemplate.
>  >> These rules have very little extra value, but they require a lot
>  >> of typing,
>  >> and decrease the general readability of the grammar.
>  >>  I was hoping to find a way of setting this "braindead"
>  >> stringtemplate rule
>  >> as a default. Is there any way somebody can save me a lot of time
>  >> typing
>  >> these rules?
>  >>
>  >> kind regards
>  >> Philippe
>  >>
>  >>
>  >
>  >
>  >
>  > --
>  > =====================================================
>  > Grzegorz Cieslewski
>  > Research Assistant
>  > High-performance Computing & Simulation (HCS) Research Laboratory
>  > University of Florida, Dept. of Electrical and Computer Engineering
>  > 330 Benton Hall, Gainesville, FL, 32611-6200
>  > Phone: (352) 392-9041
>  > Email: cieslewski at hcs.ufl.edu
>  > Web: www.hcs.ufl.edu
>  > =====================================================
>
>



-- 
=====================================================
Grzegorz Cieslewski
Research Assistant
High-performance Computing & Simulation (HCS) Research Laboratory
University of Florida, Dept. of Electrical and Computer Engineering
330 Benton Hall, Gainesville, FL, 32611-6200
Phone: (352) 392-9041
Email: cieslewski at hcs.ufl.edu
Web: www.hcs.ufl.edu
=====================================================


More information about the antlr-interest mailing list