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
).
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):
For this, we will implement the Packt\Chp8\DSL\AST\Equals
class. This class can inherit the BinaryOperation
class that we implemented earlier:
namespace Packt\Chp8\DSL\AST; class Equals extends BinaryOperation...