2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,41 +1,45 @@
|
|||
/*REXX pgm executes a Turing machine based on initial state, tape, rules*/
|
||||
state = 'q0' /*initial Turing machine state. */
|
||||
term = 'qf' /*a state that is used for halt. */
|
||||
blank = 'B' /*this character is a true blank.*/
|
||||
call turing_rule 'q0 1 1 right q0' /*define a rule for the machine. */
|
||||
call turing_rule 'q0 B 1 stay qf' /* " " " " " " */
|
||||
call turing_init 1 1 1 /*initialize tape to string(s). */
|
||||
call turing_machine /*go invoke the Turning machine. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────TURING_MACHINE subroutine───────────*/
|
||||
turing_machine: !=1; bot=1; top=1 /*start at the tape location 1. */
|
||||
say /*might as well show a blank line*/
|
||||
do cycle=1 until state==term /*do Turing machine instructions.*/
|
||||
do k=1 for rules /*process the Turning mach. rules*/
|
||||
parse var rule.k rState rTape rWrite rMove rNext . /*pick pieces*/
|
||||
if state\==rState | @.!\==rTape then iterate /*wrong rule?*/
|
||||
@.!=rWrite /*right rule; write it ──► tape.*/
|
||||
if rMove== 'left' then !=!-1 /*Move left? Then subtract one.*/
|
||||
if rMove=='right' then !=!+1 /*Move right? Then add one.*/
|
||||
bot=min(bot,!); top=max(top,!) /*find the tape bottom and top.*/
|
||||
state=rNext /*use this for the next state. */
|
||||
iterate cycle /*go process another instruction.*/
|
||||
end /*k*/
|
||||
say '***error!*** unknown state:' state; leave /*oops.*/
|
||||
end /*cycle*/
|
||||
$= /*start with empty string (tape).*/
|
||||
do t=bot to top; _=@.t; if _==blank then _=' ' /*translate?*/
|
||||
$=$ || pad || _ /*build chr by chr, maybe pad it.*/
|
||||
end /*t*/ /* [↑] build the tape's contents.*/
|
||||
if $='' then $= "[tape is blank.]" /*make an empty tape visible.*/
|
||||
say 'Turning machine used' rules "rules in" cycle 'cycles, tape is:' $
|
||||
return
|
||||
/*──────────────────────────────────TURING_INIT subroutine──────────────*/
|
||||
turing_init: @.=blank; parse arg x
|
||||
do j=1 for words(x); @.j=word(x,j); end /*j*/
|
||||
return
|
||||
/*──────────────────────────────────TURING_RULE subroutine──────────────*/
|
||||
turing_rule: if symbol('RULES')=="LIT" then rules=0; rules=rules+1
|
||||
pad=left('',length(word(arg(1),2))\==1) /*used if any symbol's length>1.*/
|
||||
rule.rules=arg(1); say right('rule' rules,20) "═══►" rule.rules
|
||||
return
|
||||
/*REXX program executes a Turing machine based on initial state, tape, and rules. */
|
||||
state = 'q0' /*the initial Turing machine state. */
|
||||
term = 'qf' /*a state that is used for a halt. */
|
||||
blank = 'B' /*this character is a "true" blank. */
|
||||
call Turing_rule 'q0 1 1 right q0' /*define a rule for the Turing machine.*/
|
||||
call Turing_rule 'q0 B 1 stay qf' /* " " " " " " " */
|
||||
call Turing_init 1 1 1 /*initialize the tape to some string(s)*/
|
||||
call TM /*go and invoke the Turning machine. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
TM: !=1; bot=1; top=1; @er= '***error***' /*start at the tape location 1. */
|
||||
say /*might as well display a blank line. */
|
||||
do cycle=1 until state==term /*process Turing machine instructions.*/
|
||||
do k=1 for rules /* " " " rules. */
|
||||
parse var rule.k rState rTape rWrite rMove rNext . /*pick pieces. */
|
||||
if state\==rState | @.!\==rTape then iterate /*wrong rule ? */
|
||||
@.!=rWrite /*right rule; write it ───► the tape. */
|
||||
if rMove== 'left' then !=!-1 /*Are we moving left? Then subtract 1*/
|
||||
if rMove=='right' then !=!+1 /* " " " right? " add 1*/
|
||||
bot=min(bot, !); top=max(top, !) /*find the tape bottom and top. */
|
||||
state=rNext /*use this for the next state. */
|
||||
iterate cycle /*go process another TM instruction. */
|
||||
end /*k*/
|
||||
say @er 'unknown state:' state; leave /*oops, we have an unknown state error.*/
|
||||
end /*cycle*/
|
||||
$= /*start with empty string (the tape). */
|
||||
do t=bot to top; _=@.t
|
||||
if _==blank then _=' ' /*do we need to translate a true blank?*/
|
||||
$=$ || pad || _ /*construct char by char, maybe pad it.*/
|
||||
end /*t*/ /* [↑] construct the tape's contents.*/
|
||||
L=length($)
|
||||
if L==0 then $= "[tape is blank.]" /*make an empty tape visible to user.*/
|
||||
if L>1000 then $=left($, 1000) ... /*truncate tape to 1k bytes, append ···*/
|
||||
say "tape's contents:" $ /*show the tape's contents (or 1st 1k).*/
|
||||
say "tape's length: " L /* " " " length. */
|
||||
say 'Turning machine used ' rules " rules in " cycle ' cycles.'
|
||||
return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
Turing_init: @.=blank; parse arg x; do j=1 for words(x); @.j=word(x,j); end /*j*/
|
||||
return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
Turing_rule: if symbol('RULES')=="LIT" then rules=0; rules=rules+1
|
||||
pad=left('', length( word( arg(1),2 ) ) \==1 ) /*padding for rule*/
|
||||
rule.rules=arg(1); say right('rule' rules, 20) "═══►" rule.rules
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
/*REXX pgm executes a Turing machine based on initial state, tape, rules*/
|
||||
state = 'a' /*initial Turing machine state. */
|
||||
term = 'halt' /*a state that is used for halt. */
|
||||
blank = 0 /*this character is a true blank.*/
|
||||
call turing_rule 'a 0 1 right b' /*define a rule for the machine. */
|
||||
call turing_rule 'a 1 1 left c' /* " " " " " " */
|
||||
call turing_rule 'b 0 1 left a' /* " " " " " " */
|
||||
call turing_rule 'b 1 1 right b' /* " " " " " " */
|
||||
call turing_rule 'c 0 1 left b' /* " " " " " " */
|
||||
call turing_rule 'c 1 1 stay halt' /* " " " " " " */
|
||||
call turing_init /*initialize tape to string(s). */
|
||||
call turing_machine /*go invoke the Turning machine. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────TURING_MACHINE subroutine───────────*/
|
||||
turing_machine ∙∙∙
|
||||
/*REXX program executes a Turing machine based on initial state, tape, and rules. */
|
||||
state = 'a' /*the initial Turing machine state. */
|
||||
term = 'halt' /*a state that is used for a halt. */
|
||||
blank = 0 /*this character is a "true" blank. */
|
||||
call Turing_rule 'a 0 1 right b' /*define a rule for the Turing machine.*/
|
||||
call Turing_rule 'a 1 1 left c' /* " " " " " " " */
|
||||
call Turing_rule 'b 0 1 left a' /* " " " " " " " */
|
||||
call Turing_rule 'b 1 1 right b' /* " " " " " " " */
|
||||
call Turing_rule 'c 0 1 left b' /* " " " " " " " */
|
||||
call Turing_rule 'c 1 1 stay halt' /* " " " " " " " */
|
||||
call Turing_init /*initialize the tape to some string(s)*/
|
||||
call TM /*go and invoke the Turning machine. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
TM: ∙∙∙
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
/*REXX pgm executes a Turing machine based on initial state, tape, rules*/
|
||||
state = 'A' /*initial Turing machine state. */
|
||||
term = 'H' /*a state that is used for halt. */
|
||||
blank = 0 /*this character is a true blank.*/
|
||||
call turing_rule 'A 0 1 right B' /*define a rule for the machine. */
|
||||
call turing_rule 'A 1 1 left C' /* " " " " " " */
|
||||
call turing_rule 'B 0 1 right C' /* " " " " " " */
|
||||
call turing_rule 'B 1 1 right B' /* " " " " " " */
|
||||
call turing_rule 'C 0 1 right D' /* " " " " " " */
|
||||
call turing_rule 'C 1 1 left E' /* " " " " " " */
|
||||
call turing_rule 'D 0 1 left A' /* " " " " " " */
|
||||
call turing_rule 'D 1 1 left D' /* " " " " " " */
|
||||
call turing_rule 'E 0 1 stay H' /* " " " " " " */
|
||||
call turing_rule 'E 1 1 left A' /* " " " " " " */
|
||||
call turing_init /*initialize tape to string(s). */
|
||||
call turing_machine /*go invoke the Turning machine. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────TURING_MACHINE subroutine───────────*/
|
||||
turing_machine ∙∙∙
|
||||
/*REXX program executes a Turing machine based on initial state, tape, and rules. */
|
||||
state = 'A' /*initialize the Turing machine state.*/
|
||||
term = 'H' /*a state that is used for the halt. */
|
||||
blank = 0 /*this character is a "true" blank. */
|
||||
call Turing_rule 'A 0 1 right B' /*define a rule for the Turing machine.*/
|
||||
call Turing_rule 'A 1 1 left C' /* " " " " " " " */
|
||||
call Turing_rule 'B 0 1 right C' /* " " " " " " " */
|
||||
call Turing_rule 'B 1 1 right B' /* " " " " " " " */
|
||||
call Turing_rule 'C 0 1 right D' /* " " " " " " " */
|
||||
call Turing_rule 'C 1 0 left E' /* " " " " " " " */
|
||||
call Turing_rule 'D 0 1 left A' /* " " " " " " " */
|
||||
call Turing_rule 'D 1 1 left D' /* " " " " " " " */
|
||||
call Turing_rule 'E 0 1 stay H' /* " " " " " " " */
|
||||
call Turing_rule 'E 1 0 left A' /* " " " " " " " */
|
||||
call Turing_init /*initialize the tape to some string(s)*/
|
||||
call TM /*go and invoke the Turning machine. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
TM: ∙∙∙
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
/*REXX pgm executes a Turing machine based on initial state, tape, rules*/
|
||||
state = 'A' /*initial Turing machine state. */
|
||||
term = 'halt' /*a state that is used for halt. */
|
||||
blank = 0 /*this character is a true blank.*/
|
||||
call turing_rule 'A 1 1 right A' /*define a rule for the machine. */
|
||||
call turing_rule 'A 2 3 right B' /* " " " " " " */
|
||||
call turing_rule 'A 0 0 left E' /* " " " " " " */
|
||||
call turing_rule 'B 1 1 right B' /* " " " " " " */
|
||||
call turing_rule 'B 2 2 right B' /* " " " " " " */
|
||||
call turing_rule 'B 0 0 left C' /* " " " " " " */
|
||||
call turing_rule 'C 1 2 left D' /* " " " " " " */
|
||||
call turing_rule 'C 2 2 left C' /* " " " " " " */
|
||||
call turing_rule 'C 3 2 left E' /* " " " " " " */
|
||||
call turing_rule 'D 1 1 left D' /* " " " " " " */
|
||||
call turing_rule 'D 2 2 left D' /* " " " " " " */
|
||||
call turing_rule 'D 3 1 right A' /* " " " " " " */
|
||||
call turing_rule 'E 1 1 left E' /* " " " " " " */
|
||||
call turing_rule 'E 0 0 right halt' /* " " " " " " */
|
||||
call turing_init 1 2 2 1 2 2 1 2 1 2 1 2 1 2 /*init. tape to string(s). */
|
||||
call turing_machine /*go invoke the Turning machine. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────TURING_MACHINE subroutine───────────*/
|
||||
turing_machine ∙∙∙
|
||||
/*REXX program executes a Turing machine based on initial state, tape, and rules. */
|
||||
state = 'A' /*the initial Turing machine state. */
|
||||
term = 'halt' /*a state that is used for the halt. */
|
||||
blank = 0 /*this character is a "true" blank. */
|
||||
call Turing_rule 'A 1 1 right A' /*define a rule for the Turing machine.*/
|
||||
call Turing_rule 'A 2 3 right B' /* " " " " " " " */
|
||||
call Turing_rule 'A 0 0 left E' /* " " " " " " " */
|
||||
call Turing_rule 'B 1 1 right B' /* " " " " " " " */
|
||||
call Turing_rule 'B 2 2 right B' /* " " " " " " " */
|
||||
call Turing_rule 'B 0 0 left C' /* " " " " " " " */
|
||||
call Turing_rule 'C 1 2 left D' /* " " " " " " " */
|
||||
call Turing_rule 'C 2 2 left C' /* " " " " " " " */
|
||||
call Turing_rule 'C 3 2 left E' /* " " " " " " " */
|
||||
call Turing_rule 'D 1 1 left D' /* " " " " " " " */
|
||||
call Turing_rule 'D 2 2 left D' /* " " " " " " " */
|
||||
call Turing_rule 'D 3 1 right A' /* " " " " " " " */
|
||||
call Turing_rule 'E 1 1 left E' /* " " " " " " " */
|
||||
call Turing_rule 'E 0 0 right halt' /* " " " " " " " */
|
||||
call Turing_init 1 2 2 1 2 2 1 2 1 2 1 2 1 2 /*initialize the tape to some string(s)*/
|
||||
call TM /*go and invoke the Turning machine. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
TM: ∙∙∙
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue