https://github.com/keyvank/30cc Skip to content Navigation Menu Toggle navigation Sign in * Product + GitHub Copilot Write better code with AI + Security Find and fix vulnerabilities + Actions Automate any workflow + Codespaces Instant dev environments + Issues Plan and track work + Code Review Manage code changes + Discussions Collaborate outside of code + Code Search Find more, search less Explore + All features + Documentation + GitHub Skills + Blog * Solutions By company size + Enterprises + Small and medium teams + Startups By use case + DevSecOps + DevOps + CI/CD + View all use cases By industry + Healthcare + Financial services + Manufacturing + Government + View all industries View all solutions * Resources Topics + AI + DevOps + Security + Software Development + View all Explore + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Enterprise + Enterprise platform AI-powered developer platform Available add-ons + Advanced Security Enterprise-grade security features + GitHub Copilot Enterprise-grade AI features + Premium Support Enterprise-grade 24/7 support * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up Reseting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} keyvank / 30cc Public * Notifications You must be signed in to change notification settings * Fork 6 * Star 55 30 C Compiler 55 stars 6 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings * Code * Issues 9 * Pull requests 0 * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Projects * Security * Insights keyvank/30cc main BranchesTags [ ] Go to file Code Folders and files Name Name Last commit Last commit message date Latest commit History 199 Commits .github/workflows .github/ workflows codegen codegen examples examples parser parser preprocess preprocess scripts scripts tests/output tests/output .gitignore .gitignore Makefile Makefile README.md README.md build.py build.py lexer.c lexer.c lexer.h lexer.h libc.h libc.h linked_list.c linked_list.c linked_list.h linked_list.h main.c main.c vec.c vec.c vec.h vec.h View all files Repository files navigation * README 30 C Compiler! 30cc (Pronounced as CCC, because in the Persian language, the number 30 is pronounced as C) is a toy C compiler written in C, which is strong enough to compile itself This was my first attempt in writing a self-hosting software! What is a self-hosting software? * Imagine 30cc gets strong enough to be able to compile itself. * I will first compile 30cc with gcc to get the 30cc compiler's binary. * I will then use the gcc-generated 30cc binary file to compile the 30cc again. * I now have a 30cc-compiled version of 30cc, which I can use for further developing the compiler! * I can forget about gcc, as if it never existed! Beautiful hah? 30cc is now all alive by itself! 30cc emits x86-64 assembly as its output. The outputs are totally unoptimized, but that's fine, the project aims to be educational. Usage * You'll first need to bootstrap the compiler by running make. This will compile the 30cc compiler and store its binary in a.out. * Then run ./build.py. This will use the bootstrapped 30cc-compiler to compile 30cc itself. It then again uses the 30cc-compiled compiler to compile 30cc once again. The final compiler is then stored as ./30cc. * In the end, you will have 3 binary files which should all behave the same: 1. a.out which is the bootstrapped gcc-compiled version of 30cc 2. 30cc_gcc which is the output of gcc-compiled 30cc compiler, compiling the 30cc compiler 3. 30cc which is the output of 30cc-compiled 30cc compiler, compiling the 30cc compiler Running independent source-files through make: make run program=./examples/inp.c arguments=something Contribute Tests To run tests use python scripts/test.py update Then check the output of the tests. If you are on mac use ./scripts/test_mac.sh to run the tests in docker. About 30 C Compiler Topics c compiler educational Resources Readme Activity Stars 55 stars Watchers 2 watching Forks 6 forks Report repository Releases No releases published Packages 0 No packages published Contributors 4 * @keyvank keyvank Keyvan Kambakhsh * @Glyphack Glyphack Shaygan Hooshyari * @amiremohamadi amiremohamadi AMIR * @thehxdev thehxdev Hossein Khosravi Languages * C 58.8% * Assembly 37.8% * Python 3.0% * Other 0.4% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.