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

**URL:** <https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004>\
**Category:** Teaching & Outreach\
**Created:** [July 13, 2024, 3:50pm UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004 "2024-07-13T15:50:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![KZiemian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kziemian/32/9020_2.png) [@KZiemian](https://discourse.julialang.org/u/KZiemian)\
**Post date:** [July 13, 2024, 3:50pm UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/1 "2024-07-13T15:50:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [July 13, 2024, 7:00pm UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/2 "2024-07-13T19:00:19Z")

</div>

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/](https://juliateachingctu.github.io/Scientific-Programming-in-Julia/)

if you are interested in

Tomas

---

<div class="post-metadata">

**Author:** ![xiaoxi](https://avatars.discourse-cdn.com/v4/letter/x/a9adbd/32.png) [@xiaoxi](https://discourse.julialang.org/u/xiaoxi)\
**Post date:** [July 13, 2024, 7:02pm UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/3 "2024-07-13T19:02:57Z")

</div>

What are the main objectives of the course?

---

<div class="post-metadata">

**Author:** ![savq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/savq/32/22063_2.png) [@savq](https://discourse.julialang.org/u/savq)\
**Post date:** [July 13, 2024, 7:26pm UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/4 "2024-07-13T19:26:55Z")

</div>

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](https://iucompilercourse.github.io/tutorial-web-page) ([talk](https://www.youtube.com/watch?v=43VA_QaTRT8)). I _think_ [PLAI](https://www.plai.org/) 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.

---

<div class="post-metadata">

**Author:** ![KZiemian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kziemian/32/9020_2.png) [@KZiemian](https://discourse.julialang.org/u/KZiemian)\
**Post date:** [July 13, 2024, 8:51pm UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/5 "2024-07-13T20:51:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [July 13, 2024, 9:16pm UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/6 "2024-07-13T21:16:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xiaoxi](https://avatars.discourse-cdn.com/v4/letter/x/a9adbd/32.png) [@xiaoxi](https://discourse.julialang.org/u/xiaoxi)\
**Post date:** [July 14, 2024, 4:34am UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/7 "2024-07-14T04:34:56Z")

</div>

> [@KZiemian](#):
>
> Short and unsatisfactory answer: opening the hood of compilers and show students what is there.

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](https://www.python.org/downloads/release/python-360/), which can easily be compiled to a target such as [RISC-V](https://riscv.org/). The language is [fully specified using formal grammar, typing rules, and operational semantics](https://chocopy.org/chocopy_language_reference.pdf). ChocoPy was originally used to teach [CS 164 at UC Berkeley](https://www2.eecs.berkeley.edu/Courses/CS164/), but has since been used by [several other institutions](https://chocopy.org/#uses). ChocoPy was designed by [Rohan Padhye](https://rohan.padhye.org/) and [Koushik Sen](https://people.eecs.berkeley.edu/~ksen), with substantial contributions from [Paul Hilfinger](https://www2.eecs.berkeley.edu/Faculty/Homepages/hilfinger.html).

[https://chocopy.org](https://chocopy.org)

---

<div class="post-metadata">

**Author:** ![pitsianis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pitsianis/32/26588_2.png) [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Post date:** [July 16, 2024, 12:27am UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/8 "2024-07-16T00:27:37Z")

</div>

Have a look at Andrew Appel’s [Modern Compiler Construction](https://www.cs.princeton.edu/~appel/modern/)

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

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [July 16, 2024, 12:38am UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/9 "2024-07-16T00:38:59Z")

</div>

> [@xiaoxi](#):
>
> 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/](https://interpreterbook.com/) and [https://compilerbook.com/](https://compilerbook.com/) in Julia. There’s a thread here somewhere someone else did the same (Update: I found the thread [[ANN] MonkeyLang.jl](https://discourse.julialang.org/t/ann-monkeylang-jl/74664)). Ball’s books are low on theory and and he mines a lot from Lua.

---

<div class="post-metadata">

**Author:** ![KZiemian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kziemian/32/9020_2.png) [@KZiemian](https://discourse.julialang.org/u/KZiemian)\
**Post date:** [July 19, 2024, 8:59pm UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/10 "2024-07-19T20:59:09Z")

</div>

> [@xiaoxi](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![xiaoxi](https://avatars.discourse-cdn.com/v4/letter/x/a9adbd/32.png) [@xiaoxi](https://discourse.julialang.org/u/xiaoxi)\
**Post date:** [July 20, 2024, 9:51am UTC](https://discourse.julialang.org/t/teaching-mini-course-introduction-to-compilers-with-julia-good-or-bad-idea/117004/11 "2024-07-20T09:51:05Z")

</div>

You can explain concepts with a programming language as small as you want. For instance, this paper explains language semantics with only integer addition.

> **[Programming language semantics: It’s easy as 1,2,3 | Journal of Functional...](https://www.cambridge.org/core/journals/journal-of-functional-programming/article/programming-language-semantics-its-easy-as-123/EC2C046CF94382B3B408036B84475DC7)**
>
> Programming language semantics: It’s easy as 1,2,3 - Volume 33

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.

> **[Course Webpage for Compilers (P423, P523, E313, and E513)](https://iucompilercourse.github.io/IU-Fall-2023/)**
>
> Course web page for IU Fall 2023
