3 public class LiteralNode extends ExpressionNode {
4 public final static int INTEGER=1;
5 public final static int FLOAT=2;
6 public final static int BOOLEAN=3;
7 public final static int CHAR=4;
8 public final static int STRING=5;
9 public final static int NULL=6;
14 public LiteralNode(String type, Object o) {
15 this.type=parseType(type);
19 public Object getValue() {
23 private static int parseType(String type) {
24 if (type.equals("integer"))
26 else if (type.equals("float"))
28 else if (type.equals("boolean"))
30 else if (type.equals("char"))
32 else if (type.equals("string"))
34 else if (type.equals("null"))
36 else throw new Error();
39 private String getStringType() {
44 else if (type==BOOLEAN)
48 else if (type==STRING)
52 else throw new Error();
56 public String printNode(int indent) {
60 return '"'+escapeString(value.toString())+'"';
62 return "/*"+getType()+ "*/"+value.toString();
64 private static String escapeString(String st) {
66 for(int i=0;i<st.length();i++) {
77 return Kind.LiteralNode;