private void initVars() { vars = new Table(); vars.put( symbol("malloc"), new VarEntry( new FUNCTION( new RECORD(symbol("s"), Type.INT, null), Type.VOIDPTR, false, new Label("malloc")))); vars.put( symbol("strcpy"), new VarEntry( new FUNCTION( new RECORD( symbol("s1"), Type.CHARPTR, new RECORD( symbol("s2"), Type.CHARPTR, new RECORD(symbol("size"), Type.INT, null))), Type.CHARPTR, false, new Label("strcpy")))); vars.put( symbol("printf"), new VarEntry( new FUNCTION( new RECORD(symbol("s"), Type.CHARPTR, null), Type.INT, true, new Label("printf")))); }
private void initTypes() { types = new Table(); types.put(symbol("int"), Type.INT); types.put(symbol("char"), Type.CHAR); types.put(symbol("void"), Type.VOID); types.put(symbol("void*"), Type.VOIDPTR); types.put(symbol("char*"), Type.CHARPTR); }
public void endScope() { vars.endScope(); types.endScope(); }
public void beginScope() { vars.beginScope(); types.beginScope(); }
public static void main(String[] args) { Table<Integer> t = new Table<Integer>(); t.put(Symbol.symbol("abc"), new Integer(1)); t.put(Symbol.symbol("efg"), new Integer(2)); System.out.println(t.get(Symbol.symbol("efg"))); System.out.println(t.get(Symbol.symbol(""))); t.put(Symbol.symbol("efg"), new Integer(3)); System.out.println(t.get(Symbol.symbol("efg"))); t.beginScope(); System.out.println(t.get(Symbol.symbol("efg"))); t.put(Symbol.symbol("efg"), new Integer(4)); System.out.println(t.get(Symbol.symbol("efg"))); t.put(Symbol.symbol("efg"), new Integer(5)); System.out.println(t.get(Symbol.symbol("efg"))); t.put(Symbol.symbol("new"), new Integer(6)); System.out.println(t.get(Symbol.symbol("d"))); System.out.println(t.get(Symbol.symbol("new"))); t.endScope(); System.out.println(t.get(Symbol.symbol("efg"))); System.out.println(t.get(Symbol.symbol("new"))); }