Documentation ¶
Overview ¶
math-engine
--------
数学表达式计算引擎
使用 Go 实现的数学表达式解析计算引擎,无任何依赖,相对比较完整的完成了数学表达式解析执行,包括词法分析、语法分析、构建AST、运行。
能够处理的表达式样例:
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)
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 int) 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 ¶
View Source
const ( RadianMode = iota AngleMode )
View Source
const ( Identifier = iota // e.g. 50 Literal // e.g. + - * / Operator // , COMMA )
Variables ¶
View Source
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)
Types ¶
type AST ¶
func (*AST) ParseExpression ¶
type BinaryExprAST ¶
type FunCallerExprAST ¶
type NumberExprAST ¶
Click to show internal directories.
Click to hide internal directories.