Universal Turing machine: Difference between revisions

Line 2,386:
<symbol> : op <- symbol</pre>
 
2. Machine definition
2. Interpreter
 
<pre>M = <f i q h b> where
 
f is a transition function
i is an input tape
q is the current state
h is the halt state
b is the blank symbol</pre>
 
23. Interpreter
 
Tape is split into two stacks.
 
<pre>T = reverse(l) . ri where ri is the scanned symbol.
0</pre>
 
The simpler the better.
 
<lang lisp>;;(defun 22.06.14run (f i q h b)
(let (l code op x)
 
(loop until (eql q h) do
(defun run (table input state halt blank)
(letsetf code (lcdr (rassoc inputq f)) rule op exec'null x t)
(loop until (eqldolist state(c haltcode) do
(case c
(setf rule (cdr (assoc state table)) op 'null x t)
(dolist= (symbolsetf x (eql (car i) ruleop)))
(case% (when x (rplaca i symbolop)))
(=< (setfwhen x (eqlpush (carpop rl) opi)))
(%> (when x (rplacapush r(pop i) opl)))
(<@ (when x (pushsetf (popq lop) r(return)))
(>t (whensetf xop (push (pop r) lc)))
(@unless (whencar xi) (setfpop state opi) (returnpush b i))))
(format t "M = (~a, ~{~a~}.~{~a~})~%" (tq (setfreverse opl) symboli)))</lang>
(unless (car r) (pop r) (push blank r))))
(format t "M = (~a, ~{~a~}.~{~a~})~%" state (reverse l) r)))</lang>
 
34. Rules
 
Instructions are stored in association lists.
Line 2,424 ⟶ 2,432:
(c . (0 = 1 % < b @ 1 = halt @))))</lang>
 
45. Execution
 
{{out}}
Line 2,434 ⟶ 2,442:
That's all Folks !
 
''cyril nocton (cyril.nocton@gmail.com)''
 
=={{header|Cowgol}}==
422

edits