-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.java
More file actions
190 lines (176 loc) · 8.18 KB
/
Copy pathParser.java
File metadata and controls
190 lines (176 loc) · 8.18 KB
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
import beaver.*;
import java.util.ArrayList;
/**
* This class is a LALR parser generated by
* <a href="http://beaver.sourceforge.net">Beaver</a> v0.9.6.1
* from the grammar specification "path.grammar".
*/
public class Parser extends beaver.Parser {
static final ParsingTables PARSING_TABLES = new ParsingTables(Parser.class);
static final Action RETURN2 = new Action() {
public Symbol reduce(Symbol[] _symbols, int offset) {
return _symbols[offset + 2];
}
};
static final Action RETURN17 = new Action() {
public Symbol reduce(Symbol[] _symbols, int offset) {
return _symbols[offset + 17];
}
};
static final Action RETURN6 = new Action() {
public Symbol reduce(Symbol[] _symbols, int offset) {
return _symbols[offset + 6];
}
};
static final Action RETURN8 = new Action() {
public Symbol reduce(Symbol[] _symbols, int offset) {
return _symbols[offset + 8];
}
};
static final Action RETURN13 = new Action() {
public Symbol reduce(Symbol[] _symbols, int offset) {
return _symbols[offset + 13];
}
};
static final Action RETURN3 = new Action() {
public Symbol reduce(Symbol[] _symbols, int offset) {
return _symbols[offset + 3];
}
};
static final Action RETURN7 = new Action() {
public Symbol reduce(Symbol[] _symbols, int offset) {
return _symbols[offset + 7];
}
};
static final Action RETURN5 = new Action() {
public Symbol reduce(Symbol[] _symbols, int offset) {
return _symbols[offset + 5];
}
};
static final Action RETURN4 = new Action() {
public Symbol reduce(Symbol[] _symbols, int offset) {
return _symbols[offset + 4];
}
};
private final Action[] actions;
public Parser() {
super(PARSING_TABLES);
actions = new Action[] {
new Action() { // [0] lst$ClassDecl = ClassDecl
public Symbol reduce(Symbol[] _symbols, int offset) {
ArrayList lst = new ArrayList(); lst.add(_symbols[offset + 1]); return new Symbol(lst);
}
},
new Action() { // [1] lst$ClassDecl = lst$ClassDecl ClassDecl
public Symbol reduce(Symbol[] _symbols, int offset) {
((ArrayList) _symbols[offset + 1].value).add(_symbols[offset + 2]); return _symbols[offset + 1];
}
},
Action.NONE, // [2] opt$lst$ClassDecl =
Action.RETURN, // [3] opt$lst$ClassDecl = lst$ClassDecl
RETURN2, // [4] Program = MainClass opt$lst$ClassDecl; returns 'opt$lst$ClassDecl' although none is marked
RETURN17, // [5] MainClass = CLASS ID LBRACE PUBLIC STATIC VOID MAIN LPAREN STRING LBRACK RBRACK ID RPAREN LBRACE Statement RBRACE RBRACE; returns 'RBRACE' although none is marked
new Action() { // [6] lst$VarDecl = VarDecl
public Symbol reduce(Symbol[] _symbols, int offset) {
ArrayList lst = new ArrayList(); lst.add(_symbols[offset + 1]); return new Symbol(lst);
}
},
new Action() { // [7] lst$VarDecl = lst$VarDecl VarDecl
public Symbol reduce(Symbol[] _symbols, int offset) {
((ArrayList) _symbols[offset + 1].value).add(_symbols[offset + 2]); return _symbols[offset + 1];
}
},
Action.NONE, // [8] opt$lst$VarDecl =
Action.RETURN, // [9] opt$lst$VarDecl = lst$VarDecl
new Action() { // [10] lst$MethodDecl = MethodDecl
public Symbol reduce(Symbol[] _symbols, int offset) {
ArrayList lst = new ArrayList(); lst.add(_symbols[offset + 1]); return new Symbol(lst);
}
},
new Action() { // [11] lst$MethodDecl = lst$MethodDecl MethodDecl
public Symbol reduce(Symbol[] _symbols, int offset) {
((ArrayList) _symbols[offset + 1].value).add(_symbols[offset + 2]); return _symbols[offset + 1];
}
},
Action.NONE, // [12] opt$lst$MethodDecl =
Action.RETURN, // [13] opt$lst$MethodDecl = lst$MethodDecl
RETURN6, // [14] ClassDecl = CLASS ID LBRACE opt$lst$VarDecl opt$lst$MethodDecl RBRACE; returns 'RBRACE' although none is marked
RETURN8, // [15] ClassDecl = CLASS ID EXTENDS ID LBRACE opt$lst$VarDecl opt$lst$MethodDecl RBRACE; returns 'RBRACE' although none is marked
RETURN2, // [16] VarDecl = Type ID; returns 'ID' although none is marked
new Action() { // [17] lst$Statement = Statement
public Symbol reduce(Symbol[] _symbols, int offset) {
ArrayList lst = new ArrayList(); lst.add(_symbols[offset + 1]); return new Symbol(lst);
}
},
new Action() { // [18] lst$Statement = lst$Statement Statement
public Symbol reduce(Symbol[] _symbols, int offset) {
((ArrayList) _symbols[offset + 1].value).add(_symbols[offset + 2]); return _symbols[offset + 1];
}
},
Action.NONE, // [19] opt$lst$Statement =
Action.RETURN, // [20] opt$lst$Statement = lst$Statement
RETURN13, // [21] MethodDecl = PUBLIC Type ID LPAREN FormalList RPAREN LBRACE opt$lst$VarDecl opt$lst$Statement RETURN Exp SEMI RBRACE; returns 'RBRACE' although none is marked
new Action() { // [22] lst$FormalRest = FormalRest
public Symbol reduce(Symbol[] _symbols, int offset) {
ArrayList lst = new ArrayList(); lst.add(_symbols[offset + 1]); return new Symbol(lst);
}
},
new Action() { // [23] lst$FormalRest = lst$FormalRest FormalRest
public Symbol reduce(Symbol[] _symbols, int offset) {
((ArrayList) _symbols[offset + 1].value).add(_symbols[offset + 2]); return _symbols[offset + 1];
}
},
Action.NONE, // [24] opt$lst$FormalRest =
Action.RETURN, // [25] opt$lst$FormalRest = lst$FormalRest
RETURN3, // [26] FormalList = Type ID opt$lst$FormalRest; returns 'opt$lst$FormalRest' although none is marked
Action.NONE, // [27] FormalList =
RETURN3, // [28] FormalRest = COMMA Type ID; returns 'ID' although none is marked
RETURN3, // [29] Type = INT LBRACK RBRACK; returns 'RBRACK' although none is marked
Action.RETURN, // [30] Type = BOOLEAN
Action.RETURN, // [31] Type = INT
Action.RETURN, // [32] Type = ID
RETURN3, // [33] Statement = LBRACE opt$lst$Statement RBRACE; returns 'RBRACE' although none is marked
RETURN7, // [34] Statement = IF LPAREN Exp RPAREN Statement ELSE Statement; returns 'Statement' although none is marked
RETURN5, // [35] Statement = WHILE LPAREN Exp RPAREN Statement; returns 'Statement' although none is marked
RETURN5, // [36] Statement = PRINT LPAREN Exp RPAREN SEMI; returns 'SEMI' although none is marked
RETURN4, // [37] Statement = ID EQUALS Exp SEMI; returns 'SEMI' although none is marked
RETURN7, // [38] Statement = ID LBRACK Exp RBRACK EQUALS Exp SEMI; returns 'SEMI' although none is marked
RETURN3, // [39] Exp = Exp Op Exp; returns 'Exp' although none is marked
RETURN4, // [40] Exp = Exp LBRACK Exp RBRACK; returns 'RBRACK' although none is marked
RETURN3, // [41] Exp = Exp DOT LENGTH; returns 'LENGTH' although none is marked
RETURN6, // [42] Exp = Exp DOT ID LPAREN ExpList RPAREN; returns 'RPAREN' although none is marked
Action.RETURN, // [43] Exp = INT_LIT
Action.RETURN, // [44] Exp = TRUE
Action.RETURN, // [45] Exp = FALSE
Action.RETURN, // [46] Exp = ID
Action.RETURN, // [47] Exp = THIS
RETURN5, // [48] Exp = NEW INT LBRACK Exp RBRACK; returns 'RBRACK' although none is marked
RETURN4, // [49] Exp = NEW ID LPAREN RPAREN; returns 'RPAREN' although none is marked
RETURN2, // [50] Exp = NOT Exp; returns 'Exp' although none is marked
RETURN3, // [51] Exp = LPAREN Exp RPAREN; returns 'RPAREN' although none is marked
new Action() { // [52] lst$ExpRest = ExpRest
public Symbol reduce(Symbol[] _symbols, int offset) {
ArrayList lst = new ArrayList(); lst.add(_symbols[offset + 1]); return new Symbol(lst);
}
},
new Action() { // [53] lst$ExpRest = lst$ExpRest ExpRest
public Symbol reduce(Symbol[] _symbols, int offset) {
((ArrayList) _symbols[offset + 1].value).add(_symbols[offset + 2]); return _symbols[offset + 1];
}
},
Action.NONE, // [54] opt$lst$ExpRest =
Action.RETURN, // [55] opt$lst$ExpRest = lst$ExpRest
RETURN2, // [56] ExpList = Exp opt$lst$ExpRest; returns 'opt$lst$ExpRest' although none is marked
Action.NONE, // [57] ExpList =
RETURN2, // [58] ExpRest = COMMA Exp; returns 'Exp' although none is marked
Action.RETURN, // [59] Op = TIMES
Action.RETURN, // [60] Op = PLUS
Action.RETURN, // [61] Op = MINUS
Action.RETURN, // [62] Op = LESS
Action.RETURN // [63] Op = AND
};
}
protected Symbol invokeReduceAction(int rule_num, int offset) {
return actions[rule_num].reduce(_symbols, offset);
}
}