當前位置: 首頁>>代碼示例>>Python>>正文


Python SymbolTable.search方法代碼示例

本文整理匯總了Python中SymbolTable.SymbolTable.search方法的典型用法代碼示例。如果您正苦於以下問題:Python SymbolTable.search方法的具體用法?Python SymbolTable.search怎麽用?Python SymbolTable.search使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SymbolTable.SymbolTable的用法示例。


在下文中一共展示了SymbolTable.search方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: STManager

# 需要導入模塊: from SymbolTable import SymbolTable [as 別名]
# 或者: from SymbolTable.SymbolTable import search [as 別名]
class STManager():
    def __init__(self):
        # create the root symbol table
        self.root = ST()
        # intialize the stack of symbol tables for activation record
        self.activeSTs = [self.root]
        # table of funcitons
        self.ftable = {};


    """ Make Symbol Table
        create a new table and return a pointer to new table
        @params _prev {SymbolTable}  --  parent symbol table pointer
        @return {SymbolTable} -- newly created symbol table
    """
    def makeTable(self, _prev):
        # create a new symbol table table
        newST = ST()
        # make _prev the parent of new table
        newST.parent = _prev
        # return the new symbol table
        return newST


    """ Lookup
        Loopup for the symbol in the activation record
        @params _symbol {string} -- symbol for which look to be done
        @return {bool} -- symbol found or not
    """
    def lookup(self, _symbol):
        return self.currActive.search(_symbol)


    """ Lookup In Root for a symbol. Used to lookup for globals and functions 
        Loopup for the symbol in the activation record
        @params _symbol {string} -- symbol for which look to be done
        @return {bool} -- symbol found or not
    """
    def lookupInRoot(self, _symbol):
        return self.root.search(_symbol)

    """ Push
        push symbol table onto symbol tables stack
        @params _st {SymbolTable} -- symbol table to be pushed onto the stack
    """
    def push(self, _st):
        # push the new symbol on activation record's stack
        self.activeSTs.append(_st)


    """ Pop
        remove the top of the symbol tables stack
        @return {SymbolTable} -- removed symbol table
    """
    def pop(self):
        return self.activeSTs.pop()


    """ Insert into symbol table
        create a new entry into symbol table and put the data
        @params _name {string} -- name (key | id) of the new entry
        @params _type {string} -- type of name (an attribute)
        @params _offset {integer} -- size | offset for the name
    """
    def insert(self, _name, _type, _width, _scope=None):
        return self.currActive.insert(_name, _type, _width, _scope)


    """ Add link to global variable into the current active symbol table
        
    """
    def linkGlobalSym(self, _name, _attrs):
        self.currActive.linkGlobalSym(_name, _attrs)

    """ Enter a new entry for a procedure
        Create a new entry for a procedure.
        @params _name {string} -- name of the procedure
        @params _lineNumber {int}  -- liner number where function is defined
        @params _procST {SymbolTable} -- symbol table for a procedure
    """
    def enterProc(self, _name, _lineNumber, _numParams, _procST):
        self.ftable[_lineNumber] = {
            "place": _name,
            "numParams": _numParams,
            "st": _procST
        }
        return self.currActive.enterProc(_name, _lineNumber, _numParams, _procST)


    """ Set attribute
        set attributes for a symbol in symbol table
        @params _symbol {string} -- symbol for which attribute is to be set
        @params _key {string} -- key for the attribute
        @params _val {object} -- value for the attribute
    """
    def setAttr(self, _symbol, _key, _val):
        self.currActive.setAttr(_symbol, _key, _val)


    """ Get attribute
#.........這裏部分代碼省略.........
開發者ID:ssolanki,項目名稱:php-python-mips-1,代碼行數:103,代碼來源:STManager.py


注:本文中的SymbolTable.SymbolTable.search方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。