eval

package
v0.0.0-...-0c35626 Latest Latest
Warning

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

Go to latest
Published: May 1, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package eval zapewnia ewaluator wyrażeń.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(e Expr) string

Format formatuje wyrażenie jako łańcuch znaków. Nie próbuje usuwać niepotrzebnych nawiasów.

Types

type Env

type Env map[Var]float64

type Expr

type Expr interface {
	// Eval zwraca wartość tego wyrażenia Expr w środowisku env.
	Eval(env Env) float64
	// Check zgłasza błędy w tym wyrażeniu Expr i dodaje do zbioru swoje wartości Var.
	Check(vars map[Var]bool) error
}

Expr jest wyrażeniem arytmetycznym.

func Parse

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

Parse parsuje wejściowy łańcuch znaków jako wyrażenie arytmetyczne.

expr = num                         literał liczbowy, np., 3.14159
     | id                          nazwa zmiennej, np., x
     | id '(' expr ',' ... ')'     wywołanie funkcji
     | '-' expr                    operator jednoargumentowy (+-)
     | expr '+' expr               operator binarny (+-*/)

type Var

type Var string

Var identyfikuje zmienną, np. x.

func (Var) Check

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

func (Var) Eval

func (v Var) Eval(env Env) float64

Jump to

Keyboard shortcuts

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