001: /* Generated By:JavaCC: Do not edit this line. mtGrammar.java */
002: package org.apache.derby.impl.tools.ij;
003:
004: import java.util.Hashtable;
005: import java.util.Vector;
006: import java.io.IOException;
007: import org.apache.derby.iapi.tools.i18n.*;
008:
009: public class mtGrammar implements mtGrammarConstants {
010: private LocalizedOutput currOut;
011: private LocalizedInput currIn;
012:
013: mtGrammar() {
014: }
015:
016: //
017: // start of BNF rules
018: //
019: final public mtTestSuite grammarStatement() throws ParseException {
020: Vector cases = null;
021: Vector init = null;
022: Vector last = null;
023: int threads = 0;
024: mtTime time;
025: threads = numThreads();
026: time = runTime();
027: switch (jj_nt.kind) {
028: case INIT:
029: init = init();
030: break;
031: default:
032: jj_la1[0] = jj_gen;
033: ;
034: }
035: cases = cases();
036: switch (jj_nt.kind) {
037: case LAST:
038: last = last();
039: break;
040: default:
041: jj_la1[1] = jj_gen;
042: ;
043: }
044: jj_consume_token(0);
045: {
046: if (true)
047: return new mtTestSuite(threads, time, init, cases, last);
048: }
049: throw new Error("Missing return statement in function");
050: }
051:
052: final public int numThreads() throws ParseException {
053: Token t;
054: jj_consume_token(THREADS);
055: t = jj_consume_token(INT);
056: int val = Integer.decode(t.image).intValue();
057: {
058: if (true)
059: return val;
060: }
061: throw new Error("Missing return statement in function");
062: }
063:
064: final public mtTime runTime() throws ParseException {
065: mtTime time;
066: jj_consume_token(RUNTIME);
067: time = time();
068: {
069: if (true)
070: return time;
071: }
072: throw new Error("Missing return statement in function");
073: }
074:
075: final public Vector cases() throws ParseException {
076: Vector testCases = new Vector(5);
077: label_1: while (true) {
078: testCase(testCases);
079: switch (jj_nt.kind) {
080: case CASE:
081: ;
082: break;
083: default:
084: jj_la1[2] = jj_gen;
085: break label_1;
086: }
087: }
088: {
089: if (true)
090: return testCases;
091: }
092: throw new Error("Missing return statement in function");
093: }
094:
095: final public void testCase(Vector testCases) throws ParseException {
096: Token t;
097: mtTestCase testCase = new mtTestCase();
098: jj_consume_token(CASE);
099: t = jj_consume_token(WORD);
100: caseInfo(testCase);
101: testCase.setName(t.image);
102: testCases.addElement(testCase);
103: }
104:
105: final public Vector init() throws ParseException {
106: Vector testCases = new Vector(5);
107: label_2: while (true) {
108: initCase(testCases);
109: switch (jj_nt.kind) {
110: case INIT:
111: ;
112: break;
113: default:
114: jj_la1[3] = jj_gen;
115: break label_2;
116: }
117: }
118: {
119: if (true)
120: return testCases;
121: }
122: throw new Error("Missing return statement in function");
123: }
124:
125: final public void initCase(Vector testCases) throws ParseException {
126: Token t;
127: mtTestCase testCase = new mtTestCase();
128: jj_consume_token(INIT);
129: t = jj_consume_token(WORD);
130: caseInfo(testCase);
131: testCase.setName(t.image);
132: testCases.addElement(testCase);
133: }
134:
135: final public Vector last() throws ParseException {
136: Vector testCases = new Vector(1);
137: label_3: while (true) {
138: lastCase(testCases);
139: switch (jj_nt.kind) {
140: case LAST:
141: ;
142: break;
143: default:
144: jj_la1[4] = jj_gen;
145: break label_3;
146: }
147: }
148: {
149: if (true)
150: return testCases;
151: }
152: throw new Error("Missing return statement in function");
153: }
154:
155: final public void lastCase(Vector testCases) throws ParseException {
156: Token t;
157: mtTestCase testCase = new mtTestCase();
158: jj_consume_token(LAST);
159: t = jj_consume_token(WORD);
160: caseInfo(testCase);
161: testCase.setName(t.image);
162: testCases.addElement(testCase);
163: }
164:
165: final public void caseInfo(mtTestCase testCase)
166: throws ParseException {
167: String file;
168: String prop = null;
169: int weight = 50;
170: Hashtable errorList = null;
171: String description = null;
172: file = scriptFile();
173: testCase.setFile(file);
174: switch (jj_nt.kind) {
175: case PROPERTIES:
176: prop = propFile();
177: break;
178: default:
179: jj_la1[5] = jj_gen;
180: ;
181: }
182: testCase.setPropFile(prop);
183: switch (jj_nt.kind) {
184: case WEIGHT:
185: weight = weight();
186: break;
187: default:
188: jj_la1[6] = jj_gen;
189: ;
190: }
191: testCase.setWeight(weight);
192: switch (jj_nt.kind) {
193: case IGNOREERRORS:
194: errorList = ignoreErrors();
195: break;
196: default:
197: jj_la1[7] = jj_gen;
198: ;
199: }
200: if (errorList == null)
201: errorList = new Hashtable();
202:
203: testCase.setIgnoreErrors(errorList);
204: switch (jj_nt.kind) {
205: case DESCRIPTION:
206: description = description();
207: break;
208: default:
209: jj_la1[8] = jj_gen;
210: ;
211: }
212: testCase.setDescription(description);
213: }
214:
215: final public String scriptFile() throws ParseException {
216: Token t;
217: jj_consume_token(FILE);
218: t = jj_consume_token(WORD);
219: {
220: if (true)
221: return t.image;
222: }
223: throw new Error("Missing return statement in function");
224: }
225:
226: final public String propFile() throws ParseException {
227: Token t;
228: jj_consume_token(PROPERTIES);
229: t = jj_consume_token(WORD);
230: {
231: if (true)
232: return t.image;
233: }
234: throw new Error("Missing return statement in function");
235: }
236:
237: final public int weight() throws ParseException {
238: Token t;
239: jj_consume_token(WEIGHT);
240: t = jj_consume_token(INT);
241: int val = Integer.decode(t.image).intValue();
242: if (val > 100 || val < 1) {
243: System.out.println("LINE " + t.beginLine + ": Weight '"
244: + t.image + "' is invalid, must be between 1..100"
245: + " -- defaulting to 50.");
246: val = 50;
247: }
248: {
249: if (true)
250: return val;
251: }
252: throw new Error("Missing return statement in function");
253: }
254:
255: final public String description() throws ParseException {
256: Token t;
257: jj_consume_token(DESCRIPTION);
258: t = jj_consume_token(STRING);
259: {
260: if (true)
261: return t.image;
262: }
263: throw new Error("Missing return statement in function");
264: }
265:
266: final public Hashtable ignoreErrors() throws ParseException {
267: // note: we need a non-null errorlist even
268: // if there is nothing in it
269: Hashtable errorList = new Hashtable();
270: jj_consume_token(IGNOREERRORS);
271: getError(errorList);
272: label_4: while (true) {
273: switch (jj_nt.kind) {
274: case COMMA:
275: ;
276: break;
277: default:
278: jj_la1[9] = jj_gen;
279: break label_4;
280: }
281: jj_consume_token(COMMA);
282: getError(errorList);
283: }
284: {
285: if (true)
286: return errorList;
287: }
288: throw new Error("Missing return statement in function");
289: }
290:
291: final public void getError(Hashtable errorList)
292: throws ParseException {
293: String s;
294: s = word_or_int();
295: if (errorList == null) {
296: }
297: errorList.put(s, new Integer(0));
298: }
299:
300: final public String word_or_int() throws ParseException {
301: Token t;
302: switch (jj_nt.kind) {
303: case WORD:
304: t = jj_consume_token(WORD);
305: {
306: if (true)
307: return t.image;
308: }
309: break;
310: case INT:
311: t = jj_consume_token(INT);
312: {
313: if (true)
314: return t.image;
315: }
316: break;
317: default:
318: jj_la1[10] = jj_gen;
319: jj_consume_token(-1);
320: throw new ParseException();
321: }
322: throw new Error("Missing return statement in function");
323: }
324:
325: /*
326: ** Possible formats:
327: **
328: ** HH:MM:SS
329: ** MM:SS
330: ** SS
331: */
332: final public mtTime time() throws ParseException {
333: Token h, m, s;
334: if (jj_2_1(4)) {
335: h = jj_consume_token(INT);
336: jj_consume_token(COLON);
337: m = jj_consume_token(INT);
338: jj_consume_token(COLON);
339: s = jj_consume_token(INT);
340: {
341: if (true)
342: return new mtTime(Integer.decode(h.image)
343: .intValue(), Integer.decode(m.image)
344: .intValue(), Integer.decode(s.image)
345: .intValue());
346: }
347: } else if (jj_2_2(2)) {
348: m = jj_consume_token(INT);
349: jj_consume_token(COLON);
350: s = jj_consume_token(INT);
351: {
352: if (true)
353: return new mtTime(0, Integer.decode(m.image)
354: .intValue(), Integer.decode(s.image)
355: .intValue());
356: }
357: } else {
358: switch (jj_nt.kind) {
359: case INT:
360: s = jj_consume_token(INT);
361: {
362: if (true)
363: return new mtTime(0, 0, Integer.decode(s.image)
364: .intValue());
365: }
366: break;
367: default:
368: jj_la1[11] = jj_gen;
369: jj_consume_token(-1);
370: throw new ParseException();
371: }
372: }
373: throw new Error("Missing return statement in function");
374: }
375:
376: final private boolean jj_2_1(int xla) {
377: jj_la = xla;
378: jj_lastpos = jj_scanpos = token;
379: try {
380: return !jj_3_1();
381: } catch (LookaheadSuccess ls) {
382: return true;
383: } finally {
384: jj_save(0, xla);
385: }
386: }
387:
388: final private boolean jj_2_2(int xla) {
389: jj_la = xla;
390: jj_lastpos = jj_scanpos = token;
391: try {
392: return !jj_3_2();
393: } catch (LookaheadSuccess ls) {
394: return true;
395: } finally {
396: jj_save(1, xla);
397: }
398: }
399:
400: final private boolean jj_3_1() {
401: if (jj_scan_token(INT))
402: return true;
403: if (jj_scan_token(COLON))
404: return true;
405: if (jj_scan_token(INT))
406: return true;
407: if (jj_scan_token(COLON))
408: return true;
409: return false;
410: }
411:
412: final private boolean jj_3_2() {
413: if (jj_scan_token(INT))
414: return true;
415: if (jj_scan_token(COLON))
416: return true;
417: return false;
418: }
419:
420: public mtGrammarTokenManager token_source;
421: SimpleCharStream jj_input_stream;
422: public Token token, jj_nt;
423: private Token jj_scanpos, jj_lastpos;
424: private int jj_la;
425: public boolean lookingAhead = false;
426: private boolean jj_semLA;
427: private int jj_gen;
428: final private int[] jj_la1 = new int[12];
429: static private int[] jj_la1_0;
430: static {
431: jj_la1_0();
432: }
433:
434: private static void jj_la1_0() {
435: jj_la1_0 = new int[] { 0x2000, 0x1000, 0x400, 0x2000, 0x1000,
436: 0x20000, 0x4000, 0x10000, 0x8000, 0x800000, 0x300000,
437: 0x100000, };
438: }
439:
440: final private JJCalls[] jj_2_rtns = new JJCalls[2];
441: private boolean jj_rescan = false;
442: private int jj_gc = 0;
443:
444: public mtGrammar(java.io.InputStream stream) {
445: this (stream, null);
446: }
447:
448: public mtGrammar(java.io.InputStream stream, String encoding) {
449: try {
450: jj_input_stream = new SimpleCharStream(stream, encoding, 1,
451: 1);
452: } catch (java.io.UnsupportedEncodingException e) {
453: throw new RuntimeException(e);
454: }
455: token_source = new mtGrammarTokenManager(jj_input_stream);
456: token = new Token();
457: token.next = jj_nt = token_source.getNextToken();
458: jj_gen = 0;
459: for (int i = 0; i < 12; i++)
460: jj_la1[i] = -1;
461: for (int i = 0; i < jj_2_rtns.length; i++)
462: jj_2_rtns[i] = new JJCalls();
463: }
464:
465: public void ReInit(java.io.InputStream stream) {
466: ReInit(stream, null);
467: }
468:
469: public void ReInit(java.io.InputStream stream, String encoding) {
470: try {
471: jj_input_stream.ReInit(stream, encoding, 1, 1);
472: } catch (java.io.UnsupportedEncodingException e) {
473: throw new RuntimeException(e);
474: }
475: token_source.ReInit(jj_input_stream);
476: token = new Token();
477: token.next = jj_nt = token_source.getNextToken();
478: jj_gen = 0;
479: for (int i = 0; i < 12; i++)
480: jj_la1[i] = -1;
481: for (int i = 0; i < jj_2_rtns.length; i++)
482: jj_2_rtns[i] = new JJCalls();
483: }
484:
485: public mtGrammar(java.io.Reader stream) {
486: jj_input_stream = new SimpleCharStream(stream, 1, 1);
487: token_source = new mtGrammarTokenManager(jj_input_stream);
488: token = new Token();
489: token.next = jj_nt = token_source.getNextToken();
490: jj_gen = 0;
491: for (int i = 0; i < 12; i++)
492: jj_la1[i] = -1;
493: for (int i = 0; i < jj_2_rtns.length; i++)
494: jj_2_rtns[i] = new JJCalls();
495: }
496:
497: public void ReInit(java.io.Reader stream) {
498: jj_input_stream.ReInit(stream, 1, 1);
499: token_source.ReInit(jj_input_stream);
500: token = new Token();
501: token.next = jj_nt = token_source.getNextToken();
502: jj_gen = 0;
503: for (int i = 0; i < 12; i++)
504: jj_la1[i] = -1;
505: for (int i = 0; i < jj_2_rtns.length; i++)
506: jj_2_rtns[i] = new JJCalls();
507: }
508:
509: public mtGrammar(mtGrammarTokenManager tm) {
510: token_source = tm;
511: token = new Token();
512: token.next = jj_nt = token_source.getNextToken();
513: jj_gen = 0;
514: for (int i = 0; i < 12; i++)
515: jj_la1[i] = -1;
516: for (int i = 0; i < jj_2_rtns.length; i++)
517: jj_2_rtns[i] = new JJCalls();
518: }
519:
520: public void ReInit(mtGrammarTokenManager tm) {
521: token_source = tm;
522: token = new Token();
523: token.next = jj_nt = token_source.getNextToken();
524: jj_gen = 0;
525: for (int i = 0; i < 12; i++)
526: jj_la1[i] = -1;
527: for (int i = 0; i < jj_2_rtns.length; i++)
528: jj_2_rtns[i] = new JJCalls();
529: }
530:
531: final private Token jj_consume_token(int kind)
532: throws ParseException {
533: Token oldToken = token;
534: if ((token = jj_nt).next != null)
535: jj_nt = jj_nt.next;
536: else
537: jj_nt = jj_nt.next = token_source.getNextToken();
538: if (token.kind == kind) {
539: jj_gen++;
540: if (++jj_gc > 100) {
541: jj_gc = 0;
542: for (int i = 0; i < jj_2_rtns.length; i++) {
543: JJCalls c = jj_2_rtns[i];
544: while (c != null) {
545: if (c.gen < jj_gen)
546: c.first = null;
547: c = c.next;
548: }
549: }
550: }
551: return token;
552: }
553: jj_nt = token;
554: token = oldToken;
555: jj_kind = kind;
556: throw generateParseException();
557: }
558:
559: static private final class LookaheadSuccess extends java.lang.Error {
560: }
561:
562: final private LookaheadSuccess jj_ls = new LookaheadSuccess();
563:
564: final private boolean jj_scan_token(int kind) {
565: if (jj_scanpos == jj_lastpos) {
566: jj_la--;
567: if (jj_scanpos.next == null) {
568: jj_lastpos = jj_scanpos = jj_scanpos.next = token_source
569: .getNextToken();
570: } else {
571: jj_lastpos = jj_scanpos = jj_scanpos.next;
572: }
573: } else {
574: jj_scanpos = jj_scanpos.next;
575: }
576: if (jj_rescan) {
577: int i = 0;
578: Token tok = token;
579: while (tok != null && tok != jj_scanpos) {
580: i++;
581: tok = tok.next;
582: }
583: if (tok != null)
584: jj_add_error_token(kind, i);
585: }
586: if (jj_scanpos.kind != kind)
587: return true;
588: if (jj_la == 0 && jj_scanpos == jj_lastpos)
589: throw jj_ls;
590: return false;
591: }
592:
593: final public Token getNextToken() {
594: if ((token = jj_nt).next != null)
595: jj_nt = jj_nt.next;
596: else
597: jj_nt = jj_nt.next = token_source.getNextToken();
598: jj_gen++;
599: return token;
600: }
601:
602: final public Token getToken(int index) {
603: Token t = lookingAhead ? jj_scanpos : token;
604: for (int i = 0; i < index; i++) {
605: if (t.next != null)
606: t = t.next;
607: else
608: t = t.next = token_source.getNextToken();
609: }
610: return t;
611: }
612:
613: private java.util.Vector jj_expentries = new java.util.Vector();
614: private int[] jj_expentry;
615: private int jj_kind = -1;
616: private int[] jj_lasttokens = new int[100];
617: private int jj_endpos;
618:
619: private void jj_add_error_token(int kind, int pos) {
620: if (pos >= 100)
621: return;
622: if (pos == jj_endpos + 1) {
623: jj_lasttokens[jj_endpos++] = kind;
624: } else if (jj_endpos != 0) {
625: jj_expentry = new int[jj_endpos];
626: for (int i = 0; i < jj_endpos; i++) {
627: jj_expentry[i] = jj_lasttokens[i];
628: }
629: boolean exists = false;
630: for (java.util.Enumeration e = jj_expentries.elements(); e
631: .hasMoreElements();) {
632: int[] oldentry = (int[]) (e.nextElement());
633: if (oldentry.length == jj_expentry.length) {
634: exists = true;
635: for (int i = 0; i < jj_expentry.length; i++) {
636: if (oldentry[i] != jj_expentry[i]) {
637: exists = false;
638: break;
639: }
640: }
641: if (exists)
642: break;
643: }
644: }
645: if (!exists)
646: jj_expentries.addElement(jj_expentry);
647: if (pos != 0)
648: jj_lasttokens[(jj_endpos = pos) - 1] = kind;
649: }
650: }
651:
652: public ParseException generateParseException() {
653: jj_expentries.removeAllElements();
654: boolean[] la1tokens = new boolean[25];
655: for (int i = 0; i < 25; i++) {
656: la1tokens[i] = false;
657: }
658: if (jj_kind >= 0) {
659: la1tokens[jj_kind] = true;
660: jj_kind = -1;
661: }
662: for (int i = 0; i < 12; i++) {
663: if (jj_la1[i] == jj_gen) {
664: for (int j = 0; j < 32; j++) {
665: if ((jj_la1_0[i] & (1 << j)) != 0) {
666: la1tokens[j] = true;
667: }
668: }
669: }
670: }
671: for (int i = 0; i < 25; i++) {
672: if (la1tokens[i]) {
673: jj_expentry = new int[1];
674: jj_expentry[0] = i;
675: jj_expentries.addElement(jj_expentry);
676: }
677: }
678: jj_endpos = 0;
679: jj_rescan_token();
680: jj_add_error_token(0, 0);
681: int[][] exptokseq = new int[jj_expentries.size()][];
682: for (int i = 0; i < jj_expentries.size(); i++) {
683: exptokseq[i] = (int[]) jj_expentries.elementAt(i);
684: }
685: return new ParseException(token, exptokseq,
686: mtGrammarConstants.tokenImage);
687: }
688:
689: final public void enable_tracing() {
690: }
691:
692: final public void disable_tracing() {
693: }
694:
695: final private void jj_rescan_token() {
696: jj_rescan = true;
697: for (int i = 0; i < 2; i++) {
698: try {
699: JJCalls p = jj_2_rtns[i];
700: do {
701: if (p.gen > jj_gen) {
702: jj_la = p.arg;
703: jj_lastpos = jj_scanpos = p.first;
704: switch (i) {
705: case 0:
706: jj_3_1();
707: break;
708: case 1:
709: jj_3_2();
710: break;
711: }
712: }
713: p = p.next;
714: } while (p != null);
715: } catch (LookaheadSuccess ls) {
716: }
717: }
718: jj_rescan = false;
719: }
720:
721: final private void jj_save(int index, int xla) {
722: JJCalls p = jj_2_rtns[index];
723: while (p.gen > jj_gen) {
724: if (p.next == null) {
725: p = p.next = new JJCalls();
726: break;
727: }
728: p = p.next;
729: }
730: p.gen = jj_gen + xla - jj_la;
731: p.first = token;
732: p.arg = xla;
733: }
734:
735: static final class JJCalls {
736: int gen;
737: Token first;
738: int arg;
739: JJCalls next;
740: }
741:
742: }
|