-1

在嵌套数组中转换带有嵌套括号的文本的最有效形式是什么?这是一个例子:

$input="((A = 8) AND((BC > 5 OR DE < 3) OR (FG = ALPHA))"

$output=array(
    [A>] => 8,
    [AND] =array(
             [BC>]=>5,
             [OR]=array([DE<]=>3)
              ),
    [OR]=>array([FG=]=>alpha)

)

或另一种可能的解决方案

$output=array(
    [A] =>array(['operator']=>'>',['value']=>8),
    [AND] =array(
             [BC>]=array(['operator']=>'>',['value']=>5),
             [OR]=array([DE]=>array(['operator']=>'<',['value']=>3))
              ),
    [OR]=>array([FG]=>array(['operator']=>'=',['value']=>3))

)
4

1 回答 1

1

我认为它可能看起来像这样(可以做出其他选择,但假设您想要评估该声明,我认为这很好用):

$operand = array("sum", array(
    "op1" => array("sum", array(
        "op1" => array("lit", "A")
        "op" => "AND"
        "op2" => array("lit", "8")
    )),
    "op" => "AND"
    "op2" => array("sum", array(
        "op1" => array("sum", /* .. */)
        "op" => "OR"
        "op2" => array("sum", /* .. */)
    ))
))

你的语法是:

sum: operand operation operand
operand: sum | lit
lit: string
operation: OR | AND | = | < | >
于 2013-10-23T09:53:25.420 回答