An C++
implementation of the Turing Machine.
The default filename for the configuration is config.tm
(soon an option to change it...) and it follows this grammar:
config_file | { tm_elements } | |
tm_elements | option | option , tm_elements | |
option |
instructions = { instruction_list } | alphabet = { symbol_list } | states = { symbol_list } | initial_state = { state } | memory = { symbol_list } |
|
instruction_list | tuple | tuple , instruction_list | |
symbol_list | symbol | symbol , symbol_list | |
tuple | < state , symbol , state , symbol , move > | |
state | ID | |
symbol | ID | |
ID | Char , CharID | |
Char |
a | b | |
|
move | L | R | l | r |
where terminals are in bold font and nonterminals in italics. Vertical bars |
separate alternatives.
Keywords instructions
, alphabet
, states
, initial_state
, memory
are, at the moment, case sensitive.
{
instructions = {
<q0,$,q1,0,L>,
<q1,$,q2,$,R>,
<q1,1,q1,1,R>,
<q1,0,q1,0,R>,
<q2,$,q3,$,R>,
<q2,1,q2,1,R>,
<q2,0,q2,0,R>
},
alphabet = {
$,0,1
},
memory = {
$,1,1,0,1,1,$
},
states = {
q0,q1,q2,q3
},
initial_state = {
q0
}
}
After writing the config file, you have to create a TouringMachine tm
object, a ConfigLoader cl
and call the function
void loadConfig(TuringMachine& turingMachine, const std::string& fileName);
then simply
std::cerr << tm.getMemory() << std::endl;
tm.run();
std::cerr << tm.getMemory() << std::endl;
to print the output.
Inside the test
folder type:
g++ -Wall -Wextra -I../include ../src/configLoader.cpp ../src/turingMachine.cpp <your_file>.cpp
or
g++ -DDEBUG -Wall -Wextra -I../include ../src/configLoader.cpp ../src/turingMachine.cpp <your_file>.cpp
to get a step-by-step computation.
command | |
---|---|
-c, --head-color |
Changes head's highlighting color |
-t, --tab-width |
Set the tab width (default is 4, useful in DEBUG mode) |
-h,--help |
Shows the help message (look here for available colors) |