Suppose we want to compile an AST for a structured C-like language to a lower-level representation:
enum Stmt {
If {
cond: BoolExpr,
then: Stmt,
else_: Stmt,
},
While {
cond: BoolExpr,
body: Stmt,
},
Break,
Continue,
...
}
enum BoolExpr {
And(BoolExpr, BoolExpr),
Or(BoolExpr, BoolExpr),
Not(BoolExpr),
...
}
This involves generating forward and backward jumps,
and some of the jump targets may not be known until later in the AST traversal.
Most of the jumps (counted by the number of cases in the compiler code) are forward jumps,
so it's more convenient to generate the code in reverse order.
This way forward jumps will point to known destinations,
and only the backward jump that comes up in the while loop will need a temporary placeholder to patch later.
There will be compiler pseudocode here.