Bool reorder_action_list (agent* thisAgent, action **action_list, tc_number lhs_tc) { list *new_bound_vars; action *remaining_actions; action *first_action, *last_action; action *a, *prev_a; Bool result_flag; new_bound_vars = NIL; remaining_actions = *action_list; first_action = NIL; last_action = NIL; while (remaining_actions) { /* --- scan through remaining_actions, look for one that's legal --- */ prev_a = NIL; a = remaining_actions; while (TRUE) { if (!a) break; /* looked at all candidates, but none were legal */ if (legal_to_execute_action (a, lhs_tc)) break; prev_a = a; a = a->next; } if (!a) break; /* --- move action a from remaining_actions to reordered list --- */ if (prev_a) prev_a->next = a->next; else remaining_actions = a->next; a->next = NIL; if (last_action) last_action->next = a; else first_action = a; last_action = a; /* --- add new variables from a to new_bound_vars --- */ add_all_variables_in_action (thisAgent, a, lhs_tc, &new_bound_vars); } if (remaining_actions) { /* --- there are remaining_actions but none can be legally added --- */ print (thisAgent, "Error: production %s has a bad RHS--\n", thisAgent->name_of_production_being_reordered); print (thisAgent, " Either it creates structure not connected to anything\n"); print (thisAgent, " else in WM, or it tries to pass an unbound variable as\n"); print (thisAgent, " an argument to a function.\n"); /* --- reconstruct list of all actions --- */ if (last_action) last_action->next = remaining_actions; else first_action = remaining_actions; result_flag = FALSE; } else { result_flag = TRUE; } /* --- unmark variables that we just marked --- */ unmark_variables_and_free_list (thisAgent, new_bound_vars); /* --- return final result --- */ *action_list = first_action; return result_flag; }
void add_all_variables_in_action_list(agent* thisAgent, action* actions, tc_number tc, cons** var_list) { action* a; for (a = actions; a != NIL; a = a->next) { add_all_variables_in_action(thisAgent, a, tc, var_list); } }