101 if (is_null($pFormula)) {
102 throw new Exception(
"Invalid parameter passed: formula");
106 $this->_formula = trim($pFormula);
128 if (isset($this->_tokens[$pId])) {
129 return $this->_tokens[$pId];
131 throw new Exception(
"Token with id $pId does not exist.");
141 return count($this->_tokens);
161 $formulaLength = strlen($this->_formula);
162 if ($formulaLength < 2 || $this->_formula{0} !=
'=')
return;
165 $tokens1 = $tokens2 = $stack = array();
166 $inString = $inPath = $inRange = $inError =
false;
167 $token = $previousToken = $nextToken = null;
172 $ERRORS = array(
"#NULL!",
"#DIV/0!",
"#VALUE!",
"#REF!",
"#NAME?",
"#NUM!",
"#N/A");
173 $COMPARATORS_MULTI = array(
">=",
"<=",
"<>");
175 while ($index < $formulaLength) {
192 $value .= $this->_formula{$index};
210 $value .= $this->_formula{$index};
223 $value .= $this->_formula{$index};
231 $value .= $this->_formula{$index};
233 if (in_array($value, $ERRORS)) {
243 if (strlen($value) > 1) {
244 if (preg_match(
"/^[1-9]{1}(\.[0-9]+)?E{1}$/", $this->_formula{$index}) != 0) {
245 $value .= $this->_formula{$index};
256 if (strlen($value > 0)) {
266 if (strlen($value) > 0) {
283 if (strlen($value) > 0) {
295 if (strlen($value) > 0) {
302 $stack[] = clone $tmp;
306 $stack[] = clone $tmp;
313 if (strlen($value) > 0) {
318 $tmp = array_pop($stack);
328 $stack[] = clone $tmp;
335 if (strlen($value) > 0) {
340 $tmp = array_pop($stack);
345 $tmp = array_pop($stack);
356 if (strlen($value) > 0) {
369 if (($index + 2) <= $formulaLength) {
370 if (in_array(substr($this->_formula, $index, 2), $COMPARATORS_MULTI)) {
371 if (strlen($value) > 0) {
383 if (strlen($value) > 0) {
394 if (strlen($value) > 0) {
405 if (strlen($value) > 0) {
408 $stack[] = clone $tmp;
413 $stack[] = clone $tmp;
421 if (strlen($value) > 0) {
426 $tmp = array_pop($stack);
442 if (strlen($value) > 0) {
447 $tmp = array_pop($stack);
457 $value .= $this->_formula{$index};
462 if (strlen($value) > 0) {
467 $tokenCount = count($tokens1);
468 for ($i = 0; $i < $tokenCount; ++$i) {
469 $token = $tokens1[$i];
470 if (isset($tokens1[$i - 1])) {
471 $previousToken = $tokens1[$i - 1];
473 $previousToken = null;
475 if (isset($tokens1[$i + 1])) {
476 $nextToken = $tokens1[$i + 1];
481 if (is_null($token)) {
490 if (is_null($previousToken)) {
502 if (is_null($nextToken)) {
519 $this->_tokens = array();
521 $tokenCount = count($tokens2);
522 for ($i = 0; $i < $tokenCount; ++$i) {
523 $token = $tokens2[$i];
524 if (isset($tokens2[$i - 1])) {
525 $previousToken = $tokens2[$i - 1];
527 $previousToken = null;
529 if (isset($tokens2[$i + 1])) {
530 $nextToken = $tokens2[$i + 1];
535 if (is_null($token)) {
553 $this->_tokens[] = $token;
571 $this->_tokens[] = $token;
576 if (strpos(
"<>=", substr($token->getValue(), 0, 1)) !==
false) {
578 }
else if ($token->getValue() ==
"&") {
584 $this->_tokens[] = $token;
589 if (!is_numeric($token->getValue())) {
590 if (strtoupper($token->getValue()) ==
"TRUE" || strtoupper($token->getValue() ==
"FALSE")) {
599 $this->_tokens[] = $token;
604 if (strlen($token->getValue() > 0)) {
605 if (substr($token->getValue(), 0, 1) ==
"@") {
606 $token->setValue(substr($token->getValue(), 1));
611 $this->_tokens[] = $token;