Can a lexer/parser be used as a transcoder?

304 Views Asked by At

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 ?

3

There are 3 best solutions below

0
On BEST ANSWER

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.

0
On

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.

0
On

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