https://github.com/Xorcerer/zexpression
A library to parse and evalate math expression with functions and variables.
https://github.com/Xorcerer/zexpression
Last synced: 6 months ago
JSON representation
A library to parse and evalate math expression with functions and variables.
- Host: GitHub
- URL: https://github.com/Xorcerer/zexpression
- Owner: Xorcerer
- Created: 2012-11-19T12:38:59.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2014-03-04T08:18:11.000Z (over 11 years ago)
- Last Synced: 2024-08-04T05:04:24.309Z (about 1 year ago)
- Language: ActionScript
- Homepage:
- Size: 226 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-actionscript-sorted - zexpression - A library to parse and evalate math expression with functions and variables. (Utilities / Math)
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.