[antlr-interest] Would antlr be suited for this task?

Gary Rosales gary.rosales at neovera.com
Fri Oct 10 12:45:38 PDT 2008


Hi, 

 

I am a newbie with ANTLR but I have a question that it's been itching me to
ask for a while. I am in a project where we are migrating a bunch of c code
that has embedded SQL (E/SQL from Informix) to c code that has also embedded
SQL but in another format (Pro*C from Oracle). The Informix c code (ec
files) is full of non-ANSI 92 SQL that needs to be converted, this code is
inside strcpy, sprintf, strcat, and so on. For instance, code fragments
like:

 

strcpy(sqlstr, "select x, y, z from t1, outer t2, outer t3 where t1_t2.id =
t2_id  and t2_t3.id = t3.id");

 

would be translated to 

 

strcpy(sqlstr, "select x,y,z from t1 left join t2 on t1_t2.id = t2_id  left
join t3 on t2_t3 = t3.id ");

 

and 

 

  strcpy(UpdSqlStr, "UPDATE ");

  strcat(UpdSqlStr, HELLO);

  strcat(UpdSqlStr, " SET (");

  strcat(UpdSqlStr, "foo,");

  strcat(UpdSqlStr, "bar");

  strcat(UpdSqlStr, ") = (");

 

  strcpy(sqlcomstr, UpdSqlStr);

  strcat(sqlcomstr, ":p_var,");             

  strcat(sqlcomstr, ":p_var");        

  strcat(sqlcomstr, " WHERE hello.name = :p_var");

 

would be :

 

  strcpy(UpdSqlStr, "UPDATE ");

  strcat(UpdSqlStr, HELLO);

  strcat(UpdSqlStr, " SET foo =:p_var, bar=:p_var ");

  strcat(UpdSqlStr, " WHERE hello.name =:p_var ");

 

 

there are many fragments like this (but they are longer and more complex).  

There is already a tool that does this that it's provided by Oracle, but
it's incomplete because it doesn't work on cases like the example I just
gave. So we do use the tool; the tool takes care of other embedded sql that
it's not within strings variables but, would it be possible to create a
compiler to transform the dynamic sql that it's generated in the variables.
There are many files that use definitions on other files (macros and such)
that are used  for the business logic in the dynamic sql, so the compiler
would have to link the files and do semantic checking. Is this feasible? The
approach we have right now is using a custom framework with match and
replace files for the source, it's quite tedious and I 'd love to hear of a
better way to do this. I would think it's possible but I'd rather ask people
who have much more experienced than me with compiler creation and ANTLR.

 

Thank you for your help.

 

Gary Rosales

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081010/eb73456b/attachment.html 


More information about the antlr-interest mailing list