5 ms·
I did a compiler for a subset of the C programming language (int & bool types, arrays, functions, loops, ...) for my post-graduate compiler course last year :
by raphaelj 13y ago
I did a compiler for a subset of the C programming language (int & bool types, arrays, functions, loops, ...) for my post-graduate compiler course last year :
https://github.com/RaphaelJ/Cours-passerelle/blob/master/Compilateur/ https://github.com/RaphaelJ/Cours-passerelle/blob/master/Com...
(comments are in French)
It was amazing : the full compiler was around 650 lines of code while only using Parsec as a third party library and was able to compile correctly at the first successful compilation. Compiling to LLVM (as text, I didn't used any library for code generation) using monads and Text-Lazy was also pretty pleasant.
My only deception was to be unable to use GADTs : these are awesome but so hard to use with a parser.
- frik 13y agoWow, cool. Thanks for sharing the link! (the code is in English, only the comments are in French) One rather minor question: Is writing comments or even code in the local language still common in France? Afaik, in most European countries the CS courses are taught in English.
- pjmlp 13y ago> Afaik, in most European countries the CS courses are taught in English. Not really. You only write stuff in English if it intended for publication like papers and stuff.
- thu 13y agoHe is from Belgium, and it is not common. Maybe it was a requirement for his course.
- Dewie 13y agoAll the literature, programming libraries etc. have corrupted my brain to the point that I write my code in English when it's only for my own eyes, even though it isn't my native tongue.
- pjmlp 13y agoI do the same. :)
- raphaelj 13y agoI mostly write my assignments in French. It just feels "strange" to me to write comments (which are just real sentences) in English when anyone which will read the thing shares my native language. When I'm comment complex things (like some parts of this compiler), I feel it easier and more comprehensive to explain them in my mother tongue. Anyway, I write all of my "public code" in English. The audience is different.
- evincarofautumn 13y agoRe. GADTs, you can parse to an ADT then have a separate function to add the extra type information. The problem is that you want to add static information to dynamic input, so you need to handle the error cases.
- deleted 13y ago[deleted]
- raphaelj 13y agoYep. I tought about it, but I was a few days from the deadline date, and this will add a significant amount of work. Anyway, I was dissatisfied of that. GADTs are awesome to add some "proofness" to a type checker.