4

Do we have a PL/SQL grammer for Java target yet? I got the one for C#, but need for Java target.

I would like to use this with ANTLR to generate Java using StringTemplates. I've gone through the documentation and have a decent understanding of how to achieve this, just wanted to check if any one has already done this kind of thing.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Abhay Chaware
  • 333
  • 4
  • 14

1 Answers1

3

Well, there's a grammar at the ANTLR site: http://antlr.org/grammar/1279318813752/PLSQL.g

The author says it doesn't parse the SQL part.

I don't know what you expect to be able to generate reading just the syntax. You usually need much more than that. See my answer here as to why not: antlr generate ast for c and parse the ast

EDIT: OP says he wants to translate PL/SQL code to Java. See my answer on what it takes to build a language-to-language translator: What kinds of patterns could I enforce on the code to make it easier to translate to another programming language?

Community
  • 1
  • 1
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • 1
    Yes, i am looking at that grammer from Patrick.. what I intend to do is, modify it to use StringTemplate to generate java source code. Any hint on how to go about doing it ? – Abhay Chaware Nov 11 '11 at 04:30
  • You haven't said what parts of the PLSQL are interesting, and what kind of Java you want to generate, so no hints except considerable pessimism because ASTs generally aren't enough. When you can explain what you want to do clearly, I might be able to suggest what you will really need. – Ira Baxter Nov 11 '11 at 05:00
  • I have a few PLSQL stored procedures, which I would like to convert to java/sqlj classes automatically. With the antlr and stringtemplates, I would like to generate java/sqlj source files from the plsql procedures. – Abhay Chaware Nov 11 '11 at 05:43
  • If you have only a modest amount of code to convert, you'll be done a lot faster if you just do it by hand. Code translators take time to build, and only make sense if you will translate a lot in one lump, or a little bit repeatedly. And doing real translation well will require you have a lot more than just the AST; I assume you read the other answer? – Ira Baxter Nov 11 '11 at 06:03
  • Yes I read both the answers .. I understand that it is not an easy task to do. But that's what makes it more interesting. My attempt is to write such a tool that can be used over and over. Btw, I was able to generate a sample / empty java class using Patrick's grammer and stringtemplate with antlr. So conceptually things seem to be fine, but I must agree that its loads of work .. – Abhay Chaware Nov 11 '11 at 06:56
  • ... from your history of questions, you sound pretty determined to to this. OK, maybe you're one of the few that will succeed. Yes, you'll find it is a LOT of work. – Ira Baxter Nov 11 '11 at 07:07
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/4906/discussion-between-abhay-chaware-and-ira-baxter) – Abhay Chaware Nov 11 '11 at 10:57
  • 1
    ALL: I tried to have an intelligent conversation in the chat room. It has some stupid 5 or 10 line limit, and rejected my long response to OP. Having wasted my time throroughly, I won't spend any more energy in the chat room, and will instead annoy the the StackOverflow machinery by continuing to post "extended discussions". – Ira Baxter Nov 12 '11 at 03:26
  • I've posted an ANTLR question here .. can you help ?http://stackoverflow.com/questions/8117836/antlr-rewriting-output-of-a-rule – Abhay Chaware Nov 14 '11 at 06:11