added 18
[williamcminus.git] / assign16 / src / ExprParser.jj
blob1224c771f6adec6b9aaa71a0a56066732a5d9899
1 /*@bgen(jjtree) Generated By:JJTree: Do not edit this line. ExprParser.jj */
2 /*@egen*/
3 options {
4               
5                 
6   FORCE_LA_CHECK= false;
9 PARSER_BEGIN(ExprParser)
10 import java.io.FileReader;
11 import java.io.Reader;
13 public class ExprParser/*@bgen(jjtree)*/implements ExprParserTreeConstants/*@egen*/ {/*@bgen(jjtree)*/
14   protected static JJTExprParserState jjtree = new JJTExprParserState();
16 /*@egen*/
18     public static void main(String[] args) throws Exception {
19         /* Check the command-line arguments. */
20         if (args.length < 1) {
21             throw new Exception("No source file specified on command-line.");
22         }
24         /* Open the input file to be processed. */
25         Reader input = new FileReader(args[0]);
27         /* Create an instance of the parser. */
28         ExprParser p = new ExprParser(input);
30         /* Perform the parse with 'infix' as the initial production. */
31         try {
32             SimpleNode root = p.infix();
34             /* Dump the AST. */
35             root.dump("====>");
37             /* Let the PostfixVisitor run. */
38             PostfixVisitor pfv= new PostfixVisitor();
39             root.jjtAccept(pfv,null);
40         } catch (Exception e) {
41             e.printStackTrace(System.out);
42         }
43     }
45 PARSER_END(ExprParser)
47 SKIP : {
48         <SPACE : (" ")+>
52 TOKEN : {
53         <integer : ["1"-"9"](["0"-"9"])* >
54         | <plus : "+">
55         | <minus : "-">
56         | <mult : "*">
57         | <div : "/">
58         | <left_paren : "(">
59         | <right_paren : ")">
62 SimpleNode infix() : {/*@bgen(jjtree) infix */
63   ASTinfix jjtn000 = new ASTinfix(JJTINFIX);
64   boolean jjtc000 = true;
65   jjtree.openNodeScope(jjtn000);
66 /*@egen*/} {/*@bgen(jjtree) infix */
67     try {
68 /*@egen*/
69     expression()/*@bgen(jjtree)*/
70     {
71       jjtree.closeNodeScope(jjtn000, true);
72       jjtc000 = false;
73     }
74 /*@egen*/
75     {return jjtn000;}/*@bgen(jjtree)*/
76     } catch (Throwable jjte000) {
77       if (jjtc000) {
78         jjtree.clearNodeScope(jjtn000);
79         jjtc000 = false;
80       } else {
81         jjtree.popNode();
82       }
83       if (jjte000 instanceof RuntimeException) {
84         throw (RuntimeException)jjte000;
85       }
86       if (jjte000 instanceof ParseException) {
87         throw (ParseException)jjte000;
88       }
89       throw (Error)jjte000;
90     } finally {
91       if (jjtc000) {
92         jjtree.closeNodeScope(jjtn000, true);
93       }
94     }
95 /*@egen*/
98 void expression() : {/*@bgen(jjtree) expression */
99   ASTexpression jjtn000 = new ASTexpression(JJTEXPRESSION);
100   boolean jjtc000 = true;
101   jjtree.openNodeScope(jjtn000);
102 /*@egen*/} {/*@bgen(jjtree) expression */
103     try {
104 /*@egen*/
105     term() (expressionPrime())*/*@bgen(jjtree)*/
106     } catch (Throwable jjte000) {
107       if (jjtc000) {
108         jjtree.clearNodeScope(jjtn000);
109         jjtc000 = false;
110       } else {
111         jjtree.popNode();
112       }
113       if (jjte000 instanceof RuntimeException) {
114         throw (RuntimeException)jjte000;
115       }
116       if (jjte000 instanceof ParseException) {
117         throw (ParseException)jjte000;
118       }
119       throw (Error)jjte000;
120     } finally {
121       if (jjtc000) {
122         jjtree.closeNodeScope(jjtn000, true);
123       }
124     }
125 /*@egen*/
128 void addop() : {/*@bgen(jjtree) addop */
129   ASTaddop jjtn000 = new ASTaddop(JJTADDOP);
130   boolean jjtc000 = true;
131   jjtree.openNodeScope(jjtn000);
132 /*@egen*/} {/*@bgen(jjtree) addop */
133     try {
134 /*@egen*/
135     <plus>/*@bgen(jjtree)*/
136            {
137              jjtree.closeNodeScope(jjtn000, true);
138              jjtc000 = false;
139            }
140 /*@egen*/ {jjtn000.value = token;} | <minus>/*@bgen(jjtree)*/
141                                               {
142                                                 jjtree.closeNodeScope(jjtn000, true);
143                                                 jjtc000 = false;
144                                               }
145 /*@egen*/ {jjtn000.value = token;}/*@bgen(jjtree)*/
146     } finally {
147       if (jjtc000) {
148         jjtree.closeNodeScope(jjtn000, true);
149       }
150     }
151 /*@egen*/
154 void expressionPrime() : {/*@bgen(jjtree) expressionPrime */
155   ASTexpressionPrime jjtn000 = new ASTexpressionPrime(JJTEXPRESSIONPRIME);
156   boolean jjtc000 = true;
157   jjtree.openNodeScope(jjtn000);
158 /*@egen*/} {/*@bgen(jjtree) expressionPrime */
159     try {
160 /*@egen*/
161     addop() term()/*@bgen(jjtree)*/
162     } catch (Throwable jjte000) {
163       if (jjtc000) {
164         jjtree.clearNodeScope(jjtn000);
165         jjtc000 = false;
166       } else {
167         jjtree.popNode();
168       }
169       if (jjte000 instanceof RuntimeException) {
170         throw (RuntimeException)jjte000;
171       }
172       if (jjte000 instanceof ParseException) {
173         throw (ParseException)jjte000;
174       }
175       throw (Error)jjte000;
176     } finally {
177       if (jjtc000) {
178         jjtree.closeNodeScope(jjtn000, true);
179       }
180     }
181 /*@egen*/
184 void term() : {/*@bgen(jjtree) term */
185   ASTterm jjtn000 = new ASTterm(JJTTERM);
186   boolean jjtc000 = true;
187   jjtree.openNodeScope(jjtn000);
188 /*@egen*/} {/*@bgen(jjtree) term */
189     try {
190 /*@egen*/
191     factor() (termPrime())*/*@bgen(jjtree)*/
192     } catch (Throwable jjte000) {
193       if (jjtc000) {
194         jjtree.clearNodeScope(jjtn000);
195         jjtc000 = false;
196       } else {
197         jjtree.popNode();
198       }
199       if (jjte000 instanceof RuntimeException) {
200         throw (RuntimeException)jjte000;
201       }
202       if (jjte000 instanceof ParseException) {
203         throw (ParseException)jjte000;
204       }
205       throw (Error)jjte000;
206     } finally {
207       if (jjtc000) {
208         jjtree.closeNodeScope(jjtn000, true);
209       }
210     }
211 /*@egen*/
214 void termPrime() : {/*@bgen(jjtree) termPrime */
215   ASTtermPrime jjtn000 = new ASTtermPrime(JJTTERMPRIME);
216   boolean jjtc000 = true;
217   jjtree.openNodeScope(jjtn000);
218 /*@egen*/} {/*@bgen(jjtree) termPrime */
219     try {
220 /*@egen*/
221     multop() factor()/*@bgen(jjtree)*/
222     } catch (Throwable jjte000) {
223       if (jjtc000) {
224         jjtree.clearNodeScope(jjtn000);
225         jjtc000 = false;
226       } else {
227         jjtree.popNode();
228       }
229       if (jjte000 instanceof RuntimeException) {
230         throw (RuntimeException)jjte000;
231       }
232       if (jjte000 instanceof ParseException) {
233         throw (ParseException)jjte000;
234       }
235       throw (Error)jjte000;
236     } finally {
237       if (jjtc000) {
238         jjtree.closeNodeScope(jjtn000, true);
239       }
240     }
241 /*@egen*/
244 void multop() : {/*@bgen(jjtree) multop */
245   ASTmultop jjtn000 = new ASTmultop(JJTMULTOP);
246   boolean jjtc000 = true;
247   jjtree.openNodeScope(jjtn000);
248 /*@egen*/} {/*@bgen(jjtree) multop */
249     try {
250 /*@egen*/
251     <mult>/*@bgen(jjtree)*/
252            {
253              jjtree.closeNodeScope(jjtn000, true);
254              jjtc000 = false;
255            }
256 /*@egen*/ {jjtn000.value = token;} | <div>/*@bgen(jjtree)*/
257                                             {
258                                               jjtree.closeNodeScope(jjtn000, true);
259                                               jjtc000 = false;
260                                             }
261 /*@egen*/ {jjtn000.value = token;}/*@bgen(jjtree)*/
262     } finally {
263       if (jjtc000) {
264         jjtree.closeNodeScope(jjtn000, true);
265       }
266     }
267 /*@egen*/
270 void factor() : {/*@bgen(jjtree) factor */
271   ASTfactor jjtn000 = new ASTfactor(JJTFACTOR);
272   boolean jjtc000 = true;
273   jjtree.openNodeScope(jjtn000);
274 /*@egen*/} {/*@bgen(jjtree) factor */
275     try {
276 /*@egen*/
277     <left_paren> infix() <right_paren> | <integer>/*@bgen(jjtree)*/
278     {
279       jjtree.closeNodeScope(jjtn000, true);
280       jjtc000 = false;
281     }
282 /*@egen*/
283     {jjtn000.value = token;}/*@bgen(jjtree)*/
284     } catch (Throwable jjte000) {
285       if (jjtc000) {
286         jjtree.clearNodeScope(jjtn000);
287         jjtc000 = false;
288       } else {
289         jjtree.popNode();
290       }
291       if (jjte000 instanceof RuntimeException) {
292         throw (RuntimeException)jjte000;
293       }
294       if (jjte000 instanceof ParseException) {
295         throw (ParseException)jjte000;
296       }
297       throw (Error)jjte000;
298     } finally {
299       if (jjtc000) {
300         jjtree.closeNodeScope(jjtn000, true);
301       }
302     }
303 /*@egen*/