teaching machines

CS 330 Lecture 36 – Guish Interpreter

Dear students,

I am gone to learn about the state of computer science in high schools across Wisconsin. However, since at least one of you objected to my being gone a few times this semester, we continue our discussion of writing our interpreter!

We pick up where we left off last lecture. We ended with an interpreter that could respond to a sequence of rectangle commands with integer literal operands. That was interesting, but nothing we wrote couldn’t have been written with a much simpler algorithm that used regular expressions to parse.

Now we extend our language to feel like a real programming language. We first add variable references:

Referencing a variable in an expression is no good if we can’t also assign to them. Let’s add assignment statements:

This next step isn’t really directly related to writing an interpreter. But let’s add a slider that can also be used to assign a variable’s values to support easy parameter tweaking and animation:

Our expressions are currently limited to integer literals and variables. We want to expand this, but let’s add parentheses first:

Now, we can add operators, which in my mind is the craziest part of writing our own interpreter:

What’s a programming language without loops? (Haskell. Ha!) We’ll add a cute little repeat construct to put motors in our code:

It’s time for the last big feature: functions. We start by adding support for function definitions:

And for function definitions to have any value, we must be able to call them:

That’s it!

Here’s your TODO list for Monday:

  • For a participation point, write a Guish program to draw something interesting. I’ve posted the interpreter. Use at least some of the features we’ve added: variables, color, loops, mathematical operations, the t parameter, and functions. Share your program on Piazza in folder guish.
  • Alternatively, for a participation point plus an extra credit point, extend the language and write a program using your new feature. But I ask that you host your new interpreter somewhere and post a link to it.

See you then!

Sincerely,

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *