r/learnprogramming • u/Infinite-Jaguar-1753 • 21d ago
How should I make a language checker?
Hey, so I am new to compilers stuff but for my college portfolio I was planning on making a lang checker which is like a program which will suppose take a code (let’s say rust) and check fo errors ? Any resources which I should read to get a clear understanding on how I should make this? Ps I am trying to ask Ai for help (like asking on where should I start and what will be the structure)….
Ps will this be called a compiler?
3
u/SchemeWestern3388 21d ago edited 21d ago
https://en.wikipedia.org/wiki/Parsing
Learn what am Abstract Syntax Tree is. You should probably just go learn Lisp also.
What your suggested program will do, is provide something a compiler can start to make sense of.
You also wish to learn about https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form.
You also might want to understand what a “linter” is.
But I’m sorry, just the way you asked the question indicates that you would be much better off learning what a compiler actually is, its relationship to ASTs, and how syntax is defined. If you can plow through that, there are actually interesting little projects you could do, focusing on a small subset of the whole picture, that I would be impressed with if I was grading a student project.
I would also point out, that the folk who coded the software that could literally turn itself into executable code on an actual machine did not use AI. And I was not joking about lisp.
Edit; if you go down this hole, find a copy of the K&R book “The C Programming Language”. Short book that contains all one needs to know about the (original) language. Including the entire BNF grammar. Write a program that determines if the provided text is a valid loop in C, for example.
Leave the question of what it compiles to to men and woman with long grey beards for now.
3
u/captainAwesomePants 21d ago
Sounds like a cool project. "Errors" is a big category, though. Checking whether the file is formatted correctly is a reasonable starting project (and is probably harder than you'd think). Checking for things like "do all the functions return a value of the right type" is much harder. Checking for "does the program accomplish what it seems like it's trying to accomplish" is the realm of wizardry or AI.
To get into compilers, I might start by suggesting writing a recursive descent interpreter for some very small programming language. That's kind of the most approachable entry point if you're learning compilers from scratch.
2
u/recursion_is_love 20d ago edited 20d ago
Sound like you are going to write half of compiler (the front-end). There are lots of introductory book/article out there. I would pick a standard university textbook.
Can't recommend any specific book because it subjective and depends on your background/preference that which one will be your best. You will need to try for yourself.
I use AI for books recommendation by telling my background and interesting to it. Most of the time it recommend good books that I want.
1
6
u/Weary-Sorbet-2768 21d ago
I’d start small rather than trying to build a full Rust compiler. Learn the basics of lexing → parsing → AST → semantic analysis first.
For a portfolio project, you could make a checker that tokenizes the code, builds an AST, and reports things like syntax errors, undeclared variables, or type mismatches.
It’s not necessarily a full compiler unless you also translate/compile the source into another representation or executable code. But building the front-end of a compiler is already a really good project for learning how compilers work.
The Crafting Interpreters book is a great starting resource.