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:
Here’s your TODO list for Monday:
tparameter, and functions. Share your program on Piazza in folder
See you then!