Exemplo n.º 1
0
    def insert_formal(self, header, formal, t, lineno=-1):
        if len(self.formals) == 0:
            raise PCLSymbolTableError('Formals lists do not exist')

        try:
            self.formals[-1].insert(header, formal, t)
        except PCLSymbolTableError as e:
            raise PCLSymbolTableError('{} at line {}'.format(str(e), lineno))
Exemplo n.º 2
0
    def insert(self, c, t, lineno=-1):
        if len(self.scopes) == 0:
            raise PCLSymbolTableError('Scopes do not exist')

        try:
            self.scopes[-1].insert(c, t)
        except PCLSymbolTableError as e:
            raise PCLSymbolTableError('{} at line {}'.format(str(e), lineno))
Exemplo n.º 3
0
 def close_scope(self):
     if len(self.scopes) == 0:
         raise PCLSymbolTableError('Tried to pop nonexistent scope')
     if self.scopes[-1].name is not None:
         self.scope_names_indices.pop()
     self.scopes.pop()
     self.formals.pop()
Exemplo n.º 4
0
    def lookup_formal(self, header, formal, lineno=-1, last_scope=False):
        if len(self.formals) == 0:
            raise PCLSymbolTableError('Formal scopes do not exist')

        if last_scope:
            entry = self.formals[-1].lookup(header, formal)
            if entry:
                return entry
        else:
            for formal in reversed(self.formals):
                entry = formal.lookup(header, formal)
                if entry:
                    return entry

        msg = 'Unknown formal {} in header {} at line {}'.format(
            formal, header, lineno)
        raise PCLSymbolTableError(msg)
Exemplo n.º 5
0
    def lookup(self, c, lineno=-1, last_scope=False):
        if len(self.scopes) == 0:
            raise PCLSymbolTableError('Scopes do not exist')

        if last_scope:
            entry = self.scopes[-1].lookup(c)
            if entry:
                entry.num_queries += 1
                return entry
        else:
            for scope in reversed(self.scopes):
                entry = scope.lookup(c)
                if entry:
                    entry.num_queries += 1
                    return entry

        msg = 'Unknown name: {} at line {}'.format(c, lineno)
        raise PCLSymbolTableError(msg)
Exemplo n.º 6
0
    def __del__(self):
        if len(self.scopes) > 1:
            raise PCLSymbolTableError('Open scope(s) not closed.')

        # close built-in scopes
        self.close_scope()
Exemplo n.º 7
0
 def insert(self, h, c, st):
     if self.lookup(h, c):
         msg = 'Duplicate name {} at line {}'.format(c, -1)
         raise PCLSymbolTableError(msg)
     else:
         self.locals_[h][c] = st