def compile(self): if self.block_token_list is None: self.stmt_list = None else: self.stmt_list = larc_stmt.parse_stmt_list(self.block_token_list, self.module, None, (self.arg_set.copy(), ), 0) self.block_token_list.pop_sym("}") assert not self.block_token_list del self.block_token_list
def _parse_method(self, token_list, cls, class_blk_indent_count): name_token = token_list.pop() if not name_token.is_name: name_token.syntax_err("非法的方法名") method_name = name_token.value token_list.pop_sym("(") arg_list = self._parse_func_arg_list(token_list) method_key = method_name, len(arg_list) if method_key in cls.method_map: name_token.syntax_err("方法重复定义") stmt_list, global_var_set = ( larc_stmt.parse_stmt_list(token_list, class_blk_indent_count, 0)) cls.method_map[method_key] = ( _Method(method_name, arg_list, global_var_set, stmt_list, name_token))
def _parse_method(self, token_list, cls, class_blk_indent_count): name_token = token_list.pop() if not name_token.is_name: name_token.syntax_err("非法的方法名") method_name = name_token.value token_list.pop_sym("(") arg_list = self._parse_func_arg_list(token_list) method_key = method_name, len(arg_list) if method_key in cls.method_map: name_token.syntax_err("方法重复定义") stmt_list, global_var_set = (larc_stmt.parse_stmt_list( token_list, class_blk_indent_count, 0)) cls.method_map[method_key] = (_Method(method_name, arg_list, global_var_set, stmt_list, name_token))
def _parse_func(self, token_list, export): name_token = token_list.pop() if not name_token.is_name: name_token.syntax_err("非法的函数名") func_name = name_token.value if func_name in self.dep_module_set: name_token.syntax_err("函数名和模块名重复") if func_name in self.global_var_map: name_token.syntax_err("函数名和全局变量名重复") if func_name in self.class_map: name_token.syntax_err("函数名和类名重复") token_list.pop_sym("(") arg_list = self._parse_func_arg_list(token_list) func_key = func_name, len(arg_list) if func_key in self.func_map: name_token.syntax_err("函数重复定义") stmt_list, global_var_set = larc_stmt.parse_stmt_list(token_list, 0, 0) self.func_map[func_key] = func = ( _Func(func_name, arg_list, global_var_set, stmt_list, name_token)) if export: self.export_func_set.add(func_key) func.set_export()
def _parse_func(self, token_list, export): name_token = token_list.pop() if not name_token.is_name: name_token.syntax_err("非法的函数名") func_name = name_token.value if func_name in self.dep_module_set: name_token.syntax_err("函数名和模块名重复") if func_name in self.global_var_map: name_token.syntax_err("函数名和全局变量名重复") if func_name in self.class_map: name_token.syntax_err("函数名和类名重复") token_list.pop_sym("(") arg_list = self._parse_func_arg_list(token_list) func_key = func_name, len(arg_list) if func_key in self.func_map: name_token.syntax_err("函数重复定义") stmt_list, global_var_set = larc_stmt.parse_stmt_list(token_list, 0, 0) self.func_map[func_key] = func = (_Func(func_name, arg_list, global_var_set, stmt_list, name_token)) if export: self.export_func_set.add(func_key) func.set_export()