{"id":22942448,"url":"https://github.com/stardustdl/turing-machine-emulator","last_synced_at":"2025-07-21T03:02:57.461Z","repository":{"id":97887175,"uuid":"435771159","full_name":"StardustDL/turing-machine-emulator","owner":"StardustDL","description":"An emulator for multi-tape deterministic turing machine.","archived":false,"fork":false,"pushed_at":"2021-12-30T02:40:26.000Z","size":31,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-01T21:19:03.982Z","etag":null,"topics":["emulator","nju","nju-cs","turing-machine"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StardustDL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-07T06:39:12.000Z","updated_at":"2022-11-30T08:43:40.000Z","dependencies_parsed_at":"2023-05-31T11:46:04.736Z","dependency_job_id":null,"html_url":"https://github.com/StardustDL/turing-machine-emulator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/StardustDL/turing-machine-emulator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StardustDL%2Fturing-machine-emulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StardustDL%2Fturing-machine-emulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StardustDL%2Fturing-machine-emulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StardustDL%2Fturing-machine-emulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StardustDL","download_url":"https://codeload.github.com/StardustDL/turing-machine-emulator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StardustDL%2Fturing-machine-emulator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266231762,"owners_count":23896473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["emulator","nju","nju-cs","turing-machine"],"created_at":"2024-12-14T13:47:51.811Z","updated_at":"2025-07-21T03:02:57.434Z","avatar_url":"https://github.com/StardustDL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Turing Machine Emulator](https://socialify.git.ci/StardustDL/turing-machine-emulator/image?description=1\u0026font=Bitter\u0026forks=1\u0026issues=1\u0026language=1\u0026owner=1\u0026pulls=1\u0026stargazers=1\u0026theme=Light)\n\n![CI](https://github.com/StardustDL/turing-machine-emulator/workflows/CI/badge.svg) ![](https://img.shields.io/github/license/StardustDL/turing-machine-emulator.svg)\n\nAn emulator for multi-tape deterministic turing machine.\n\n## Turing Machine Description Language\n\n### Metadata\n\nEach line of metadata is in form `#\u003cname\u003e = \u003cvalue\u003e` where `\u003cname\u003e` is the metadata id, and `\u003cvalue\u003e` is the metadata value.\n\n```\n; the finite set of states\n#Q = {0,cp,cmp,mh,accept,halt_accept,reject,halt_reject}\n\n; the finite set of input symbols\n#S = {0,1}\n\n; the complete set of tape symbols\n#G = {0,1,_,T,r,u,e,F,a,l,s}\n\n; the start state\n#q0 = 0\n\n; the blank symbol\n#B = _\n\n; the set of final states\n#F = {halt_accept}\n\n; the number of tapes\n#N = 2 \n```\n\nThe metadata can be inferred (replaced) by transfer edges using auto mode in parser.\n\n- Use `0` as start state if not defined.\n- Use `_` as blank symbol if not defined.\n- Any state starting with 'halt', eg. halt, halt-accept, will be a final state.\n\n### Transfer Edges\n\n- Each line of transfer edge should contain one tuple of the form `\u003ccurrent state\u003e \u003ccurrent symbol\u003e \u003cnew symbol\u003e \u003cdirection\u003e \u003cnew state\u003e`.\n- You can use any number or word for `\u003ccurrent state\u003e` and `\u003cnew state\u003e`, eg. 10, a, state1. State labels are case-sensitive.\n- You can use almost any character for `\u003ccurrent symbol\u003e` and `\u003cnew symbol\u003e`, or `_` to represent blank (space). Symbols are case-sensitive.\n- You can't use `;`, `*`, `_` or whitespace as symbols.\n\u003cdirection\u003e should be `l`, `r` or `*`, denoting 'move left', 'move right' or 'do not move', respectively.\n- Anything after a `;` is a comment and is ignored.\n- `*` can be used as a wildcard in `\u003ccurrent symbol\u003e` or `\u003ccurrent state\u003e` to match any character or state.\n- `*` can be used in `\u003cnew symbol\u003e` or `\u003cnew state\u003e` to mean 'no change'.\n- `!` can be used at the end of a line to set a breakpoint, eg. `1 a b r 2 !`.\n\n## Parser\n\nThe parser will parse the text in the description language, and check the semantic:\n\n- All states are declared in Q\n- All symbols are declared in G\n- S is a subset of Q\n- q0 is in Q\n- B is in G\n- F is a subset of Q\n- N is a positive integer\n\n## Emulator\n\nIt emulates a multi-tape deterministic turing machine.\n\n## Build\n\n```sh\n$ cd ./turing-project\n$ chmod +x ./build.sh\n$ bash -c ./build.sh\n```\n\n## Run\n\n```sh\n./turing \u003cfile to description text\u003e \u003cinput string\u003e \u003cflags\u003e\n```\n\nPossible flags:\n\n- `-v/--verbose` Details about error in parser and execution states in emulator.\n- `-a/--auto` Use the metadata inferred from transfer edges when parsing.\n- `-d/--debug` Pause the emulator when a breakpoint hits.\n\n```sh\n$ ./turing ./samples/gcd.tm 11110111111\n11\n$ ./turing ./samples/gcd.tm 11110111111 -v\nInput: 11110111111\n==================== RUN ====================\nStep   : 0\nIndex0 : 0 1 2 3 4 5 6 7 8 9 10\nTape0  : 1 1 1 1 0 1 1 1 1 1 1 \nHead0  : ^                     \nIndex1 : 0\nTape1  : _\nHead1  : ^\nIndex2 : 0\nTape2  : _\nHead2  : ^\nState  : 0\n---------------------------------------------\nStep   : 1\nIndex0 : 0 1 2 3 4 5 6 7 8 9 10\nTape0  : 1 1 1 1 0 1 1 1 1 1 1 \nHead0  : ^                     \nIndex1 : 0\nTape1  : _\nHead1  : ^\nIndex2 : 0\nTape2  : _\nHead2  : ^\nState  : pre1\n---------------------------------------------\nStep   : 2\nIndex0 : 0 1 2 3 4 5 6 7 8 9 10\nTape0  : 1 1 1 1 0 1 1 1 1 1 1 \nHead0  :   ^                   \nIndex1 : 0 1\nTape1  : 1 _\nHead1  :   ^\nIndex2 : 0\nTape2  : _\nHead2  : ^\nState  : pre1\n---------------------------------------------\n...\n---------------------------------------------\nStep   : 150\nIndex0 : 0 1 2\nTape0  : 1 1 _\nHead0  :     ^\nIndex1 : 0 1 2 3\nTape1  : 1 1 1 1\nHead1  :       ^\nIndex2 : 0 1 2 3 4 5 6\nTape2  : 1 1 1 1 1 1 _\nHead2  :             ^\nState  : test2\n---------------------------------------------\nStep   : 151\nIndex0 : 0 1\nTape0  : 1 1\nHead0  :   ^\nIndex1 : 0 1 2 3\nTape1  : 1 1 1 1\nHead1  :       ^\nIndex2 : 0 1 2 3 4 5\nTape2  : 1 1 1 1 1 1\nHead2  :           ^\nState  : final\n---------------------------------------------\nResult: 11\n==================== END ====================\n```\n\n## Samples\n\n`/samples` contains some sample turing machines.\n\n\u003e Some of the samples are from [jsturing](https://github.com/awmorp/jsturing). These samples need to use `auto` mode to parse.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstardustdl%2Fturing-machine-emulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstardustdl%2Fturing-machine-emulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstardustdl%2Fturing-machine-emulator/lists"}