* Note that $values is passed to all expression but it
* is used by Variable only. This is required to abstract
* away the tree structure.
*/
public
function
evaluate(
array
$values
);
}
/**
* A terminal expression which is a literal value.
*/
class
Literal
implements
MathExpression
{
private
$_value
;
public
function
__construct(
$value
)
{
$this
->_value =
$value
;
}
public
function
evaluate(
array
$values
)
{
return
$this
->_value;
}
}
/**
* A terminal expression which represents a variable.
*/
class
Variable
implements
MathExpression
{
private
$_letter
;
public
function
__construct(
$letter
)
{
$this
->_letter =
$letter
;
}
public
function
evaluate(
array
$values
)
{