The SyntaxTree structure, also defined in the generated D source file, basically looks like this:
struct SyntaxTree
{
uint _ST_rule,
_ST_line_number,
_ST_column_number;
union
{
struct {
string _ST_match,
_ST_match_ws;
}
SyntaxTree*[] _ST_children;
}
// functions
}
An AST node for a non-terminal contains pointers to it's children. A leaf node contains the terminal match of the rule that generated the node
.
_ST_match_ws is the match including preceding whitespace.
_ST_rule is the number of the rule. The numbering of the rules can be seen in the grammar debug output (command line option -g).
_ST_line_number and _ST_column_number are the line- and column numbers of the first character of the match.
If the node is a non-leaf node, it's the line- and column number of the first terminal in the subtree rooted at that node, that is, the first terminal of the given rule's expansion.
The tree is used to do semantical analysis. The only thing you need to know for common use, is that you can use these member variables in your semantic code. Usually that will only be _ST_match and _ST_line_number.
The structure also defines all the semantic code. APaGeD extends the blocks of code that you write after each rule such that you don't have to care about which code to call for which rule, etc.