Documentation ¶
Index ¶
- func IsPossibleFunctionName(tok string) bool
- type Association
- type Converter
- func (c *Converter) ConvertMinusToNegationTokenInInfixExpr(minusOpToken string, negationOpToken string, infix []string) []string
- func (c *Converter) IsFunction(tok string) bool
- func (c *Converter) IsOperand(tok string) bool
- func (c *Converter) IsOperator(tok string) (bool, Operator)
- func (c *Converter) ToPostfix(nftokens []string) []string
- type Element
- type Operator
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPossibleFunctionName ¶
IsPossibleFunctionName returns if a given string _could_ be a function i.e. if it begins with a zero, it cannot be a function
Types ¶
type Association ¶
type Association int
Association is an enum for identifying if operators are left, right, or not associative
const ( AssociationLeft Association = -1 AssociationRight Association = 1 AssociationNone Association = 0 )
AssociativeXXXX define the possible Association types
type Converter ¶
type Converter struct {
Operators []Operator
}
A Converter is used to convert between infix and postfix
func NewConverter ¶
NewConverter creates a converter for a list of operators
func (*Converter) ConvertMinusToNegationTokenInInfixExpr ¶
func (c *Converter) ConvertMinusToNegationTokenInInfixExpr(minusOpToken string, negationOpToken string, infix []string) []string
ConvertMinusToNegationTokenInInfixExpr scans through an Infix Expression and converts minuses that should be negatives to negatives (i.e. "2 + -3" becomes "2 + [minus]3")
func (*Converter) IsFunction ¶
IsFunction returns if this is a function call or not
func (*Converter) IsOperator ¶
IsOperator checks if a given token is an operator, and if so, returns it
func (*Converter) ToPostfix ¶
ToPostfix converts a string slice of tokens in infix format to postfix this is an implementation of the Shunting-Yard algorithm https://en.wikipedia.org/wiki/Shunting-yard_algorithm
It has been extended to support arbitrary function calls. These are treated as right-aligned operators (i.e. function(2, 3) becomes "2 3 function<2>")
type Operator ¶
type Operator interface { GetToken() string GetPrecedence() int GetNumOperands() int LeftAssociative() bool GetAssociation() Association }
Operator defines an operation (like AND or ADD or *)
which has a precedence and also a number of operands
func IsFunction ¶
IsFunction returns if this is a function call or not