Week 3/38
Exercises on abstract syntax trees
- Extend the tiny expressions with a modulo operator
% and
an abs(_) function.
- Write a better pretty printer that only outputs the minimal number
of parentheses required to preserve the semantics of the expression.
- Introduce a unary minus operator
-x as syntactic sugar
for the expression 0-x . This means that unary minus is
defined in the grammar, but not in the syntax trees.
- Implement a function that simplifies the constant parts of a tiny
expression. Include algebraic rules on expressions involving identifiers,
if you feel up to it.
- Discuss how an LALR(1) parser could avoid building backwards lists.
- Study the code for parsing JOOS programs and building and weeding
abstract syntax trees.
|