Documentation ¶
Index ¶
- func CompareToken(t1, t2 *Token) bool
- func CompareTokenString(t1, t2 []Token) bool
- func IsBracket(s string) bool
- func IsComparisonOp(s string) bool
- func IsLeftBracket(s string) bool
- func IsOperator(s string) bool
- func IsRightBracket(s string) bool
- func OperatorPriority(op Token) uint8
- func StringifyTokenString(tokens []Token, v bool) string
- func StringifyTokenType(t TokenType) string
- func TokenTypeOneOf(token *Token, types ...TokenType) bool
- type Token
- type TokenStack
- type TokenType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareToken ¶
Compare two tokens and return true if they are equal or false if not
@param t1 *Token @param t2 *Token
@return bool True if tokens are equal, false if not equal or any of it is nil
func CompareTokenString ¶
Compare two token strings and return false if they don't match
@param t1 []Token @param t2 []Token
@return bool
func IsComparisonOp ¶
func IsLeftBracket ¶
func IsOperator ¶
func IsRightBracket ¶
func OperatorPriority ¶
Returns priority of operator based on its type
@param op Token Operator token
@return uint8 Priority
func StringifyTokenString ¶
Print array of tokens (eg. variable content)
@param []Token Slice of tokens @param bool Verbose mode - prints token type along with its content
func StringifyTokenType ¶
Convert token type to human readable string to print it out
func TokenTypeOneOf ¶
Types ¶
type Token ¶
type Token struct { Type TokenType Hidden bool // token and its ancestors should be hidden from user (added for calculation purposes, eg. * (multiplication) before polynomial) Value interface{} // string representation of value }
general token
func PostfixToValue ¶
Calculate value of postfix token string, we got only operands and operators, no brackets
@param postfix []Token Array of tokens in postfix notation
@return Token Resulting token
@return error Error if any
func TokenStringToPostfix ¶
Convert token string from infix to postfix notation for easier calculation
@param in []Token Array of tokens in infix notation
@return []Token Array of tokens in postfix notation
@return error Error if any
type TokenStack ¶
type TokenStack struct {
// contains filtered or unexported fields
}
Token stack
func (*TokenStack) Peek ¶
func (s *TokenStack) Peek() Token
Look at the top token on the stack
@return Token
type TokenType ¶
type TokenType uint8
const ( TokenTypeVariable TokenType = iota + 10 // start at 10, because 0-3 are already reserved for variable types and may expand in time TokenTypeFunction TokenTypeOperator TokenTypeBracket TokenTypeInt // simple number TokenTypeFloat TokenTypeEqualSign TokenTypeUnknownIdent // unknown identifier TokenTypeUnknown )