Transpiling Jzero code to Unicon
All this talk about transpilers is all well and good, but seeing is believing. This section presents a transpiler implementation of the Jzero language, writing out Unicon code from the Jzero source code. The implementation is structured to resemble the tree traversal that is used to generate intermediate code in Chapter 9, so you might experience some déjà vu. But before we go there, consider what the transpiler code generator needs to do. As we’ve seen before, this involves a set of semantic attributes and a set of rules for how to compute them.
Semantic attributes for transpiling to Unicon
Our transpiler will introduce three semantic attributes. The first semantic attribute will be a representation of the output Unicon code. Like the icode
attribute introduced for building a list of intermediate code instructions in Chapter 9, the transpiler implementation introduces an attribute named icncode
that is used to build a list...