class Expression

This class represents an arithmetic or a logical expression.

Properties

protected array $tokens
protected bool $postfixed

Methods

array
get()

Returns the token list of this expression.

void
set(array $tokens)

Sets the token list of this expression

void
push(Token $t)

Adds a token at the end of the token list of this expression.

pop()

Returns the last added token of this expression and removes it from the list of tokens.

peek()

Returns the last added token of this expression

void
postfix()

Implementation of the Shunting Yard algorithm to transform an infix expression to a RPN expression.

void
setFields(array $fields)

Sets the value of all tokens with type T_FIELD

setNamedFields(array $fields)

Sets the value of all tokens with type T_IDENT

bool
setVariables(array $variables)

Sets the value of all tokens with type T_IDENT or T_FIELD

void
setToken(Token $token, string $value)

Detects the type of the given value, converts it according to this type and sets the value of the given token with the result.

void
setDateToken(Token $token, string $value)

Converts the given value into a DateTime object and sets the value of the given token with the result.

Token|false
evaluate()

Evaluates this expression

Details

at line 61
array get()

Returns the token list of this expression.

Return Value

array The token list of this expression

at line 73
void set(array $tokens)

Sets the token list of this expression

Parameters

array $tokens The token list of this expression

Return Value

void

at line 86
void push(Token $t)

Adds a token at the end of the token list of this expression.

Parameters

Token $t The token to be added

Return Value

void

at line 97
Token pop()

Returns the last added token of this expression and removes it from the list of tokens.

Return Value

Token The last added token

at line 108
Token peek()

Returns the last added token of this expression

Return Value

Token The last added token

at line 120
void postfix()

Implementation of the Shunting Yard algorithm to transform an infix expression to a RPN expression.

Return Value

void

Exceptions

Exception

at line 196
void setFields(array $fields)

Sets the value of all tokens with type T_FIELD

Parameters

array $fields The token values

Return Value

void

at line 212
setNamedFields(array $fields)

Sets the value of all tokens with type T_IDENT

Parameters

array $fields The token values

at line 229
bool setVariables(array $variables)

Sets the value of all tokens with type T_IDENT or T_FIELD

Parameters

array $variables The token values

Return Value

bool true if all tokens with type T_IDENT or T_FIELD have a value, false otherwise

at line 256
protected void setToken(Token $token, string $value)

Detects the type of the given value, converts it according to this type and sets the value of the given token with the result.

Parameters

Token $token &$token The given token
string $value The given value

Return Value

void

at line 284
protected void setDateToken(Token $token, string $value)

Converts the given value into a DateTime object and sets the value of the given token with the result.

Parameters

Token $token &$token The given token
string $value The given value

Return Value

void

Exceptions

Exception

at line 296
Token|false evaluate()

Evaluates this expression

Return Value

Token|false The result token of the evaluation