-
Notifications
You must be signed in to change notification settings - Fork 3
/
parser.java
264 lines (230 loc) · 12.4 KB
/
parser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//----------------------------------------------------
// The following code was generated by CUP v0.11a beta 20060608
// Thu Jul 01 17:58:05 PDT 2010
//----------------------------------------------------
import java_cup.runtime.*;
import tree.*;
/** CUP v0.11a beta 20060608 generated parser.
* @version Thu Jul 01 17:58:05 PDT 2010
*/
public class parser extends java_cup.runtime.lr_parser {
/** Default constructor. */
public parser() {super();}
/** Constructor which sets the default scanner. */
public parser(java_cup.runtime.Scanner s) {super(s);}
/** Constructor which sets the default scanner. */
public parser(java_cup.runtime.Scanner s, java_cup.runtime.SymbolFactory sf) {super(s,sf);}
/** Production table. */
protected static final short _production_table[][] =
unpackFromStrings(new String[] {
"\000\011\000\002\002\005\000\002\002\004\000\002\002" +
"\005\000\002\002\005\000\002\002\005\000\002\002\005" +
"\000\002\002\005\000\002\002\003\000\002\002\003" });
/** Access to production table. */
public short[][] production_table() {return _production_table;}
/** Parse-action table. */
protected static final short[][] _action_table =
unpackFromStrings(new String[] {
"\000\022\000\010\011\007\013\004\014\005\001\002\000" +
"\016\002\ufff9\004\ufff9\005\ufff9\006\ufff9\007\ufff9\012\ufff9" +
"\001\002\000\020\002\ufffa\004\ufffa\005\ufffa\006\ufffa\007" +
"\ufffa\010\023\012\ufffa\001\002\000\014\002\022\004\012" +
"\005\014\006\013\007\015\001\002\000\010\011\007\013" +
"\004\014\005\001\002\000\014\004\012\005\014\006\013" +
"\007\015\012\011\001\002\000\016\002\ufffc\004\ufffc\005" +
"\ufffc\006\ufffc\007\ufffc\012\ufffc\001\002\000\010\011\007" +
"\013\004\014\005\001\002\000\010\011\007\013\004\014" +
"\005\001\002\000\010\011\007\013\004\014\005\001\002" +
"\000\010\011\007\013\004\014\005\001\002\000\016\002" +
"\ufffd\004\ufffd\005\ufffd\006\ufffd\007\ufffd\012\ufffd\001\002" +
"\000\016\002\uffff\004\uffff\005\uffff\006\013\007\015\012" +
"\uffff\001\002\000\016\002\ufffe\004\ufffe\005\ufffe\006\ufffe" +
"\007\ufffe\012\ufffe\001\002\000\016\002\001\004\001\005" +
"\001\006\013\007\015\012\001\001\002\000\004\002\000" +
"\001\002\000\010\011\007\013\004\014\005\001\002\000" +
"\016\002\ufffb\004\ufffb\005\ufffb\006\ufffb\007\ufffb\012\ufffb" +
"\001\002" });
/** Access to parse-action table. */
public short[][] action_table() {return _action_table;}
/** <code>reduce_goto</code> table. */
protected static final short[][] _reduce_table =
unpackFromStrings(new String[] {
"\000\022\000\004\002\005\001\001\000\002\001\001\000" +
"\002\001\001\000\002\001\001\000\004\002\007\001\001" +
"\000\002\001\001\000\002\001\001\000\004\002\020\001" +
"\001\000\004\002\017\001\001\000\004\002\016\001\001" +
"\000\004\002\015\001\001\000\002\001\001\000\002\001" +
"\001\000\002\001\001\000\002\001\001\000\002\001\001" +
"\000\004\002\023\001\001\000\002\001\001" });
/** Access to <code>reduce_goto</code> table. */
public short[][] reduce_table() {return _reduce_table;}
/** Instance of action encapsulation class. */
protected CUP$parser$actions action_obj;
/** Action encapsulation object initializer. */
protected void init_actions()
{
action_obj = new CUP$parser$actions(this);
}
/** Invoke a user supplied parse action. */
public java_cup.runtime.Symbol do_action(
int act_num,
java_cup.runtime.lr_parser parser,
java.util.Stack stack,
int top)
throws java.lang.Exception
{
/* call code in generated class */
return action_obj.CUP$parser$do_action(act_num, parser, stack, top);
}
/** Indicates start state. */
public int start_state() {return 0;}
/** Indicates start production. */
public int start_production() {return 1;}
/** <code>EOF</code> Symbol index. */
public int EOF_sym() {return 0;}
/** <code>error</code> Symbol index. */
public int error_sym() {return 1;}
}
/** Cup generated class to encapsulate user supplied action code.*/
class CUP$parser$actions {
private final parser parser;
/** Constructor */
CUP$parser$actions(parser parser) {
this.parser = parser;
}
/** Method with the actual generated action code. */
public final java_cup.runtime.Symbol CUP$parser$do_action(
int CUP$parser$act_num,
java_cup.runtime.lr_parser CUP$parser$parser,
java.util.Stack CUP$parser$stack,
int CUP$parser$top)
throws java.lang.Exception
{
/* Symbol object for return from actions */
java_cup.runtime.Symbol CUP$parser$result;
/* select the action based on the action number */
switch (CUP$parser$act_num)
{
/*. . . . . . . . . . . . . . . . . . . .*/
case 8: // expr ::= NUMBER
{
Tree RESULT =null;
int nleft = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).left;
int nright = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).right;
Integer n = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
RESULT = new Literal(n);
CUP$parser$result = parser.getSymbolFactory().newSymbol("expr",0, ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
}
return CUP$parser$result;
/*. . . . . . . . . . . . . . . . . . . .*/
case 7: // expr ::= IDENT
{
Tree RESULT =null;
int sleft = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).left;
int sright = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).right;
String s = (String)((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
RESULT = new Identifier(s);
CUP$parser$result = parser.getSymbolFactory().newSymbol("expr",0, ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
}
return CUP$parser$result;
/*. . . . . . . . . . . . . . . . . . . .*/
case 6: // expr ::= IDENT ASSIGN expr
{
Tree RESULT =null;
int sleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
int sright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
String s = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
int eleft = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).left;
int eright = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).right;
Tree e = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
RESULT = new Assignment(s, e);
CUP$parser$result = parser.getSymbolFactory().newSymbol("expr",0, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
}
return CUP$parser$result;
/*. . . . . . . . . . . . . . . . . . . .*/
case 5: // expr ::= LPAREN expr RPAREN
{
Tree RESULT =null;
int eleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left;
int eright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right;
Tree e = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value;
RESULT = e;
CUP$parser$result = parser.getSymbolFactory().newSymbol("expr",0, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
}
return CUP$parser$result;
/*. . . . . . . . . . . . . . . . . . . .*/
case 4: // expr ::= expr DIV expr
{
Tree RESULT =null;
int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
Tree e1 = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).left;
int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).right;
Tree e2 = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
RESULT = new Divide(e1, e2);
CUP$parser$result = parser.getSymbolFactory().newSymbol("expr",0, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
}
return CUP$parser$result;
/*. . . . . . . . . . . . . . . . . . . .*/
case 3: // expr ::= expr MUL expr
{
Tree RESULT =null;
int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
Tree e1 = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).left;
int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).right;
Tree e2 = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
RESULT = new Multiply(e1, e2);
CUP$parser$result = parser.getSymbolFactory().newSymbol("expr",0, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
}
return CUP$parser$result;
/*. . . . . . . . . . . . . . . . . . . .*/
case 2: // expr ::= expr MINUS expr
{
Tree RESULT =null;
int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
Tree e1 = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).left;
int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).right;
Tree e2 = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
RESULT = new Minus(e1, e2);
CUP$parser$result = parser.getSymbolFactory().newSymbol("expr",0, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
}
return CUP$parser$result;
/*. . . . . . . . . . . . . . . . . . . .*/
case 1: // $START ::= expr EOF
{
Object RESULT =null;
int start_valleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left;
int start_valright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right;
Tree start_val = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value;
RESULT = start_val;
CUP$parser$result = parser.getSymbolFactory().newSymbol("$START",0, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
}
/* ACCEPT */
CUP$parser$parser.done_parsing();
return CUP$parser$result;
/*. . . . . . . . . . . . . . . . . . . .*/
case 0: // expr ::= expr PLUS expr
{
Tree RESULT =null;
int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
Tree e1 = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).left;
int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).right;
Tree e2 = (Tree)((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
RESULT = new Plus(e1, e2);
CUP$parser$result = parser.getSymbolFactory().newSymbol("expr",0, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
}
return CUP$parser$result;
/* . . . . . .*/
default:
throw new Exception(
"Invalid action number found in internal parse table");
}
}
}