Example #1
0
 public SymbolTable(Parser parser)
 {
     this.parser = parser;
     topScope = null;
     curLevel = -1;
     undefObj = new Obj();
     undefObj.name  =  "undef"; undefObj.type = undef; undefObj.kind = var;
     undefObj.adr = 0; undefObj.level = 0; undefObj.next = null;
 }
Example #2
0
 // create a new object node in the current scope
 public Obj NewObj(string name, int kind, int type)
 {
     Obj p, last, obj = new Obj();
     obj.name = name; obj.kind = kind; obj.type = type;
     obj.level = curLevel;
     p = topScope.locals; last = null;
     while (p != null) {
     if (p.name == name) parser.SemErr("name declared twice");
     last = p; p = p.next;
     }
     if (last == null) topScope.locals = obj; else last.next = obj;
     if (kind == var) obj.adr = topScope.nextAdr++;
     return obj;
 }
Example #3
0
 // open a new scope and make it the current scope (topScope)
 public void OpenScope()
 {
     Obj scop = new Obj();
     scop.name = ""; scop.kind = scope;
     scop.locals = null; scop.nextAdr = 0;
     scop.next = topScope; topScope = scop;
     curLevel++;
 }
Example #4
0
 // close the current scope
 public void CloseScope()
 {
     topScope = topScope.next; curLevel--;
 }