GithubHelp home page GithubHelp logo

soniah / evaler Goto Github PK

View Code? Open in Web Editor NEW
52.0 52.0 17.0 100 KB

Implements a simple floating point arithmetic expression evaluator in Go (golang).

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%
go golang

evaler's People

Contributors

hiroxy avatar lexszero avatar soniah avatar thecardinelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

evaler's Issues

fails w/o initial zeros

.5 * 2 comes out as 10
fix is
var fp_rx = regexp.MustCompile(([0-9]*\.?[0-9]+))
I believe.
(and add a test like):
{".5 * 2", big.NewRat(1, 1), true}, // no leading zero

tried to submit, but I clearly dont know how to use github yet...so submitting as issue.
-s

radix?

numbers that lead with '0' is radix 8 and '0x' is 16.

allow variable names to contain numbers

Unfortunately it gives an error if I try to pass a variable name which has a number in it;
For example, a map with
{"catX":"33"}
evaluates fine; but if I pass:
{"cat1":"33"}
it says that there is no such variable "cat", ignoring the number in the name

if there is no way to solve this, maybe indicate that in the "readme" file

pass two or more variables to expression,it doesn't work

for k := range symbolTable {
s += k
}
symbols_rx = regexp.MustCompile(fmt.Sprintf("(%s)", s))
func Tokenis (expr string) []string {
if symbols_rx != nil {
spaced = symbols_rx.ReplaceAllString(spaced, " ${1} ")//it doesn't work
}
}

Add support for variables

The Eval function should also accept a hashmap of string -> float64 for passing variables and their values in. This should use a symboltable under the covers.

I will likely work on this feature.

goroutine-safe?

It seems this lib is not goroutine-safe for there is a variable symbolTable in package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.