本文整理汇总了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
#.........这里部分代码省略.........