scope = Scope() functions = [] trim_tree(root) DotExporter(root).to_picture('new_tree.png') for node in PreOrderIter(root): node_name = get_name(node) if node_name in scope.generators: if get_name(node.children[0]) == 'ID': all_scopes_names = [scp['name'] for scp in scope.scopes] if get_last_value_name(node.children[0]) in all_scopes_names: raise Exception( "Função previamente definida (linha {})".format( node.children[0].line)) elif get_name(node.children[0]) in ('SE', 'REPITA'): scope.create_scope(get_name(node.children[0])) if node_name == 'cabecalho': scope_name = get_last_value_name(node.children[0]) type_fun = '' if get_name(node.parent) == 'declaracao_funcao': type_fun = get_name(node.parent.children[0].children[0]) scope.create_scope(scope_name, type_fun, node.children[0].line, is_function=True) else: scope.create_scope(scope_name, line_param=node.children[0].line, is_function=True) param_list = [] param_list = get_params(node.children[2], param_list)