Week 3

Exercises on abstract syntax trees

Study the A- code for parsing JOOS programs and building and weeding abstract syntax trees, specifically the files joos.l, joos.y, tree.c, tree.h, weed.c, and weed.h. Answer the following questions:
  1. How could calloc() simplify the scanner? Is there a good reason not to use it?
  2. Why do we need the *noshortif productions (rules)? Illustrate with example input.
  3. Why do we need the *ne* productions? What does "ne" stand for?
  4. What kinds of illegal input are weeded out? For each kind of illegal input, explain why the designers of the JOOS language made it illegal.
  5. How could an LALR(1) parser could avoid building backwards lists? Illustrate with an example from joos.y and tree.c.

Maintained by Christopher J. F. Pickett. [HOME]