本文整理汇总了Python中Table.Table.declare_var方法的典型用法代码示例。如果您正苦于以下问题:Python Table.declare_var方法的具体用法?Python Table.declare_var怎么用?Python Table.declare_var使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table.Table
的用法示例。
在下文中一共展示了Table.declare_var方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Table import Table [as 别名]
# 或者: from Table.Table import declare_var [as 别名]
#.........这里部分代码省略.........
self.assert_leaf("KR_VOID")
self.assert_leaf("D_ZAGRADA")
## 6
self.slozena_naredba(in_function = True, function_to = [expr])
elif self.check_expressions(["<ime_tipa>", "IDN", "L_ZAGRADA", "<lista_parametara>", "D_ZAGRADA"
, "<slozena_naredba>"]):
## 1
expr = self.ime_tipa()
## 2
if expr.is_const:
return self.parse_error(curr_line)
idn = self.assert_leaf("IDN")
## X
self.assert_leaf("L_ZAGRADA")
## 4
types, names = self.lista_parametara()
## 5
if self.table.is_declared(idn, types, [expr]):
return self.parse_error(curr_line)
## 3
if self.table.contains(idn) or self.table.is_defined(idn, types, [expr]):
return self.parse_error(curr_line)
## 6
if not self.table.is_declared(idn, types, [expr]):
self.table.declare_fun(idn, types, [expr])
if not self.table.is_defined(idn, types, [expr]):
self.table.define(idn, types, [expr])
#### SCOPING!!!!!!!!
self.table.create_new_scope() #### SCOPING!!!!!!!!
## 4 . continued
### Addomg types+names to scope (no scoping implemented yet)
for i, name in enumerate(names):
self.table.declare_var(name, types[i])
## X
self.assert_leaf("D_ZAGRADA")
## 7 !!! Careful about function parameters. Should be implemented (i think)
pprint("!!!!!!!!!!!!!!!!!!!!!!!!!!!")
pprint(expr)
self.slozena_naredba(in_function = True, function_to = [expr])
self.table.destroy_current_scope() #### SCOPING!!!!!!!!
else:
return self.parse_error(curr_line)
"""LISTA PARAMETARA"""
def lista_parametara(self):
curr_line = self.lines._iter
pprint("# lista_parametara")
pprint(self.lines.get_line())
if self.check_expressions(["<deklaracija_parametra>"]):
tip, ime = self.deklaracija_parametra()
return [tip], [ime]
elif self.check_expressions(["<lista_parametara>", "ZAREZ", "<deklaracija_parametra>"]):
tipovi, imena = self.lista_parametara()
self.assert_leaf("ZAREZ")
tip, ime = self.deklaracija_parametra()
return tipovi + [tip], imena + [ime]
else:
return self.parse_error(curr_line)
"""DEKLARACIJA PARAMETRA"""
def deklaracija_parametra(self):
curr_line = self.lines._iter
pprint("# deklaracija_parametra")