From defedcbd1208b3023b6cd669bf77dd89d6de6b35 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Tue, 13 Aug 2019 11:29:49 -0700 Subject: [PATCH] Parse ints; move line/{1,2} to main.pl. --- thun/gnu-prolog/main.pl | 10 ++++++++++ thun/gnu-prolog/parser.pl | 11 +---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/thun/gnu-prolog/main.pl b/thun/gnu-prolog/main.pl index 7705543..306ed76 100644 --- a/thun/gnu-prolog/main.pl +++ b/thun/gnu-prolog/main.pl @@ -41,3 +41,13 @@ do_line(_Line, S, S) :- write('Err'), nl. prompt :- write(`joy? `). show_stack(S) :- nl, print_stack(S), write(` <-top`), nl, nl. + +% Line is the next new-line delimited line from standard input stream as +% a list of character codes. + +line(Line) :- get_code(X), line(X, Line). + +line(10, []) :- !. % break on new-lines. +line(-1, [eof]) :- !. % break on EOF +line(X, [X|Line]) :- get_code(Y), !, line(Y, Line). + diff --git a/thun/gnu-prolog/parser.pl b/thun/gnu-prolog/parser.pl index 90fe216..ecf73da 100644 --- a/thun/gnu-prolog/parser.pl +++ b/thun/gnu-prolog/parser.pl @@ -41,6 +41,7 @@ number_digits(Codes) --> signed_float_or_integer(Codes), !, end_num. signed_float_or_integer(Codes) --> signed_digits(J), ".", !, digits(I), { append(J, [0'.|I], Codes) }. +signed_float_or_integer(Codes) --> signed_digits(Codes). signed_digits([45|Codes]) --> "-", !, digits(Codes). signed_digits( Codes ) --> digits(Codes). @@ -69,16 +70,6 @@ one_or_more_([Ch|Rest], P) --> call(P, Ch), one_or_more_(Rest, P). one_or_more_([Ch], P) --> call(P, Ch). -% Line is the next new-line delimited line from standard input stream as -% a list of character codes. - -line(Line) :- get_code(X), line(X, Line). - -line(10, []) :- !. % break on new-lines. -line(-1, [eof]) :- !. % break on EOF -line(X, [X|Line]) :- get_code(Y), !, line(Y, Line). - - /* Print state.