ExpressionCalculator

Implements an expression calculator.

Description

The ExpressionCalculator class allows you to create an expression calculator.

Constructors

NewExpressionCalculator

Constructs this class with default parameters.

NewExpressionCalculator() *ExpressionCalculator

ExpressionCalculatorFromExpression

Constructs this class and assigns expression string.

ExpressionCalculatorFromExpression(expression string) (*ExpressionCalculator, error)

  • expression: string - expression string.

ExpressionCalculatorFromExpression

Constructs this class and assigns token values.

ExpressionCalculatorFromTokens(originalTokens []*tokenizers.Token) *ExpressionCalculator

  • expression: string - expression string.
  • originalTokens: []*Token

Properties

AutoVariables

Gets the flag to turn on auto-creation of variables for a specified expression.

(c *ExpressionCalculator) AutoVariables() bool

  • returns: bool - returns the flag to turn on auto-creation.

DefaultFunctions

List with default functions.

(c *ExpressionCalculator) DefaultFunctions() IFunctionCollection

DefaultVariables

List with default variables.

(c *ExpressionCalculator) DefaultVariables() IVariableCollection

Expression

Expression string.

(c *ExpressionCalculator) Expression() string

  • returns: string - expression string.

InitialTokens

List of original expression tokens.

(c *ExpressionCalculator) InitialTokens() []*ExpressionToken

OriginalTokens

List of expression tokens.

(c *ExpressionCalculator) OriginalTokens() []*Token

  • returns: []*Token - list of expression tokens.

ResultTokens

List of processed expression tokens.

(c *ExpressionCalculator) ResultTokens() []*ExpressionToken

VariantOperations

Gets the manager for operations on variant values.

(c *ExpressionCalculator) VariantOperations() IVariantOperations

SetAutoVariables

Sets the flag to turn on auto-creation of variables for specified expression.

(c *ExpressionCalculator) SetAutoVariables(value bool)

  • value: bool - flag to turn on auto-creation.

SetExpression

Gets the expression string.

(c *ExpressionCalculator) SetExpression(value string) error

  • value: string - expression string.
  • returns: error - error or nil if no errors occured.

SetOriginalTokens

Sets list of expression tokens.

(c *ExpressionCalculator) SetOriginalTokens(value []*Token)

  • value: []*Token - list of expression tokens.

SetVariantOperations

Sets the manager for operations on variant values.

(c *ExpressionCalculator) SetVariantOperations(value IVariantOperations)

Methods

Clear

Cleans up this calculator from all data.

(c *ExpressionCalculator) Clear()

CreateVariables

Cleans up this calculator from all data.

(c *ExpressionCalculator) CreateVariables(vars IVariantOperations)

Evaluate

Evaluates this expression using default variables and functions.

(c *ExpressionCalculator) Evaluate() (*Variant, error)

  • returns: (*Variant, error) - evaluation result.

EvaluateUsingVariables

Evaluates this expression using specified variables.

(c *ExpressionCalculator) EvaluateUsingVariables(vars IVariantOperations) (*Variant, error)

evaluateWithVariablesAndFunctions

Evaluates this expression using specified variables and functions.

(c *ExpressionCalculator) EvaluateUsingVariablesAndFunctions(vars IVariantOperations, funcs IFunctionCollection) (*Variant, error)