I'm interested in implementing a compiler for some subset of the C++ language, as a learning exercise, inspired by Tsoding's recreational programming.
The compiler's goal is to produce X86_64 assembly.
- Tsoding's recreational programming series
- Bisqwit's "Creating a compiler" series
- The FASM 1.73 manual
- en.cppreference.com, which I access through DevDocs
- The combined Intel IA-32/64-bit Software Developer's Manual
For information on parsing:
- GLR Parser on Wikipedia
- The GNU Bison manual, particularly 5. The Bison Parser Algorithm
- "(Right-Nulled) Generalised LR Parsing" by Jeff Smits
- "Generalised LR parsing algorithms" by Giorgios Robert Economopoulos (website, pdf)
- Install
fasm,git, a C++ compiler supporting C++17 and GNU Make:sudo apt install git fasm gcc-c++ make
- Clone the project and compile toycpp using
make:git clone https://github.com/PracticallyNothing/toycpp cd toycpp make -j4 - Run
toycppon a C++ file - this will produce a file calledexecutablein the current directory../toycpp test/add.cpp
- Run
executable- voila!./executable
This is to avoid the most vexing parse - C (and C++ by extension) technically allows you to put parentheses around the names of function parameters:
// These two are equivalent.
int main(int argc, const char** argv);
int main(int (argc), const char** (argv));I have no idea what the use of this is and I've never seen it used anywhere. Skipping support for this makes parsing other things easier.