SI 413 Fall 2023 / Homeworks


This is the archived website of SI 413 from the Fall 2023 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

Homework 6: ASTs

1 Draw an AST

Here is a program written in Python. Draw its AST.

x = 10
while x > 0:
    print(x)
    x = x - 3
print("done")

2 Type checking

The following C++ program has a type error that a compiler like gcc or clang would recognize.

int main() {
    int bert = 100 % 3;;
    string ernie = "howdy";
    while (bert > 10) {
        bert = bert - 7;
        ernie = ernie + bert;
    }
    return 0;
}

First draw the AST for this program.

Then indicate clearly with a box or arrows a single node of the AST where the type error is identified during compilation.

3 Undraw an AST

Write a program in the language of your choosing that would generate the following AST:

(Be sure to specify which language you have chosen!)