本文整理匯總了Python中SymbolTable.SymbolTable.kind_of方法的典型用法代碼示例。如果您正苦於以下問題:Python SymbolTable.kind_of方法的具體用法?Python SymbolTable.kind_of怎麽用?Python SymbolTable.kind_of使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SymbolTable.SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.kind_of方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from SymbolTable import SymbolTable [as 別名]
# 或者: from SymbolTable.SymbolTable import kind_of [as 別名]
#.........這裏部分代碼省略.........
self.jack_tokenizer.advance()
if self.jack_tokenizer.token_type() == KEYWORD and self.jack_tokenizer.key_word() == "while":
self.compile_while()
self.jack_tokenizer.has_more_tokens()
self.jack_tokenizer.advance()
if self.jack_tokenizer.token_type() == KEYWORD and self.jack_tokenizer.key_word() == "return":
self.compile_return()
self.jack_tokenizer.has_more_tokens()
self.jack_tokenizer.advance()
# compile_if returns advanced
if self.jack_tokenizer.token_type() == KEYWORD and self.jack_tokenizer.key_word() == "if":
self.compile_if()
if self.jack_tokenizer.token_type() == SYMBOL and self.jack_tokenizer.symbol() == "}":
break
def compile_do(self):
self.num_args_called_function = 0
self.compile_subroutine_call()
self.writer.write_pop(TEMP , 0)
self.jack_tokenizer.has_more_tokens()
self.jack_tokenizer.advance()
# return from compile_subroutine_call with ";"
def compile_let(self):
init = True
# the curr token - "let"
while self.jack_tokenizer.has_more_tokens():
self.jack_tokenizer.advance()
token_type = self.jack_tokenizer.token_type()
if token_type == IDENTIFIER:
name = self.jack_tokenizer.identifier()
type = self.symbol_table.type_of(name)
kind = self.symbol_table.kind_of(name)
index = self.symbol_table.index_of(name)
if token_type == SYMBOL:
# there is an assignment to an array
if self.jack_tokenizer.symbol() == "[":
self.jack_tokenizer.has_more_tokens()
self.jack_tokenizer.advance()
# handle - [expression]
self.compile_expression()
# the curr token - "]"
self.writer.write_push(self.find_segment(kind), index)
self.writer.write_arithmetic("add")
self.writer.write_pop("pointer", 1)
init = False
# should return from the compile_expression only with ";" or "]"
if self.jack_tokenizer.symbol() == "=":
self.jack_tokenizer.has_more_tokens()
self.jack_tokenizer.advance()
# handle the = expression
self.compile_expression()
# that is only for array
if init == False: # was also if type == "Array"
self.writer.write_pop(THAT, 0)
else:
self.writer.write_pop(self.find_segment(kind), index)
# end of let statement
if self.jack_tokenizer.symbol() == ";":
break
def compile_while(self):
while_counter = self.label_counter_while
self.label_counter_while += 1