import es.uniovi.lsi.typeChecking.errorHandling.TypeException; public class Evaluator { Type.TypesTableAdapter typesTable = Type.typesTable; SemanticValue getConst(SemanticValue v, String s) { SemanticValue r = new SemanticValue(v.dval); r.bval = v.bval; try { r.type = typesTable.getType(s); } catch (TypeException e) { System.err.println(e); } return r; } SemanticValue unarySign(SemanticValue v, char operator) { SemanticValue r = new SemanticValue(v.dval); try { r.type = v.type.unarySign();//TypeChecking if (operator == '-') r.dval = -r.dval; } catch (TypeException e) { System.err.println(e); } return r; } SemanticValue not(SemanticValue v) { SemanticValue r = new SemanticValue(v.dval); try { r.type = v.type.not(); //TypeChecking r.bval = !makeBool(v);//TypeChecking Interpreter Interaction } catch (TypeException e) { System.err.println(e); } return r; } SemanticValue aritmetical(SemanticValue v1, SemanticValue v2, char operator) { SemanticValue r = new SemanticValue(v1.dval); try { r.type = v1.type.aritmetical(v2.type);//TypeChecking switch (operator) { case '+' : r.dval += v2.dval; break; case '-' : r.dval -= v2.dval; break; case '/' : r.dval /= v2.dval; break; case '*' : r.dval *= v2.dval; break; default: throw new TypeException("Unknown operator " + operator); } } catch (TypeException e) { System.err.println(e); } return r; } SemanticValue mod (SemanticValue v1, SemanticValue v2) { SemanticValue r = new SemanticValue(v1.dval); try { v1.type.mod();//TypeChecking r.type = v2.type.mod();//TypeChecking r.dval = (int)v1.dval % (int)v2.dval; } catch (TypeException e) { System.err.println(e); } return r; } SemanticValue logical(SemanticValue v1, SemanticValue v2, char operator) { SemanticValue r = new SemanticValue(v1.dval); try { v1.type.logical(); //TypeChecking r.type = v2.type.logical(); //TypeChecking boolean b1 = makeBool(v1); boolean b2 = makeBool(v2); switch (operator) { case '&' : r.bval = b1 && b2; break; case '|' : r.bval = b1 || b2; break; default: throw new TypeException("Unknown operator " + operator); } } catch (TypeException e) { System.err.println(e); } return r; } boolean makeBool (SemanticValue v) throws TypeException { return v.type.makeBool(v); } void print(SemanticValue v){ try { v.type.print(v); } catch (TypeException e) { System.err.println(e); } } }