To support conditional evaluation in Camille, we add the following rules to the grammar and corresponding pattern-action rules to the PLY parser generator:
We must also add the if and else keywords to the generator of the scanner on lines 10–16 of the listing at the beginning of Section 10.6.1.
The following code segment of the evaluate_expr function accesses the ntIfElse variant of the abstract-syntax tree of type TreeNode and evaluates the conditional expression it represents:
Notice that we implement conditional evaluation in Camille using the support for conditional evaluation in Python (i.e., if . . . else; lines 7–10). In addition, we avoid adding a boolean type (for now) by associating 0 with false and anything else with true (as in the C programming language). Example expressions in this version of Camille with their evaluated results follow:
5. Camille version 1.1(named CLS).
3.145.17.18