{"id":13575381,"url":"https://github.com/zakirullin/tiny-compiler","last_synced_at":"2025-04-04T21:09:47.794Z","repository":{"id":44164645,"uuid":"88029459","full_name":"zakirullin/tiny-compiler","owner":"zakirullin","description":"A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the \"real\" thing works whilst not being a mere toy example","archived":false,"fork":false,"pushed_at":"2023-03-20T18:32:10.000Z","size":80,"stargazers_count":566,"open_issues_count":2,"forks_count":46,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-28T20:09:14.933Z","etag":null,"topics":["asm","ast","compiler","lexer","parser"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zakirullin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-04-12T08:40:25.000Z","updated_at":"2025-03-25T17:05:50.000Z","dependencies_parsed_at":"2024-01-14T06:32:48.697Z","dependency_job_id":"16aa7bfc-247a-49c8-ac4e-f9d04ae4d9f1","html_url":"https://github.com/zakirullin/tiny-compiler","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/zakirullin%2Ftiny-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakirullin%2Ftiny-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakirullin%2Ftiny-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakirullin%2Ftiny-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zakirullin","download_url":"https://codeload.github.com/zakirullin/tiny-compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249532,"owners_count":20908212,"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":["asm","ast","compiler","lexer","parser"],"created_at":"2024-08-01T15:01:00.492Z","updated_at":"2025-04-04T21:09:47.773Z","avatar_url":"https://github.com/zakirullin.png","language":"C","readme":"# A tiny compiler for a simple synthetic language featuring [LL(2) grammar](https://en.wikipedia.org/wiki/LL_grammar), written in pure C \n## The compiler consist of typical parts, known as:\n* [Lexer](https://en.wikipedia.org/wiki/Lexical_analysis) ([`lex.c`](./src/lex.c))\n* [Parser](https://en.wikipedia.org/wiki/Parsing) ([`parser.c`](./src/parser.c))\n* Assembler like [code generator](https://en.wikipedia.org/wiki/Code_generation_(compiler)) ([`gen.c`](./src/gen.c))\n* [Virtual machine](https://en.wikipedia.org/wiki/Virtual_machine) ([`vm.c`](./src/vm.c))\n* [Symbol table](https://en.wikipedia.org/wiki/Symbol_table) ([`sym.c`](./src/sym.c))\n* [Abstract syntax tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) ([`ast.c`](./src/ast.c))\n## It is by no means a complete industry standard implementation. Some parts are simplified for the sake of better understanding\n## Build\n```$ cmake -S . -B 'build' \u0026\u0026 cmake --build 'build'```\n## Usage\n```$ ./build/tinycompiler \u003csource\u003e```\n## An example program for Pythagorean theorem:\n```\ncath1 = 3;\ncath2 = 4;\nhypsquare = cath1 * cath1 + cath2 * cath2;\n```\nExecution result:\n```\nhypsquare = 25\n```\nGenerated ASM:\n```asm\nPUSH 3\nWRITE cath1\nPUSH 4\nWRITE cath2\nREAD cath1\nREAD cath1\nMUL POP, POP\nREAD cath2\nREAD cath2\nMUL POP, POP\nADD POP, POP\nWRITE hypsquare\n```\n## The language description in [EBNF](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form):\n```\nprogram = expr, \";\", { program } ;\nexpr = id, \"=\", expr | term, { (\"+\"|\"-\"), term } ;\nterm = factor, { (\"*\"|\"/\"), factor } ;\nfactor = \"id\" | \"num\" | \"(\", expr, \")\" ;\n```\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzakirullin%2Ftiny-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzakirullin%2Ftiny-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzakirullin%2Ftiny-compiler/lists"}