expression

package module
v0.0.0-...-17e5bb8 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: GPL-3.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LITERAL           uint8 = 1
	NAME              uint8 = 2
	FUNCTION_NAME     uint8 = 3
	ADD_OPERATOR      uint8 = 4
	SUB_OPERATOR      uint8 = 5
	TIMES_OPERATOR    uint8 = 6
	DIV_OPERATOR      uint8 = 7
	OPEN_PARENTHESIS  uint8 = 8
	CLOSE_PARENTHESIS uint8 = 9
	EMPTY             uint8 = 10
)

types of tokens used in expressions (terminal symbols)

View Source
const (
	TARGET          uint8 = 101
	EXPRESSION      uint8 = 102
	TERM            uint8 = 103
	EXPRESSION_LINE uint8 = 104
	FACTOR          uint8 = 105
	TERM_LINE       uint8 = 106
	PARAMETER_LIST  uint8 = 107
)

types of syntax elements used in expressions

View Source
const (
	UNKNOWN  uint8 = 0
	CONSTANT uint8 = 1
	VARIABLE uint8 = 2
	FUNCTION uint8 = 3
)

types of symbols

Variables

This section is empty.

Functions

func AddStandardMathFuncs

func AddStandardMathFuncs(s SymbolTable)

AddStandardMathFuncs add to symbol table all standard mathematical functions

Types

type Expression

type Expression interface {
	Evaluate(symbol SymbolTable) (float64, error)
}

func NewExpression

func NewExpression(expression string) (Expression, error)

New create a new parsed expression

type ParsedExpression

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

func (*ParsedExpression) Evaluate

func (p *ParsedExpression) Evaluate(symbol SymbolTable) (float64, error)

evaluatePolishReverse evaluate the Polish reverse expression (postfix) and return a numerical result

type Queue

type Queue interface {
	Put(value interface{})
	Get() interface{}
	IsEmpty() bool
	Copy() Queue
}

func NewQueue

func NewQueue() Queue

New create a new queue as array

type QueueAsArray

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

func (*QueueAsArray) Copy

func (q *QueueAsArray) Copy() Queue

Create a copy of queue as array

func (*QueueAsArray) Get

func (q *QueueAsArray) Get() interface{}

func (*QueueAsArray) IsEmpty

func (q *QueueAsArray) IsEmpty() bool

func (*QueueAsArray) Put

func (q *QueueAsArray) Put(value interface{})

type Stack

type Stack interface {
	Push(value interface{})
	Pop() interface{}
	IsEmpty() bool
}

func NewStack

func NewStack() Stack

New create a new stack as array

type StackAsArray

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

func (*StackAsArray) IsEmpty

func (s *StackAsArray) IsEmpty() bool

IsEmpty return true if the stack is empty

func (*StackAsArray) Pop

func (s *StackAsArray) Pop() interface{}

Pop return the item in the top of the stack after removing it

func (*StackAsArray) Push

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

Push pushes a new item to the top of the stack

type SymbolTable

type SymbolTable interface {
	Exists(name string) bool
	SetValue(name string, value float64)
	GetValue(name string) (float64, error)

	DefineFunc(name string, function func(parameter ...float64) float64, params int)
	InvokeFunc(name string, parameter ...float64) (float64, error)
}

func NewFloatSymbolTable

func NewFloatSymbolTable() SymbolTable

New create a new float64 onlye symbol table

Jump to

Keyboard shortcuts

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