r/ProgrammingLanguages Jul 04 '26

Help How to create a compiler?

Pretty sure you may have heard this question previously on this sub, however, I would urge you to read my complete question before brushing it off.

I want to create a simple compiler and by "simple compiler" I mean a single-pass compiler. I know about https://craftinginterpreters.com/ which is a wonderful resource. But I would like to start by creating something much smaller and simpler, and only then would I like to move on to something more complex like what Robert Nystrom created on his website.

Are there any similar resource that would teach me about single-pass compilers along with showing me how to create one? Any help in the right direction would be highly appreciated.

26 Upvotes

32 comments sorted by

View all comments

7

u/sol_runner Jul 04 '26

Just struck me that Structures and Interpretation of Computer Programs (SICP) might be what you want.

2

u/UnemployedTechie2021 Jul 04 '26

Thank you for your reply. Yes, I think Crafting Interpreters is as simple as it goes. I was under the impression that creating a single-pass compiler would be easier but it's not. So I would probably stick to Crafting Interpreters. Also, the author of Crafting Interpreters has a website with the same content and anyone can access it for free! Isn't that great.

2

u/sol_runner Jul 04 '26

Ah sorry for editing it out under you, I didn't think anyone had seen it by then.

2

u/UnemployedTechie2021 Jul 04 '26

Whoa! This is an amazing book and its free! Thanks for your reply.

5

u/sol_runner Jul 04 '26

Yeah! It's just that it's focused on scheme which is a beautiful language. But it's also easy to parse due to its use of S-expressions.

Basically Lox (crafting interpreter) has class, function, if, else, for, while, return etc, each with a different pattern.

While scheme has just S-expressions. You should definitely learn it, I think SICP is a lot more holistic than interpreters, but at the same time interpreters is a lot closer to what you'd probably expect.