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;
15 public LiteralNode(String type, Object o) {
16 this.type=parseType(type);
20 private static int parseType(String type) {
21 if (type.equals("integer"))
23 else if (type.equals("float"))
25 else if (type.equals("boolean"))
27 else if (type.equals("char"))
29 else if (type.equals("string"))
31 else if (type.equals("null"))
33 else throw new Error();
36 private String getType() {
41 else if (type==BOOLEAN)
45 else if (type==STRING)
49 else throw new Error();
53 public String printNode(int indent) {
57 return '"'+escapeString(value.toString())+'"';
59 return "/*"+getType()+ "*/"+value.toString();
61 private static String escapeString(String st) {
63 for(int i=0;i<st.length();i++) {
74 return Kind.LiteralNode;