eval

package
v0.0.0-...-c4986e2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package eval provides an expression evaluator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(e Expr) string

Format formats an expression as a string.

Types

type Env

type Env map[Var]float64

Env represents environment for executing expression.

type Expr

type Expr interface {
	// Eval returns the value of this Expr in the environment env.
	Eval(env Env) float64
	// Check reports errors in this Expr and adds its Vars to the set.
	Check(vars map[Var]bool) error
	// String returns string representation of expression.
	String() string
}

An Expr is an arithmetic expression.

func Parse

func Parse(input string) (_ Expr, err error)

Parse parses the input string as an arithmetic expression.

type Var

type Var string

A Var identifies a variable, e.g., x.

func (Var) Check

func (v Var) Check(vars map[Var]bool) error

Check verifies that variable meets requriments.

func (Var) Eval

func (v Var) Eval(env Env) float64

Eval transforms string representation of var to value.

func (Var) String

func (e Var) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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