Annotating syntax trees with labels for control flow
The code for some tree nodes will be sources or targets of control flow. To generate code, we need a way to generate the labels at the targets and propagate that information to the instructions that will go to those targets. It makes sense to start with the attribute named first
. The first
attribute holds a label to which branch instructions can jump to execute a given statement or expression. It can be synthesized by brute force if need be; if you had to, you could just allocate a unique label to each tree node. The result would be replete with redundant and unused labels, but it would work. For most nodes, the first
label can be synthesized from one of their children, instead of allocating a new one.
Consider the additive expression e1 + e2
, which builds a non-terminal named AddExpr
. If there was any code in e1
, it would have a first
field, and that would be the label to use for the first
field of the entire AddExpr
. If e1...