Turing Machine
A simplistic simulation of turing machines written in TypeScript. Tested on NodeJS v8, although eralier versions should word as well.
Installation
The module is available through npm as:
npm install --save turing-machine
Usage
We can use pre-built machines.
; // In this case, the erase machine requires the domain of our language; ; eraseMachine.diagnose eraseTape ;
Or we can create our own custom machines.
; // Let's create a machine that accepts a's and b's and removes all the a's.; ; ; // We can even compose machines!; ; ; // After we have defined the states, we can add transitions between themstateInitial.addTransition stateConsume, ;stateConsume.addTransition stateErase, ;stateConsume.addTransition stateConsume, ;stateConsume.addTransition stateRollback, ;stateErase.addTransition stateConsume ;stateRollback.addTransition stateRollback, ;stateRollback.addTransition stateFinal, ; machine.setInitialState stateInitial ; machine.setFinalState stateFinal ; // Automatically enables debug mode and prints the productions used and the resultmachine.diagnose 'bbaabab' ;// Otherwise, just call the method run and get the final Tape statemachine.run 'bbaabab' ; // Additionaly, it's also possible to generate the Dot representation of our graphmachine.toDot;// Or save it directly to a filemachine.toDotFile 'graph.dot' ;