evaluator

package
v1.25.4 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package evaluator contains expression evaluator with the ability to provide named values into expressions. Evaluator supports all arithmetic operators, logical operators, arithmetic operators, and it is possible to use parenthesis to change priority of operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Evaluate

func Evaluate(expression string, values map[string]int) (int, error)

Evaluate function evaluates given algebraic expression and return its result

Types

type Operator

type Operator func(int, int) int

Operator type for all functions that implements any dyadic operator

type Stack

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

Stack struct is naive but fully functional implementation of operand stack

func (*Stack) Empty

func (stack *Stack) Empty() bool

Empty method checks if the stack is empty

func (*Stack) Pop

func (stack *Stack) Pop() (int, error)

Pop method pops value from stack with check if stack is empty

func (*Stack) Push

func (stack *Stack) Push(value int)

Push method pushes value onto the stack

func (*Stack) Size

func (stack *Stack) Size() int

Size method returns number of items on stack

type TokenWithValue

type TokenWithValue struct {
	Token      token.Token
	Value      int
	Identifier string
}

TokenWithValue structure represents token tied with its value (if any)

func IdentifierToken

func IdentifierToken(tok token.Token, identifier string) TokenWithValue

IdentifierToken is constructor for TokenWithValue structure

func OperatorToken

func OperatorToken(tok token.Token) TokenWithValue

OperatorToken is constructor for TokenWithValue structure

func ValueToken

func ValueToken(tok token.Token, value int) TokenWithValue

ValueToken is constructor for TokenWithValue structure

Jump to

Keyboard shortcuts

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