[antlr-interest] What to do when you need to semantically validate	an expression?
    Bill Mayfield 
    antlr at telenet.be
       
    Wed Dec 13 18:31:39 PST 2006
    
    
  
Hi,
I need to create a formula language for our product. The formulas 
entered need to be translated to SQL statements that can be executed 
against our database.
Basically I would create a lexer and parser for the formula language 
using ANTLR so that I can build an expression tree. But then I'm 
somewhat *stuck*.
1. Do I let ANTLR create an AST automatically or do I create a tree by 
hand with more meaningful types like Expression, Sum, etc...
2. The parsed result needs to be semantically validated. I presume I 
need to write custom validation logic in each type for this??? This 
might answer question 1?
for instance: (pseudo-code)
public class Sum
{
    private Expression left;
    private Expression right;
    public void validate()
    {
       //validate whether left and right are of correct datatypes
    }
}
3. Would it be better to write a translater by hand to translate the 
expression tree to SQL or would it be better to use a treewalker to do 
this?
I'm new to ANTLR, have just read (most of) the spec, and I could use 
some guidance.
Thanks!
    
    
More information about the antlr-interest
mailing list