@@ -26,12 +26,12 @@ This is a browser-based application. A fully functional build is available
2626For a guide to the [ description language] ( #description-language ) and some
2727[ examples] ( #examples ) , see below.
2828
29- Here is a screenshot of the main view, showing the state diagram of a machine
30- on the left and its low level textual description on the right:
29+ Here is a screenshot of the main view, showing the transition diagram of a
30+ machine on the left and its low level textual description on the right:
3131
3232![ A screenshot of the diagram view] ( screenshot.png )
3333
34- ## Building
34+ ## Building from source
3535
3636In order to build the application yourself, clone the repository and run
3737```
@@ -65,10 +65,10 @@ invokes the peggy binary with the right options.
6565
6666At present, only the first part of the project is developed and already quite
6767usable. It takes as input a low level textual description of a Turing machine
68- and provides an interactive visualization of the state transition diagram and
69- table, together with a tape editor and navigator and tools for running the
70- program. There is still room for improvement, for example by adding a suite of
71- keyboard shortcuts, graphical editing tools and code navigation utilities.
68+ and provides an interactive visualization of the transition diagram and table,
69+ together with a tape editor and navigator and tools for running the program.
70+ There is still room for improvement, for example by adding a suite of keyboard
71+ shortcuts, graphical editing tools and code navigation utilities.
7272
7373Eventually, a high-level description language (with composable blocks and
7474structured control flow) will be implemented together with tools for
@@ -81,16 +81,243 @@ comprising exactly a load, a branch on the loaded value, a store, a pointer
8181update and a jump. The idea is to apply well-known decompilation techniques
8282to recover structured flow control constructs from the transition graph.
8383
84- ** TODO:** detailed roadmap.
84+ - [ ] Description editor
85+ - [x] Load and export code
86+ - [x] Error highlighting
87+ - [ ] Code navigation and refactoring tools
88+ - [ ] Keyboard shortcuts
89+ - [ ] Visualization
90+ - [x] Interactive view of the transition diagram
91+ - [x] Transition table
92+ - [ ] Tape editor
93+ - [x] Keyboard based input
94+ - [x] Paste from clipboard
95+ - [x] Navigation shortcuts
96+ - [ ] Jump to leftmost and rightmost non-blank symbol
97+ - [ ] Simulation
98+ - [x] Pause/Resume simulation
99+ - [x] Simulation speed selector
100+ - [x] Manual stepping
101+ - [x] Execution trace inspector
102+ - [ ] Keyboard shortcuts
103+ - [ ] Analysis
104+ - [ ] Comment syntax
105+ - [ ] High-level description language
106+ - [ ] Basic block/Branch/Loop/Register discovery
107+ - [ ] Code deduplication
108+ - [ ] Automated analysis algorithms
109+ - [ ] Documentation
110+ - [x] Low-level description language
111+ - [ ] High-level description language
112+ - [ ] GUI documentation
113+ - [ ] Shortcut reference
114+ - [ ] Popup-based tutorial
85115
86- ## GUI and keyboard shortcuts
116+ ## Low-level description language
87117
88- ## Description language
118+ The low-level description language is just a list of transitions, preceded by
119+ two mandatory directives defining the initial state and the blank symbol, and
120+ a variable number of directives defining accepting and rejecting states. At the
121+ moment, support for comments is planned but not implemented.
122+
123+ The symbol alphabet is taken to be the set of all non-whitespace characters.
124+ The blank symbol (specified in the description) is used to mark empty cells on
125+ the tape. States are represented by strings of non-whitespace characters and
126+ are created automatically as soon as they appear in the description.
127+ Transitions are required to be strictly deterministic (i.e. at present only
128+ deterministic TMs may be described and simulated); an error message is
129+ displayed when this is not the case. Accepting and rejecting states are purely
130+ cosmetic, i.e. they are marked in green and red, respectively, in the
131+ resulting diagram. The simulation may halt in any state, whenever no transition
132+ is found matching the current state and tape symbol.
133+
134+ The general structure of a description is as follows; three examples can be
135+ found in the next section.
136+ ```
137+ init INIT_STATE
138+ blank SYMBOL
139+
140+ [accept STATE]
141+ [reject STATE]
142+ ...
143+
144+ PREV_STATE INPUT_SYMBOL OUTPUT_SYMBOL MOVE NEXT_STATE
145+ ...
146+ ```
147+ The parser is case-sensitive. The lowercase keywords ` init ` , ` blank ` , ` accept `
148+ and ` reject ` are reserved (i.e. they cannot be used as state names). ` init `
149+ and ` blank ` directives are mandatory and must appear only once, at the
150+ beginning, in the order shown above. ` accept ` and ` reject ` directives are
151+ optional, may appear any number of times in any order, and must appear before
152+ the list of transitions. The transition list may contain arbitrarily many rows
153+ (it may even be empty). Directives and transitions may be surrounded and
154+ interspersed by any amount of whitespace, but cannot be broken into multiple
155+ lines, and must be terminated by a newline.
156+
157+ The placeholders must be replaced as follows:
158+ - ` INIT_STATE ` , ` STATE ` , ` PREV_STATE ` , ` NEXT_STATE ` : any sequence of
159+ non-whitespace characters excluding the four keywords listed above;
160+ - ` SYMBOL ` , ` INPUT_SYMBOL ` , ` OUTPUT_SYMBOL ` : any non-whitespace character;
161+ - ` MOVE ` : either ` L ` (left), ` R ` (right) or ` N ` (no move).
89162
90163## Examples
91164
165+ <details >
166+ <summary >Unary multiplication by 2</summary >
167+
168+ A machine that reads from the tape an integer in _ unary_ notation (_ n_ is
169+ represented by a list of _ n_ occurrences of the symbol ` 1 ` ) and writes it back
170+ doubled.
171+
172+ [ Load in the simulator] ( https://fbbdev.it/turing/?fetch=https%3A%2F%2Fraw.githubusercontent.com%2Ffbbdev%2Fturing%2Fmain%2Fexamples%2FunaryDup.txt )
173+
174+ _ Instructions:_ click the link above; when the machine has been loaded, click
175+ the tape head (the cell with a large black border), type ` 1 ` as many times as
176+ you like, press the ` Enter ` key and hit the play button.
177+
178+ ```
179+ init test
180+ blank *
181+
182+ test 1 * R skipOrigR
183+ test * * R halt
184+
185+ skipOrigR 1 1 R skipOrigR
186+ skipOrigR * * R skipCopyR
187+
188+ skipCopyR 1 1 R skipCopyR
189+ skipCopyR * 1 R write1
190+
191+ write1 * 1 L skipCopyL
192+
193+ skipCopyL 1 1 L skipCopyL
194+ skipCopyL * * L skipOrigL
195+
196+ skipOrigL 1 1 L skipOrigL
197+ skipOrigL * * R test
198+ ```
199+ </details >
200+
201+ <details >
202+ <summary >Binary increment by one</summary >
203+
204+ A machine that reads from the tape an integer in _ binary_ notation and writes
205+ it back incremented by one.
206+
207+ [ Load in the simulator] ( https://fbbdev.it/turing/?fetch=https%3A%2F%2Fraw.githubusercontent.com%2Ffbbdev%2Fturing%2Fmain%2Fexamples%2FbinaryIncr.txt )
208+
209+ _ Instructions:_ click the link above; when the machine has been loaded, click
210+ the tape head (the cell with a large black border), type a sequence of ` 1 ` s and
211+ ` 0 ` s, press the ` Enter ` key and hit the play button.
212+
213+ ```
214+ init q0
215+ blank *
216+
217+ q0 * * L q1
218+ q0 0 0 R q0
219+ q0 1 1 R q0
220+
221+ q1 * 1 L q2
222+ q1 0 1 L q2
223+ q1 1 0 L q1
224+
225+ q2 * * R halt
226+ q2 0 0 L q2
227+ q2 1 1 L q2
228+ ```
229+ </details >
230+
231+ <details >
232+ <summary >Binary addition</summary >
233+
234+ A machine that reads from the tape two integers in _ binary_ notation, separated
235+ by a blank, and writes back their sum.
236+
237+ [ Load in the simulator] ( https://fbbdev.it/turing/?fetch=https%3A%2F%2Fraw.githubusercontent.com%2Ffbbdev%2Fturing%2Fmain%2Fexamples%2FbinaryAdd.txt )
238+
239+ _ Instructions:_ click the link above; when the machine has been loaded, click
240+ the tape head (the cell with a large black border), type a sequence of ` 1 ` s and
241+ ` 0 ` s, press ` Space ` , then type again a sequence of ` 1 ` s and ` 0 ` s, press the
242+ ` Enter ` key and hit the play button.
243+
244+ ```
245+ init test
246+ blank *
247+
248+ test 0 0 R skipO1
249+ test 1 1 R skipO1
250+ test * * R halt
251+
252+ skipO1 z z R skipO1
253+ skipO1 o o R skipO1
254+ skipO1 0 0 R skipO1
255+ skipO1 1 1 R skipO1
256+ skipO1 * * R getO2
257+
258+ getO2 * * L rewrite
259+ getO2 0 0 R getO2_0
260+ getO2 1 1 R getO2_1
261+
262+ getO2_0 0 0 R getO2_0
263+ getO2_0 1 1 R getO2_1
264+ getO2_0 * * L biteO2_0
265+
266+ getO2_1 0 0 R getO2_0
267+ getO2_1 1 1 R getO2_1
268+ getO2_1 * * L biteO2_1
269+
270+ biteO2_0 0 * L rskipO2_0
271+
272+ biteO2_1 1 * L rskipO2_1
273+
274+ rskipO2_0 0 0 L rskipO2_0
275+ rskipO2_0 1 1 L rskipO2_0
276+ rskipO2_0 * * L add_0
277+
278+ add_0 z z L add_0
279+ add_0 o o L add_0
280+ add_0 0 z R skipO1
281+ add_0 1 o R skipO1
282+ add_0 * z R skipO1
283+
284+ rskipO2_1 0 0 L rskipO2_1
285+ rskipO2_1 1 1 L rskipO2_1
286+ rskipO2_1 * * L add_1
287+
288+ add_1 z z L add_1
289+ add_1 o o L add_1
290+ add_1 0 o R skipO1
291+ add_1 1 z L incr
292+ add_1 * o R skipO1
293+
294+ incr 1 0 L incr
295+ incr 0 1 R skipO1
296+ incr * 1 R skipO1
297+
298+ rewrite * * L rewrite'
299+
300+ rewrite' z 0 L rewrite'
301+ rewrite' o 1 L rewrite'
302+ rewrite' 0 0 L rewrite'
303+ rewrite' 1 1 L rewrite'
304+ rewrite' * * R halt
305+ ```
306+ </details >
307+
92308## Acknowledgements
93309
310+ The diagram viewer is based upon the
311+ [ vis-network] ( https://visjs.github.io/vis-network/docs/ ) library from the
312+ awesome [ vis.js] ( https://visjs.org/ ) project.
313+
314+ The description language parser is generated from a grammar description using
315+ [ peggy] ( https://peggyjs.org/ ) .
316+
317+ The graphical user interface is built with the [ UIkit 3] ( https://getuikit.com/ )
318+ framework and the [ mustache] ( https://mustache.github.io/ ) logic-less templating
319+ engine.
320+
94321## License
95322
96323Copyright (C) 2023 Fabio Massaioli
0 commit comments