Say NO to duplicated output
This commit is contained in:
parent
4264649271
commit
3af7f72aa4
78
polymani.pl
78
polymani.pl
@ -59,53 +59,44 @@ polyplay :-
|
|||||||
nl,
|
nl,
|
||||||
!
|
!
|
||||||
;
|
;
|
||||||
(
|
|
||||||
%% Parse the input into a tree
|
|
||||||
parse_input(TIn, LA, NC),
|
|
||||||
(
|
(
|
||||||
%% If the tree is empty, it means nothing was understood
|
%% Parse the input into a tree
|
||||||
TIn == void,
|
parse_input(TIn, LA, NC),
|
||||||
writeln("I didn't understand what you want."),
|
(
|
||||||
writeln(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)
|
||||||
|
)
|
||||||
|
)
|
||||||
;
|
;
|
||||||
(
|
%% Parsing failed
|
||||||
%% If there is unconsumed input, it means there was a syntatic error
|
writeln("I didn't understand what you want.")
|
||||||
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.")
|
|
||||||
),
|
|
||||||
%% Go back to the beginning
|
%% Go back to the beginning
|
||||||
polyplay
|
polyplay
|
||||||
),
|
),
|
||||||
!.
|
!.
|
||||||
|
|
||||||
%% Flag which determines whether to print the parsed input or to process it
|
%% process_input(+Tree) is det
|
||||||
debug_print(false).
|
|
||||||
|
|
||||||
%% process_input(+tree) is determines
|
|
||||||
%
|
%
|
||||||
% Execute the commands from the parse tree
|
% 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_input(command(CL, TCR)) :-
|
||||||
%% Process first command
|
%% Process first command
|
||||||
do_process_input(CL),
|
do_process_input(CL),
|
||||||
@ -113,11 +104,8 @@ process_input(command(CL, TCR)) :-
|
|||||||
TCR \== void,
|
TCR \== void,
|
||||||
%% recurse
|
%% recurse
|
||||||
process_input(TCR).
|
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
|
% Process a single command from the input
|
||||||
% Takes, as the only argument, the tree representing
|
% 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),
|
polynomial_tree_to_polynomial(PT, P),
|
||||||
(
|
(
|
||||||
not(number(N)),
|
not(number(N)),
|
||||||
scalepoly(N, P, P2)
|
scalepoly(N, P, P2)
|
||||||
;
|
;
|
||||||
number(N),
|
number(N),
|
||||||
scalepoly(P, N, P2)
|
scalepoly(P, N, P2)
|
||||||
),
|
),
|
||||||
simpoly(P2, SP),
|
simpoly(P2, SP),
|
||||||
@ -280,9 +268,9 @@ do_process_input(multiply(TN, PT)) :-
|
|||||||
%% Use function from UI layer
|
%% Use function from UI layer
|
||||||
(
|
(
|
||||||
not(number(N)),
|
not(number(N)),
|
||||||
scalepoly(N, P, P2)
|
scalepoly(N, P, P2)
|
||||||
;
|
;
|
||||||
number(N),
|
number(N),
|
||||||
scalepoly(P, N, P2)
|
scalepoly(P, N, P2)
|
||||||
),
|
),
|
||||||
simpoly(P2, SP),
|
simpoly(P2, SP),
|
||||||
|
Reference in New Issue
Block a user