r/Compilers • u/Sewter0 • Sep 18 '26
Looking for feedback to my compiler
Hi everyone
I’ve been working on my own programming language and compiler in C++, mostly as a learning project.
The main idea is to experiment with compiler architecture while also trying to make the language’s syntax more convenient for mathematical expressions, but now I am doing programming language.
After this I will add equations.
Currently works:
Lexer
Parser
AST
IR generation
I am still relatively new to compiler development, so I’m sure there are things I am doing in non ideal ways.
I’d especially appreciate feedback on:
compiler architecture
parser design
C++ implementation
things that I should learn next
mistakes or questionable design decision
Github: https://github.com/0sewter0/Compiler.git
Thanks for an attention!
10
u/NYU_VM Sep 18 '26 edited Sep 18 '26
Documentation is a good starting point here, your project seems to have none, not even sparse comments. And what about language grammar? You have leaned on LLVM for backend which for a learning project I would say is a missed opportunity on learning so many things about the backend by delegating to LLVM, plus it's a massive dependency for such a lean project. I didn't go through much but your main.cpp. I instantly noticed that you included the heavy filesystem header for just one filepath extraction. It could be done with simple string handling, so filepath is redundant if not used for other purposes. And, '__argv[]' is platform specific extension, not the standard.
5
u/GenericPointer Sep 18 '26
I mean... nice you're building a compiler, but PLEASE Clean up your repo:
Once you did that others will actually try to understand what you did, because most people just close the tab when there's no docs.
But nice that you're doing that.
2
u/GenericPointer Sep 18 '26
About your Parser:
- It has no precedence rules
- You use a unique pointer class hierarchy instead of actual recursive AST.
- Your look ahead has potential out-of-bounds
- You have only very few error recovery, I'd recommend using a unified error system.
1
u/AeroForger Sep 21 '26
Hey!
I'm a compiler developer as well, and I looked through your repo. Overall, it's pretty decent, especially considering it's still a learning project.
There are a few things I didn't really like:
mainis currently treated like a normalintfunction, so examples such asreturn x + y;directly become the program's exit status. That's technically valid, but I think it would be clearer to encouragemainto return intentional exit codes rather than arbitrary computation results.The project itself has a pretty recognizable compiler structure already, though, and I like that you're actually implementing things like structs, loops, functions, arrays, and LLVM codegen instead of keeping it at calculator-language level.
Feel free to open an issue or DM me if you have any questions. I'd be happy to help you out!
1
u/recursion_is_love Sep 19 '26
Take a look at some documentation system. Maybe start with doxygen
https://www.doxygen.nl/
-1
u/Mean-Decision-3502 Sep 18 '26
Show examples from your language.
0
u/[deleted] Sep 18 '26
[deleted] — view deleted comment