%{ import java.io.*; %} Types = { Int < Real Bool } class Int{ Type aritmetical (Type t){ if (majorType(t) == null) throw new TypeException("Operation aritmetical not allowed between Int and " + t.getName()); return t; } Type mod() { return Type.typesTable.getType("Int"); } Type unarySign() { return Type.typesTable.getType("Int"); } boolean makeBool(SemanticValue v) { return v.dval != 0; } void print(SemanticValue v) { System.out.println(info() + ", Value = " + (int)v.dval); } Type implicitCast(Type t) { if (t.getName().equals("Bool")) return Type.typesTable.getType("Bool"); return super.implicitCast(t); } } class BaseType{ String info(){ return "Type -> " + getName(); } Type majorType(Type t) { Type ret = implicitCast(t); if (ret == null) ret = t.implicitCast(Type.typesTable.getType(getName())); return ret; } Type not() { Type t = implicitCast(Type.typesTable.getType("Bool")); if (t == null) throw new TypeException("Cannot make operation upon a " + getName()); return t; } Type logical() { Type t = implicitCast(Type.typesTable.getType("Bool")); if (t == null) throw new TypeException("Cannot make logical operationsnot upon a " + getName()); return t; } } class Real { Type aritmetical (Type t){ if (majorType(t) == null) throw new TypeException("Operation aritmetical not allowed between Real and " + t.getType()); return majorType(t); } Type unarySign() { return Type.typesTable.getType("Real"); } void print(SemanticValue v) { System.out.println(info() + ", Value = " + v.dval); } } class Bool { boolean makeBool(SemanticValue v) { return v.bval; } void print(SemanticValue v) { System.out.println(info() + ", Value = " + v.bval); } }