Homework 6: ASTs
- Print version, with cover page (pdf)
- Due Date: Tuesday, October 10
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!)