Make addition great again

This commit is contained in:
Diogo Cordeiro 2018-12-20 03:26:17 +00:00
parent 3daaee65a5
commit 4264649271

View File

@ -117,7 +117,6 @@ process_input(command(CL, void)) :-
%% Process only command left
do_process_input(CL).
%% do_process_input(+tree) is det
%
% Process a single command from the input
@ -288,6 +287,22 @@ do_process_input(multiply(TN, PT)) :-
),
simpoly(P2, SP),
writeln(SP).
do_process_input(op(+, TN, PT)) :-
polynomial_tree_to_polynomial(TN, N),
polynomial_tree_to_polynomial(PT, P),
addpoly(N, P, P2),
simpoly(P2, SP),
writeln(SP).
do_process_input(store_addition(TN, PT, V)) :-
polynomial_tree_to_polynomial(TN, N),
polynomial_tree_to_polynomial(PT, P),
addpoly(N, P, P2),
simpoly(P2, SP),
assertz(polynomial_store(V, SP)),
write(V),
write(" = "),
write(SP),
nl.
%% print_all_stored_variables
%
@ -780,6 +795,14 @@ parse_command(op(-, TN, TP)) -->
[X],
{ member(X, [to, from, with]) },
parse_polynomial(TP).
parse_command(store_addition(TN, TP, V)) -->
[add],
parse_polynomial(TN),
[X],
{ member(X, [to, with]) },
parse_polynomial(TP),
[as],
[V].
parse_command(op(+, TN, TP)) -->
[add],
parse_polynomial(TN),