本文整理汇总了Python中Table.Table.is_declared方法的典型用法代码示例。如果您正苦于以下问题:Python Table.is_declared方法的具体用法?Python Table.is_declared怎么用?Python Table.is_declared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table.Table
的用法示例。
在下文中一共展示了Table.is_declared方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Table import Table [as 别名]
# 或者: from Table.Table import is_declared [as 别名]
class SemantickiAnalizator:
"""INIT"""
def __init__(self, lines):
# Turn padding into preceding number
lines = [ str(calculate_padding(line)) + ' ' + line.strip() for line in lines ]
self.table = Table()
self.lines = Lines(lines)
self.terminate = False
self.result = ""
return
"""CHECK EXPRESSIONS"""
def check_expressions(self, expressions):
if self.terminate: return False
else: return self.lines.check_expressions(expressions)
"""ASSERT LEAF"""
def assert_leaf(self, fst_exp, snd_exp = ""):
global counter
counter += 1
if self.terminate: return False
else: return self.lines.assert_leaf(fst_exp, snd_exp)
"""PARSE ERROR"""
def parse_error(self, curr_line):
self.terminate = True
return self.lines.parse_error(curr_line)
"""CHECK BOTH FOR INT AND RETURN INT"""
def check_both_for_int_and_return_int(self, curr_line, fst_fun, expr, snd_fun):
if not fst_fun() == Expr("INT"):
return self.parse_error(curr_line)
self.assert_leaf(expr)
if not snd_fun() == Expr("INT"):
return self.parse_error(curr_line)
return Expr("INT")
"""CAN CAST"""
def can_cast(self, fst_exp, snd_exp):
return fst_exp == snd_exp \
or fst_exp == Expr("INT") and snd_exp == Expr("CHAR")
"""POST TRAVERSAL CHECKS"""
def post_traversal_checks(self):
if not self.table.is_declared("main", [Expr("VOID")], [Expr("INT")]) \
or not "main" in self.table._scopes[0]['_functions'] \
or not self.table.get_function("main")._function_to_types[0]._type == "INT":
self.result = "main"
return True
for scope in self.table._scopes:
for function in scope['_functions']:
if not function in self.table._defined_functions:
self.result = "funkcija"
return True
return False
"""PARSE"""
def parse(self):
#pprint("# Starting and checking for <prijevodna_jedinica>")
self.check_expressions(["<prijevodna_jedinica>"])
#pprint("Calling self.prijevodna_jedinica()")
self.prijevodna_jedinica()
self.result = self.lines.result
if not self.terminate:
if not self.post_traversal_checks():
pprint("Succesful semantic analysis. No errors!")
else:
pprint("Post traversal errors found!")
return(self.result)
######################################
############### IZRAZI ###############
######################################
"""PRIMARNI IZRAZ"""
def primarni_izraz(self):
curr_line = self.lines._iter
pprint("# primarni_izraz")
pprint(self.lines.get_line())
if self.check_expressions(["IDN"]):
idn = self.assert_leaf("IDN")
if self.table.contains(idn):
return self.table.get_var(idn)
elif self.table.is_JUST_declared(idn):
return self.table.get_function(idn)
else:
return self.parse_error(curr_line)
elif self.check_expressions(["BROJ"]):
expr = self.assert_leaf("BROJ")
if int(expr) < -2**31 or int(expr) >= 2**31:
return self.parse_error(curr_line)
return Expr("INT")
elif self.check_expressions(["ZNAK"]):
expr = self.assert_leaf("ZNAK")
if not len(expr) == 3 or ord(expr[1]) < 0 or ord(expr[1]) > 255:
return self.parse_error(curr_line)
#.........这里部分代码省略.........