KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > percederberg > grammatica > test > ArithmeticAnalyzer


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

23
24 package net.percederberg.grammatica.test;
25
26 import net.percederberg.grammatica.parser.Analyzer;
27 import net.percederberg.grammatica.parser.Node;
28 import net.percederberg.grammatica.parser.ParseException;
29 import net.percederberg.grammatica.parser.Production;
30 import net.percederberg.grammatica.parser.Token;
31
32 /**
33  * A class providing callback methods for the parser.
34  *
35  * @author Per Cederberg, <per at percederberg dot net>
36  * @version 1.0
37  */

38 abstract class ArithmeticAnalyzer extends Analyzer {
39
40     /**
41      * Called when entering a parse tree node.
42      *
43      * @param node the node being entered
44      *
45      * @throws ParseException if the node analysis discovered errors
46      */

47     protected void enter(Node node) throws ParseException {
48         switch (node.getId()) {
49         case ArithmeticConstants.ADD:
50             enterAdd((Token) node);
51             break;
52         case ArithmeticConstants.SUB:
53             enterSub((Token) node);
54             break;
55         case ArithmeticConstants.MUL:
56             enterMul((Token) node);
57             break;
58         case ArithmeticConstants.DIV:
59             enterDiv((Token) node);
60             break;
61         case ArithmeticConstants.LEFT_PAREN:
62             enterLeftParen((Token) node);
63             break;
64         case ArithmeticConstants.RIGHT_PAREN:
65             enterRightParen((Token) node);
66             break;
67         case ArithmeticConstants.NUMBER:
68             enterNumber((Token) node);
69             break;
70         case ArithmeticConstants.IDENTIFIER:
71             enterIdentifier((Token) node);
72             break;
73         case ArithmeticConstants.EXPRESSION:
74             enterExpression((Production) node);
75             break;
76         case ArithmeticConstants.EXPRESSION_REST:
77             enterExpressionRest((Production) node);
78             break;
79         case ArithmeticConstants.TERM:
80             enterTerm((Production) node);
81             break;
82         case ArithmeticConstants.TERM_REST:
83             enterTermRest((Production) node);
84             break;
85         case ArithmeticConstants.FACTOR:
86             enterFactor((Production) node);
87             break;
88         case ArithmeticConstants.ATOM:
89             enterAtom((Production) node);
90             break;
91         }
92     }
93
94     /**
95      * Called when exiting a parse tree node.
96      *
97      * @param node the node being exited
98      *
99      * @return the node to add to the parse tree, or
100      * null if no parse tree should be created
101      *
102      * @throws ParseException if the node analysis discovered errors
103      */

104     protected Node exit(Node node) throws ParseException {
105         switch (node.getId()) {
106         case ArithmeticConstants.ADD:
107             return exitAdd((Token) node);
108         case ArithmeticConstants.SUB:
109             return exitSub((Token) node);
110         case ArithmeticConstants.MUL:
111             return exitMul((Token) node);
112         case ArithmeticConstants.DIV:
113             return exitDiv((Token) node);
114         case ArithmeticConstants.LEFT_PAREN:
115             return exitLeftParen((Token) node);
116         case ArithmeticConstants.RIGHT_PAREN:
117             return exitRightParen((Token) node);
118         case ArithmeticConstants.NUMBER:
119             return exitNumber((Token) node);
120         case ArithmeticConstants.IDENTIFIER:
121             return exitIdentifier((Token) node);
122         case ArithmeticConstants.EXPRESSION:
123             return exitExpression((Production) node);
124         case ArithmeticConstants.EXPRESSION_REST:
125             return exitExpressionRest((Production) node);
126         case ArithmeticConstants.TERM:
127             return exitTerm((Production) node);
128         case ArithmeticConstants.TERM_REST:
129             return exitTermRest((Production) node);
130         case ArithmeticConstants.FACTOR:
131             return exitFactor((Production) node);
132         case ArithmeticConstants.ATOM:
133             return exitAtom((Production) node);
134         }
135         return node;
136     }
137
138     /**
139      * Called when adding a child to a parse tree node.
140      *
141      * @param node the parent node
142      * @param child the child node, or null
143      *
144      * @throws ParseException if the node analysis discovered errors
145      */

146     protected void child(Production node, Node child)
147         throws ParseException {
148
149         switch (node.getId()) {
150         case ArithmeticConstants.EXPRESSION:
151             childExpression(node, child);
152             break;
153         case ArithmeticConstants.EXPRESSION_REST:
154             childExpressionRest(node, child);
155             break;
156         case ArithmeticConstants.TERM:
157             childTerm(node, child);
158             break;
159         case ArithmeticConstants.TERM_REST:
160             childTermRest(node, child);
161             break;
162         case ArithmeticConstants.FACTOR:
163             childFactor(node, child);
164             break;
165         case ArithmeticConstants.ATOM:
166             childAtom(node, child);
167             break;
168         }
169     }
170
171     /**
172      * Called when entering a parse tree node.
173      *
174      * @param node the node being entered
175      *
176      * @throws ParseException if the node analysis discovered errors
177      */

178     protected void enterAdd(Token node) throws ParseException {
179     }
180
181     /**
182      * Called when exiting a parse tree node.
183      *
184      * @param node the node being exited
185      *
186      * @return the node to add to the parse tree, or
187      * null if no parse tree should be created
188      *
189      * @throws ParseException if the node analysis discovered errors
190      */

191     protected Node exitAdd(Token node) throws ParseException {
192         return node;
193     }
194
195     /**
196      * Called when entering a parse tree node.
197      *
198      * @param node the node being entered
199      *
200      * @throws ParseException if the node analysis discovered errors
201      */

202     protected void enterSub(Token node) throws ParseException {
203     }
204
205     /**
206      * Called when exiting a parse tree node.
207      *
208      * @param node the node being exited
209      *
210      * @return the node to add to the parse tree, or
211      * null if no parse tree should be created
212      *
213      * @throws ParseException if the node analysis discovered errors
214      */

215     protected Node exitSub(Token node) throws ParseException {
216         return node;
217     }
218
219     /**
220      * Called when entering a parse tree node.
221      *
222      * @param node the node being entered
223      *
224      * @throws ParseException if the node analysis discovered errors
225      */

226     protected void enterMul(Token node) throws ParseException {
227     }
228
229     /**
230      * Called when exiting a parse tree node.
231      *
232      * @param node the node being exited
233      *
234      * @return the node to add to the parse tree, or
235      * null if no parse tree should be created
236      *
237      * @throws ParseException if the node analysis discovered errors
238      */

239     protected Node exitMul(Token node) throws ParseException {
240         return node;
241     }
242
243     /**
244      * Called when entering a parse tree node.
245      *
246      * @param node the node being entered
247      *
248      * @throws ParseException if the node analysis discovered errors
249      */

250     protected void enterDiv(Token node) throws ParseException {
251     }
252
253     /**
254      * Called when exiting a parse tree node.
255      *
256      * @param node the node being exited
257      *
258      * @return the node to add to the parse tree, or
259      * null if no parse tree should be created
260      *
261      * @throws ParseException if the node analysis discovered errors
262      */

263     protected Node exitDiv(Token node) throws ParseException {
264         return node;
265     }
266
267     /**
268      * Called when entering a parse tree node.
269      *
270      * @param node the node being entered
271      *
272      * @throws ParseException if the node analysis discovered errors
273      */

274     protected void enterLeftParen(Token node) throws ParseException {
275     }
276
277     /**
278      * Called when exiting a parse tree node.
279      *
280      * @param node the node being exited
281      *
282      * @return the node to add to the parse tree, or
283      * null if no parse tree should be created
284      *
285      * @throws ParseException if the node analysis discovered errors
286      */

287     protected Node exitLeftParen(Token node) throws ParseException {
288         return node;
289     }
290
291     /**
292      * Called when entering a parse tree node.
293      *
294      * @param node the node being entered
295      *
296      * @throws ParseException if the node analysis discovered errors
297      */

298     protected void enterRightParen(Token node) throws ParseException {
299     }
300
301     /**
302      * Called when exiting a parse tree node.
303      *
304      * @param node the node being exited
305      *
306      * @return the node to add to the parse tree, or
307      * null if no parse tree should be created
308      *
309      * @throws ParseException if the node analysis discovered errors
310      */

311     protected Node exitRightParen(Token node) throws ParseException {
312         return node;
313     }
314
315     /**
316      * Called when entering a parse tree node.
317      *
318      * @param node the node being entered
319      *
320      * @throws ParseException if the node analysis discovered errors
321      */

322     protected void enterNumber(Token node) throws ParseException {
323     }
324
325     /**
326      * Called when exiting a parse tree node.
327      *
328      * @param node the node being exited
329      *
330      * @return the node to add to the parse tree, or
331      * null if no parse tree should be created
332      *
333      * @throws ParseException if the node analysis discovered errors
334      */

335     protected Node exitNumber(Token node) throws ParseException {
336         return node;
337     }
338
339     /**
340      * Called when entering a parse tree node.
341      *
342      * @param node the node being entered
343      *
344      * @throws ParseException if the node analysis discovered errors
345      */

346     protected void enterIdentifier(Token node) throws ParseException {
347     }
348
349     /**
350      * Called when exiting a parse tree node.
351      *
352      * @param node the node being exited
353      *
354      * @return the node to add to the parse tree, or
355      * null if no parse tree should be created
356      *
357      * @throws ParseException if the node analysis discovered errors
358      */

359     protected Node exitIdentifier(Token node) throws ParseException {
360         return node;
361     }
362
363     /**
364      * Called when entering a parse tree node.
365      *
366      * @param node the node being entered
367      *
368      * @throws ParseException if the node analysis discovered errors
369      */

370     protected void enterExpression(Production node)
371         throws ParseException {
372     }
373
374     /**
375      * Called when exiting a parse tree node.
376      *
377      * @param node the node being exited
378      *
379      * @return the node to add to the parse tree, or
380      * null if no parse tree should be created
381      *
382      * @throws ParseException if the node analysis discovered errors
383      */

384     protected Node exitExpression(Production node)
385         throws ParseException {
386
387         return node;
388     }
389
390     /**
391      * Called when adding a child to a parse tree node.
392      *
393      * @param node the parent node
394      * @param child the child node, or null
395      *
396      * @throws ParseException if the node analysis discovered errors
397      */

398     protected void childExpression(Production node, Node child)
399         throws ParseException {
400
401         node.addChild(child);
402     }
403
404     /**
405      * Called when entering a parse tree node.
406      *
407      * @param node the node being entered
408      *
409      * @throws ParseException if the node analysis discovered errors
410      */

411     protected void enterExpressionRest(Production node)
412         throws ParseException {
413     }
414
415     /**
416      * Called when exiting a parse tree node.
417      *
418      * @param node the node being exited
419      *
420      * @return the node to add to the parse tree, or
421      * null if no parse tree should be created
422      *
423      * @throws ParseException if the node analysis discovered errors
424      */

425     protected Node exitExpressionRest(Production node)
426         throws ParseException {
427
428         return node;
429     }
430
431     /**
432      * Called when adding a child to a parse tree node.
433      *
434      * @param node the parent node
435      * @param child the child node, or null
436      *
437      * @throws ParseException if the node analysis discovered errors
438      */

439     protected void childExpressionRest(Production node, Node child)
440         throws ParseException {
441
442         node.addChild(child);
443     }
444
445     /**
446      * Called when entering a parse tree node.
447      *
448      * @param node the node being entered
449      *
450      * @throws ParseException if the node analysis discovered errors
451      */

452     protected void enterTerm(Production node) throws ParseException {
453     }
454
455     /**
456      * Called when exiting a parse tree node.
457      *
458      * @param node the node being exited
459      *
460      * @return the node to add to the parse tree, or
461      * null if no parse tree should be created
462      *
463      * @throws ParseException if the node analysis discovered errors
464      */

465     protected Node exitTerm(Production node) throws ParseException {
466         return node;
467     }
468
469     /**
470      * Called when adding a child to a parse tree node.
471      *
472      * @param node the parent node
473      * @param child the child node, or null
474      *
475      * @throws ParseException if the node analysis discovered errors
476      */

477     protected void childTerm(Production node, Node child)
478         throws ParseException {
479
480         node.addChild(child);
481     }
482
483     /**
484      * Called when entering a parse tree node.
485      *
486      * @param node the node being entered
487      *
488      * @throws ParseException if the node analysis discovered errors
489      */

490     protected void enterTermRest(Production node)
491         throws ParseException {
492     }
493
494     /**
495      * Called when exiting a parse tree node.
496      *
497      * @param node the node being exited
498      *
499      * @return the node to add to the parse tree, or
500      * null if no parse tree should be created
501      *
502      * @throws ParseException if the node analysis discovered errors
503      */

504     protected Node exitTermRest(Production node) throws ParseException {
505         return node;
506     }
507
508     /**
509      * Called when adding a child to a parse tree node.
510      *
511      * @param node the parent node
512      * @param child the child node, or null
513      *
514      * @throws ParseException if the node analysis discovered errors
515      */

516     protected void childTermRest(Production node, Node child)
517         throws ParseException {
518
519         node.addChild(child);
520     }
521
522     /**
523      * Called when entering a parse tree node.
524      *
525      * @param node the node being entered
526      *
527      * @throws ParseException if the node analysis discovered errors
528      */

529     protected void enterFactor(Production node) throws ParseException {
530     }
531
532     /**
533      * Called when exiting a parse tree node.
534      *
535      * @param node the node being exited
536      *
537      * @return the node to add to the parse tree, or
538      * null if no parse tree should be created
539      *
540      * @throws ParseException if the node analysis discovered errors
541      */

542     protected Node exitFactor(Production node) throws ParseException {
543         return node;
544     }
545
546     /**
547      * Called when adding a child to a parse tree node.
548      *
549      * @param node the parent node
550      * @param child the child node, or null
551      *
552      * @throws ParseException if the node analysis discovered errors
553      */

554     protected void childFactor(Production node, Node child)
555         throws ParseException {
556
557         node.addChild(child);
558     }
559
560     /**
561      * Called when entering a parse tree node.
562      *
563      * @param node the node being entered
564      *
565      * @throws ParseException if the node analysis discovered errors
566      */

567     protected void enterAtom(Production node) throws ParseException {
568     }
569
570     /**
571      * Called when exiting a parse tree node.
572      *
573      * @param node the node being exited
574      *
575      * @return the node to add to the parse tree, or
576      * null if no parse tree should be created
577      *
578      * @throws ParseException if the node analysis discovered errors
579      */

580     protected Node exitAtom(Production node) throws ParseException {
581         return node;
582     }
583
584     /**
585      * Called when adding a child to a parse tree node.
586      *
587      * @param node the parent node
588      * @param child the child node, or null
589      *
590      * @throws ParseException if the node analysis discovered errors
591      */

592     protected void childAtom(Production node, Node child)
593         throws ParseException {
594
595         node.addChild(child);
596     }
597 }
598
Popular Tags