Since the repo is not in GitHub, and that basically wipes completely any chance of anyone discovering the project accidentally –at least it would pop-up in my followers’ feed-, I thought I would use this blog to make it “public”.
I’m learning Haskell and I have decided to use the same project I used to re-learn Go, which again is huge and it is unlikely I will finish it, but there you go! I’m focusing on the compiler part, as I already scratched the interpreter itch.
The public repo is accessible at micro2-lang and the usual disclaimers apply –specially as I’m a Haskell newbie–. I know the name isn’t great, I may change it later on.
So far it has been a lot of fun. I’m using parser combinators via parsec and it is amazing the amount of functionality I have with a tiny fraction of the code I wrote in Micro. There are some downsides, though. For example, the errors messages are a bit less good.
For example, this program has an error:
1module main
2
3// just add two numbers
4def add(a: u8, b: u8): u8 {
5 return a + b
6}
7
8add(3, 2); // 10
The statements in Micro2 are delimited by semicolons, so the compiler reports:
error: "add.cr2" (line 6, column 1):
unexpected "}"
expecting statement
Which is not terrible, but is not great either. Serviceable I would say. Considering the objectives of the project, this is absolutely fine.
I am currently working on the type-checking and semantic analysis, which is really parsing, but can’t be all implemented using parsec
(it will know how a “return” looks like, but can’t tell if it is used inside a function and returns the right type).
As I did it already in Go, is not too complicated, but I’m getting comfortable with Haskell and its Monads. The harder part I suspect will be the code generation, and I’m looking forward to it!