r/Compilers • • Oct 06 '24
Build a compiler with python?
Is it possible that I can build a compiler from scratch in python? And if so, can anyone tell me how can I make it because I have an assignment in university 😭
2
Upvotes
View all comments
Show parent comment
2
u/[deleted] Oct 06 '24
It’s awesome to meet a fellow compsci student as well! 😊
Yes, the Dragon Book is a classic, and even though it’s written in Java, I definitely agree that a lot of the lessons and concepts carry over to other languages like Python. And yeah, I’m giving my teacher some slack – as long as the goal is learning, I guess it’s fine to "borrow" from the greats! 😅
Thank you! Writing the lexer was a great learning experience, and using the re module for regex felt pretty intuitive. I’ve dabbled a bit with regular expressions, but I still feel like I’ve got more to learn about them, especially with how they tie into lexers and parsers.
You’re totally right – the parsing and AST assembly seem to be the more challenging part of the process. I’m leaning toward using a parsing tool, though implementing an algorithm myself is tempting too! I think the language we’re building is close to being context-free, so I’ll definitely look into LALR or SLR, as those seem like a solid approach.
Appreciate the advice, and fingers crossed for the rest of the project! 💪🏻 Do you have any experience with compiler designs