KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > formula > Operator


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.biff.formula;
21
22 import java.util.Stack JavaDoc;
23 import java.util.ArrayList JavaDoc;
24
25 /**
26  * An operator is a node in a parse tree. Its children can be other
27  * operators or operands
28  * Arithmetic operators and functions are all considered operators
29  */

30 abstract class Operator extends ParseItem
31 {
32   /**
33    * The items which this operator manipulates. There will be at most two
34    */

35   private ParseItem[] operands;
36
37   /**
38    * Constructor
39    */

40   public Operator()
41   {
42     operands = new ParseItem[0];
43   }
44   
45   /**
46    * Tells the operands to use the alternate code
47    */

48   protected void setOperandAlternateCode()
49   {
50     for (int i = 0 ; i < operands.length ; i++)
51     {
52       operands[i].setAlternateCode();
53     }
54   }
55
56   /**
57    * Adds operands to this item
58    */

59   protected void add(ParseItem n)
60   {
61     n.setParent(this);
62
63     // Grow the array
64
ParseItem[] newOperands = new ParseItem[operands.length + 1];
65     System.arraycopy(operands, 0, newOperands, 0, operands.length);
66     newOperands[operands.length] = n;
67     operands = newOperands;
68   }
69
70   /**
71    * Gets the operands for this operator from the stack
72    */

73   public abstract void getOperands(Stack JavaDoc s);
74
75   /**
76    * Gets the operands ie. the children of the node
77    */

78   protected ParseItem[] getOperands()
79   {
80     return operands;
81   }
82
83   /**
84    * Gets the precedence for this operator. Operator precedents run from
85    * 1 to 5, one being the highest, 5 being the lowest
86    *
87    * @return the operator precedence
88    */

89   abstract int getPrecedence();
90
91 }
92
Popular Tags