Abhay Chaware
Abhay Chaware

Reputation: 333

Can a lexer/parser be used as a transcoder?

I am looking at converting plsql procedures / packages to java classes. I just came across the "ANTLR PL/SQL 11g parser" (link). Still trying to understand what it does and how to use it. Assuming that I have mapping between plsql constructs and java constructs,is it possible to use this plsql parser to generate java code ?

Upvotes: 1

Views: 285

Answers (3)

robermorales
robermorales

Reputation: 3488

I would use Xtext and Xtend. Really magical. Please see their videos on vimeo.

Upvotes: 0

Ira Baxter
Ira Baxter

Reputation: 95334

Another poster says "a parser isn't enough".

I agree, but want to make the case that a parser is a long way from making this practical (even assuming it builds a complete AST).

You also need name and type resolution as a minimum so you know which types and operators in Java to use when you encounter a PLSQL operator. To do a good job, you might need various kinds of flow analysis (control and data flow).

See What kinds of patterns could I enforce on the code to make it easier to translate to another programming language? for some discussion about the difficulties.

Upvotes: 2

Slartibartfast
Slartibartfast

Reputation: 8805

Yes, but just throwing grammar at the problem isn't enough. You'll need to figure out how you gonna map PL/SQL semantics to Java's. Using linked parser will probably help, so as the abstract syntax tree walker provided in the same project. Generating Java code should not be difficult, but not a trivial undertaking either.

Upvotes: 1

Related Questions