Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/doctorwkt/subc
A Tour Through the SubC Compiler
https://github.com/doctorwkt/subc
c compiler lexical parsing
Last synced: about 23 hours ago
JSON representation
A Tour Through the SubC Compiler
- Host: GitHub
- URL: https://github.com/doctorwkt/subc
- Owner: DoctorWkt
- Created: 2019-09-07T10:52:15.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-12-11T22:17:37.000Z (about 3 years ago)
- Last Synced: 2024-07-30T19:48:49.614Z (5 months ago)
- Topics: c, compiler, lexical, parsing
- Language: C
- Size: 382 KB
- Stars: 81
- Watchers: 12
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# A Tour Through the SubC C Compiler
I've always wanted to [grok](https://en.wikipedia.org/wiki/Grok) how a
real compiler works. I've done compiler courses which were theoretical, and
I've written my own [toy compiler](https://github.com/DoctorWkt/h-compiler).This is my own personal tour through the
[SubC](http://www.t3x.org/subc/) C compiler,
written by Nils M Holm. I've done this to help me grok a compiler that
is small but which is complete enough to be able to recompile itself.I've added a lot of comments to the original compiler code,
[subc-20161212.tgz](http://www.t3x.org/subc/subc-20161212.tgz), and I've
written the descriptions of the stages below.I haven't really covered much of the compiler theory behind the operation
of SubC, so you really should buy and read Nils' book about SubC:
[Practical Compiler Construction](http://www.t3x.org/reload/index.html).
What I have done is to give an alternate viewpoint of the operation of
SubC, and to cover the additions to the compiler written after Nils' book.
Please don't read my descriptions instead of the book; Nils has put a
lot of effort into SubC and he deserves some recompense.The topics that I will cover are:
+ [The Basic Operation of a Compiler](1_Basic_Operation.md)
+ [Lexical Analysis]( 2_Lexical_Analysis.md)
+ [The C Pre-processor](3_Preprocessor.md)
+ [Parsing of Statements](4_Statement_Parsing.md)
+ [The Symbol Table](5_Symbol_Table.md)
+ [Parsing of Declarations](6_Declarations.md)
+ [Abstract Syntax Trees](7_Abstract_Syntax_Trees.md)
+ [Parsing of Expressions](8_Expression_Parsing.md)
+ [General Optimisation](9_Optimisation.md)
+ [General Code Generation](10_Generic_Code_Generation.md)
+ [The x86-64 Code Generator](11_x86-64_Code_Generation.md)
+ [Cyclic Register Allocation](12_Register_Allocation.md)## Putting It Into Action
If you've cloned this GitHub repository to a Linux or BSD box, you should
be able to do:```
$ ./configure
```to get the source ready to compile on your system. Then `cd src` into
the source code tree and do:```
$ make
```to build the `scc0` compiler binary. To prove that the compiler works,
you can do this:```
$ make scc
```which is the *compiler triple test*: compile the compiler with another
compiler (e.g. Gnu C), then compile the compiler with itself, then
use this second compiler executable to compile itself again.After that, you can do:
```
$ sudo make install
```to install `scc` into `/usr/local/bin`.
Now go back and read through the descriptions and following along
in the source code.## Copyrights
Unless otherwise noted,
+ all source code and scripts are © Nils M Holm and
have been placed in the public domain.
+ all non-source code documents (e.g. English documents,
image files) are © Warren Toomey under the
[Creative Commons BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/) license.