Fixed major bug with parsing
This commit is contained in:
parent
90b5c6b3f1
commit
4e37792c0a
22
polymani.pl
22
polymani.pl
|
@ -451,6 +451,9 @@ parse_floating_number(op('.', TL, TR)) -->
|
||||||
{ member(X, [point, dot]), ! },
|
{ member(X, [point, dot]), ! },
|
||||||
%% Followed by another number
|
%% Followed by another number
|
||||||
parse_positive_number(TR).
|
parse_positive_number(TR).
|
||||||
|
parse_floating_number(TN) -->
|
||||||
|
%% Or just a number
|
||||||
|
parse_number(TN).
|
||||||
|
|
||||||
%% parse_positive_number(-tree, +stream, -not_consumed) is det
|
%% parse_positive_number(-tree, +stream, -not_consumed) is det
|
||||||
%
|
%
|
||||||
|
@ -560,6 +563,11 @@ parse_polynomial_operand(load(T)) -->
|
||||||
%% Tag the variable, to be loaded later
|
%% Tag the variable, to be loaded later
|
||||||
parse_stored_variable(T),
|
parse_stored_variable(T),
|
||||||
{ ! }.
|
{ ! }.
|
||||||
|
%% Tests:
|
||||||
|
%% ?- parse_polynomial_operand(T, [two], NC).
|
||||||
|
%@ T = 2,
|
||||||
|
%@ NC = [] ;
|
||||||
|
%@ false.
|
||||||
|
|
||||||
%% Declare polynomial_store as a dynamic predicate with two arguments
|
%% Declare polynomial_store as a dynamic predicate with two arguments
|
||||||
%% Used to store and retrieve polynomials associated with a variable
|
%% Used to store and retrieve polynomials associated with a variable
|
||||||
|
@ -618,10 +626,6 @@ parse_polynomial(T) -->
|
||||||
{ ! },
|
{ ! },
|
||||||
%% Delegate
|
%% Delegate
|
||||||
parse_polynomial_explicit(_-_, T).
|
parse_polynomial_explicit(_-_, T).
|
||||||
parse_polynomial(void, NC, NC) :-
|
|
||||||
%% If can't parse more, done here
|
|
||||||
not(parse_polynomial_explicit(_-_, _, NC, _)),
|
|
||||||
!.
|
|
||||||
parse_polynomial(T) -->
|
parse_polynomial(T) -->
|
||||||
%% Delegate
|
%% Delegate
|
||||||
parse_polynomial_explicit(_-_, T),
|
parse_polynomial_explicit(_-_, T),
|
||||||
|
@ -630,9 +634,11 @@ parse_polynomial(T) -->
|
||||||
%% ?- parse_polynomial(T, [], _).
|
%% ?- parse_polynomial(T, [], _).
|
||||||
%@ false.
|
%@ false.
|
||||||
%% ?- parse_polynomial(T, [two], _).
|
%% ?- parse_polynomial(T, [two], _).
|
||||||
%@ T = 2.
|
%@ T = 2,
|
||||||
|
%@ NC = [].
|
||||||
%% ?- parse_polynomial(T, [two, times, three], _).
|
%% ?- parse_polynomial(T, [two, times, three], _).
|
||||||
%@ T = op(*, 2, 3).
|
%@ T = op(*, 2, 3),
|
||||||
|
%@ NC = [].
|
||||||
%% ?- parse_polynomial(T, [two, times, three, plus, four], _).
|
%% ?- parse_polynomial(T, [two, times, three, plus, four], _).
|
||||||
%@ T = op(+, op(*, 2, 3), 4).
|
%@ T = op(+, op(*, 2, 3), 4).
|
||||||
%% ?- parse_polynomial(T, [two, plus, three, times, four], _).
|
%% ?- parse_polynomial(T, [two, plus, three, times, four], _).
|
||||||
|
@ -680,7 +686,7 @@ parse_polynomial_explicit(TLP-TL, T) -->
|
||||||
%% on the left, through the difference structure,
|
%% on the left, through the difference structure,
|
||||||
parse_polynomial_operand(TL),
|
parse_polynomial_operand(TL),
|
||||||
%% parse either a minus or a plus
|
%% parse either a minus or a plus
|
||||||
member(COp, [-, +]),
|
{ member(COp, [-, +]) },
|
||||||
parse_operation(COp),
|
parse_operation(COp),
|
||||||
!,
|
!,
|
||||||
%% Recurse on the right with add; position the sub tree on the right
|
%% Recurse on the right with add; position the sub tree on the right
|
||||||
|
@ -772,7 +778,7 @@ parse_command(op(-, TN, TP)) -->
|
||||||
[sub],
|
[sub],
|
||||||
parse_polynomial(TN),
|
parse_polynomial(TN),
|
||||||
[X],
|
[X],
|
||||||
{ member(X, [to, with]) },
|
{ member(X, [to, from, with]) },
|
||||||
parse_polynomial(TP).
|
parse_polynomial(TP).
|
||||||
parse_command(op(+, TN, TP)) -->
|
parse_command(op(+, TN, TP)) -->
|
||||||
[add],
|
[add],
|
||||||
|
|
Reference in New Issue