diff options
| author | Mirek Kratochvil <exa.exa@gmail.com> | 2023-03-10 21:55:16 +0100 |
|---|---|---|
| committer | Mirek Kratochvil <exa.exa@gmail.com> | 2023-03-10 21:55:16 +0100 |
| commit | 038bc63b45136b5eb84dbc5ee8469ffaf589c9d1 (patch) | |
| tree | 7c5a86b72b25aa274b40562f4f538cc96dea87e5 /inst | |
| parent | 768fb712004f04357668636bf7cb95a9401527a4 (diff) | |
| download | prlg-038bc63b45136b5eb84dbc5ee8469ffaf589c9d1.tar.gz prlg-038bc63b45136b5eb84dbc5ee8469ffaf589c9d1.tar.bz2 | |
dcgs dcg.
Diffstat (limited to 'inst')
| -rw-r--r-- | inst/prelude.pl | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/inst/prelude.pl b/inst/prelude.pl index 34e7853..54246ba 100644 --- a/inst/prelude.pl +++ b/inst/prelude.pl @@ -1,9 +1,13 @@ member(X, [X|_]). member(X, [_|T]) :- member(X,T). -append([], X, X). +append([], [], []) :- !. +append([], [H|T], [H|T]) :- !. append([X|T], Y, [X|TY]) :- append(T,Y,TY). +list([]). +list([_|_]). + :- op(700, xfx, is), op(700, xfx, <), op(700, xfx, =<), @@ -50,3 +54,32 @@ gcd(X,Y,R) :- zero(Y), !, R=X. gcd(X,Y,R) :- X1 is X mod Y, gcd(Y,X1,R). lcm(X,Y,R) :- gcd(X,Y,GCD), R is X*(Y/GCD). + +:- op(1200, xfx, -->). + +say([], SameState, SameState) :- !. +say(Tokens, ParsedList, Rest) :- + append(Tokens, Rest, ParsedList). + +load_expansion(X --> Y, Xp :- Yp) :- !, + expand_phrasecall(X, Xp, S0, S), + expand_phrase(Y, Yp, S0, S). + +expand_phrase((A, B), (Ap, Bp), S0, S) :- !, + expand_phrase(A, Ap, S0, S1), + expand_phrase(B, Bp, S1, S). +expand_phrase((A; B), (Ap; Bp), S0, S) :- !, + expand_phrase(A, Ap, S0, S), + expand_phrase(B, Bp, S0, S). +expand_phrase(L, say(L, S0, S), S0, S) :- list(L), !. +expand_phrase({X}, X, S, S) :- !. +expand_phrase(!, !, S, S) :- !. +expand_phrase(X, Xp, S0, S) :- expand_phrasecall(X, Xp, S0, S). + +expand_phrasecall(X, Xp, S0, S) :- + atom(X), !, + struct(Xp, X, [S0, S]). +expand_phrasecall(X, Xp, S0, S) :- !, + struct(X, Id, Args), + append(Args, [S0, S], Args1), + struct(Xp, Id, Args1). |
