def convert_to_ast(node): program = Program() program.set_name(node.get_name()) program.set_type(node.get_type()) dclr_child = node.get_child_nodes()[0] dclr_list = DclrList() while True: if dclr_child is not None and dclr_child.get_name() == 'var': ident_name = dclr_child.get_child_nodes()[0] declaration = Declaration(ident_name.get_name()) declaration.set_name(ident_name.get_name()) declaration.set_type(symbol_table.get(ident_name.get_name())) dclr_list.add_declaration_to_list(declaration) AST.dot.edge(dclr_list.get_gv_name(), declaration.get_gv_name()) length = len(dclr_child.get_child_nodes()) dclr_child = dclr_child.get_child_nodes()[length - 1] else: break program.set_dclr_list(dclr_list) AST.dot.edge(program.get_gv_name(), dclr_list.get_gv_name()) stmt_child = node.get_child_nodes()[2] stmt_list = generate_statement_list(stmt_child) if stmt_list.get_type_error(): AST.dot.edge(program.get_gv_name(), stmt_list.get_gv_name(), color='red') else: AST.dot.edge(program.get_gv_name(), stmt_list.get_gv_name()) program.set_stmt_list(stmt_list) return program