MathParser\Lexing\Token Class Reference

Token class. More...

Public Member Functions

 __construct ($value, $type, $match=null)
 Public constructor. More...
 
 length ()
 Length of the input string matching the token. More...
 
 getValue ()
 Standarized value/name of the Token, usually the same as what was matched in the the input string. More...
 
 getType ()
 Returns the type of the token, as defined in the TokenType class. More...
 
 __toString ()
 Helper function, converting the Token to a printable string. More...
 

Static Public Member Functions

static canFactorsInImplicitMultiplication ($token1, $token2)
 Helper function, determining whether a pair of tokens can form an implicit multiplication. More...
 

Private Attributes

 $value
 string $value (Standadized) value of token. More...
 
 $type
 int $type Token type as defined in TokenType class
 
 $match
 string $match The actual string matched in the input. More...
 

Detailed Description

Token class.

Class to handle tokens, i.e. discrete pieces of the input string that has specific meaning.

Constructor & Destructor Documentation

MathParser\Lexing\Token::__construct (   $value,
  $type,
  $match = null 
)

Public constructor.

Create a token with a given value and type, as well as an optional 'match' which is the actual character string matching the token definition. Most of the time, $value and $match are the same, but in order to handle token synonyms, they may be different.

As an example illustrating the above, the natural logarithm can be denoted ln() as well as log(). In order to standardize the token list, both inputs might generate a token with value 'log' and type TokenType::FunctionName, but the match parameter will be the actual string matched, i.e. 'log' and 'ln', respectively, so that the token knows its own length so that the rest of the input string will be handled correctly.

Parameters
string$valueStandardized value of Token
int$typeToken type, as defined by the TokenType class
string$matchOptional actual match in the input string

Member Function Documentation

MathParser\Lexing\Token::__toString ( )

Helper function, converting the Token to a printable string.

Return values
string
static MathParser\Lexing\Token::canFactorsInImplicitMultiplication (   $token1,
  $token2 
)
static

Helper function, determining whether a pair of tokens can form an implicit multiplication.

Mathematical shorthand writing often leaves out explicit multiplication symbols, writing "2x" instead of "2*x" or "2 \cdot x". The parser accepts implicit multiplication if the first token is a nullary operator or a a closing parenthesis, and the second token is a nullary operator or an opening parenthesis. (Unless the first token is a a function name, and the second is an opening parentheis.)

Return values
boolean
MathParser\Lexing\Token::getType ( )

Returns the type of the token, as defined in the TokenType class.

Return values
inttoken type (as defined by TokenType)
MathParser\Lexing\Token::getValue ( )

Standarized value/name of the Token, usually the same as what was matched in the the input string.

Return values
stringvalue of token
MathParser\Lexing\Token::length ( )

Length of the input string matching the token.

Return values
intlength of string matching the token.

Member Data Documentation

MathParser\Lexing\Token::$match
private

string $match The actual string matched in the input.

MathParser\Lexing\Token::$value
private

string $value (Standadized) value of token.


The documentation for this class was generated from the following file: