mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Update prolog samples
This commit is contained in:
21
samples/Prolog/turing.pl
Normal file
21
samples/Prolog/turing.pl
Normal file
@@ -0,0 +1,21 @@
|
||||
-turing(Tape0, Tape) :-
|
||||
- perform(q0, [], Ls, Tape0, Rs),
|
||||
- reverse(Ls, Ls1),
|
||||
- append(Ls1, Rs, Tape).
|
||||
-
|
||||
-perform(qf, Ls, Ls, Rs, Rs) :- !.
|
||||
-perform(Q0, Ls0, Ls, Rs0, Rs) :-
|
||||
- symbol(Rs0, Sym, RsRest),
|
||||
- once(rule(Q0, Sym, Q1, NewSym, Action)),
|
||||
- action(Action, Ls0, Ls1, [NewSym|RsRest], Rs1),
|
||||
- perform(Q1, Ls1, Ls, Rs1, Rs).
|
||||
-
|
||||
-symbol([], b, []).
|
||||
-symbol([Sym|Rs], Sym, Rs).
|
||||
-
|
||||
-action(left, Ls0, Ls, Rs0, Rs) :- left(Ls0, Ls, Rs0, Rs).
|
||||
-action(stay, Ls, Ls, Rs, Rs).
|
||||
-action(right, Ls0, [Sym|Ls0], [Sym|Rs], Rs).
|
||||
-
|
||||
-left([], [], Rs0, [b|Rs0]).
|
||||
-left([L|Ls], Ls, Rs, [L|Rs]).
|
||||
Reference in New Issue
Block a user