Build an expression abstract syntax tree by representing operands, parentheses, and operations in the order dictated by evaluation. The resulting tree mirrors evaluation, simplifying runtime code generation. section 12.1
Follow the evaluation order while constructing the tree:
- Represent each operation as a Binary Operation with its operator and left and right operands. section 12.1
- Use shorthand AST notation to encode labels, values, containment, and parentheses while building expressions such as 1 + 2 * 3. section 12.1
1 + 2 * 3
Apply PEMDAS by constructing the multiplication subtree for 2 * 3 before attaching it as the right operand of the addition operation. section 12.1
Figure 12.9 The AST-building process recapped using shorthand notation
Review the complete AST-building process in shorthand notation. section 12.1
