%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % MISCELLANEOUS RULES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% :- add_rule( drop_node_into_empty_buffer if stack([[SomeHead|RestOfHead]|RestStack]) and buffer([]) and check(not_equal(SomeHead, s)) then remove(stack(_)) and add(stack(RestStack)) and remove(buffer(_)) and add(buffer([[SomeHead|RestOfHead]]))). :- add_rule( successful_parse if stack([[s|Contents]]) and buffer([]) then print('Success! The parse tree is: ') and print([s|Contents]) and print('\n') and remove(stack(_)) and add(stack([])) and remove(buffer(_)) and add(buffer([])) and end and reset). :- add_rule( ask_for_input if stack([]) and buffer([]) then print('What is the next sentence?\n') and read(List) and remove(stack(_)) and add(stack([[s]])) and remove(buffer(_)) and add(buffer(List))). :- add_rule( failed_parse if stack(Contents) and check(not_equal(Contents, [])) then print('Parse failed: Current stack: ') and print(Contents) and print('\n') and remove(stack(_)) and add(stack([])) and remove(buffer(_)) and add(buffer([])) and end and reset).