KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > tools > ij > mtGrammar


1 /* Generated By:JavaCC: Do not edit this line. mtGrammar.java */
2 package org.apache.derby.impl.tools.ij;
3
4 import java.util.Hashtable JavaDoc;
5 import java.util.Vector JavaDoc;
6 import java.io.IOException JavaDoc;
7 import org.apache.derby.iapi.tools.i18n.*;
8
9 public class mtGrammar implements mtGrammarConstants {
10         private LocalizedOutput currOut;
11         private LocalizedInput currIn;
12
13
14         mtGrammar() { }
15
16 //
17
// start of BNF rules
18
//
19
final public mtTestSuite grammarStatement() throws ParseException {
20         Vector JavaDoc cases = null;
21         Vector JavaDoc init = null;
22         Vector JavaDoc last = null;
23         int threads = 0;
24         mtTime time;
25     threads = numThreads();
26     time = runTime();
27     switch (jj_nt.kind) {
28     case INIT:
29       init = init();
30       break;
31     default:
32       jj_la1[0] = jj_gen;
33       ;
34     }
35     cases = cases();
36     switch (jj_nt.kind) {
37     case LAST:
38       last = last();
39       break;
40     default:
41       jj_la1[1] = jj_gen;
42       ;
43     }
44     jj_consume_token(0);
45                 {if (true) return new mtTestSuite(threads, time, init, cases, last);}
46     throw new Error JavaDoc("Missing return statement in function");
47   }
48
49   final public int numThreads() throws ParseException {
50         Token t;
51     jj_consume_token(THREADS);
52     t = jj_consume_token(INT);
53                 int val = Integer.decode(t.image).intValue();
54                 {if (true) return val;}
55     throw new Error JavaDoc("Missing return statement in function");
56   }
57
58   final public mtTime runTime() throws ParseException {
59         mtTime time;
60     jj_consume_token(RUNTIME);
61     time = time();
62                 {if (true) return time;}
63     throw new Error JavaDoc("Missing return statement in function");
64   }
65
66   final public Vector JavaDoc cases() throws ParseException {
67         Vector JavaDoc testCases = new Vector JavaDoc(5);
68     label_1:
69     while (true) {
70       testCase(testCases);
71       switch (jj_nt.kind) {
72       case CASE:
73         ;
74         break;
75       default:
76         jj_la1[2] = jj_gen;
77         break label_1;
78       }
79     }
80                 {if (true) return testCases;}
81     throw new Error JavaDoc("Missing return statement in function");
82   }
83
84   final public void testCase(Vector JavaDoc testCases) throws ParseException {
85         Token t;
86         mtTestCase testCase = new mtTestCase();
87     jj_consume_token(CASE);
88     t = jj_consume_token(WORD);
89     caseInfo(testCase);
90                 testCase.setName(t.image);
91                 testCases.addElement(testCase);
92   }
93
94   final public Vector JavaDoc init() throws ParseException {
95         Vector JavaDoc testCases = new Vector JavaDoc(5);
96     label_2:
97     while (true) {
98       initCase(testCases);
99       switch (jj_nt.kind) {
100       case INIT:
101         ;
102         break;
103       default:
104         jj_la1[3] = jj_gen;
105         break label_2;
106       }
107     }
108                 {if (true) return testCases;}
109     throw new Error JavaDoc("Missing return statement in function");
110   }
111
112   final public void initCase(Vector JavaDoc testCases) throws ParseException {
113         Token t;
114         mtTestCase testCase = new mtTestCase();
115     jj_consume_token(INIT);
116     t = jj_consume_token(WORD);
117     caseInfo(testCase);
118                 testCase.setName(t.image);
119                 testCases.addElement(testCase);
120   }
121
122   final public Vector JavaDoc last() throws ParseException {
123         Vector JavaDoc testCases = new Vector JavaDoc(1);
124     label_3:
125     while (true) {
126       lastCase(testCases);
127       switch (jj_nt.kind) {
128       case LAST:
129         ;
130         break;
131       default:
132         jj_la1[4] = jj_gen;
133         break label_3;
134       }
135     }
136                 {if (true) return testCases;}
137     throw new Error JavaDoc("Missing return statement in function");
138   }
139
140   final public void lastCase(Vector JavaDoc testCases) throws ParseException {
141         Token t;
142         mtTestCase testCase = new mtTestCase();
143     jj_consume_token(LAST);
144     t = jj_consume_token(WORD);
145     caseInfo(testCase);
146                 testCase.setName(t.image);
147                 testCases.addElement(testCase);
148   }
149
150   final public void caseInfo(mtTestCase testCase) throws ParseException {
151         String JavaDoc file;
152         String JavaDoc prop = null;
153         int weight = 50;
154         Hashtable JavaDoc errorList = null;
155         String JavaDoc description = null;
156     file = scriptFile();
157                 testCase.setFile(file);
158     switch (jj_nt.kind) {
159     case PROPERTIES:
160       prop = propFile();
161       break;
162     default:
163       jj_la1[5] = jj_gen;
164       ;
165     }
166                 testCase.setPropFile(prop);
167     switch (jj_nt.kind) {
168     case WEIGHT:
169       weight = weight();
170       break;
171     default:
172       jj_la1[6] = jj_gen;
173       ;
174     }
175                 testCase.setWeight(weight);
176     switch (jj_nt.kind) {
177     case IGNOREERRORS:
178       errorList = ignoreErrors();
179       break;
180     default:
181       jj_la1[7] = jj_gen;
182       ;
183     }
184                 if (errorList == null)
185                         errorList = new Hashtable JavaDoc();
186
187                 testCase.setIgnoreErrors(errorList);
188     switch (jj_nt.kind) {
189     case DESCRIPTION:
190       description = description();
191       break;
192     default:
193       jj_la1[8] = jj_gen;
194       ;
195     }
196                 testCase.setDescription(description);
197   }
198
199   final public String JavaDoc scriptFile() throws ParseException {
200         Token t;
201     jj_consume_token(FILE);
202     t = jj_consume_token(WORD);
203                 {if (true) return t.image;}
204     throw new Error JavaDoc("Missing return statement in function");
205   }
206
207   final public String JavaDoc propFile() throws ParseException {
208         Token t;
209     jj_consume_token(PROPERTIES);
210     t = jj_consume_token(WORD);
211                 {if (true) return t.image;}
212     throw new Error JavaDoc("Missing return statement in function");
213   }
214
215   final public int weight() throws ParseException {
216         Token t;
217     jj_consume_token(WEIGHT);
218     t = jj_consume_token(INT);
219                 int val = Integer.decode(t.image).intValue();
220                 if (val > 100 || val < 1)
221                 {
222                         System.out.println("LINE "+t.beginLine +": Weight '"+t.image
223                                                         +"' is invalid, must be between 1..100"
224                                                         +" -- defaulting to 50.");
225                         val = 50;
226                 }
227                 {if (true) return val;}
228     throw new Error JavaDoc("Missing return statement in function");
229   }
230
231   final public String JavaDoc description() throws ParseException {
232         Token t;
233     jj_consume_token(DESCRIPTION);
234     t = jj_consume_token(STRING);
235                 {if (true) return t.image;}
236     throw new Error JavaDoc("Missing return statement in function");
237   }
238
239   final public Hashtable JavaDoc ignoreErrors() throws ParseException {
240         // note: we need a non-null errorlist even
241
// if there is nothing in it
242
Hashtable JavaDoc errorList = new Hashtable JavaDoc();
243     jj_consume_token(IGNOREERRORS);
244     getError(errorList);
245     label_4:
246     while (true) {
247       switch (jj_nt.kind) {
248       case COMMA:
249         ;
250         break;
251       default:
252         jj_la1[9] = jj_gen;
253         break label_4;
254       }
255       jj_consume_token(COMMA);
256       getError(errorList);
257     }
258                 {if (true) return errorList;}
259     throw new Error JavaDoc("Missing return statement in function");
260   }
261
262   final public void getError(Hashtable JavaDoc errorList) throws ParseException {
263         String JavaDoc s;
264     s = word_or_int();
265                 if (errorList == null)
266                 {
267                 }
268                 errorList.put(s, new Integer JavaDoc(0));
269   }
270
271   final public String JavaDoc word_or_int() throws ParseException {
272         Token t;
273     switch (jj_nt.kind) {
274     case WORD:
275       t = jj_consume_token(WORD);
276                 {if (true) return t.image;}
277       break;
278     case INT:
279       t = jj_consume_token(INT);
280                 {if (true) return t.image;}
281       break;
282     default:
283       jj_la1[10] = jj_gen;
284       jj_consume_token(-1);
285       throw new ParseException();
286     }
287     throw new Error JavaDoc("Missing return statement in function");
288   }
289
290 /*
291 ** Possible formats:
292 **
293 ** HH:MM:SS
294 ** MM:SS
295 ** SS
296 */

297   final public mtTime time() throws ParseException {
298         Token h, m, s;
299     if (jj_2_1(4)) {
300       h = jj_consume_token(INT);
301       jj_consume_token(COLON);
302       m = jj_consume_token(INT);
303       jj_consume_token(COLON);
304       s = jj_consume_token(INT);
305                 {if (true) return new mtTime(
306                                 Integer.decode(h.image).intValue(),
307                                 Integer.decode(m.image).intValue(),
308                                 Integer.decode(s.image).intValue());}
309     } else if (jj_2_2(2)) {
310       m = jj_consume_token(INT);
311       jj_consume_token(COLON);
312       s = jj_consume_token(INT);
313                 {if (true) return new mtTime(
314                                 0,
315                                 Integer.decode(m.image).intValue(),
316                                 Integer.decode(s.image).intValue());}
317     } else {
318       switch (jj_nt.kind) {
319       case INT:
320         s = jj_consume_token(INT);
321                 {if (true) return new mtTime(
322                                 0,
323                                 0,
324                                 Integer.decode(s.image).intValue());}
325         break;
326       default:
327         jj_la1[11] = jj_gen;
328         jj_consume_token(-1);
329         throw new ParseException();
330       }
331     }
332     throw new Error JavaDoc("Missing return statement in function");
333   }
334
335   final private boolean jj_2_1(int xla) {
336     jj_la = xla; jj_lastpos = jj_scanpos = token;
337     try { return !jj_3_1(); }
338     catch(LookaheadSuccess ls) { return true; }
339     finally { jj_save(0, xla); }
340   }
341
342   final private boolean jj_2_2(int xla) {
343     jj_la = xla; jj_lastpos = jj_scanpos = token;
344     try { return !jj_3_2(); }
345     catch(LookaheadSuccess ls) { return true; }
346     finally { jj_save(1, xla); }
347   }
348
349   final private boolean jj_3_1() {
350     if (jj_scan_token(INT)) return true;
351     if (jj_scan_token(COLON)) return true;
352     if (jj_scan_token(INT)) return true;
353     if (jj_scan_token(COLON)) return true;
354     return false;
355   }
356
357   final private boolean jj_3_2() {
358     if (jj_scan_token(INT)) return true;
359     if (jj_scan_token(COLON)) return true;
360     return false;
361   }
362
363   public mtGrammarTokenManager token_source;
364   SimpleCharStream jj_input_stream;
365   public Token token, jj_nt;
366   private Token jj_scanpos, jj_lastpos;
367   private int jj_la;
368   public boolean lookingAhead = false;
369   private boolean jj_semLA;
370   private int jj_gen;
371   final private int[] jj_la1 = new int[12];
372   static private int[] jj_la1_0;
373   static {
374       jj_la1_0();
375    }
376    private static void jj_la1_0() {
377       jj_la1_0 = new int[] {0x2000,0x1000,0x400,0x2000,0x1000,0x20000,0x4000,0x10000,0x8000,0x800000,0x300000,0x100000,};
378    }
379   final private JJCalls[] jj_2_rtns = new JJCalls[2];
380   private boolean jj_rescan = false;
381   private int jj_gc = 0;
382
383   public mtGrammar(java.io.InputStream JavaDoc stream) {
384      this(stream, null);
385   }
386   public mtGrammar(java.io.InputStream JavaDoc stream, String JavaDoc encoding) {
387     try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException JavaDoc e) { throw new RuntimeException JavaDoc(e); }
388     token_source = new mtGrammarTokenManager(jj_input_stream);
389     token = new Token();
390     token.next = jj_nt = token_source.getNextToken();
391     jj_gen = 0;
392     for (int i = 0; i < 12; i++) jj_la1[i] = -1;
393     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
394   }
395
396   public void ReInit(java.io.InputStream JavaDoc stream) {
397      ReInit(stream, null);
398   }
399   public void ReInit(java.io.InputStream JavaDoc stream, String JavaDoc encoding) {
400     try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException JavaDoc e) { throw new RuntimeException JavaDoc(e); }
401     token_source.ReInit(jj_input_stream);
402     token = new Token();
403     token.next = jj_nt = token_source.getNextToken();
404     jj_gen = 0;
405     for (int i = 0; i < 12; i++) jj_la1[i] = -1;
406     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
407   }
408
409   public mtGrammar(java.io.Reader JavaDoc stream) {
410     jj_input_stream = new SimpleCharStream(stream, 1, 1);
411     token_source = new mtGrammarTokenManager(jj_input_stream);
412     token = new Token();
413     token.next = jj_nt = token_source.getNextToken();
414     jj_gen = 0;
415     for (int i = 0; i < 12; i++) jj_la1[i] = -1;
416     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
417   }
418
419   public void ReInit(java.io.Reader JavaDoc stream) {
420     jj_input_stream.ReInit(stream, 1, 1);
421     token_source.ReInit(jj_input_stream);
422     token = new Token();
423     token.next = jj_nt = token_source.getNextToken();
424     jj_gen = 0;
425     for (int i = 0; i < 12; i++) jj_la1[i] = -1;
426     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
427   }
428
429   public mtGrammar(mtGrammarTokenManager tm) {
430     token_source = tm;
431     token = new Token();
432     token.next = jj_nt = token_source.getNextToken();
433     jj_gen = 0;
434     for (int i = 0; i < 12; i++) jj_la1[i] = -1;
435     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
436   }
437
438   public void ReInit(mtGrammarTokenManager tm) {
439     token_source = tm;
440     token = new Token();
441     token.next = jj_nt = token_source.getNextToken();
442     jj_gen = 0;
443     for (int i = 0; i < 12; i++) jj_la1[i] = -1;
444     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
445   }
446
447   final private Token jj_consume_token(int kind) throws ParseException {
448     Token oldToken = token;
449     if ((token = jj_nt).next != null) jj_nt = jj_nt.next;
450     else jj_nt = jj_nt.next = token_source.getNextToken();
451     if (token.kind == kind) {
452       jj_gen++;
453       if (++jj_gc > 100) {
454         jj_gc = 0;
455         for (int i = 0; i < jj_2_rtns.length; i++) {
456           JJCalls c = jj_2_rtns[i];
457           while (c != null) {
458             if (c.gen < jj_gen) c.first = null;
459             c = c.next;
460           }
461         }
462       }
463       return token;
464     }
465     jj_nt = token;
466     token = oldToken;
467     jj_kind = kind;
468     throw generateParseException();
469   }
470
471   static private final class LookaheadSuccess extends java.lang.Error JavaDoc { }
472   final private LookaheadSuccess jj_ls = new LookaheadSuccess();
473   final private boolean jj_scan_token(int kind) {
474     if (jj_scanpos == jj_lastpos) {
475       jj_la--;
476       if (jj_scanpos.next == null) {
477         jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
478       } else {
479         jj_lastpos = jj_scanpos = jj_scanpos.next;
480       }
481     } else {
482       jj_scanpos = jj_scanpos.next;
483     }
484     if (jj_rescan) {
485       int i = 0; Token tok = token;
486       while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
487       if (tok != null) jj_add_error_token(kind, i);
488     }
489     if (jj_scanpos.kind != kind) return true;
490     if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
491     return false;
492   }
493
494   final public Token getNextToken() {
495     if ((token = jj_nt).next != null) jj_nt = jj_nt.next;
496     else jj_nt = jj_nt.next = token_source.getNextToken();
497     jj_gen++;
498     return token;
499   }
500
501   final public Token getToken(int index) {
502     Token t = lookingAhead ? jj_scanpos : token;
503     for (int i = 0; i < index; i++) {
504       if (t.next != null) t = t.next;
505       else t = t.next = token_source.getNextToken();
506     }
507     return t;
508   }
509
510   private java.util.Vector JavaDoc jj_expentries = new java.util.Vector JavaDoc();
511   private int[] jj_expentry;
512   private int jj_kind = -1;
513   private int[] jj_lasttokens = new int[100];
514   private int jj_endpos;
515
516   private void jj_add_error_token(int kind, int pos) {
517     if (pos >= 100) return;
518     if (pos == jj_endpos + 1) {
519       jj_lasttokens[jj_endpos++] = kind;
520     } else if (jj_endpos != 0) {
521       jj_expentry = new int[jj_endpos];
522       for (int i = 0; i < jj_endpos; i++) {
523         jj_expentry[i] = jj_lasttokens[i];
524       }
525       boolean exists = false;
526       for (java.util.Enumeration JavaDoc e = jj_expentries.elements(); e.hasMoreElements();) {
527         int[] oldentry = (int[])(e.nextElement());
528         if (oldentry.length == jj_expentry.length) {
529           exists = true;
530           for (int i = 0; i < jj_expentry.length; i++) {
531             if (oldentry[i] != jj_expentry[i]) {
532               exists = false;
533               break;
534             }
535           }
536           if (exists) break;
537         }
538       }
539       if (!exists) jj_expentries.addElement(jj_expentry);
540       if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
541     }
542   }
543
544   public ParseException generateParseException() {
545     jj_expentries.removeAllElements();
546     boolean[] la1tokens = new boolean[25];
547     for (int i = 0; i < 25; i++) {
548       la1tokens[i] = false;
549     }
550     if (jj_kind >= 0) {
551       la1tokens[jj_kind] = true;
552       jj_kind = -1;
553     }
554     for (int i = 0; i < 12; i++) {
555       if (jj_la1[i] == jj_gen) {
556         for (int j = 0; j < 32; j++) {
557           if ((jj_la1_0[i] & (1<<j)) != 0) {
558             la1tokens[j] = true;
559           }
560         }
561       }
562     }
563     for (int i = 0; i < 25; i++) {
564       if (la1tokens[i]) {
565         jj_expentry = new int[1];
566         jj_expentry[0] = i;
567         jj_expentries.addElement(jj_expentry);
568       }
569     }
570     jj_endpos = 0;
571     jj_rescan_token();
572     jj_add_error_token(0, 0);
573     int[][] exptokseq = new int[jj_expentries.size()][];
574     for (int i = 0; i < jj_expentries.size(); i++) {
575       exptokseq[i] = (int[])jj_expentries.elementAt(i);
576     }
577     return new ParseException(token, exptokseq, mtGrammarConstants.tokenImage);
578   }
579
580   final public void enable_tracing() {
581   }
582
583   final public void disable_tracing() {
584   }
585
586   final private void jj_rescan_token() {
587     jj_rescan = true;
588     for (int i = 0; i < 2; i++) {
589     try {
590       JJCalls p = jj_2_rtns[i];
591       do {
592         if (p.gen > jj_gen) {
593           jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
594           switch (i) {
595             case 0: jj_3_1(); break;
596             case 1: jj_3_2(); break;
597           }
598         }
599         p = p.next;
600       } while (p != null);
601       } catch(LookaheadSuccess ls) { }
602     }
603     jj_rescan = false;
604   }
605
606   final private void jj_save(int index, int xla) {
607     JJCalls p = jj_2_rtns[index];
608     while (p.gen > jj_gen) {
609       if (p.next == null) { p = p.next = new JJCalls(); break; }
610       p = p.next;
611     }
612     p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
613   }
614
615   static final class JJCalls {
616     int gen;
617     Token first;
618     int arg;
619     JJCalls next;
620   }
621
622 }
623
Popular Tags