r/Compilers • u/apoetixart • May 28 '26
Review My Parser
I just built my first Recursive Descent Parser (AI guided me, I didn't vibe code it, kinda like acted as a teacher so it's human written code).
Can experienced devs please review my Parser and tell me if the AI was good at tutoring or it was trash. Personally, I tested and results were pretty good. The ASTs were correct.
https://github.com/anubhav-1207/Project-Arc
But still, please review it.
0
Upvotes
2
u/DistributionOk5056 May 28 '26
i havent really looked into the code much yet but i would say to give instructions and/or diagrams in the README.md
3
u/Only-Archer-2398 May 28 '26
I don't care about the implementation, is not really important at this stage and can be change easily. What's missing:
- unit/integration tests
Your tokenizer only test `, . 3.14`. That's not enough, especially as your tokeniser implementation seems to support a lot more than that. Your parser is not tested at all.
Before jumping into the next pass, ensure that the previous pass is well tested: unit, integration, fuzzy tests, even a benchnark, anything that can help you to catch a critical bugs earlier.
2
u/User_reddit69 May 28 '26
Nycc code is clean
2
u/Key_River7180 May 28 '26
A few notes:
.vscode, it's gross!if-elif-elsechains, that needs a reformthe lexer also gross! Why don't you use a dictionary, for a school project it's fine man
enumpackage for token types, it looks cleaner1
u/AustinVelonaut May 28 '26
The one thing I saw in in the parser was inconsistent use of
expectin cases where a simpleadvance()ortok = self.current_token; advance()would work. Theexpectcall works, but does extra extraneous work checking a match again that isn't required.1
u/Quirky-Ad-292 Jun 03 '26
Looks good, but some things could be discussed. Like storing all tokens at once, instead of generating them two at a time! For smaller files this is fine, but for a 10k line project it might be a memory issue in Python! You only need to save the location and name after knowing the token-type! Also if you’re using Python, look into dataclasses and enums!
2
u/[deleted] May 28 '26
[removed] — view removed comment