启动开源项目 JSON Expression Parser (文本表达式解析、求值器) 欢迎提出意见:)(300)

  • 主题发起人 creation-zy
  • 开始时间
C

creation-zy

Unregistered / Unconfirmed
GUEST, unregistred user!
表达式的解析和求值是一个应用面非常广的功能。现有的表达式分析器虽然各具特点,但基本上毫无例外的都使用自己独特的内存结构,不具有通用性。而JSON格式因其简明、易于操作,使用面日渐广泛。在此,我启动了一个开源项目,将表达式分析的结果存放在JSON对象中,可以非常方便的进行解读,同时,还具有相当的开放性。 开源项目在sourceforge.net上,源码文件URL为: http://jsonexpr.svn.sourceforge.net/viewvc/jsonexpr/ google上也有: http://code.google.com/p/jsonexpr/ :p功能 * ExprToJSON 文本表达式=>JSON对象树 * JSONToExpr JSON对象树=>文本表达式 * Eval JSON对象树求值 * EvalNumber JSON对象树求数值 * VarNeeded 提取表达式中用到的变量插件: * Var Helper * Func Helper支持: * Math operation: + - * / / % & | ^ ~ ! >> << SHR SHL * Bool operation: AND OR XOR * * Compare operation: = > < <> >= <= * Object operation: . IS * Value set: IN (a,b) * Condition expr: IF( condition, value1, value2) 下面是一些解析的范例: 2 + X * Sin(Y) => {op:"+",p1:2,p2:{op:"*",p1:"X",p2:{op:"SIN",p1:"Y"}}} Z*(X.Max+0.5) => {op:"*",p1:"Z",p2:{op:"+",p1:{op:".",p1:"X",p2:"Max"},p2:0.5}} A IS NOT NULL => {op:"IS",p1:"A",p2:{op:"NOT",p1:null}} Name1 in ( 'Mike' , '', 'Nike' , @@Name ) => {op:"IN",p1:"Name1",p2:{op:"(",p1:"'Mike",p2:"'",p3:"'Nike",p4:"@@Name"}} IF(X>=0,X,Y-X+Power(Z,3)) => {op:"IF",p1:{op:">=",p1:"X",p2:0},p2:"X",p3:{op:"+",p1:{op:"-",p1:"Y",p2:"X"},p2:{op:"POWER",p1:"Z",p2:3}}} 欢迎大家提出改进意见:)
 
D

dark_power

Unregistered / Unconfirmed
GUEST, unregistred user!
嗯,很好,很强大。支持下。加油啦!
 
C

creation-zy

Unregistered / Unconfirmed
GUEST, unregistred user!
Add Funtions: Set value (with operator ":=" ) Sentence end tag ";"Bug Fixed: Free const object in JSONObject.Put method 现在支持带有赋值语句的表达式计算: X:=X^X;
Y:=(12|9)^(15%6);
X:=(8+X)/5;
IF(Y IS not NULL, 3*0.5+Y, 5.875-(9<<2)*X) 整个表达式的值(最后一个语句的值): 14.5[:D]
 
C

creation-zy

Unregistered / Unconfirmed
GUEST, unregistred user!
Ver 0.2.2 支持集合运算: 并 交 异或 减 = > < >= <= 4 IN ( (2,3,4,6,8,5+5) & (8-2, 6>>1, 2<<1) ) => True
 
Y

yanghai0437

Unregistered / Unconfirmed
GUEST, unregistred user!
好东西,先看看
 
L

liugaohui

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢老版主了!!!
 
顶部