{"id":30437512,"url":"https://github.com/ariful305/c-to-assembly-code-generator-compiler-project","last_synced_at":"2026-04-21T10:04:04.957Z","repository":{"id":310527448,"uuid":"1040215126","full_name":"ariful305/C-to-Assembly-code-generator-compiler-project","owner":"ariful305","description":"A tiny C→pseudo-assembly compiler: Flex-based lexer + recursive-descent parser that emits a simple MOV/ADD/SUB/MUL/DIV IR and runs peephole optimizations (identity removal, constant folding, copy-prop, NOP compaction). Includes sample input.c and Windows binary. MIT licensed.","archived":false,"fork":false,"pushed_at":"2025-08-18T16:29:29.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-18T18:26:49.759Z","etag":null,"topics":["assembly","c","c-to-assembly","compiler-design","project"],"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/ariful305.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,"zenodo":null}},"created_at":"2025-08-18T16:19:33.000Z","updated_at":"2025-08-18T16:29:33.000Z","dependencies_parsed_at":"2025-08-18T18:27:09.832Z","dependency_job_id":null,"html_url":"https://github.com/ariful305/C-to-Assembly-code-generator-compiler-project","commit_stats":null,"previous_names":["ariful305/c-to-assembly-code-generator-compiler-project"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ariful305/C-to-Assembly-code-generator-compiler-project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariful305%2FC-to-Assembly-code-generator-compiler-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariful305%2FC-to-Assembly-code-generator-compiler-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariful305%2FC-to-Assembly-code-generator-compiler-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariful305%2FC-to-Assembly-code-generator-compiler-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ariful305","download_url":"https://codeload.github.com/ariful305/C-to-Assembly-code-generator-compiler-project/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariful305%2FC-to-Assembly-code-generator-compiler-project/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271740198,"owners_count":24812636,"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-08-23T02:00:09.327Z","response_time":69,"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":["assembly","c","c-to-assembly","compiler-design","project"],"created_at":"2025-08-23T03:50:12.766Z","updated_at":"2026-04-21T10:04:04.894Z","avatar_url":"https://github.com/ariful305.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C-to-Assembly Code Generator (Toy Compiler)\n\nA tiny educational compiler that reads a **C-like subset** from `input.c`, parses expressions/statements, generates a **simple pseudo-assembly IR** (instructions like `MOV/ADD/SUB/MUL/DIV`), runs a few **peephole optimizations**, and writes two outputs:\n\n- `output_before.c` – raw IR (with `; NOP` lines)\n- `output_after.c` – optimized IR (NOPs removed)\n\n\u003e This project is great for learning **lexing**, **recursive-descent parsing**, and **local code optimizations**.\n\n---\n\n## ✨ Features\n\n- **Lexer (Flex)**: tokenizes keywords, identifiers, numbers, operators.\n- **Parser (recursive-descent)**:\n  - Expressions with `+ - * /` and parentheses\n  - Simple relational forms parsed (placeholders only)\n  - Statements: `int` declarations, assignments, `if/else`, `for`, `return`, `{ ... }` blocks\n- **IR emission**: instructions `MOV/ADD/SUB/MUL/DIV` + `OP_TEXT` comments\n- **Optimizations (peephole)**\n  1. Identity cleanup (e.g., `x+0`, `x*1`, `x/1` → NOP; `x*0` → `MOV x,0`)\n  2. Local constant folding (`MOV d,C; ADD d,k; …` → `MOV d, C'`)\n  3. Adjacent copy-prop (`MOV t,X; MOV A,t` → `MOV A,X`)\n  4. NOP compaction (physically removes NOPs)\n\n---\n\n## 📁 Repository layout\n\nThe repo includes these files (highlights):  \n- `main.c` – parser, IR builder, optimizer, and driver  \n- `lexer.l` – Flex lexer rules  \n- `lex.yy.c` – generated lexer C file (committed for convenience)  \n- `input.c` – sample input program  \n- `output_before.c`, `output_after.c`, `output.c` – example outputs/artifacts  \n- `cmini.exe` – prebuilt Windows binary  \n- `.vscode/`, `.gitattributes`, `LICENSE` (MIT)  \n\n_Source: repo file list \u0026 license block on GitHub._ :contentReference[oaicite:1]{index=1}\n\n---\n\n## 🛠️ Build\n\n### Prereqs\n- A C compiler (GCC/Clang or MSVC)\n- **Flex** (only needed if you want to regenerate `lex.yy.c`; otherwise the committed `lex.yy.c` is enough)\n\n### Run code\n```bash\nFlex lexer.l\ngcc -O2 -o cmini.exe main.c lex.yy.c\n.\\cmini.exe\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariful305%2Fc-to-assembly-code-generator-compiler-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fariful305%2Fc-to-assembly-code-generator-compiler-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariful305%2Fc-to-assembly-code-generator-compiler-project/lists"}