{"id":23586524,"url":"https://github.com/doctorwkt/subc","last_synced_at":"2025-05-07T07:47:07.087Z","repository":{"id":45477932,"uuid":"206954616","full_name":"DoctorWkt/SubC","owner":"DoctorWkt","description":"A Tour Through the SubC Compiler","archived":false,"fork":false,"pushed_at":"2021-12-11T22:17:37.000Z","size":391,"stargazers_count":89,"open_issues_count":1,"forks_count":15,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-31T07:51:18.284Z","etag":null,"topics":["c","compiler","lexical","parsing"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DoctorWkt.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-07T10:52:15.000Z","updated_at":"2025-02-20T04:39:46.000Z","dependencies_parsed_at":"2022-07-18T23:17:58.322Z","dependency_job_id":null,"html_url":"https://github.com/DoctorWkt/SubC","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/DoctorWkt%2FSubC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoctorWkt%2FSubC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoctorWkt%2FSubC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoctorWkt%2FSubC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DoctorWkt","download_url":"https://codeload.github.com/DoctorWkt/SubC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252838920,"owners_count":21812082,"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","lexical","parsing"],"created_at":"2024-12-27T04:11:29.505Z","updated_at":"2025-05-07T07:47:07.068Z","avatar_url":"https://github.com/DoctorWkt.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Tour Through the SubC C Compiler\n\nI've always wanted to [grok](https://en.wikipedia.org/wiki/Grok) how a\nreal compiler works. I've done compiler courses which were theoretical, and\nI've written my own [toy compiler](https://github.com/DoctorWkt/h-compiler).\n\nThis is my own personal tour through the\n[SubC](http://www.t3x.org/subc/) C compiler,\nwritten by Nils M Holm. I've done this to help me grok a compiler that\nis small but which is complete enough to be able to recompile itself.\n\nI've added a lot of comments to the original compiler code,\n[subc-20161212.tgz](http://www.t3x.org/subc/subc-20161212.tgz), and I've\nwritten the descriptions of the stages below.\n\nI haven't really covered much of the compiler theory behind the operation\nof SubC, so you really should buy and read Nils' book about SubC:\n[Practical Compiler Construction](http://www.t3x.org/reload/index.html).\nWhat I have done is to give an alternate viewpoint of the operation of\nSubC, and to cover the additions to the compiler written after Nils' book.\nPlease don't read my descriptions instead of the book; Nils has put a\nlot of effort into SubC and he deserves some recompense.\n\nThe topics that I will cover are:\n\n + [The Basic Operation of a Compiler](1_Basic_Operation.md)\n + [Lexical Analysis]( 2_Lexical_Analysis.md)\n + [The C Pre-processor](3_Preprocessor.md)\n + [Parsing of Statements](4_Statement_Parsing.md)\n + [The Symbol Table](5_Symbol_Table.md)\n + [Parsing of Declarations](6_Declarations.md)\n + [Abstract Syntax Trees](7_Abstract_Syntax_Trees.md)\n + [Parsing of Expressions](8_Expression_Parsing.md)\n + [General Optimisation](9_Optimisation.md)\n + [General Code Generation](10_Generic_Code_Generation.md)\n + [The x86-64 Code Generator](11_x86-64_Code_Generation.md)\n + [Cyclic Register Allocation](12_Register_Allocation.md)\n\n## Putting It Into Action\n\nIf you've cloned this GitHub repository to a Linux or BSD box, you should\nbe able to do:\n\n```\n$ ./configure\n```\n\nto get the source ready to compile on your system. Then `cd src` into\nthe source code tree and do:\n\n```\n$ make\n```\n\nto build the `scc0` compiler binary. To prove that the compiler works,\nyou can do this:\n\n```\n$ make scc\n```\n\nwhich is the *compiler triple test*: compile the compiler with another\ncompiler (e.g. Gnu C), then compile the compiler with itself, then\nuse this second compiler executable to compile itself again.\n\nAfter that, you can do:\n\n```\n$ sudo make install\n```\n\nto install `scc` into `/usr/local/bin`.\n\nNow go back and read through the descriptions and following along\nin the source code.\n\n## Copyrights\n\nUnless otherwise noted,\n\n + all source code and scripts are \u0026copy; Nils M Holm and\n   have been placed in the public domain.\n + all non-source code documents (e.g. English documents,\n   image files) are \u0026copy; Warren Toomey under the\n   [Creative Commons BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoctorwkt%2Fsubc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoctorwkt%2Fsubc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoctorwkt%2Fsubc/lists"}