09.05.2013 Views

Link alle Slide Conferenza La Macchina di Turing - ITIS G. Marconi

Link alle Slide Conferenza La Macchina di Turing - ITIS G. Marconi

Link alle Slide Conferenza La Macchina di Turing - ITIS G. Marconi

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Struttura <strong>di</strong> un self-interpreter: <strong>Turing</strong>!!!<br />

input P,d; Program to be interpreted, and its data<br />

pc := 2; Initialise program counter and store<br />

store := [in ↦→ d,out ↦→ 0,x1 ↦→ 0,...];<br />

while pc < length(P) do<br />

instruction := lookup(P,pc); Find the pc-th instruction<br />

case instruction of Dispatch on syntax<br />

skip : pc := pc+1;<br />

x := e : store := store[x ↦→ eval(e,store)]; pc := pc+1;<br />

... endw ;<br />

output store[out];<br />

eval(e,store) = case e of Function to evaluate expressions<br />

constant : e<br />

variable : store(e)<br />

e1+e2 : eval(e1,store)+eval(e2,store)<br />

e1−e2 : eval(e1,store)−eval(e2,store)<br />

e1∗e2 : eval(e1,store)∗eval(e2,store) ...<br />

Mathesis: Verona - 10.03.2012 – p.45/56

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!