Esempio n. 1
0
 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"))));
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 public void endScope() {
   vars.endScope();
   types.endScope();
 }
Esempio n. 4
0
 public void beginScope() {
   vars.beginScope();
   types.beginScope();
 }
Esempio n. 5
0
 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")));
 }