Skip to content

Implementations for the compiler(s) described in "Writing a C Compiler" by Nora Sandler

Notifications You must be signed in to change notification settings

NashFP/c_compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Writing a C Compiler

Nora Sandler's No Starch Press book "Writing a C Compiler" may be an interesting way to explore writing a compiler in a functional language.

There is some initial setup involved. The book includes a suite of tests here: https://github.com/nlsandler/writing-a-c-compiler-tests/

In order to use these tests, you need a driver.sh script that will run the C preprocessor on your file and then potentially run the assembler and linker on your code. There is a stub driver.sh in this directory that you can modify to execute your compiler. This stub assumes it is running on Linux.

The book mentions running on Apple Silicon. It suggests this command:

arch -x86_64

This mostly works, except that the Mac uses clang instead of gcc, and the assembly file requires a few changes. I modified the default driver.sh to check to see if it is running on a Mac, and if it is, it does a very minimal fixup. I don't know if this will work for everyone in the long run, but on my Macbook Air, I am able to pass all the tests at least through chapter 3 with the minimal changes.

The book has a companion web site here: https://norasandler.com/book/ and it has links to many useful tools including the Intel 64 Software Developer's Manual and Matt Godbolt's Compiler Explorer

About

Implementations for the compiler(s) described in "Writing a C Compiler" by Nora Sandler

Resources

Stars

Watchers

Forks

Packages

No packages published