Say NO to duplicated output

This commit is contained in:
Diogo Cordeiro 2018-12-20 04:03:38 +00:00
parent 4264649271
commit 3af7f72aa4
1 changed files with 33 additions and 45 deletions

View File

@ -59,53 +59,44 @@ polyplay :-
nl,
!
;
(
%% Parse the input into a tree
parse_input(TIn, LA, NC),
(
%% If the tree is empty, it means nothing was understood
TIn == void,
writeln("I didn't understand what you want."),
writeln(NC)
%% Parse the input into a tree
parse_input(TIn, LA, NC),
(
%% If the tree is empty, it means nothing was understood
TIn == void,
writeln("I didn't understand what you want."),
writeln(NC)
;
(
%% If there is unconsumed input, it means there was a syntatic error
NC \== [],
write("Syntax error in token: "),
%% Take the head of the list
cons(H, _, NC),
write(H),
nl
;
%% Otherwise, process the parse tree and execute the commands within
process_input(TIn)
)
)
;
(
%% If there is unconsumed input, it means there was a syntatic error
NC \== [],
write("Syntax error in token: "),
%% Take the head of the list
cons(H, _, NC),
write(H),
nl
;
(
%% If the debug_print flag is true, print some extract debug info
debug_print(true),
write(LA),
nl,
write(TIn),
nl
;
%% Otherwise, process the parse tree and execute the commands within
process_input(TIn)
)
)
)
;
%% Parsing failed
writeln("I didn't understand what you want.")
),
%% Parsing failed
writeln("I didn't understand what you want.")
),
%% Go back to the beginning
polyplay
),
!.
%% Flag which determines whether to print the parsed input or to process it
debug_print(false).
%% process_input(+tree) is determines
%% process_input(+Tree) is det
%
% Execute the commands from the parse tree
%
process_input(command(CL, void)) :-
%% Process only command left
do_process_input(CL).
process_input(command(CL, TCR)) :-
%% Process first command
do_process_input(CL),
@ -113,11 +104,8 @@ process_input(command(CL, TCR)) :-
TCR \== void,
%% recurse
process_input(TCR).
process_input(command(CL, void)) :-
%% Process only command left
do_process_input(CL).
%% do_process_input(+tree) is det
%% do_process_input(+Tree) is det
%
% Process a single command from the input
% Takes, as the only argument, the tree representing
@ -261,9 +249,9 @@ do_process_input(store_multiplication(TN, PT, V)) :-
polynomial_tree_to_polynomial(PT, P),
(
not(number(N)),
scalepoly(N, P, P2)
scalepoly(N, P, P2)
;
number(N),
number(N),
scalepoly(P, N, P2)
),
simpoly(P2, SP),
@ -280,9 +268,9 @@ do_process_input(multiply(TN, PT)) :-
%% Use function from UI layer
(
not(number(N)),
scalepoly(N, P, P2)
scalepoly(N, P, P2)
;
number(N),
number(N),
scalepoly(P, N, P2)
),
simpoly(P2, SP),