summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-02-20 14:33:23 +0000
committerDries Buytaert <dries@buytaert.net>2010-02-20 14:33:23 +0000
commit557f3114ff8851b49883fd372fbddd41a1c7e2fe (patch)
tree5c4831293be7ba66db9f2b6f80c81beefd3c6a3e
parentf37242fad3f7d89616786a8d74e5ceaffcad0fa3 (diff)
downloadbrdo-557f3114ff8851b49883fd372fbddd41a1c7e2fe.tar.gz
brdo-557f3114ff8851b49883fd372fbddd41a1c7e2fe.tar.bz2
- Patch #539428 by MarcDeLay: renamed old non-descriptive variables.
-rw-r--r--includes/locale.inc80
1 files changed, 41 insertions, 39 deletions
diff --git a/includes/locale.inc b/includes/locale.inc
index a5e651aa7..d1343dcbc 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -927,48 +927,50 @@ function _locale_import_parse_plural_forms($pluralforms, $filepath) {
*/
function _locale_import_parse_arithmetic($string) {
// Operator precedence table
- $prec = array("(" => -1, ")" => -1, "?" => 1, ":" => 1, "||" => 3, "&&" => 4, "==" => 5, "!=" => 5, "<" => 6, ">" => 6, "<=" => 6, ">=" => 6, "+" => 7, "-" => 7, "*" => 8, "/" => 8, "%" => 8);
+ $precedence = array("(" => -1, ")" => -1, "?" => 1, ":" => 1, "||" => 3, "&&" => 4, "==" => 5, "!=" => 5, "<" => 6, ">" => 6, "<=" => 6, ">=" => 6, "+" => 7, "-" => 7, "*" => 8, "/" => 8, "%" => 8);
// Right associativity
- $rasc = array("?" => 1, ":" => 1);
+ $right_associativity = array("?" => 1, ":" => 1);
$tokens = _locale_import_tokenize_formula($string);
// Parse by converting into infix notation then back into postfix
- $opstk = array();
- $elstk = array();
+ // Operator stack - holds math operators and symbols
+ $operator_stack = array();
+ // Element Stack - holds data to be operated on
+ $element_stack = array();
foreach ($tokens as $token) {
- $ctok = $token;
+ $current_token = $token;
- // Numbers and the $n variable are simply pushed into $elarr
+ // Numbers and the $n variable are simply pushed into $element_stack
if (is_numeric($token)) {
- $elstk[] = $ctok;
+ $element_stack[] = $current_token;
}
- elseif ($ctok == "n") {
- $elstk[] = '$n';
+ elseif ($current_token == "n") {
+ $element_stack[] = '$n';
}
- elseif ($ctok == "(") {
- $opstk[] = $ctok;
+ elseif ($current_token == "(") {
+ $operator_stack[] = $current_token;
}
- elseif ($ctok == ")") {
- $topop = array_pop($opstk);
+ elseif ($current_token == ")") {
+ $topop = array_pop($operator_stack);
while (isset($topop) && ($topop != "(")) {
- $elstk[] = $topop;
- $topop = array_pop($opstk);
+ $element_stack[] = $topop;
+ $topop = array_pop($operator_stack);
}
}
- elseif (!empty($prec[$ctok])) {
- // If it's an operator, then pop from $oparr into $elarr until the
- // precedence in $oparr is less than current, then push into $oparr
- $topop = array_pop($opstk);
- while (isset($topop) && ($prec[$topop] >= $prec[$ctok]) && !(($prec[$topop] == $prec[$ctok]) && !empty($rasc[$topop]) && !empty($rasc[$ctok]))) {
- $elstk[] = $topop;
- $topop = array_pop($opstk);
+ elseif (!empty($precedence[$current_token])) {
+ // If it's an operator, then pop from $operator_stack into $element_stack until the
+ // precedence in $operator_stack is less than current, then push into $operator_stack
+ $topop = array_pop($operator_stack);
+ while (isset($topop) && ($precedence[$topop] >= $precedence[$current_token]) && !(($precedence[$topop] == $precedence[$current_token]) && !empty($right_associativity[$topop]) && !empty($right_associativity[$current_token]))) {
+ $element_stack[] = $topop;
+ $topop = array_pop($operator_stack);
}
if ($topop) {
- $opstk[] = $topop; // Return element to top
+ $operator_stack[] = $topop; // Return element to top
}
- $opstk[] = $ctok; // Parentheses are not needed
+ $operator_stack[] = $current_token; // Parentheses are not needed
}
else {
return FALSE;
@@ -976,38 +978,38 @@ function _locale_import_parse_arithmetic($string) {
}
// Flush operator stack
- $topop = array_pop($opstk);
+ $topop = array_pop($operator_stack);
while ($topop != NULL) {
- $elstk[] = $topop;
- $topop = array_pop($opstk);
+ $element_stack[] = $topop;
+ $topop = array_pop($operator_stack);
}
// Now extract formula from stack
- $prevsize = count($elstk) + 1;
- while (count($elstk) < $prevsize) {
- $prevsize = count($elstk);
- for ($i = 2; $i < count($elstk); $i++) {
- $op = $elstk[$i];
- if (!empty($prec[$op])) {
+ $previous_size = count($element_stack) + 1;
+ while (count($element_stack) < $previous_size) {
+ $previous_size = count($element_stack);
+ for ($i = 2; $i < count($element_stack); $i++) {
+ $op = $element_stack[$i];
+ if (!empty($precedence[$op])) {
$f = "";
if ($op == ":") {
- $f = $elstk[$i - 2] . "):" . $elstk[$i - 1] . ")";
+ $f = $element_stack[$i - 2] . "):" . $element_stack[$i - 1] . ")";
}
elseif ($op == "?") {
- $f = "(" . $elstk[$i - 2] . "?(" . $elstk[$i - 1];
+ $f = "(" . $element_stack[$i - 2] . "?(" . $element_stack[$i - 1];
}
else {
- $f = "(" . $elstk[$i - 2] . $op . $elstk[$i - 1] . ")";
+ $f = "(" . $element_stack[$i - 2] . $op . $element_stack[$i - 1] . ")";
}
- array_splice($elstk, $i - 2, 3, $f);
+ array_splice($element_stack, $i - 2, 3, $f);
break;
}
}
}
// If only one element is left, the number of operators is appropriate
- if (count($elstk) == 1) {
- return $elstk[0];
+ if (count($element_stack) == 1) {
+ return $element_stack[0];
}
else {
return FALSE;