Adding logical expressions

Currently, our language only supports numerical expressions. Another useful addition would be to support Boolean expressions that do not evaluate to numeric values but to true or false. Possible examples would include expressions such as 3 = 4 (which would always evaluate to false), 2 < 4 (which would always evaluate to true), or a <= 5 (which depends on the value of variable a).

Comparisons

As before, let's start by extending the object model of our syntax tree. We'll start with an Equals node that represents an equality check between two expressions. Using this node, the 1 + 2 = 4 - 1 expression would produce the following syntax tree (and should of course eventually evaluate to true):

The syntax tree that should result ...

Get PHP 7 Programming Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.