本文整理汇总了Python中Interpreter.Interpreter.to_type方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.to_type方法的具体用法?Python Interpreter.to_type怎么用?Python Interpreter.to_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.to_type方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assign
# 需要导入模块: from Interpreter import Interpreter [as 别名]
# 或者: from Interpreter.Interpreter import to_type [as 别名]
def assign(self, interpreter_flag=False):
Interpreter.interpreter_flag = interpreter_flag
sc = self.scanner
lexeme_identifier = sc.next_lexeme()
if Interpreter.interpreter_flag:
# semantic
if not self.semantic_tree.is_describe_var_early(sc.get_pointer_line(), sc.get_pointer_position(), sc.lexeme):
raise SemanticExceptionUndescribeVar(sc.get_pointer_line(), sc.get_pointer_position(), sc.lexeme)
# semantic
if Interpreter.interpreter_flag:
# Interpreter
node = self.semantic_tree.get_variable_node(sc.lexeme)
# Interpreter
sc.next_lexeme() # =
value_obj = ValueObj()
self.expression(value_obj, interpreter_flag=Interpreter.interpreter_flag)
if Interpreter.interpreter_flag:
# Interpreter
Interpreter.to_type(value_obj, node.type_data)
node.value = value_obj.value
示例2: enum_operand
# 需要导入模块: from Interpreter import Interpreter [as 别名]
# 或者: from Interpreter.Interpreter import to_type [as 别名]
def enum_operand(self, interpreter_flag=False):
Interpreter.interpreter_flag = interpreter_flag
sc = self.scanner
old_pointer = sc.get_pointer()
lexeme = sc.next_lexeme()
if lexeme != lId.TClose:
sc.set_pointer(old_pointer)
value_obj = ValueObj()
self.expression(value_obj, interpreter_flag=Interpreter.interpreter_flag)
if Interpreter.interpreter_flag:
# semantic
self.semantic_tree.current_count_parameter += 1
self.semantic_tree.go_left()
if self.semantic_tree.pointer != self.semantic_tree.dummy:
Interpreter.to_type(value_obj, self.semantic_tree.pointer.type_data)
self.semantic_tree.pointer.value = value_obj.value
# semantic
old_pointer = sc.get_pointer()
lexeme = sc.next_lexeme()
while lexeme == lId.TComma:
value_obj = ValueObj()
self.expression(value_obj, interpreter_flag=Interpreter.interpreter_flag)
if Interpreter.interpreter_flag:
# semantic
self.semantic_tree.current_count_parameter += 1
self.semantic_tree.go_left()
if self.semantic_tree.pointer != self.semantic_tree.dummy:
Interpreter.to_type(value_obj, self.semantic_tree.pointer.type_data)
self.semantic_tree.pointer.value = value_obj.value
# semantic
old_pointer = sc.get_pointer()
lexeme = sc.next_lexeme()
sc.set_pointer(old_pointer)
示例3: set_value_obj
# 需要导入模块: from Interpreter import Interpreter [as 别名]
# 或者: from Interpreter.Interpreter import to_type [as 别名]
def set_value_obj(self, value_obj):
Interpreter.to_type(value_obj, self.pointer.type_data)
self.pointer.value = value_obj.value
示例4: operator
# 需要导入模块: from Interpreter import Interpreter [as 别名]
# 或者: from Interpreter.Interpreter import to_type [as 别名]
def operator(self, interpreter_flag=False):
Interpreter.interpreter_flag = interpreter_flag
sc = self.scanner
old_pointer = sc.get_pointer()
lexeme = sc.next_lexeme()
if lexeme == lId.TOpenFigure:
sc.set_pointer(old_pointer)
self.body_function(interpreter_flag=Interpreter.interpreter_flag)
elif lexeme == lId.TSemicolon:
...
elif lexeme == lId.TDo:
self.operator(interpreter_flag=Interpreter.interpreter_flag)
lexeme_while = sc.next_lexeme()
if lexeme_while != lId.TWhile:
raise SyntaxExceptionWhile(sc.get_pointer_line(), sc.get_pointer_position(), sc.lexeme)
lexeme_open_bracket = sc.next_lexeme()
if lexeme_open_bracket != lId.TOpen:
raise SyntaxExceptionCharacter(sc.get_pointer_line(), sc.get_pointer_position(), "(", sc.lexeme)
value_obj = ValueObj()
self.expression(value_obj, interpreter_flag=Interpreter.interpreter_flag)
if Interpreter.interpreter_flag:
# Interpreter
if value_obj.value != 0:
sc.set_pointer(old_pointer)
return
# Interpreter
lexeme_close_bracket = sc.next_lexeme()
if lexeme_close_bracket != lId.TClose:
raise SyntaxExceptionCharacter(sc.get_pointer_line(), sc.get_pointer_position(), ")", sc.lexeme)
lexeme_semicolon = sc.next_lexeme()
if lexeme_semicolon != lId.TSemicolon:
raise SyntaxExceptionCharacter(sc.get_pointer_line(), sc.get_pointer_position(), ";", sc.lexeme)
elif lexeme == lId.TReturn:
value_obj = ValueObj()
self.expression(value_obj, interpreter_flag=Interpreter.interpreter_flag)
lexeme_semicolon = sc.next_lexeme()
if lexeme_semicolon != lId.TSemicolon:
raise SyntaxExceptionCharacter(sc.get_pointer_line(), sc.get_pointer_position(), ";", sc.lexeme)
if Interpreter.interpreter_flag:
# Interpreter
parent_fun = self.semantic_tree.get_node_of_parent_function()
Interpreter.to_type(value_obj, parent_fun.type_data)
if parent_fun.lexeme != 'main':
parent_fun.get_left().value = value_obj.value
else:
parent_fun.value = value_obj.value
Interpreter.interpreter_flag = False
# Interpreter
else:
sc.set_pointer(old_pointer)
lexeme_identifier = sc.next_lexeme()
if lexeme_identifier == lId.TId and sc.next_lexeme() == lId.TAssign:
sc.set_pointer(old_pointer)
self.assign(interpreter_flag=Interpreter.interpreter_flag)
else:
sc.set_pointer(old_pointer)
value_obj = ValueObj()
self.expression(value_obj, interpreter_flag=Interpreter.interpreter_flag)
lexeme_semicolon = sc.next_lexeme()
if lexeme_semicolon != lId.TSemicolon:
raise SyntaxExceptionCharacter(sc.get_pointer_line(), sc.get_pointer_position(), ";", sc.lexeme)