I made my own compiler with python.
--Implemented with python (not C language) --x86_64 Output assembler code (not running on your own virtual machine) --Parser is also made by yourself (not relying on yacc) --Practicality is not particularly considered (it is OK if you make it fun and move)
the first stage Implement something that works for the time being Implements variable declaration, assignment, and four arithmetic operations. The parser is also simple, so it's almost like handwriting an abstract syntax tree.
Second stage Implemented backend The parser remains poor, but implements arrays, namespaces, function calls, and so on. The tail-recursive function is also implemented.
Third stage Implemented front end (completed version) Define the grammar in BNF notation and implement the SLR parser.
--Munehiro Takimoto "Introduction to Practical Compiler" A book that implements a compiler in Ocaml. The back end was mainly based on this book.
--Mamoru Miyamoto "First Compiler" A book that implements a compiler in C language. I used it as a reference when implementing the front end.
Peter Norvig 「(How to Write a (Lisp) Interpreter (in Python))」 An article that implements the Lisp interpreter in Python.
Abdulaziz Ghuloum 「Compilers: Backend to Frontend」 A document that implements the Scheme compiler in Scheme.
--Rui Ueyama "Live coding to create a simple programming language" A video that is live coded in C language.
Recommended Posts