Stack.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. class PHPExcel_Calculation_Token_Stack
  8. {
  9. /**
  10. * The parser stack for formulae
  11. *
  12. * @var mixed[]
  13. */
  14. private $stack = array();
  15. /**
  16. * Count of entries in the parser stack
  17. *
  18. * @var integer
  19. */
  20. private $count = 0;
  21. /**
  22. * Return the number of entries on the stack
  23. *
  24. * @return integer
  25. */
  26. public function count()
  27. {
  28. return $this->count;
  29. }
  30. /**
  31. * Push a new entry onto the stack
  32. *
  33. * @param mixed $type
  34. * @param mixed $value
  35. * @param mixed $reference
  36. */
  37. public function push($type, $value, $reference = null)
  38. {
  39. $this->stack[$this->count++] = array(
  40. 'type' => $type,
  41. 'value' => $value,
  42. 'reference' => $reference
  43. );
  44. if ($type == 'Function') {
  45. $localeFunction = PHPExcel_Calculation::localeFunc($value);
  46. if ($localeFunction != $value) {
  47. $this->stack[($this->count - 1)]['localeValue'] = $localeFunction;
  48. }
  49. }
  50. }
  51. /**
  52. * Pop the last entry from the stack
  53. *
  54. * @return mixed
  55. */
  56. public function pop()
  57. {
  58. if ($this->count > 0) {
  59. return $this->stack[--$this->count];
  60. }
  61. return null;
  62. }
  63. /**
  64. * Return an entry from the stack without removing it
  65. *
  66. * @param integer $n number indicating how far back in the stack we want to look
  67. * @return mixed
  68. */
  69. public function last($n = 1)
  70. {
  71. if ($this->count - $n < 0) {
  72. return null;
  73. }
  74. return $this->stack[$this->count - $n];
  75. }
  76. /**
  77. * Clear the stack
  78. */
  79. public function clear()
  80. {
  81. $this->stack = array();
  82. $this->count = 0;
  83. }
  84. }