class Evaluator

This class allows the evaluation of postfixed expressions (RPN notation)

Methods

void
__construct()

Constructor of class Evaluator

Token|false
run(array $tokens)

Performs the evaluation of a postfixed expression

operation(Token $op, array $args)

Realizes an unary, binary or ternary operation and returns the result token.

comparison(Token $op, array $args)

Compares two arguments with a comparison operator and returns the result token.

bool
compatible(Token $arg1, Token $arg2)

Determines whether two arguments have compatible types.

void
guessType(Token $token)

Guess the type of a token value

func(Token $func, array $args)

Evaluates a function and returns the result token.

Details

at line 45
void __construct()

Constructor of class Evaluator

Return Value

void

at line 57
Token|false run(array $tokens)

Performs the evaluation of a postfixed expression

Parameters

array $tokens &$tokens The postfixed expression

Return Value

Token|false The result token of the evaluation

Exceptions

Exception

at line 103
private Token operation(Token $op, array $args)

Realizes an unary, binary or ternary operation and returns the result token.

Parameters

Token $op The operator token
array $args &$args The arguments of the operation

Return Value

Token The result token of the operation

Exceptions

Exception

at line 195
private Token comparison(Token $op, array $args)

Compares two arguments with a comparison operator and returns the result token.

Parameters

Token $op The comparison operator token
array $args &$args The arguments of the comparison

Return Value

Token The result token of the comparison

Exceptions

Exception

at line 248
private bool compatible(Token $arg1, Token $arg2)

Determines whether two arguments have compatible types.

Parameters

Token $arg1 The first argument
Token $arg2 The second argument

Return Value

bool true if the two arguments have compatible types, false otherwise

at line 277
private void guessType(Token $token)

Guess the type of a token value

Parameters

Token $token &$token

Return Value

void

Exceptions

Exception

at line 302
private Token func(Token $func, array $args)

Evaluates a function and returns the result token.

Parameters

Token $func The function token
array $args &$args The arguments of the fuction

Return Value

Token The result token

Exceptions

Exception