Game Development Reference
In-Depth Information
Figure 11.4 Class hierarchy for basic addition/subtraction expressions.
Code Execution or Generation
Once an AST is generated from the script file, there are two potential courses of
action, both of which require using a post-order traversal. For a more traditional
compiler, the goal of the AST traversal would be to generate the actual code that
will be run on the target machine. So when C++ code is compiled, the AST is tra-
versed and code is generated in assembly that is designed specifically to work on
the target platform.
If the game's scripting language is compiled, such as UnrealScript, then it would
definitely make sense to perform the code-generation step. But if the language is
interpreted, code generation is unnecessary. Instead, it would be preferable to just
traverse the AST and execute any actions that the nodes represent.
For the addition/subtraction example, the nodes could be defined in the following
manner:
Click here to view code image
abstract class Expression
function Execute()
end
Search WWH ::




Custom Search