-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
ElessarWebb edited this page Jan 3, 2013
·
1 revision
- Create a file that will contain the turing machine description. Sample turing descriptions are provided by the repository. For the syntax, [see below](Syntax of a turing description file)
- run
./turing <turing machine file path> <tapelength> <input tape contents>
- the program will run and show you how the tape changes over time and how the tape head moves over the tape.
This is an example run of one of the included example turing machines
$ ./src/turing ./examples/simple.t 50 0000__ # command, runs the simple turing machine
# with a tape of length 50 (arbitrary)
# and initial contents 0000_
# this machine checks if the input string contains
# a power of 2 zeros
examples/simple.t> Parsing file examples/simple.t ...
> Starting simulation...
q1 0000__ # initial tape state (in state q1; head at start of tape)
_ q2 000__ # read one character and wrote a space, now in q2
_x q3 00__ # read another character and wrote an x, in q3
_x0 q4 0__ # etc
_x0x q3 __
_x0 q5 x__
_x q5 0x__
_ q5 x0x__
q5 _x0x__
_ q2 x0x__
_x q2 0x__
_xx q3 x__
_xxx q3 __
_xx q5 x__
_x q5 xx__
_ q5 xxx__
q5 _xxx__
_ q2 xxx__
_x q2 xx__
_xx q2 x__
_xxx q2 __
> Done!
> Input accepted in state: q_accept # Simulation ended in q_accept state
The syntax is as follow:
<int:amount of states that follows>
<state>
...
<state>
<transition>
...
<transition>
The syntax for a state description is:
<name> <special>
unique identifier of the state
Can be one of:
-
A
for accept state -
R
for reject state - empty
The syntax for a transition description is:
<from state> <input> -> <to state> <write char> <move>
One of the state identifiers
Input token on which the transition occurs
One of the state identifiers
Token to write to the tape before the tape head moves.
-
_
is used as a<space>
character -
\
is used as a character that denotes do not write anything
Either L
or R
for left/right movement of the tape head