I made a Compiler in 25 Days - Here is what I learned

preview_player
Показать описание
I have implemented a compiler in C for the COOL programming language in 25 days. Check out the video to see what I learned.

book that helped me build the parser: Writing An Interpreter In Go - Thorsten Ball

Chapters
00:00:00 Intro
00:02:27 Day 0 - From Scratch
00:04:15 Days 1-3 - The Lexer
00:08:08 Days 4-6 - The Parser
00:11:56 Days 7-9 - Type Checking
00:18:11 Days 10-13 - Intermediate Represenation TAC
00:21:53 Days 14-24 - Assembly
00:37:25 Day 25 - Game of Life
00:40:34 Outro
Рекомендации по теме
Комментарии
Автор

super interesting deep-dive, the only downside is that now I want to build a compiler too 😳

alexbisag
Автор

neovim, tmux and i3/sway user spotted
nice choices

Also the explanations were really good

doce
Автор

i watched some part of your videos, it felt great, keep it up im a big fan.

emptycode
Автор

You dont need subtitles, your english is fine

fugoogle_was_already_taken
Автор

39:06 Hey, first of all, great job! I think the list/array implementation is usually done the other way around - so lists/arrays are primitives built into the compiler and a string is then added later in the language itself. Think about it, a string is just an array of bytes or a pointer and length!

JulianHartl
Автор

I recently wrote a tokenizer and parser for RESP for an implementation of Redis and I think I'll like to build on that to write my own interpreter and then compiler for a language too. Good video. 👍

samjiman
Автор

I started a calculator project in c about a week ago and i'm working like full time on that shit and i currently have a simple cli, the tokenizer and the lexer. It has pre defined math constants to use and also simple math functions like sqrt and similar. Only thing missing is the parser and the evaluator for it to be fully usable. Also i need to generate the ast but i think thats a part of the Parser. I really don't know how you did so much in so little time. Great project

flobuilds
Автор

absolutely loved the series, followed everyday, it would be helpful if you could mention references and books or papers etc

yavisthchopra
Автор

Thank you so much for making a compiler in 25 days!

BlackHermit
Автор

dang this is such an interesting video. I feel like I am so limited by just sticking to doing CRUD apps when people are building mf COMPILERS. Cool shit man please keep making stuff I love it

zachzulanas
Автор

Esti un genius frate, respectele mele !!!

axelandru
Автор

Damn, this is really interesting, I made a compiler too a while ago but it looks very different to what you can up with. I did it in Python (full soy disclosure) though, so that's probably why lol. Cool vid sir

spaghettiking
Автор

Hi, Alex! Awesome personal challenge and even more awesome that you had the grit to finish it in just 25 days 👏🏻

I'm curious what resources you used for the theoretical aspects. I think you're mentioning Thorsten Ball's "Writing An Interpreter In Go" in the Lexer section of the video, but did you use anything else besides that? Like how to represent an AST in C, how to structure lexing and parsing, different forms of IRs, etc. The README file in the repo is lacking too in this respect.

Also, you're right about type checking resembling an interpreter. I had the exact same feeling when I implemented my first type checker. Some folks even say that type checking is _abstract_ interpretation (see "Interpreting types as abstract values" by Oleg Kiselyov & Chung-chieh Shan).

igstan
Автор

Vertical slicing such as creating enough of the language to write assembly for a program that exits with a specific number has done me well so I don't get in my own head about perfecting every little stage one stage at a time. There's at least enough boilerplate code that each state can morph well for my needs because of that vertical slicing and writing lots of test cases for the target language.

Thorsten Ball's books on the subject are worth considering as primary material. He may not exactly get to the point right away, so skipping around a bit to see what he had as the final result per chapter is recommended over just reading it linearly.

SimGunther
Автор

7:25 agree, i dislike C enums too.
Grouping constant values by prefixes and __ it's annoying with the preprocessor it's annoying.
C++ it's a little bit better, at least assures you they will be constants instead of constant variables.

Hope to try cpp2 syntax with the new enums to overload functions and operators on them.

marcusmors
Автор

Man i really liked this video! Can you tell us the tools you used to create and edit the video with the nice source code and captions?

korigamik
Автор

I am building a compiler for my own language in Rust, and Rust is amazing for parser stuff!

oglothenerd
Автор

Super interesting, i have a question, i saw the repository and i found lib folder, how you implement librarys ?

YannAriell
Автор

"Never reinvent the wheel" is a dumb phrase. If everyone followed that we wouldn't have options and we wouldn't discover new and interesting wheel designs.

Hector-bjls
Автор

What is the name of the book that he is talking about during the lexer section?

bonniesimon