Hello I am trying to implement a translator. Since it is coming more and more complicated I will try to explain better what I'd like to implement.
I need to specify a new java like language. This language must implement all structure of a java method: variable declaration, expression, conditional expression, parenthesis expressions and so on... The language will work with vectors, constants and booleans. It has different function: log, avg, sqrt as wll as sum, diff, shift and so on. This language must be translated into plsql and other languages. So the method defined will become a StoredProcedure or a c++ function or whatever. I need to consider also the math constraints such as priority of operators (+,-,*,/, <<, >> and so on...).
I already get this hint: Decompose expression in base operation: ANTLR + StringTemplate
I need to know the best solution for achieving my task. I suppose I have to use all your solution in a pipelined fashion, but i don't want to use a trial and error method for the solution.
I tried different (separated) solutions, but putting all together is hard for me.
My last problem is to separate an expression between vector and constant and an expression between vector and vector. In fact using plsql I have different function for handling these situations. i.e. an expression vactor1+5 (or 5+vector1) must be translated like PKG_FUN.constant_sum(cursor1, 5) instead vector1+vector2 must be translated as PKG_FUN.vector_sum(vector1, vector2). Moreover I can have functions or expressions that produce vector and other that produces constant and this must be considered when analyzing an expression (i.e. vector a = vector1 +((5+var2)*ln(vector2)*2)^2).
An example of this language can be:
DEFINE my_new_method(date date_from, date date_to, long variable1, long variable2){
vector result;
vector out1;
vector out2;
int max = -5+(4);
out1 = GET(date_from, date_to, variable1, 20);
out2 = GET(date_from, date_to, variable2);
if(avg(out1) > max)
{
result = sqrt(ln(out2) + max)*4;
}else
{
result = out1 + ln(out1) + avg(out2);
}
for(int i=0; i<result.length ; i++)
{
int num = result.get(i);
result.set(num*5, i);
}
return result;
}
I should translate it in plsql, c or c++ or other languages.
Any help would be appreciated.