Compiler #BuildingFromScratch #CodingResources
Have you ever heard someone say they built a compiler from scratch and wondered what that really means? 🤔 Let’s break it down into two possibilities – following a guide with their own tools and low-level stuff, or relying solely on pure intuition.
📚 Utilizing Guides:
If someone followed a guide but built their own tools and low-level components, they likely had a basis to start from but still put in the effort to customize and create something unique. This process involves learning from available resources and implementing that knowledge in a personalized way.
🤔 Pure Intuition:
On the other hand, if they had no help at all and relied solely on intuition, it showcases a high level of expertise and understanding of the underlying principles of compiler construction. This approach requires a deep knowledge of programming languages and systems.
🚀 Taking Action:
If you’re looking to embark on a similar ambitious project but feeling overwhelmed by the unknowns, consider starting with a template or guide to provide structure. As you progress, don’t be afraid to delve into unfamiliar territory and research each component thoroughly.
🔍 Finding Resources:
Experienced individuals often rely on documentation, forums, and established best practices to guide their development process. It’s essential to strike a balance between referencing existing solutions and innovating with your unique approach.
🧠 Learning vs. Copying:
While it’s common to emulate more experienced individuals initially, the goal is to grow beyond replication and develop your style, solutions, and decision-making processes. Strive to understand the rationale behind established practices and adapt them to your projects.
In conclusion, building a compiler from scratch is a challenging yet rewarding endeavor that requires a combination of guidance, intuition, and perseverance. By leveraging available resources, honing your skills, and embracing the learning process, you can bridge the gap between imitation and innovation in your coding journey. Happy coding! 🚀
People who build a compiler have generally either followed a book or read up on them previously.
Nobody is just building a compiler out of intuition.
People do PhDs in compiler design, so go find an introductory compiler book if you’re interested in that stuff.
When I cook dinner from a recipe book using components in my pantry, I say I made the meal ‘from scratch’. The same applies here. The only people to have truly whipped up a compiler from absolutley zero were the pioneers doing so back in the early days of computing.
>I would have no idea how to make a compiler, but I think if I had a template I could eventually learn it
I think you severely underestimate how massive a task it is, you’ll need some pretty advanced knowledge in theoretical computer science/mathematics
For more common tasks/projects, it usually is a good mix of previous knowledge and googling skills, depending of the complexity of the project
The “template ” you are looking for is probably not practical, but theoretical. As somebody mentioned, compiler design is a topic of study, and you can see its innovations and expirementation in the design of the real compilers/toolchains out there.
You could read a book on compiler design, or see a video, take a class, etc. There are many ways to learn about the topic, but the important part won’t be the implementation, but the theory behind it. Once you understand what the components of your compiler are going to be and how they should behave to accomodate to your language, you can start work on it!
Out of all things you can learn from cs, Compilers is one of the things that’s better by learning within a course. In my 4th year of college, I took a compiler class and I basically built a cpp-like compiler using ANTLR4, which is a compiler construction tool. Like the comments below, when they say “built a compiler from scratch” They probably just mean they built the parsing and semantic rules and how their language works and passed it into a builder.
I mean, that’s like saying you want to program using machine code. Is it from scratch if you use a high level language to build your compiler?
There’s this weird belief that a good programmer needs nothing and can code everything without looking things up.
For example, in the old days, people wrote pretty bad compilers. They just used their intuition. Then, there was a study of regular expression, BNF (Backus Naur Form), and studies of formal grammars, plus learning how to think of a language as syntax vs. semantics. You can’t expect one person to figure that out from scratch. They will leverage off all that.
Great programmers like great writers have seen a lot, but they also have a deep understanding of things, like math, and such. So, they can understand parse algorithms. Donald Knuth was basically a math guy that is known for his CS and many important CS guys have a strong math background.
But, you can still write a compiler with far less knowledge by just leveraging the tools that are out there. And why wouldn’t you? Would you grow your own crops? Make your own flour? Build your own oven? I mean, at some point, it’s a ridiculous exercise.
And who says the “write it from scratch”? I mean, I could write a pretty simple interpreter without having to look TOO much up, but I’ve written stuff like it before, and the language I’d come up with would be super simple. Would that be a real language? I mean, kinda yes, but what’s the point? The language I come up with would not do anything more interesting than any other language.
What is interesting is if the language does something different, such as when they came up with functional languages like Haskell or Erlang. They were building a language that had new features.
I remember a rule of thumb but if anyone knows this to be false, please correct me.
Writing a program like Excel is difficult. Writing a compiler is three times as difficult. Writing an OS is three times as difficult as a compiler.
I would say making it from scratch means you took basic ingredients and made something. So, kitchen utensils, or coding frameworks, are allowable. But, prewritten code, or premade dough, is not.
They probably used llvm, just like all the other people who build compilers from scratch these days.
Compilers have a lot of theory behind them. If you’re interested, pick up a textbook. I like *Crafting Interpreters* as an approachable and practical introduction to it.
I used a youtube video
> You need to have a recipe book to cook something that you have never cooked before
It is simple as that
I first learned how to make compilers in a year-long college class. I made a toy compiler that turned Pascal into SPARC machine code. The professor gave us a lot of guidance and introduced the standard concepts we’d need to know – concepts that only became standards through decades of compiler research. We learned about tools like YACC to generate the parser. For supplemental reading material we used the Dragon Book. So, yeah, I did write a compiler “from scratch”, but it was with a lot of guidance and using concepts and tools developed by many others. But then I could go and use that knowledge to build a few more compilers over the years. That was all back before things like YouTube and online courses existed and the Internet was a lot smaller, and I’m sure you could find a lot of good information online these days. In the end, unless you’re sitting there with a breadboard and a bunch of circuit componentry, you’re building on stuff that others have built, and there’s nothing wrong with that (breadboards and circuits are obviously naturally-occurring).