{"id":16256444,"url":"https://github.com/masyagin1998/csc","last_synced_at":"2025-10-12T05:18:59.642Z","repository":{"id":97698122,"uuid":"181414110","full_name":"masyagin1998/CSC","owner":"masyagin1998","description":"C Subset Compiler","archived":false,"fork":false,"pushed_at":"2019-07-28T06:37:07.000Z","size":547,"stargazers_count":17,"open_issues_count":0,"forks_count":6,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-03T11:21:36.115Z","etag":null,"topics":["c","codegenerator","compiler-design","lexer","llvm","llvm-backend","parser"],"latest_commit_sha":null,"homepage":null,"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/masyagin1998.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":"2019-04-15T04:50:34.000Z","updated_at":"2025-03-13T17:24:17.000Z","dependencies_parsed_at":"2023-06-02T19:15:25.757Z","dependency_job_id":null,"html_url":"https://github.com/masyagin1998/CSC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/masyagin1998/CSC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masyagin1998%2FCSC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masyagin1998%2FCSC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masyagin1998%2FCSC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masyagin1998%2FCSC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/masyagin1998","download_url":"https://codeload.github.com/masyagin1998/CSC/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masyagin1998%2FCSC/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010337,"owners_count":26084738,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c","codegenerator","compiler-design","lexer","llvm","llvm-backend","parser"],"created_at":"2024-10-10T15:45:14.524Z","updated_at":"2025-10-12T05:18:59.619Z","avatar_url":"https://github.com/masyagin1998.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSC\n`CSC` is a simple and easy extensible C Subset Compiler. It's not realy for production, it was made JUST FOR FUN.\nIt contains lexer, parser, llvm-ir-codegenerator and SSA-form-builder.\n\n### Tech\n\n`CSC` uses a number of open source projects to work properly:\n\n* [LLVM](https://llvm.org/) - Framework for building compilers and codegenerators.\n\nAnd of course `CSC` itself is open source with a [public repository](https://github.com/masyagin1998/CSC)\n on GitHub.\n\n### Installation\n\n`CSC` requires [LLVM](https://llvm.org/) v5.0+ to run.\n\nInstall the dependencies and build compiler.\n\n```sh\n$ sudo apt-get install llvm\n$ sudo apt-get install clang\n$ git clone https://github.com/masyagin1998/CSC.git\n$ cd CSC\n$ make all  # to make compiler\n$ make test # to check compiler's work\n```\n\n### What can it do?\n\n`CSC` supports simplified version of `C89` with:\n - `int` variables definitions;\n - `while` loops;\n - `if-then` and `if-then-else` statements;\n - inner `if` and `while` statements (multiple inner statements)\n - all arithmetical and logical operations;\n - and many other;\n \n### Lexer\n\nLinear Object-Oriented lexer with error recovery and comments ignoring.\n\n### Parser\n\nRecursive top-down parser (I know it is shitty, but OK for small projects) for simplified to `LL(1)` C grammar, which turns lexemas to Abstract Syntax Tree (`AST`). AST can be debugged to file using in human-readable format.\n\n### Codegenerator\n\nCodegenerator to `LLVM IR BitCode` from abstract syntax tree. Yon can link generated object files (`*.o` files) with `main.c` \n\n### SSA-builder\n\nClassical code-generation algorithm, which firstly creates Control Flow Graph (`CFG`) from `AST`, and then creates `SSA`-form using Dominance Frontier Algorithm (`DFA`).\n\n### Examples\n\n- Check if number is even\n\n  |       Code                     |                SSA              |\n  |--------------------------------|---------------------------------|\n  | ![in](static/examples/01_in.jpg) | ![out](static/examples/01_out.jpg) |\n\n- Get sign of number\n\n  |       Code                     |                SSA              |\n  |--------------------------------|---------------------------------|\n  | ![in](static/examples/02_in.jpg) | ![out](static/examples/02_out.jpg) |\n\n- Fibonacci\n\n  |       Code                     |                SSA              |\n  |--------------------------------|---------------------------------|\n  | ![in](static/examples/03_in.jpg) | ![out](static/examples/03_out.jpg) |\n\n### Many thanks to:\nAnatoly Sinyavin - BMSTU Optimal Code Generation teacher\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasyagin1998%2Fcsc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasyagin1998%2Fcsc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasyagin1998%2Fcsc/lists"}