}
d->parent=parent;
d->tokens=reduceTokens(toks);
- qDebug()<<"expression:"<<d->tokens;
+ qDebug()<<"tokens:"<<d->tokens;
//check for nothing and complain
if(d->tokens.size()==0){
d->type=Exception;
return QVariant();
}
+void printExpression(QDebug&dbg,const Expression&ex,int level)
+{
+ printspaces(dbg,level);
+ dbg<<"Expression(type=";
+ switch(ex.d->type){
+ case Expression::Literal:dbg<<"Literal";break;
+ case Expression::Variable:dbg<<"Variable";break;
+ case Expression::Constant:dbg<<"Constant";break;
+ case Expression::Function:dbg<<"Function";break;
+ case Expression::Parentheses:dbg<<"Parentheses";break;
+ case Expression::UnaryOp:dbg<<"UnaryOperator";break;
+ case Expression::BinaryOp:dbg<<"BinaryOperator";break;
+ case Expression::AssignmentOp:dbg<<"Assignment";break;
+ case Expression::Exception:dbg<<"Exception";break;
+ default:dbg<<"Unknown:"<<(int)ex.d->type;break;
+ }
+ if(ex.d->excep.errorType()!=ELAM::Exception::NoError)
+ dbg<<",exception="<<ex.d->excep;
+ if(ex.d->subexpr.size()>0){
+ dbg<<",subexpressions:";
+ for(int i=0;i<ex.d->subexpr.size();i++){
+ dbg<<"\n";
+ printExpression(dbg,ex.d->subexpr[i],level+1);
+ }
+ }
+ dbg<<")";
+}
+
+QDebug& operator<<(QDebug&dbg,const Expression&ex)
+{
+ dbg.nospace();
+ printExpression(dbg,ex,0);
+ return dbg.space();
+}
};
\ No newline at end of file
///evaluates the expression and returns the result of the evaluation
QVariant evaluate();
private:
+ friend void printExpression(QDebug&,const Expression&,int);
///scan tokens and decide what specific sub-type they are
QList<Token>classifyTokens(QList<Token> toks);
/**pushes parentheses and function arguments into the sub-tokens of their parents;
void functionInit();
};
+QDebug& operator<<(QDebug&,const Expression&);
+
//end of namespace
};
{
IntEngine ie;
FloatEngine::configureFloatEngine(ie);
- QString ex="a=b+=345*int(3.5)+ - -(+65/(5))";
+ QString exs="a=b+=345*int(3.5)+ - -(+65/(5))";
+ Expression ex=ie.expression(exs);
+ qDebug()<<"expression:"<<ex;
QVariant v=ie.evaluate(ex);
}