[antlr-interest] V3: How to translate one language to another

Bill Mayfield antlr at telenet.be
Fri Dec 29 06:49:14 PST 2006


Hi,

I'm working on a project that requires me to translate a domain specific 
query language to a plain SQL statements. This domain specific language 
is object-oriented instead of relational like SQL.

For example:  (each employee is member of a department)

SELECT firstname + ' ' + lastname, department.name FROM employees

needs to be translated into something like:

SELECT e.firstname + ' ' + e.lastname, d.name from employees e LEFT JOIN 
departments d ON e.departmentid = d.id



I have the grammer for my parser figured out and I can build an AST that 
represents the language but I'm kind of STUCK on what to do next. I need 
to semantically validate the query; but how? Do I do this in a 
treewalker? Do I need a symbol table? And how can I translate the query 
into SQL statements? Do I use templates? TemplateString?


I'm not so much interested in any 'specific' help (altough that would be 
appreciated). I'm interested in the steps that are needed to get to the 
solution. How many treewalkers? What does each do etc...


If you have any idea, it would be greatly appreciated!


Bill



BTW: I've decided to use ANTLR v3


More information about the antlr-interest mailing list