def CLASS_ENTRY_TABLE(self): print "create_classEntryAndTable." # ensure class name does not already exist in Global Table class_entry = Entry(self.level, self.prevToken_buffer, 'class', '') if self.SymbolTable_stack[0].search(class_entry) is None: # log class name in classDict if not there if class_entry.name.value not in self.classUsageDict: self.classUsageDict[class_entry.name.value] = [] # create a table entry and link it to the new class table self.level += 1 class_entry.link = Symbol_Table(self.level, class_entry.name) # append the new entry to the global table and put the reference to the class table on top the stack if self.SymbolTable_stack: self.SymbolTable_stack[-1].addEntry(class_entry) self.SymbolTable_stack.append(class_entry.link) else: # error this class name alreay exists in global table print "Attempting new class entry/table but name " + self.prevToken_buffer.value + " already exists in global table" self.error += "\nError: Duplicate class declaration: " + str( self.prevToken_buffer) print self.error
def FUNC_ENTRY_TABLE(self): print "create_funcEntryAndTable." # ensure function name does not already exist in current scope if len(self.attr_buffer) > 1: func_name = self.attr_buffer.pop() func_type = self.attr_buffer.pop() # create a new global/local table entry and link it to the new class table entry = Entry(self.level, func_name, 'function', func_type) self.level += 1 entry.link = Symbol_Table(self.level, entry.name) if self.SymbolTable_stack[-1].search(entry) is None: # check if in class or global table if len(self.SymbolTable_stack) <= 1: if entry.name.value not in self.classUsageDict: self.classUsageDict[entry.name.value] = [] # append the new entry to the global/class table and put the reference to the class table on top the stack if self.SymbolTable_stack: self.SymbolTable_stack[-1].addEntry(entry) self.SymbolTable_stack.append(entry.link) # save function reference for later type/valid call checking self.function_defs.append(entry) else: # error this function name alreay exists in scope print "Attempting new function but name " + func_name.value + " already exists in scope" self.error += "\nError: Duplicate function declaration: " + str( func_name) print self.error
def CLASS_ENTRY_TABLE(self): print "create_classEntryAndTable." # create a table entry and link it to the new class table class_entry = Entry(self.level, self.prevToken_buffer, 'class', '') self.level += 1 class_entry.link = Symbol_Table(self.level, class_entry.name) # append the new entry to the global table and put the reference to the class table on top the stack self.SymbolTable_stack[-1].addEntry(class_entry) self.SymbolTable_stack.append(class_entry.link)
def PROGRAM_FUNC_ENTRY_TABLE(self): print 'adding the program function entry and symbol_table.' # create a new global table entry and link it to the new main program function table entry = Entry(self.level, self.prevToken_buffer, 'function', '') self.level += 1 entry.link = Symbol_Table(self.level, entry.name) # append the new entry to the global table and put the reference to the program table on top the stack if self.SymbolTable_stack: self.SymbolTable_stack[-1].addEntry(entry) self.SymbolTable_stack.append(entry.link)