Documentation ¶
Overview ¶
math-engine
--------
数学表达式解析计算引擎库
使用 Go 实现的数学表达式解析计算引擎库,它小巧,无任何依赖,具有扩展性(比如可以注册自己的函数到引擎中),比较完整的完成了数学表达式解析执行,包括词法分析、语法分析、构建AST、运行。
`go get -u github.com/dengsgo/math-engine`
能够处理的表达式样例: - `1+127-21+(3-4)*6/2.5` - `(88+(1+8)*6)/2+99` - `123_345_456 * 1.5 - 2 ^ 4` - `-4 * 6 + 2e2 - 1.6e-3` - `sin(pi/2)+cos(45-45*1)+tan(pi/4)` - `99+abs(-1)-ceil(88.8)+floor(88.8)` - `max(min(2^3, 3^2), 10*1.5-7)` - `double(6) + 3` , `double`是一个自定义的函数
Index ¶
- Constants
- Variables
- func ErrPos(s string, pos int) string
- func ExprASTResult(expr ExprAST) float64
- func Float64ToStr(f float64) string
- func ParseAndExec(s string) (r float64, err error)
- func Pow(x float64, n float64) float64
- func RegFunction(name string, argc int, fun func(...ExprAST) float64) error
- type AST
- type BinaryExprAST
- type ExprAST
- type FunCallerExprAST
- type NumberExprAST
- type Parser
- type Token
Constants ¶
const ( RadianMode = iota AngleMode )
const ( Identifier = iota // e.g. 50 Literal // e.g. + - * / Operator // , COMMA )
Variables ¶
var TrigonometricMode = RadianMode
enum "RadianMode", "AngleMode"
Functions ¶
func ExprASTResult ¶
ExprASTResult is a Top level function AST traversal if an arithmetic runtime error occurs, a panic exception is thrown
func ParseAndExec ¶
Top level function Analytical expression and execution err is not nil if an error occurs (including arithmetic runtime errors)
func RegFunction ¶
RegFunction is Top level function register a new function to use in expressions name: be register function name. the same function name only needs to be registered once. argc: this is a number of parameter signatures. should be -1, 0, or a positive integer
-1 variable-length argument; >=0 fixed numbers argument
fun: function handler