{"id":20273095,"url":"https://github.com/910jqk/test-parser","last_synced_at":"2026-04-19T02:31:48.245Z","repository":{"id":71156692,"uuid":"114357037","full_name":"910JQK/test-parser","owner":"910JQK","description":"An experimental parser for practice","archived":false,"fork":false,"pushed_at":"2017-12-27T09:05:49.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-14T06:12:11.448Z","etag":null,"topics":["interpreter","parser"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/910JQK.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2017-12-15T10:11:39.000Z","updated_at":"2017-12-27T09:02:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"d3b53029-35a7-47f4-807c-f49ab7b137fc","html_url":"https://github.com/910JQK/test-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/910JQK%2Ftest-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/910JQK%2Ftest-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/910JQK%2Ftest-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/910JQK%2Ftest-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/910JQK","download_url":"https://codeload.github.com/910JQK/test-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241763792,"owners_count":20016161,"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":["interpreter","parser"],"created_at":"2024-11-14T12:48:01.906Z","updated_at":"2025-12-02T07:00:51.957Z","avatar_url":"https://github.com/910JQK.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Toy Parser (Just for fun)\n\n## Overview\n\nThis is an interpreter for an **useless** programming language created by me for **practice**.\n\nThe program is built by 6 parts:\n\n- `definition.py` Define the LL(1) syntax and sematic rules of the programming language\n- `scanner.py` Scan source code files and match tokens using regular expression\n- `syntax.py` Generate a syntax tree for the token series\n- `translator.py` Traslate the syntax tree to 3-address code\n- `machine.py` Virtual machine to run 3-address code\n- `interpreter.py` Interpreter main program, takes argv[1] as code file\n\nThe language supports these features:\n\n- ✅ Arithmetic operations for integer and  double\n- ✅ Logical operations for bool\n- ✅ Conditional clauses such as if, while, do, for\n- ✅ Function definition and call with or without arguments\n- ✅ Recursive function call\n- ✅ Input and output for numbers\n\nBut does **NOT** support these features:\n\n- ❌ OOP\n- ❌ Array\n- ❌ String\n- ❌ Function pre-declaration\n- ❌ External functions and linked library\n\nIn addition, code in this project may have plenty of bugs and won't be fixed, because it is just a practice.\n\nBy default, the interpreter will ouput debug messages, which can be disabled in `common.py` (set `DEBUG=False`).\n\n## Example Codes\n\n### Code 1\n\n#### Source Code\n\n```\n$ cat test/test5\n```\n\n```\ndef f(int x, int y) {\n    int i;\n    for(i=0; i\u003c10; i=i+1)\n             y = y + i;\n    return x + y;\n}\n\n\ndef g(int x) -\u003e int {\n    return -x;\n}\n\n\ndef h() {\n    int x; int y;\n    read x;\n    read y;\n    print f(x, y)*g(x);\n}\n\n\ndef main() {\n    eval h();\n}\n```\n\n#### Intermediate Code\n\n```\n$ ./translate.py test/test5 2\u003e/dev/null\n```\n\n```\nproc f\nalloc int _retval 0\nalloc int y 0\nmov y _arg1\nalloc int x 0\nmov x _arg0\nalloc int i 0\nmov i 0\nlabel L0\nlt _t0 i 10\ngoto_if_false _t0 L1\nplus _t1 y i\nmov y _t1\nplus _t1 i 1\nmov i _t1\ngoto L0\nlabel L1\nplus _t0 x y\nmov _retval _t0\nret\nret\nend f\nproc g\nalloc int _retval 0\nalloc int x 0\nmov x _arg0\nminus _t0 0 x\nmov _retval _t0\nret\nret\nend g\nproc h\nalloc int x 0\nalloc int y 0\nread x\nread y\noverride _arg0 x\noverride _arg1 y\ncall f\nmov _t0 _getval\noverride _arg0 x\ncall g\nmov _t1 _getval\nmul _t2 _t0 _t1\nprint _t2\nret\nend h\nproc main\ncall h\nexit\nend main\nstart\ncall main\n```\n\n### Code 2\n\n#### Source Code\n\n```\n$ cat test/test6\n```\n\n```\ndef f(int n) -\u003e int {\n    if(n \u003c 0) {\n         return 0;\n    }\n    if(n == 1 || n == 2) {\n    \t return 1;\n    } else {\n      \t return f(n-1) + f(n-2);\n    }\n}\n\n\ndef main() {\n    int n;\n    read n;\n    print f(n);\n}\n```\n\n#### Intermediate Code\n\n```\n$ ./translator.py test/test6 2\u003e/dev/null\n```\n\n```\nproc f\nalloc int _retval 0\nalloc int n 0\nmov n _arg0\nlt _t0 n 0\ngoto_if_false _t0 L0\nmov _retval 0\nret\ngoto L1\nlabel L0\nlabel L1\neq _t0 n 1\neq _t1 n 2\nor _t2 _t0 _t1\ngoto_if_false _t2 L2\nmov _retval 1\nret\ngoto L3\nlabel L2\nminus _t1 n 1\noverride _arg0 _t1\ncall f\nmov _t1 _getval\nminus _t0 n 2\noverride _arg0 _t0\ncall f\nmov _t0 _getval\nplus _t3 _t1 _t0\nmov _retval _t3\nret\nlabel L3\nret\nend f\nproc main\nalloc int n 0\nread n\noverride _arg0 n\ncall f\nmov _t2 _getval\nprint _t2\nexit\nend main\nstart\ncall main\n```\n\n#### Run result\n\n```\n$ for i in {1..10}; do echo $i | ./interpreter.py test/test6 2\u003e/dev/null; done\n```\n\n```\n1\n1\n2\n3\n5\n8\n13\n21\n34\n55\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F910jqk%2Ftest-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F910jqk%2Ftest-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F910jqk%2Ftest-parser/lists"}