[antlr-interest] Template best practice type question.

Terence Parr parrt at cs.usfca.edu
Mon Sep 14 12:12:55 PDT 2009


[moving to ST interest]

Hi. Are you saying that you want to process the same data with  
multiple templates? or are you saying you want a template to be  
sensitive to the kind of data it's applied to?
Ter
On Sep 14, 2009, at 2:12 AM, craig at palantir.co.za wrote:

> Hi,
>
> I have a tree grammar that is walking a parsed tree and outputting SQL
> statements using templates.
>
> At particular points in the tree I need to generate join clauses and  
> where
> clauses. The template looks something like this.
>
> sql(tables, paths) ::= <<
> <tables>
> WHERE
> <paths>
>>>
>
> or(l, r) ::= <<
> <l>
> OR
> <r>
>>>
>
> and(l, r) ::= <<
> <l>
> AND
> <r>
>>>
>
> comparison(path, lv, rv, op) ::= <<
> <path> {<lv>} <op> {<rv>}
>>>
>
> paths generates nested OR/AND sections.
> My problem is that tables and paths are essentially the same thing.  
> The
> templates need to generate a set of JOIN clauses for the tables  
> part, and the
> set of OR/AND where conditions for the paths part. Only these are  
> exactly the
> same thing.
>
> There seems to be no general way of saying "generate the template  
> once in mode
> 'a', and then again in mode 'b'". I hope I am not being too vague. I  
> have the
> OR/AND clauses generating perfectly and am in the process of hacking  
> the table
> names into a list to generate that part of the template. I feel  
> there must be a
> better way.
>
> Thanks
> Regards
> Craig.
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list