Hi all,
I'm trying to develop an expression that can determine if a statement is in a valid syntax. The statement is contained within nested parens, and I need to see if the expressions not only is balanced (solved that), but valid.
The following is my expression to see if the statement is balanced, but it lacks seeing if it is valid.
/^(\((?:[^()]+|(?1))*\))$/
Statements can be of the following 2 examples:
(1 = 1)
or
(1 => (3 = 3) || ((3 < (3 = 4)) && ((1 < 3) = 2)))
or any breakdown there in where it follows the pattern of
([number | nested boolean expression] [= | => | <= | < | > | && | ||] [number | nested boolean BLOCKED EXPRESSION
So far I've come up with the following, but they are not working right.
15 define('RULE_OPERATOR', '=|==|>|>=|<|<=|!=');
16 //define('RULE_VALID', '/^(\((?:[^(?:'.RULE_OPERATOR.')]*(?:'.RULE_OPERATOR.')[^(?:'.RULE_OPERATOR.')]*\))|(?1))*$/');
17 //define('RULE_VALID', '/^(\((?:[^\((?:'.RULE_OPERATOR.')]*\s[(?:'.RULE_OPERATOR.')]\s[^)(?:'.RULE_OPERATOR.')]*|(?1))\))$/');
I'm writing in PHP, so it's a PCRE based expression engine.
Thanks for any advice or help.
--
Dave