source: sourcecode/application/libraries/PHPExcel/Calculation/Token/Stack.php @ 1

Last change on this file since 1 was 1, checked in by dungnv, 11 years ago
File size: 2.8 KB
Line 
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     1.8.0, 2014-03-02
26 */
27
28
29/**
30 * PHPExcel_Calculation_Token_Stack
31 *
32 * @category    PHPExcel_Calculation_Token_Stack
33 * @package             PHPExcel_Calculation
34 * @copyright   Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36class PHPExcel_Calculation_Token_Stack {
37
38        /**
39         *  The parser stack for formulae
40         *
41         *  @var mixed[]
42         */
43        private $_stack = array();
44
45        /**
46         *  Count of entries in the parser stack
47         *
48         *  @var integer
49         */
50        private $_count = 0;
51
52
53        /**
54         * Return the number of entries on the stack
55         *
56         * @return  integer
57         */
58        public function count() {
59                return $this->_count;
60        }       //      function count()
61
62        /**
63         * Push a new entry onto the stack
64         *
65         * @param  mixed  $type
66         * @param  mixed  $value
67         * @param  mixed  $reference
68         */
69        public function push($type, $value, $reference = NULL) {
70                $this->_stack[$this->_count++] = array('type'           => $type,
71                                                                                           'value'              => $value,
72                                                                                           'reference'  => $reference
73                                                                                          );
74                if ($type == 'Function') {
75                        $localeFunction = PHPExcel_Calculation::_localeFunc($value);
76                        if ($localeFunction != $value) {
77                                $this->_stack[($this->_count - 1)]['localeValue'] = $localeFunction;
78                        }
79                }
80        }       //      function push()
81
82        /**
83         * Pop the last entry from the stack
84         *
85         * @return  mixed
86         */
87        public function pop() {
88                if ($this->_count > 0) {
89                        return $this->_stack[--$this->_count];
90                }
91                return NULL;
92        }       //      function pop()
93
94        /**
95         * Return an entry from the stack without removing it
96         *
97         * @param   integer  $n  number indicating how far back in the stack we want to look
98         * @return  mixed
99         */
100        public function last($n = 1) {
101                if ($this->_count - $n < 0) {
102                        return NULL;
103                }
104                return $this->_stack[$this->_count - $n];
105        }       //      function last()
106
107        /**
108         * Clear the stack
109         */
110        function clear() {
111                $this->_stack = array();
112                $this->_count = 0;
113        }
114
115}       //      class PHPExcel_Calculation_Token_Stack
Note: See TracBrowser for help on using the repository browser.