Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nlsandler/write_a_c_compiler
Test suite to help you write your own C compiler
https://github.com/nlsandler/write_a_c_compiler
Last synced: 3 months ago
JSON representation
Test suite to help you write your own C compiler
- Host: GitHub
- URL: https://github.com/nlsandler/write_a_c_compiler
- Owner: nlsandler
- License: mit
- Created: 2017-11-29T22:21:51.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-11T22:37:47.000Z (over 1 year ago)
- Last Synced: 2024-08-02T01:22:14.025Z (6 months ago)
- Language: C
- Homepage: https://norasandler.com/2017/11/29/Write-a-Compiler.html
- Size: 43 KB
- Stars: 839
- Watchers: 32
- Forks: 97
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- AwesomeCompiler - write_a_c_compiler
README
# Write a C Compiler!
**This repo is no longer active. The latest version of this test suite, which accompanies the [Writing a C Compiler book](https://nostarch.com/writing-c-compiler), is available [here](https://github.com/nlsandler/writing-a-c-compiler-tests/).**
This is a set of C test programs to help you write your own compiler. They were written to accompany [this tutorial](https://norasandler.com/2017/11/29/Write-a-Compiler.html).
## Usage
### test all
```
./test_compiler.sh /path/to/your/compiler
```### test specific stages
To test stage 1 and stage 3,
```
./test_compiler.sh /path/to/your/compiler 1 3
```
To test from stage 1 to stage 6,
```
./test_compiler.sh /path/to/your/compiler `seq 1 6`
```In order to use this script, your compiler needs to follow this spec:
1. It can be invoked from the command line, taking only a C source file as an argument, e.g.: `./YOUR_COMPILER /path/to/program.c`
2. When passed `program.c`, it generates executable `program` in the same directory.
3. It doesn’t generate assembly or an executable if parsing fails (this is what the test script checks for invalid test programs).
The script doesn’t check whether your compiler outputs sensible error messages, but you can use the invalid test programs to test that manually.
## Contribute
Additional test cases welcome! You can also file issues here, either about the test suite itself or about the content of the tutorial.