How to write a compiler - ponyatov/orth GitHub Wiki

If you want really to do every phase of a compiler, you must buy Dragon book (last edition: it has many additions on type inference, dynamic memory managing, parallelism,..).

If you want to write just working compiler, write only frontend part.

Start from LLVM (it has Python bindings if you want). It has a full tutorial on writing Kaleidoscope language (and pyKaleidoscope). Using it you avoid big part of especially complex optimization and low-level code generation.

But you will be limited by C-like language model: functions, variables, object modules etc.

Do you really need a compiler?

I now experimenting with metaprogramming: it is about you write (meta)programs which write parts of another (target) program.

As an example, you can use a high-level language (I prefer Python) with rich OOP (its a key feature for my idea), and write code generation (C/C++ sources) or LLVM. I call it managed compilation (in case of LLVM used as backend).

So in result, you write some sort of program templates in rich interpreter language and at the same time avoid of interpreter slowness via compiling with good optimizing compiler backend.