{"id":20449632,"url":"https://github.com/skatsuta/9cc","last_synced_at":"2025-06-14T16:05:59.394Z","repository":{"id":81565132,"uuid":"206800129","full_name":"skatsuta/9cc","owner":"skatsuta","description":"Small C compiler designed in https://www.sigbus.info/compilerbook (Japanese).","archived":false,"fork":false,"pushed_at":"2019-09-24T16:26:12.000Z","size":178,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-05T09:19:44.971Z","etag":null,"topics":["c-compiler"],"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/skatsuta.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-09-06T13:30:32.000Z","updated_at":"2021-10-08T20:53:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"c5b1c9b9-fea1-460f-acb6-d44bda9ad29c","html_url":"https://github.com/skatsuta/9cc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/skatsuta/9cc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skatsuta%2F9cc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skatsuta%2F9cc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skatsuta%2F9cc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skatsuta%2F9cc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skatsuta","download_url":"https://codeload.github.com/skatsuta/9cc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skatsuta%2F9cc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259843327,"owners_count":22920311,"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":["c-compiler"],"created_at":"2024-11-15T10:43:21.870Z","updated_at":"2025-06-14T16:05:59.368Z","avatar_url":"https://github.com/skatsuta.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 9cc\n\nSmall C compiler designed in https://www.sigbus.info/compilerbook (Japanese).\n\n\n## Development on macOS\n\nThis repository is being developed on macOS, while the above book explains how to write a compiler for Linux. To solve this mismatch, Docker is used to emulate compilation and testing for Linux on macOS.\n\nThis repository's `Makefile` is configured to support this situation, and if your OS is macOS and you have Docker for Mac installed, `make test` automatically runs tests inside a Linux container where GCC is installed.\n\n```bash\n$ sw_vers\nProductName:    Mac OS X\nProductVersion: 10.13.6\nBuildVersion:   17G8030\n\n$ make test\ndocker container run \\\n                --rm \\\n                --mount type=bind,source=/Users/skatsuta/src/github.com/skatsuta/9cc,target=/src,consistency=delegated \\\n                --workdir /src \\\n                gcc make test\ncc -std=c11 -g -static   -c -o token.o token.c\ncc -std=c11 -g -static   -c -o main.o main.c\ncc -std=c11 -g -static   -c -o parse.o parse.c\ncc -std=c11 -g -static   -c -o codegen.o codegen.c\ncc -o 9cc token.o main.o parse.o codegen.o\n./test.sh\n...(snip)...\nOK\n```\n\n\n## Currently supported syntax of C\n\nCurrently this compiler supports the following subset of C language syntax:\n\n```\nprogram       = (global-var | function)*\nbasetype      = (\"char\" | \"int\" | struct-decl | typedef-name) \"*\"*\nstruct-decl   = \"struct\" ident\n              | \"struct\" ident? \"{\" struct-member* \"}\"\nstruct-member = basetype ident (\"[\" num \"]\")* \";\"\nglobal-var    = basetype ident (\"[\" num \"]\")* \";\"\nfunction      = basetype ident \"(\" params? \")\" \"{\" stmt* \"}\"\nparams        = param (\",\" param)*\nparam         = basetype ident\nstmt          = \"if\" \"(\" expr \")\" stmt (\"else\" stmt)?\n              | \"while\" \"(\" expr \")\" stmt\n              | \"for\" \"(\" expr \";\" expr \";\" expr \")\" stmt\n              | \"return\" expr \";\"\n              | \"{\" stmt* \"}\"\n              | \"typedef\" basetype ident (\"[\" num \"]\")* \";\"\n              | declaration\n              | expr \";\"\ndeclaration   = basetype ident (\"[\" num \"]\")* (\"=\" assign)? \";\"\n              | basetype \";\"\nexpr          = assign\nassign        = equality (\"=\" assign)?\nequality      = relational (\"==\" relational | \"!=\" relational)*\nrelational    = add (\"\u003c\" add | \"\u003c=\" add | \"\u003e\" add | \"\u003e=\" add)*\nadd           = mul (\"+\" mul | \"-\" mul)*\nmul           = unary (\"*\" unary | \"/\" unary)*\nunary         = (\"+\" | \"-\" | \"\u0026\" | \"*\" | \"sizeof\")? unary\n              | postfix\npostfix       = primary (\"[\" expr \"]\" | \".\" ident | \"-\u003e\" ident)*\nprimary       = stmt-expr\n              | \"(\" expr \")\"\n              | ident func-args?\n              | str\n              | num\nstmt-expr     = \"(\" \"{\" stmt stmt* \"}\" \")\"\nfunc-args     = \"(\" (assign (\",\" assign)*)? \")\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskatsuta%2F9cc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskatsuta%2F9cc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskatsuta%2F9cc/lists"}