changeset 8272a9b5e54c in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=8272a9b5e54c user: Simon Forman <sform****@hushm*****> date: Mon Aug 12 19:09:49 2019 -0700 description: swoncat and fiddling with parser. changeset bd22d7728c33 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=bd22d7728c33 user: Simon Forman <sform****@hushm*****> date: Mon Aug 12 19:17:15 2019 -0700 description: minor cleanup changeset be2a4392f394 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=be2a4392f394 user: Simon Forman <sform****@hushm*****> date: Mon Aug 12 19:25:13 2019 -0700 description: Oops! Regression. changeset 4ff5b74fc0a9 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=4ff5b74fc0a9 user: Simon Forman <sform****@hushm*****> date: Mon Aug 12 20:12:35 2019 -0700 description: rework parser DCGs changeset b3344d468606 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=b3344d468606 user: Simon Forman <sform****@hushm*****> date: Mon Aug 12 20:59:02 2019 -0700 description: Minor cleanup of the parser. diffstat: thun/gnu-prolog/defs.pl | 1 + thun/gnu-prolog/defs.txt | 1 + thun/gnu-prolog/parser.pl | 45 ++++++++++++++++++++------------------------- 3 files changed, 22 insertions(+), 25 deletions(-) diffs (85 lines): diff -r 482351329728 -r b3344d468606 thun/gnu-prolog/defs.pl --- a/thun/gnu-prolog/defs.pl Sun Aug 11 21:30:02 2019 -0700 +++ b/thun/gnu-prolog/defs.pl Mon Aug 12 20:59:02 2019 -0700 @@ -58,6 +58,7 @@ def(sqr,[dup,*]). def(step_zero,[0,rollup,step]). def(sum,[0,swap,[+],step]). +def(swoncat,[swap,concat]). def(swons,[swap,cons]). def(take,[[],rolldown,[shift],times,pop]). def(ternary,[binary,popd]). diff -r 482351329728 -r b3344d468606 thun/gnu-prolog/defs.txt --- a/thun/gnu-prolog/defs.txt Sun Aug 11 21:30:02 2019 -0700 +++ b/thun/gnu-prolog/defs.txt Mon Aug 12 20:59:02 2019 -0700 @@ -61,6 +61,7 @@ sqr == dup * step_zero == 0 rollup step sum == 0 swap [+] step +swoncat == swap concat swons == swap cons take == [] rolldown [shift] times pop ternary == binary popd diff -r 482351329728 -r b3344d468606 thun/gnu-prolog/parser.pl --- a/thun/gnu-prolog/parser.pl Sun Aug 11 21:30:02 2019 -0700 +++ b/thun/gnu-prolog/parser.pl Mon Aug 12 20:59:02 2019 -0700 @@ -33,6 +33,23 @@ symbol(C) --> chars(Chars), !, {Chars \= "==", atom_codes(C, Chars)}. +% TODO: negative numbers, floats, scientific notation. + +num(N) --> digits(Codes), !, { number_codes(N, Codes) }. + +% Groups of characters. + +chars(Chars) --> one_or_more(char, Chars). +blanks --> blank, !, blanks | []. +digits(Digits) --> one_or_more(digit, Digits). + +% Character types. + +char(Ch) --> [Ch], { nonvar(Ch), Ch =\= 0'[, Ch =\= 0'], between(33, 126, Ch) }. +blank --> [Ch], { nonvar(Ch),(Ch =:= 32 ; between(9, 13, Ch)) }. +digit(Ch) --> [Ch], { nonvar(Ch), between(48, 57, Ch) }. + + % Line is the next new-line delimited line from standard input stream as % a list of character codes. @@ -42,32 +59,10 @@ line(-1, [eof]) :- !. % break on EOF line(X, [X|Line]) :- get_code(Y), !, line(Y, Line). - -chars([Ch|Rest]) --> char(Ch), chars(Rest). -chars([Ch]) --> char(Ch). - -char(Ch) --> [Ch], { Ch \== 0'[, Ch \== 0'], Ch >= 33, Ch =< 126 }. - - -blanks --> blank, !, blanks. -blanks --> []. - -blank --> [32] | [13] | [10]. - +one_or_more(E, List) --> one_or_more_(List, E). -% TODO: negative numbers, floats, scientific notation. - -num(N) --> digits(Codes), !, { num(N, Codes) }. - -num(_, []) :- fail, !. -num(N, [C|Codes]) :- number_codes(N, [C|Codes]). - - -digits([H|T]) --> digit(H), !, digits(T). -digits([]) --> []. - -digit(C) --> [C], { nonvar(C), C =< 57, C >= 48 }. - +one_or_more_([Ch|Rest], P) --> call(P, Ch), one_or_more_(Rest, P). +one_or_more_([Ch], P) --> call(P, Ch). /*