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:
- How could calloc() simplify the scanner? Is there a good reason
not to use it?
- Why do we need the *noshortif productions (rules)? Illustrate
with example input.
- Why do we need the *ne* productions? What does "ne" stand for?
- What kinds of illegal input are weeded out? For each kind of
illegal input, explain why the designers of the JOOS language made it
- How could an LALR(1) parser could avoid building backwards lists?
Illustrate with an example from joos.y and tree.c.