Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Xorcerer/zexpression

A library to parse and evalate math expression with functions and variables.
https://github.com/Xorcerer/zexpression

Last synced: about 2 months ago
JSON representation

A library to parse and evalate math expression with functions and variables.

Awesome Lists containing this project

README

        

# zExpression

A library to parse and evalate math expression with functions and
variables.

### Example:

ActionScript 3:
```actionscript
var c:Number = 1

var expSet:ExpressionSet = new ExpressionSet

// Step 1: Parse expression strings.
expSet.putExp('b', '1 + c + 100 * min(a, 100) / 2')
expSet.putExp('a', 'min(1, 10)')

// Step 2: Set variables and functions
expSet.setVariable('c', c)
expSet.setFunction('min', Math.min) // min() is built-in actually, example only.

// Step 3: Get the result. Step 2, 3 could be done repeatly.
trace('b = ', expSet.getValue('b'))
```

Optional i18n variables support, by replacing the letterValidator, you
can make it support any language:

```actionscript
var expSet:ExpressionSet = new ExpressionSet

// Set a custom letter validator
expSet.letterValidator = CnUtils.isLetterOrCnChar

expSet.putExp('面包', '面粉 * 水')
expSet.putExp('家庭', '爱情 + 面包')
expSet.setVariable('爱情', 99)
expSet.setVariable('面粉', 1)
expSet.setVariable('水', 1)

trace('家庭 = ', expSet.getValue('家庭'))
```

### Supported languages:
* ActionScript 3

### TODO:
* C# support.
* C++ support.
* More test cases.