aa7f41ad1abf040e07336658a7c9dac6bfe1560b.svn-base 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Calculation
  23. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /**
  28. * PHPExcel_Calculation_Token_Stack
  29. *
  30. * @category PHPExcel_Calculation_Token_Stack
  31. * @package PHPExcel_Calculation
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Calculation_Token_Stack {
  35. /**
  36. * The parser stack for formulae
  37. *
  38. * @var mixed[]
  39. */
  40. private $_stack = array();
  41. /**
  42. * Count of entries in the parser stack
  43. *
  44. * @var integer
  45. */
  46. private $_count = 0;
  47. /**
  48. * Return the number of entries on the stack
  49. *
  50. * @return integer
  51. */
  52. public function count() {
  53. return $this->_count;
  54. } // function count()
  55. /**
  56. * Push a new entry onto the stack
  57. *
  58. * @param mixed $type
  59. * @param mixed $value
  60. * @param mixed $reference
  61. */
  62. public function push($type, $value, $reference = NULL) {
  63. $this->_stack[$this->_count++] = array('type' => $type,
  64. 'value' => $value,
  65. 'reference' => $reference
  66. );
  67. if ($type == 'Function') {
  68. $localeFunction = PHPExcel_Calculation::_localeFunc($value);
  69. if ($localeFunction != $value) {
  70. $this->_stack[($this->_count - 1)]['localeValue'] = $localeFunction;
  71. }
  72. }
  73. } // function push()
  74. /**
  75. * Pop the last entry from the stack
  76. *
  77. * @return mixed
  78. */
  79. public function pop() {
  80. if ($this->_count > 0) {
  81. return $this->_stack[--$this->_count];
  82. }
  83. return NULL;
  84. } // function pop()
  85. /**
  86. * Return an entry from the stack without removing it
  87. *
  88. * @param integer $n number indicating how far back in the stack we want to look
  89. * @return mixed
  90. */
  91. public function last($n = 1) {
  92. if ($this->_count - $n < 0) {
  93. return NULL;
  94. }
  95. return $this->_stack[$this->_count - $n];
  96. } // function last()
  97. /**
  98. * Clear the stack
  99. */
  100. function clear() {
  101. $this->_stack = array();
  102. $this->_count = 0;
  103. }
  104. } // class PHPExcel_Calculation_Token_Stack