项目作者: pk-rawat

项目描述 :
Mathematical and logical expression evaluator in Golang
高级语言: Go
项目地址: git://github.com/pk-rawat/gostr.git
创建时间: 2015-10-11T05:38:24Z
项目社区:https://github.com/pk-rawat/gostr

开源协议:MIT License

下载


Build Status
wercker status

gostr

DESCRIPTION

Gostr is a evaluator for a mathematical and logical expressions that allows run-time binding of values to variables referenced in the formulas.

EXAMPLE

This is probably simplest to illustrate in code:

  1. values := make(map[string]interface{})
  2. values["a"] = 5
  3. result := gostr.Evaluate("a * 2", values)
  4. fmt.Println("Result:", result)
  5. #=> Result: 10
  6. result := gostr.Evaluate("a + 3 * 2", values)
  7. fmt.Println("Result:", result)
  8. #=> Result: 11
  9. result := gostr.Evaluate("(a + 3) * 2", values)
  10. fmt.Println("Result:", result)
  11. #=> Result: 16

I have added some simple examples. Run example.go to check those.

BUILT-IN OPERATORS AND FUNCTIONS

Math: + - * /

Logic: < > <= >= <> != = AND OR

Functions: ISBLANK LENGTH NOT ROUND