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
- 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
toycpp
on a C++ file - this will produce a file calledexecutable
in 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.