Some progress in supporting floats

Fixed some typos
This commit is contained in:
Diogo Cordeiro 2018-12-20 20:45:11 +00:00
parent 3af7f72aa4
commit d054989bc0
1 changed files with 26 additions and 11 deletions

View File

@ -261,7 +261,6 @@ do_process_input(store_multiplication(TN, PT, V)) :-
write(SP),
nl.
do_process_input(multiply(TN, PT)) :-
%% To multiply, assume the left is a number
%% Flatten both
polynomial_tree_to_polynomial(TN, N),
polynomial_tree_to_polynomial(PT, P),
@ -445,18 +444,30 @@ parse_number_explicit(_, T, T, [], []) :-
%
% Parse a floating point number
%
parse_floating_number(N) -->
{
not(compound(N))
},
[N],
{
% Assert it must be between negative and positive infinity
% This uses the CLPR library, which makes this reversible,
% whereas `number(N)` is always false, since it only succeeds
% if the argument is bound (to a integer or float)
(N >= 0; N < 0)
}.
parse_floating_number(op('.', TL, TR)) -->
%% A float is a node with a dot as the operator
%% If there's a number on the left
parse_number(TL),
%% Followed by either point or dot
[X],
{ member(X, [point, dot]), ! },
[RadixPoint],
{
member(RadixPoint, [point, dot]),
!
},
%% Followed by another number
parse_positive_number(TR).
parse_floating_number(TN) -->
%% Or just a number
parse_number(TN).
%% parse_positive_number(-tree, +stream, -not_consumed) is det
%
@ -464,8 +475,11 @@ parse_floating_number(TN) -->
%
parse_positive_number(N) -->
[N],
%% CLPFD, a number between 0 and infinity
{ N in 0..sup, ! }.
{
not(compound(N)),
%% CLPFD, a number between 0 and infinity
N in 0..sup, !
}.
parse_positive_number(T) -->
parse_number_explicit(void, void, T).
@ -476,7 +490,7 @@ parse_positive_number(T) -->
parse_number(N) -->
[N],
%% CLPFD, a number between negative infinity and positive infinity
{ not(atom(N)), N in inf..sup, ! }.
{ N in inf..sup, ! }.
parse_number(op(neg, T)) --> % TODO
%% A number can start with negative, to negate it
[negative],
@ -574,6 +588,7 @@ parse_polynomial_operand(load(T)) -->
%% Declare polynomial_store as a dynamic predicate with two arguments
%% Used to store and retrieve polynomials associated with a variable
%% First being the variable name and the second its content
:- dynamic polynomial_store/2.
%% parse_stored_variable(-var) is det
@ -624,7 +639,7 @@ parse_polynomial_variable(B) -->
% Parse a polynomial. Delegates to explicit variant
%
parse_polynomial(T) -->
%% Ignore "polynomail", if followed by a valid polynomial
%% Ignore "polynomial", if followed by a valid polynomial
[polynomial],
{ ! },
%% Delegate
@ -809,7 +824,7 @@ parse_command(op(+, TN, TP)) -->
%% parse_input(-tree) is det
%
% Parse each command and string it into a list
% Parse each command and string into a list
%
parse_input(command(TCL, TCR)) -->
%% Result is a struct with a command on the left