def compile_statements(self): local_root = SyntaxTreeNode('statements') local_root.add_many(lambda: or_compile(( self.compile_do, self.compile_let, self.compile_while, self.compile_return, self.compile_if, ))) return local_root
def compile_subroutine_body(self): # subroutineBody # '{' varDec* statements '}' local_root = SyntaxTreeNode('subroutineBody') # '{' node = self.__expect_symbol('{') if not node: return None local_root.add_child(node) # varDesc* local_root.add_many(self.compile_var_dec) # statements local_root.add_child(self.compile_statements(), 'expect statements') # '}' local_root.add_child(self.__expect_symbol('}'), 'expect }') return local_root
def compile_class(self): # class: 'class' className '{' classVarDec* subroutineDec* '}' local_root = SyntaxTreeNode('class') # 'class' local_root.add_child(self.__expect_keyword('class'), 'expect keyword class') # className class_name_node = self.__expect_identifier() local_root.add_child(class_name_node, 'expect identifier className') self.class_name = class_name_node.value # '{' local_root.add_child(self.__expect_symbol('{'), 'expect {') # classVarDec* local_root.add_many(self.compile_class_var_dec) # subroutineDec* local_root.add_many(self.compile_subroutine) # '}' local_root.add_child(self.__expect_symbol('}'), 'expect } in class') return local_root