At university the by far coolest and most fun course was compiler construction. We had to write something which would compile a small subset of Java (Javalette) into the Java Virtual Machine instruction set.
I wrote my compiler in Haskell because it seemed that it'd be much less hassle compared to do it in a object oriented or procedual language.
But it definitely was, oh and when you compared the results, I don't remember the exact number anymore but compared to especially the solutions in Java and C++ the haskell ones used around 1/10 of the lines of code to solve this particular problem. Because in the end this problem really has a recursive nature.
16 Comments
jeena@jemmy.jeena.net · 22 pts · 3y
At university the by far coolest and most fun course was compiler construction. We had to write something which would compile a small subset of Java (Javalette) into the Java Virtual Machine instruction set.
I wrote my compiler in Haskell because it seemed that it'd be much less hassle compared to do it in a object oriented or procedual language.
It ain't pretty but it's honest work: https://github.com/jeena/CC/blob/master/Compiler.hs
cashews_win@lemmy.world · 4 pts · 3y
That is not a feeling I'd associate with Haskell!!
jeena@jemmy.jeena.net · 8 pts · 3y
But it definitely was, oh and when you compared the results, I don't remember the exact number anymore but compared to especially the solutions in Java and C++ the haskell ones used around 1/10 of the lines of code to solve this particular problem. Because in the end this problem really has a recursive nature.
CanadaPlus@lemmy.sdf.org · 4 pts · 3y
I have an idea for a Rust-like language with total functional methods bouncing around in my head. Lord knows when I'll get around to building it.
pewpew@feddit.it · 15 pts · 3y
The programmer who made the OS
nychtelios@rlyeh.icu · 23 pts · 3y
Actually compilers are more complex than operative systems, and incredibly they are built using compilers.
cdnalsi@lemmy.world · 4 pts · 3y
Compilers are built using compilers?
phorq@lemmy.ml · 15 pts · 3y
Yup, C is written in C. You bootstrap using a compiler written in another language until your language is complete enough to write its own compiler.
Martineski@lemmy.fmhy.ml · 4 pts · 3y
Alright, that's kinda crazy lol.
nychtelios@rlyeh.icu · 3 pts · 3y
gcc and clang are open source, you can read their source code whenever you want!
pewpew@feddit.it · 3 pts · 3y
I belive you. I made a basic OS in around a month and now i'm starting a C compiler, I think I underestimated it a bit
joyjoy@lemmy.world · 11 pts · 3y
When you write a compiler, you eventually have to write it twice. Once in a pre-existing language, then again in the language it compiles.
Just say no to bootstrapping.
Lemminary@lemmy.ml · 1 pts · 3y
*Boostrap 5 sad noises*
joyjoy@lemmy.world · 1 pts · 3y
Just make your own components. It's not that hard. Tailwindcss and its cousins can handle the utility classes.
Iamfallen@midwest.social · 1 pts · 3y
print("Hello World!")