KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java_cup > simple_calc > parser


1
2 //----------------------------------------------------
3
// The following code was generated by CUP v0.10k
4
// Sun Jul 25 13:36:02 EDT 1999
5
//----------------------------------------------------
6

7 package java_cup.simple_calc;
8
9 import java_cup.runtime.*;
10
11 /** CUP v0.10k generated parser.
12   * @version Sun Jul 25 13:36:02 EDT 1999
13   */

14 public class parser extends java_cup.runtime.lr_parser {
15
16   /** Default constructor. */
17   public parser() {super();}
18
19   /** Constructor which sets the default scanner. */
20   public parser(java_cup.runtime.Scanner s) {super(s);}
21
22   /** Production table. */
23   protected static final short _production_table[][] =
24     unpackFromStrings(new String JavaDoc[] {
25     "\000\015\000\002\003\004\000\002\002\004\000\002\003" +
26     "\003\000\002\006\002\000\002\004\005\000\002\005\005" +
27     "\000\002\005\005\000\002\005\005\000\002\005\005\000" +
28     "\002\005\005\000\002\005\003\000\002\005\004\000\002" +
29     "\005\005" });
30
31   /** Access to production table. */
32   public short[][] production_table() {return _production_table;}
33
34   /** Parse-action table. */
35   protected static final short[][] _action_table =
36     unpackFromStrings(new String JavaDoc[] {
37     "\000\030\000\010\006\004\013\011\015\005\001\002\000" +
38     "\010\006\004\013\011\015\005\001\002\000\020\004\ufff7" +
39     "\005\ufff7\006\ufff7\007\ufff7\010\ufff7\011\ufff7\014\ufff7\001" +
40     "\002\000\012\002\uffff\006\uffff\013\uffff\015\uffff\001\002" +
41     "\000\016\004\ufffe\005\016\006\014\007\020\010\017\011" +
42     "\013\001\002\000\012\002\027\006\004\013\011\015\005" +
43     "\001\002\000\010\006\004\013\011\015\005\001\002\000" +
44     "\016\005\016\006\014\007\020\010\017\011\013\014\015" +
45     "\001\002\000\010\006\004\013\011\015\005\001\002\000" +
46     "\010\006\004\013\011\015\005\001\002\000\020\004\ufff5" +
47     "\005\ufff5\006\ufff5\007\ufff5\010\ufff5\011\ufff5\014\ufff5\001" +
48     "\002\000\010\006\004\013\011\015\005\001\002\000\010" +
49     "\006\004\013\011\015\005\001\002\000\010\006\004\013" +
50     "\011\015\005\001\002\000\020\004\ufffa\005\ufffa\006\ufffa" +
51     "\007\ufffa\010\ufffa\011\ufffa\014\ufffa\001\002\000\020\004" +
52     "\ufff9\005\ufff9\006\ufff9\007\ufff9\010\ufff9\011\ufff9\014\ufff9" +
53     "\001\002\000\020\004\ufffc\005\ufffc\006\ufffc\007\020\010" +
54     "\017\011\013\014\ufffc\001\002\000\020\004\ufffb\005\ufffb" +
55     "\006\ufffb\007\020\010\017\011\013\014\ufffb\001\002\000" +
56     "\020\004\ufff8\005\ufff8\006\ufff8\007\ufff8\010\ufff8\011\ufff8" +
57     "\014\ufff8\001\002\000\012\002\001\006\001\013\001\015" +
58     "\001\001\002\000\004\002\000\001\002\000\004\004\031" +
59     "\001\002\000\012\002\ufffd\006\ufffd\013\ufffd\015\ufffd\001" +
60     "\002\000\020\004\ufff6\005\ufff6\006\ufff6\007\ufff6\010\ufff6" +
61     "\011\ufff6\014\ufff6\001\002" });
62
63   /** Access to parse-action table. */
64   public short[][] action_table() {return _action_table;}
65
66   /** <code>reduce_goto</code> table. */
67   protected static final short[][] _reduce_table =
68     unpackFromStrings(new String JavaDoc[] {
69     "\000\030\000\010\003\007\004\005\005\006\001\001\000" +
70     "\004\005\031\001\001\000\002\001\001\000\002\001\001" +
71     "\000\004\006\027\001\001\000\006\004\025\005\006\001" +
72     "\001\000\004\005\011\001\001\000\002\001\001\000\004" +
73     "\005\024\001\001\000\004\005\023\001\001\000\002\001" +
74     "\001\000\004\005\022\001\001\000\004\005\021\001\001" +
75     "\000\004\005\020\001\001\000\002\001\001\000\002\001" +
76     "\001\000\002\001\001\000\002\001\001\000\002\001\001" +
77     "\000\002\001\001\000\002\001\001\000\002\001\001\000" +
78     "\002\001\001\000\002\001\001" });
79
80   /** Access to <code>reduce_goto</code> table. */
81   public short[][] reduce_table() {return _reduce_table;}
82
83   /** Instance of action encapsulation class. */
84   protected CUP$parser$actions action_obj;
85
86   /** Action encapsulation object initializer. */
87   protected void init_actions()
88     {
89       action_obj = new CUP$parser$actions(this);
90     }
91
92   /** Invoke a user supplied parse action. */
93   public java_cup.runtime.Symbol do_action(
94     int act_num,
95     java_cup.runtime.lr_parser parser,
96     java.util.Stack JavaDoc stack,
97     int top)
98     throws java.lang.Exception JavaDoc
99   {
100     /* call code in generated class */
101     return action_obj.CUP$parser$do_action(act_num, parser, stack, top);
102   }
103
104   /** Indicates start state. */
105   public int start_state() {return 0;}
106   /** Indicates start production. */
107   public int start_production() {return 1;}
108
109   /** <code>EOF</code> Symbol index. */
110   public int EOF_sym() {return 0;}
111
112   /** <code>error</code> Symbol index. */
113   public int error_sym() {return 1;}
114
115 }
116
117 /** Cup generated class to encapsulate user supplied action code.*/
118 class CUP$parser$actions {
119   private final parser parser;
120
121   /** Constructor */
122   CUP$parser$actions(parser parser) {
123     this.parser = parser;
124   }
125
126   /** Method with the actual generated action code. */
127   public final java_cup.runtime.Symbol CUP$parser$do_action(
128     int CUP$parser$act_num,
129     java_cup.runtime.lr_parser CUP$parser$parser,
130     java.util.Stack JavaDoc CUP$parser$stack,
131     int CUP$parser$top)
132     throws java.lang.Exception JavaDoc
133     {
134       /* Symbol object for return from actions */
135       java_cup.runtime.Symbol CUP$parser$result;
136
137       /* select the action based on the action number */
138       switch (CUP$parser$act_num)
139         {
140           /*. . . . . . . . . . . . . . . . . . . .*/
141           case 12: // expr ::= LPAREN expr RPAREN
142
{
143               Integer JavaDoc RESULT = null;
144         int eleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left;
145         int eright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right;
146         Integer JavaDoc e = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value;
147          RESULT = e;
148               CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
149             }
150           return CUP$parser$result;
151
152           /*. . . . . . . . . . . . . . . . . . . .*/
153           case 11: // expr ::= MINUS expr
154
{
155               Integer JavaDoc RESULT = null;
156         int eleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left;
157         int eright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right;
158         Integer JavaDoc e = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value;
159          RESULT = new Integer JavaDoc(0 - e.intValue());
160               CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
161             }
162           return CUP$parser$result;
163
164           /*. . . . . . . . . . . . . . . . . . . .*/
165           case 10: // expr ::= NUMBER
166
{
167               Integer JavaDoc RESULT = null;
168         int nleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left;
169         int nright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right;
170         Integer JavaDoc n = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value;
171          RESULT = n;
172               CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
173             }
174           return CUP$parser$result;
175
176           /*. . . . . . . . . . . . . . . . . . . .*/
177           case 9: // expr ::= expr MOD expr
178
{
179               Integer JavaDoc RESULT = null;
180         int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
181         int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
182         Integer JavaDoc e1 = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
183         int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left;
184         int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right;
185         Integer JavaDoc e2 = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value;
186          RESULT = new Integer JavaDoc(e1.intValue() % e2.intValue());
187               CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
188             }
189           return CUP$parser$result;
190
191           /*. . . . . . . . . . . . . . . . . . . .*/
192           case 8: // expr ::= expr DIVIDE expr
193
{
194               Integer JavaDoc RESULT = null;
195         int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
196         int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
197         Integer JavaDoc e1 = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
198         int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left;
199         int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right;
200         Integer JavaDoc e2 = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value;
201          RESULT = new Integer JavaDoc(e1.intValue() / e2.intValue());
202               CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
203             }
204           return CUP$parser$result;
205
206           /*. . . . . . . . . . . . . . . . . . . .*/
207           case 7: // expr ::= expr TIMES expr
208
{
209               Integer JavaDoc RESULT = null;
210         int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
211         int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
212         Integer JavaDoc e1 = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
213         int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left;
214         int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right;
215         Integer JavaDoc e2 = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value;
216          RESULT = new Integer JavaDoc(e1.intValue() * e2.intValue());
217               CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
218             }
219           return CUP$parser$result;
220
221           /*. . . . . . . . . . . . . . . . . . . .*/
222           case 6: // expr ::= expr MINUS expr
223
{
224               Integer JavaDoc RESULT = null;
225         int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
226         int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
227         Integer JavaDoc e1 = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
228         int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left;
229         int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right;
230         Integer JavaDoc e2 = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value;
231          RESULT = new Integer JavaDoc(e1.intValue() - e2.intValue());
232               CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
233             }
234           return CUP$parser$result;
235
236           /*. . . . . . . . . . . . . . . . . . . .*/
237           case 5: // expr ::= expr PLUS expr
238
{
239               Integer JavaDoc RESULT = null;
240         int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
241         int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
242         Integer JavaDoc e1 = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
243         int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left;
244         int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right;
245         Integer JavaDoc e2 = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value;
246          RESULT = new Integer JavaDoc(e1.intValue() + e2.intValue());
247               CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
248             }
249           return CUP$parser$result;
250
251           /*. . . . . . . . . . . . . . . . . . . .*/
252           case 4: // expr_part ::= expr NT$0 SEMI
253
{
254               Object JavaDoc RESULT = null;
255               // propagate RESULT from NT$0
256
if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value != null )
257                 RESULT = (Object JavaDoc) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value;
258         int eleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
259         int eright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
260         Integer JavaDoc e = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
261
262               CUP$parser$result = new java_cup.runtime.Symbol(2/*expr_part*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
263             }
264           return CUP$parser$result;
265
266           /*. . . . . . . . . . . . . . . . . . . .*/
267           case 3: // NT$0 ::=
268
{
269               Object JavaDoc RESULT = null;
270         int eleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left;
271         int eright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right;
272         Integer JavaDoc e = (Integer JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value;
273  System.out.println("= " + e);
274               CUP$parser$result = new java_cup.runtime.Symbol(4/*NT$0*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
275             }
276           return CUP$parser$result;
277
278           /*. . . . . . . . . . . . . . . . . . . .*/
279           case 2: // expr_list ::= expr_part
280
{
281               Object JavaDoc RESULT = null;
282
283               CUP$parser$result = new java_cup.runtime.Symbol(1/*expr_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
284             }
285           return CUP$parser$result;
286
287           /*. . . . . . . . . . . . . . . . . . . .*/
288           case 1: // $START ::= expr_list EOF
289
{
290               Object JavaDoc RESULT = null;
291         int start_valleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left;
292         int start_valright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right;
293         Object JavaDoc start_val = (Object JavaDoc)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value;
294         RESULT = start_val;
295               CUP$parser$result = new java_cup.runtime.Symbol(0/*$START*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
296             }
297           /* ACCEPT */
298           CUP$parser$parser.done_parsing();
299           return CUP$parser$result;
300
301           /*. . . . . . . . . . . . . . . . . . . .*/
302           case 0: // expr_list ::= expr_list expr_part
303
{
304               Object JavaDoc RESULT = null;
305
306               CUP$parser$result = new java_cup.runtime.Symbol(1/*expr_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT);
307             }
308           return CUP$parser$result;
309
310           /* . . . . . .*/
311           default:
312             throw new Exception JavaDoc(
313                "Invalid action number found in internal parse table");
314
315         }
316     }
317 }
318
319
Popular Tags