//############################################# //## file: SemanticValue.java //## An extension of ParserVal.java, //## to use with TyCC with the -JSemantic //## option //############################################# /** This class provides some of the functionality of the yacc/C 'union' directive */ public class SemanticValue { private static java.util.ArrayList errors = new java.util.ArrayList(); static boolean errorState= false; public static boolean getErrorState() { return errorState; } public static void clearErrorState() { errorState = false; } /** integer value of this 'union' */ public int ival; /** boolean value of this 'union' */ public boolean bval; /** double value of this 'union' */ public double dval; /** string value of this 'union' */ public String sval; /** type value of this 'union' */ public Type type; /** object value of this 'union' */ public Object obj; //############################################# //## C O N S T R U C T O R S //############################################# /** Initialize me as an int */ public SemanticValue(boolean val) { bval = val; } /** Initialize me as an int */ public SemanticValue(int val) { ival = val; } /** Initialize me as a double */ public SemanticValue(double val) { dval = val; } /** Initialize me as a string */ public SemanticValue(String val) { sval = val; } /** Initialize me as a string */ public SemanticValue(Type val) { type = val; } /** Initialize me as an Object */ public SemanticValue(Object val) { obj = val; } public SemanticValue() { } public static void addError(Exception e) { System.err.println("WRONG!: " + e.getMessage()); errorState = true; errors.add(e); } public static void reportErrors() { for (int i = 0; i < errors.size(); i++) System.out.println(((Exception)errors.get(i)).toString()); } public static void clearErrors() { errors.clear(); } } //end class //############################################# //## E N D O F F I L E //#############################################