nlsandler/write_a_c_compiler
FreeTest suite to help you write your own C compiler
FreeFree tier
About nlsandler/write_a_c_compiler
This open-source test suite, written by Nora Sandler, provides a comprehensive set of C test programs designed to help developers write their own C compiler. It accompanies a tutorial and a book titled 'Writing a C Compiler.' The suite covers multiple stages of compiler development, from lexical analysis to code generation, allowing users to test specific stages or run the full suite. Test programs include both valid and invalid C code to verify correct compilation and error handling. The repository is no longer actively maintained; the latest version is available in an associated book repository.
Key Features
Comprehensive set of C test programs for compiler development
Covers multiple stages (lexical analysis, parsing, code generation, etc.)
Run all tests or specific stages using test_compiler.sh
Includes invalid test programs to verify error handling
Open source under MIT license
Accompanies the 'Writing a C Compiler' book and tutorial
Pros & Cons
Pros
- Structured test progression from simple to complex stages
- Practical, real-world test cases for compiler correctness
- Free and open source
- Includes invalid programs to test error detection
- Well-documented usage instructions
Cons
- Repository is no longer actively maintained
- Requires prior knowledge of C and compiler concepts
- Tests only a specific compiler invocation spec (input C file, output executable)
- Limited to the test programs provided; may not cover edge cases
Best For
Learning how to build a C compiler from scratchTesting a custom C compiler implementationUnderstanding compiler stages through practical examplesEducational projects in compiler design and construction
FAQ
How do I run the test suite?
Execute ./test_compiler.sh /path/to/your/compiler to run all tests, or specify stage numbers to run specific stages, e.g., ./test_compiler.sh /path/to/your/compiler 1 3.
What are the requirements for my compiler to work with this test suite?
Your compiler must be invokable from the command line with only a C source file as an argument. It should generate an executable program in the same directory, and must not generate output if parsing fails.
Is this test suite still maintained?
No, this repository is no longer active. The latest version of the test suite accompanies the 'Writing a C Compiler' book and is available in a separate repository linked from the README.
Can I contribute new test cases?
Yes, additional test cases are welcome. You can submit them via issues or pull requests on the repository.