Download code

Jump to: navigation, search

Back to Turing_machine_simulator_(Sed)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

turing.sed

  1 # test for valid tape:
  2 /^[*|]*[oI][*|]*$/! b error
  3 # extend visible tape
  4 s/^o/\*o/; s/^I/\*I/; s/o$/o\*/; s/I$/I\*/
  5 : A
  6 # print current state and tape
  7 h
  8 s/^/A /
  9 p
 10 g
 11 /o/ {
 12   # write 1
 13   s/o/I/
 14   # move right
 15   s/o\*/*o/
 16   s/o|/*I/
 17   s/I\*/|o/
 18   s/I|/|I/
 19   s/o$/o\*/
 20   s/I$/I\*/
 21   # next state: B
 22   b B
 23 }
 24 /I/ {
 25   # write 1
 26   s/o/I/
 27   # move left
 28   s/\*o/o*/
 29   s/|o/I*/
 30   s/\*I/o|/
 31   s/|I/I|/
 32   s/^o/*o/
 33   s/^I/*I/
 34 
 35   # next state: C
 36   b C
 37 }
 38 b error
 39 : B
 40 # print current state and tape
 41 h
 42 s/^/B /
 43 p
 44 g
 45 /o/ {
 46   # write 1
 47   s/o/I/
 48   # move left
 49   s/\*o/o*/
 50   s/|o/I*/
 51   s/\*I/o|/
 52   s/|I/I|/
 53   s/^o/*o/
 54   s/^I/*I/
 55 
 56   # next state: A
 57   b A
 58 }
 59 /I/ {
 60   # write 1
 61   s/o/I/
 62   # move right
 63   s/o\*/*o/
 64   s/o|/*I/
 65   s/I\*/|o/
 66   s/I|/|I/
 67   s/o$/o\*/
 68   s/I$/I\*/
 69   # next state: B
 70   b B
 71 }
 72 b error
 73 : C
 74 # print current state and tape
 75 h
 76 s/^/C /
 77 p
 78 g
 79 /o/ {
 80   # write 1
 81   s/o/I/
 82   # move left
 83   s/\*o/o*/
 84   s/|o/I*/
 85   s/\*I/o|/
 86   s/|I/I|/
 87   s/^o/*o/
 88   s/^I/*I/
 89 
 90   # next state: B
 91   b B
 92 }
 93 /I/ {
 94   # write 1
 95   s/o/I/
 96   # move right
 97   s/o\*/*o/
 98   s/o|/*I/
 99   s/I\*/|o/
100   s/I|/|I/
101   s/o$/o\*/
102   s/I$/I\*/
103   # next state: halt
104   b halt
105 }
106 b error
107 : halt
108 s/^/= /
109 q 0
110 : error
111 # display error
112 s/^/error: invalid tape: /
113 q 1


hijacker
hijacker
hijacker
hijacker