Starting in September I will be teaching a mini curse “Introduction to compilers” in small polish university. I basically have free hand, taking that I teach second year computer students compiler basics. I’m thinking about using Julia as one of three main examples of compiled languages for few reasons.
Julia is fun.
Julia is modern language with great compiler (thumbs up for Julia awesome theme).
You can easily show various stages of code compilation.
Put your reason here.
I’m first time leading this course, so I’m afraid that I will failed and also unsure that my Julia skills are good enough for such topic. As such, I want to ask more experienced people, due you think that using Julia for such curse is a good idea? If so, what you think I should include about Julia in it?
I am teaching a course on Czech Technical University in Prague and I use julia to talk about compilers and optimization (of program, not in mathematical sense). I love the latter, since it reminds me time of my high school. So go for it, I think Julia is great for this.
I was asked two weeks ago if I would like to take over of course on parallel programming, and I said I would love to if I can do it in Julia.
I was supposed to do a presentation this semester on creating a mini compiler from a subset of Julia to WebAssembly. The presentation got cancelled but I got to think about this topic quite a bit. Some thoughts I’ve had since then, in no particular order:
It’s better to create a small compiler, and expand on it iteratively, than to spend each lecture on a phase of the compiler. This is the approach taken in Essentials of compilation by Siek (talk). I thinkPLAI also takes that approach?
In general, I think that for a Julia-based course, Scheme-based resources will be more useful than ML- or Java-based resources. Be picky. Don’t throw a list of a dozen books to your students.
Parsing is boring. Julia macros allow you to skip it. Take advantage of that.
Focus on the data structures. That’s what students (should) already know.
Decide ahead of time how many third-party packages you want to use.
The most frustrating part about writing a compiler in Julia is the lack of pattern matching, so you might consider using a third-party package for that.
Don’t sell Julia too hard. Students will doubt a lot of Julia’s benefits and the maturity of the compiler because the tooling is not up to par with many other languages.
Short and unsatisfactory answer: opening the hood of compilers and show students what is there. This of course can be done in 30 minutes or take you two semesters. Hard to say more about that, since old teacher left institution and I didn’t started, so much things is flowing. Last but not least, only meeting with students will show, what can be reasonable done.
Basic example of the course is C, but I want to expand it beyond great old C.
Not about compilers per se, but I’d like to learn about best practices for using Julia to write a recursive-descent parser from scratch to parse text in a custom grammar.
If the main goal of the course is for students to implement a compiler/interpreter for a toy programming language, a good option might be to implement ChocoPy in Python.
When I was learning Julia, I implemented the code for https://interpreterbook.com/ and https://compilerbook.com/ in Julia. There’s a thread here somewhere someone else did the same (Update: I found the thread [ANN] MonkeyLang.jl). Ball’s books are low on theory and and he mines a lot from Lua.
You can explain concepts with a programming language as small as you want. For instance, this paper explains language semantics with only integer addition.
You will find Siek’s book very useful because each chapter expands the programming language it implements with more syntax.