Teaching mini-course "Introduction to compilers" with Julia, good or bad idea?

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.

  1. Julia is fun.
  2. Julia is modern language with great compiler (thumbs up for Julia awesome theme).
  3. You can easily show various stages of code compilation.
  4. 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?

7 Likes

Hi,

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.

Link to our course is here https://juliateachingctu.github.io/Scientific-Programming-in-Julia/

if you are interested in

Tomas

7 Likes

What are the main objectives of the course?

1 Like

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 :expressionless: 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 think PLAI 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.

3 Likes

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.

1 Like

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.

1 Like

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.

ChocoPy is a programming language designed for classroom use in undergraduate compilers courses. ChocoPy is a restricted subset of Python 3, which can easily be compiled to a target such as RISC-V. The language is fully specified using formal grammar, typing rules, and operational semantics. ChocoPy was originally used to teach CS 164 at UC Berkeley, but has since been used by several other institutions. ChocoPy was designed by Rohan Padhye and Koushik Sen, with substantial contributions from Paul Hilfinger.

https://chocopy.org

4 Likes

Have a look at Andrew Appel’s Modern Compiler Construction

My favorite is the SML one because the code is 1/4th the C and Java versions.

1 Like

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.

1 Like

It would be great, but this is a mini-curse, not full fledge lecture. I guess we won’t have a time for that.

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.

By the way, Siek teaches a compiler course.

2 Likes