postfixlib

package
v0.0.0-...-ec91354 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2019 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPossibleFunctionName

func IsPossibleFunctionName(tok string) bool

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

func NewConverter(Operators []Operator) Converter

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

func (c *Converter) IsFunction(tok string) bool

IsFunction returns if this is a function call or not

func (*Converter) IsOperand

func (c *Converter) IsOperand(tok string) bool

IsOperand returns if a given token is an operand

func (*Converter) IsOperator

func (c *Converter) IsOperator(tok string) (bool, Operator)

IsOperator checks if a given token is an operator, and if so, returns it

func (*Converter) ToPostfix

func (c *Converter) ToPostfix(nftokens []string) []string

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 Element

type Element struct {
	// contains filtered or unexported fields
}

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

func IsFunction(tok string) (bool, Operator)

IsFunction returns if this is a function call or not

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

func (*Stack) Empty

func (s *Stack) Empty() bool

func (*Stack) Pop

func (s *Stack) Pop() (value interface{})

func (*Stack) Push

func (s *Stack) Push(value interface{})

func (Stack) String

func (s Stack) String() string

func (*Stack) Top

func (s *Stack) Top() interface{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL