Week 3/38

Exercises on abstract syntax trees

  1. Extend the tiny expressions with a modulo operator % and an abs(_) function.
  2. Write a better pretty printer that only outputs the minimal number of parentheses required to preserve the semantics of the expression.
  3. 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.
  4. 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.
  5. Discuss how an LALR(1) parser could avoid building backwards lists.
  6. Study the code for parsing JOOS programs and building and weeding abstract syntax trees.