private Object compilePrimaryExpression(Expression expr)
{
if( expr instanceof PrimaryExpression )
{
Symbol symbol = symtbl.getSymbol((String)((PrimaryExpression) expr).getTuples().get(0));
if( symbol == null )
{
//no symbol found, so defaults to this
symbol = symtbl.getSymbol("this");
}
Object value = symbol.getValue();
for( int i=0; i< ((PrimaryExpression) expr).getTuples().size(); i++ )
{
String fieldName = (String)((PrimaryExpression) expr).getTuples().get(i);
if (!fieldName.equals("this"))
{
value = getFieldValue(value, fieldName);
}
}
stack.push(value);
return value;
}
if( expr instanceof InvokeExpression )
{
if(((InvokeExpression) expr).getTuples().get(0).toString().equals("count"))
{
Symbol symbol = symtbl.getSymbol("set");
Object it = symbol.getValue();
SetExpression setexpr = new SetExpression((Collection) it);
Object value = setexpr.count((Expression)((InvokeExpression) expr).getParameters().get(0), this);
stack.push(value);
return value;
}
else if(((InvokeExpression) expr).getTuples().get(0).toString().equals("sum"))
{
Symbol symbol = symtbl.getSymbol("set");
Object it = symbol.getValue();
SetExpression setexpr = new SetExpression((Collection) it);
Object value = setexpr.sum((Expression)((InvokeExpression) expr).getParameters().get(0), this, symtbl);
stack.push(value);
return value;
}
else if(((InvokeExpression) expr).getTuples().get(0).toString().equals("avg"))
{
Symbol symbol = symtbl.getSymbol("set");
Object it = symbol.getValue();
SetExpression setexpr = new SetExpression((Collection) it);
Object value = setexpr.avg((Expression)((InvokeExpression) expr).getParameters().get(0), this, symtbl);
stack.push(value);
return value;
}
else if(((InvokeExpression) expr).getTuples().get(0).toString().equals("min"))
{
Symbol symbol = symtbl.getSymbol("set");
Object it = symbol.getValue();
SetExpression setexpr = new SetExpression((Collection) it);
Object value = setexpr.min((Expression)((InvokeExpression) expr).getParameters().get(0), this, symtbl);
stack.push(value);
return value;
}
else if(((InvokeExpression) expr).getTuples().get(0).toString().equals("max"))
{
Symbol symbol = symtbl.getSymbol("set");
Object it = symbol.getValue();
SetExpression setexpr = new SetExpression((Collection) it);
Object value = setexpr.max((Expression)((InvokeExpression) expr).getParameters().get(0), this, symtbl);
stack.push(value);
return value;
}