[antlr-interest] Repeating pieces of a tree.

Jan van der Ven jhvdven at xs4all.nl
Thu Apr 26 14:25:40 PDT 2007


Dear list,


I am working on a SQL-92 (from Mr. Vnuk) grammar in 2.7.7.

In SQL you can define a relation that spans more than one column:
ALTER TABLE mySchema.myTable ADD FOREIGN KEY (B,C,D) REFERENCES 
ourServer.yourSchema.Table (COL1, COl2, COL3);

I am trying to create a tree that repeats: ourServer.yourSchema.Table 
for each column (COL1, COL2, COL3).

What I have tried so far was not very successfull (why post otherwise?):
//  Rule #439 <ref_column_list> was replace by <column_name_list>
//{ Rule #435 <refd_table_and_columns>
refd_table_and_columns :
//    tn:table_name (LEFT_PAREN! 
/*ref_column_list*/(r1:REGULAR_ID^|d1:DELIMITED_ID^) (COMMA! 
(r2:REGULAR_ID^|d2:DELIMITED_ID^))* RIGHT_PAREN!)?
//    tn:table_name! (LEFT_PAREN! 
/*ref_column_list*/(r1:REGULAR_ID!{##=#([COLUMN_LIST, 
"jopie"],#r1,#tn);}|d1:DELIMITED_ID^)  (COMMA! 
(r2:REGULAR_ID!{##=#([COLUMN_LIST, 
"pietje"],#r2,#tn);}|d2:DELIMITED_ID^))* RIGHT_PAREN!)?
//    tn:table_name (LEFT_PAREN! 
/*ref_column_list*/(r1:REGULAR_ID^|d1:DELIMITED_ID^)  (COMMA! 
(r2:REGULAR_ID^|d2:DELIMITED_ID^))* RIGHT_PAREN!)?
    tn:table_name! (LEFT_PAREN! 
/*ref_column_list*/(r1:REGULAR_ID!{##=#(#r1, #tn);}|d1:DELIMITED_ID^)  
(COMMA! (r2:REGULAR_ID!{##=#(#r2, #tn);}|d2:DELIMITED_ID^))* RIGHT_PAREN!)?
;

I am going for a tree with the column tops and a child table and a 
schema child of that and a server child of the schema. The table_name 
rule handles schema and server.

My best try gave me a tree that listed COL3, and then COL2 as a child 
and the COL1 and then the table,schema, server stuff.

Any advise would be greatly appreciated.


Kind regards,


Jan




More information about the antlr-interest mailing list