Skip to content

manueldiagostino/turingMachine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

turingMachine

An C++ implementation of the Turing Machine.

Configuration file

The default filename for the configuration is config.tm (soon an option to change it...) and it follows this grammar:

config_file $\rightarrow$ { tm_elements }
tm_elements $\rightarrow$ option | option , tm_elements
option $\rightarrow$ instructions = { instruction_list } |
alphabet = { symbol_list } |
states = { symbol_list } |
initial_state = { state } |
memory = { symbol_list }
instruction_list $\rightarrow$ tuple | tuple , instruction_list
symbol_list $\rightarrow$ symbol | symbol , symbol_list
tuple $\rightarrow$ < state , symbol , state , symbol , move >
state $\rightarrow$ ID
symbol $\rightarrow$ ID
ID $\rightarrow$ Char , CharID
Char $\rightarrow$ a | b | $\ldots$ | z |0 | 1 | $\ldots$ | 9 | $ | % | # | & | _
move $\rightarrow$ 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.

config.tm example

{
	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
	}
}

Usage

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.


How to compile

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.

Optional arguments

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)

About

A `C++` implementation of the Turing machine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published