Token class

From Sunhill Framework Documentation

The Token class represents a sinlge piece of information that is returned by the lexer and processed by the parser.

Public functions

__construct(string $symbol)

The construcor of a token. Every token has got a symbol (the kind of information that is processed by the parser). A symbol could be "+" or "integer".

getSymbol(): string

Getter for the symbol. Note: There is no setter, because the symbol is set in the constructor and there is no need to change it afterwards.

setValue(mixed value): static

Some symbols can take an additional value. For example a "integer" symbol can take the integer value that leads to this symbol. This is the setter for the value property.

getValue(): mixed

The getter for the value property.

setPosition(int $line, int $column): static

For error handling it is essential that the parser knows where in the input string this symbol was found. This method sets the line and the column.

getLine(): int

Getter for the line number.

getColumn(): int

Getter for the column number.

setAST($ast): static

The parser shifts symbols on the stack and tries to reduce them to other symbols until there is only one left. In this process some kind of information has to be stored so that the parse() method can return an abstract structure tree (ast). This method allowes the parser to pass such information to the symbol.

getAST()

getter for the AST.