1:
2: package ;
3:
4: import ;
5: import ;
6:
7: import ;
8: import ;
9: import ;
10: import ;
11: import ;
12: import ;
13: import ;
14: import ;
15: import ;
16: import ;
17: import ;
18: import ;
19: import ;
20: import ;
21:
22: public abstract class GeneratedFormulaParser implements GeneratedFormulaParserConstants {
23:
24: protected GeneratedFormulaParser ()
25: {
26: }
27:
28: protected abstract OperatorFactory getOperatorFactory();
29:
30: final public LValue getExpression() throws ParseException {
31: LValue retval = null;
32: Term term = null;
33: retval = getLValue();
34: switch (jj_nt.kind) {
35: case PLUS:
36: case MINUS:
37: case MULT:
38: case DIV:
39: case POW:
40: case EQUALS:
41: case NOT_EQUALS:
42: case LT_EQUALS:
43: case GT_EQUALS:
44: case LT:
45: case GT:
46: case CONCAT:
47: term = startTail(new Term(retval));
48: label_1:
49: while (true) {
50: switch (jj_nt.kind) {
51: case PLUS:
52: case MINUS:
53: case MULT:
54: case DIV:
55: case POW:
56: case EQUALS:
57: case NOT_EQUALS:
58: case LT_EQUALS:
59: case GT_EQUALS:
60: case LT:
61: case GT:
62: case CONCAT:
63: ;
64: break;
65: default:
66: jj_la1[0] = jj_gen;
67: break label_1;
68: }
69: term = startTail(term);
70: }
71: break;
72: default:
73: jj_la1[1] = jj_gen;
74: ;
75: }
76: if (term != null)
77: {
78: {if (true) return term;}
79: }
80: {if (true) return retval;}
81: throw new Error("Missing return statement in function");
82: }
83:
84: final public Term startTail(LValue retval) throws ParseException {
85: LValue val = null;
86: InfixOperator op = null;
87: Term ex = null;
88: op = getInfixOperator();
89: val = getLValue();
90: if (retval instanceof Term)
91: {
92: ex = (Term) retval;
93: }
94: else
95: {
96: ex = new Term (retval);
97: }
98: ex.add (op, val);
99:
100: {if (true) return ex;}
101: throw new Error("Missing return statement in function");
102: }
103:
104: final public LValue getLValue() throws ParseException {
105: Token value = null;
106: LValue retval = null;
107: PrefixOperator prefixOp = null;
108: PostfixOperator postfixOp = null;
109: switch (jj_nt.kind) {
110: case PLUS:
111: case MINUS:
112: prefixOp = getPrefixOperator();
113: break;
114: default:
115: jj_la1[2] = jj_gen;
116: ;
117: }
118: switch (jj_nt.kind) {
119: case COLUMN_LOOKUP:
120: value = jj_consume_token(COLUMN_LOOKUP);
121: retval = new ContextLookup (ParserTools.stripQuote(value.image));
122: break;
123: case STRING_LITERAL:
124: value = jj_consume_token(STRING_LITERAL);
125: retval = new StaticValue (ParserTools.stripQuote(value.image), TextType.TYPE);
126: break;
127: case UNSIGNED_NUMERIC_LITERAL:
128: value = jj_consume_token(UNSIGNED_NUMERIC_LITERAL);
129: retval = new StaticValue (new BigDecimal (value.image), NumberType.GENERIC_NUMBER);
130: break;
131: case UNSIGNED_INTEGER:
132: value = jj_consume_token(UNSIGNED_INTEGER);
133: retval = new StaticValue (new BigDecimal (value.image), NumberType.GENERIC_NUMBER);
134: break;
135: case NULL:
136: jj_consume_token(NULL);
137: retval = new StaticValue (null);
138: break;
139: case L_BRACE:
140: jj_consume_token(L_BRACE);
141: retval = parseArray();
142: jj_consume_token(R_BRACE);
143: break;
144: case IDENTIFIER:
145: value = jj_consume_token(IDENTIFIER);
146: jj_consume_token(L_PAREN);
147: retval = parseFunction(value.image);
148: jj_consume_token(R_PAREN);
149: break;
150: case L_PAREN:
151: jj_consume_token(L_PAREN);
152: retval = getExpression ();
153: jj_consume_token(R_PAREN);
154: if (retval instanceof Term == false)
155: {
156: System.out.println ("AUTOGEN: TERM: " + retval);
157: retval = new Term (retval);
158: }
159: break;
160: default:
161: jj_la1[3] = jj_gen;
162: jj_consume_token(-1);
163: throw new ParseException();
164: }
165: switch (jj_nt.kind) {
166: case PERCENT:
167: postfixOp = getPostfixOperator();
168: break;
169: default:
170: jj_la1[4] = jj_gen;
171: ;
172: }
173: if (postfixOp != null)
174: {
175: retval = new PostfixTerm(retval, postfixOp);
176: }
177: if (prefixOp != null)
178: {
179: retval = new PrefixTerm(prefixOp, retval);
180: }
181: {if (true) return retval;}
182: throw new Error("Missing return statement in function");
183: }
184:
185: final public LValue parseArray() throws ParseException {
186: ArrayList rows = new ArrayList();
187: LValue[] row = null;
188: row = parseRow();
189: rows.add(row);
190: label_2:
191: while (true) {
192: switch (jj_nt.kind) {
193: case PIPE:
194: ;
195: break;
196: default:
197: jj_la1[5] = jj_gen;
198: break label_2;
199: }
200: jj_consume_token(PIPE);
201: row = parseRow();
202:
203:
204: rows.add(row);
205: }
206: LValue[][] table = (LValue[][])rows.toArray(new LValue[rows.size()][]);
207: {if (true) return new DefaultDataTable(table);}
208: throw new Error("Missing return statement in function");
209: }
210:
211: final public LValue[] parseRow() throws ParseException {
212: ArrayList cols = new ArrayList();;
213: LValue column = null;
214: column = getExpression();
215: cols.add(column);
216: label_3:
217: while (true) {
218: switch (jj_nt.kind) {
219: case SEMICOLON:
220: ;
221: break;
222: default:
223: jj_la1[6] = jj_gen;
224: break label_3;
225: }
226: jj_consume_token(SEMICOLON);
227: column = getExpression();
228: cols.add(column);
229: }
230: {if (true) return (LValue[]) cols.toArray(new LValue[cols.size()]);}
231: throw new Error("Missing return statement in function");
232: }
233:
234: final public LValue parseFunction(String name) throws ParseException {
235: ArrayList params = new ArrayList();
236: LValue parameter = null;
237: switch (jj_nt.kind) {
238: case UNSIGNED_INTEGER:
239: case SEMICOLON:
240: case L_PAREN:
241: case L_BRACE:
242: case PLUS:
243: case MINUS:
244: case IDENTIFIER:
245: case COLUMN_LOOKUP:
246: case STRING_LITERAL:
247: case UNSIGNED_NUMERIC_LITERAL:
248: case NULL:
249: switch (jj_nt.kind) {
250: case SEMICOLON:
251: jj_consume_token(SEMICOLON);
252: params.add(new StaticValue(null));
253: break;
254: case UNSIGNED_INTEGER:
255: case L_PAREN:
256: case L_BRACE:
257: case PLUS:
258: case MINUS:
259: case IDENTIFIER:
260: case COLUMN_LOOKUP:
261: case STRING_LITERAL:
262: case UNSIGNED_NUMERIC_LITERAL:
263: case NULL:
264: parameter = getExpression();
265: params.add(parameter);
266: break;
267: default:
268: jj_la1[7] = jj_gen;
269: jj_consume_token(-1);
270: throw new ParseException();
271: }
272: label_4:
273: while (true) {
274: switch (jj_nt.kind) {
275: case SEMICOLON:
276: ;
277: break;
278: default:
279: jj_la1[8] = jj_gen;
280: break label_4;
281: }
282: jj_consume_token(SEMICOLON);
283: switch (jj_nt.kind) {
284: case UNSIGNED_INTEGER:
285: case L_PAREN:
286: case L_BRACE:
287: case PLUS:
288: case MINUS:
289: case IDENTIFIER:
290: case COLUMN_LOOKUP:
291: case STRING_LITERAL:
292: case UNSIGNED_NUMERIC_LITERAL:
293: case NULL:
294: parameter = getExpression();
295: params.add(parameter);
296: break;
297: default:
298: jj_la1[9] = jj_gen;
299: ;
300: }
301: }
302: break;
303: default:
304: jj_la1[10] = jj_gen;
305: ;
306: }
307: if (params == null)
308: {
309: {if (true) return new FormulaFunction(name, new LValue[0]);}
310: }
311:
312: LValue[] paramVals = (LValue[]) params.toArray(new LValue[params.size()]);
313: {if (true) return new FormulaFunction(name, paramVals);}
314: throw new Error("Missing return statement in function");
315: }
316:
317: final public PrefixOperator getPrefixOperator() throws ParseException {
318: Token value = null;
319: switch (jj_nt.kind) {
320: case PLUS:
321: value = jj_consume_token(PLUS);
322: break;
323: case MINUS:
324: value = jj_consume_token(MINUS);
325: break;
326: default:
327: jj_la1[11] = jj_gen;
328: jj_consume_token(-1);
329: throw new ParseException();
330: }
331: {if (true) return getOperatorFactory().createPrefixOperator(value.image);}
332: throw new Error("Missing return statement in function");
333: }
334:
335: final public PostfixOperator getPostfixOperator() throws ParseException {
336: Token value = null;
337: value = jj_consume_token(PERCENT);
338: {if (true) return getOperatorFactory().createPostfixOperator(value.image);}
339: throw new Error("Missing return statement in function");
340: }
341:
342: final public InfixOperator getInfixOperator() throws ParseException {
343: InfixOperator op = null;
344: Token value = null;
345: switch (jj_nt.kind) {
346: case PLUS:
347: value = jj_consume_token(PLUS);
348: break;
349: case MINUS:
350: value = jj_consume_token(MINUS);
351: break;
352: case MULT:
353: value = jj_consume_token(MULT);
354: break;
355: case DIV:
356: value = jj_consume_token(DIV);
357: break;
358: case POW:
359: value = jj_consume_token(POW);
360: break;
361: case EQUALS:
362: value = jj_consume_token(EQUALS);
363: break;
364: case NOT_EQUALS:
365: value = jj_consume_token(NOT_EQUALS);
366: break;
367: case LT_EQUALS:
368: value = jj_consume_token(LT_EQUALS);
369: break;
370: case GT_EQUALS:
371: value = jj_consume_token(GT_EQUALS);
372: break;
373: case LT:
374: value = jj_consume_token(LT);
375: break;
376: case GT:
377: value = jj_consume_token(GT);
378: break;
379: case CONCAT:
380: value = jj_consume_token(CONCAT);
381: break;
382: default:
383: jj_la1[12] = jj_gen;
384: jj_consume_token(-1);
385: throw new ParseException();
386: }
387: {if (true) return getOperatorFactory().createInfixOperator(value.image);}
388: throw new Error("Missing return statement in function");
389: }
390:
391: public GeneratedFormulaParserTokenManager token_source;
392: JavaCharStream jj_input_stream;
393: public Token token, jj_nt;
394: private int jj_gen;
395: final private int[] jj_la1 = new int[13];
396: static private int[] jj_la1_0;
397: static private int[] jj_la1_1;
398: static {
399: jj_la1_0();
400: jj_la1_1();
401: }
402: private static void jj_la1_0() {
403: jj_la1_0 = new int[] {0xf8000000,0xf8000000,0x18000000,0x1080100,0x0,0x4000000,0x40000,0x190c0100,0x40000,0x19080100,0x190c0100,0x18000000,0xf8000000,};
404: }
405: private static void jj_la1_1() {
406: jj_la1_1 = new int[] {0x7f,0x7f,0x0,0x10f00,0x80,0x0,0x0,0x10f00,0x0,0x10f00,0x10f00,0x0,0x7f,};
407: }
408:
409: public GeneratedFormulaParser(java.io.InputStream stream) {
410: this(stream, null);
411: }
412: public GeneratedFormulaParser(java.io.InputStream stream, String encoding) {
413: try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
414: token_source = new GeneratedFormulaParserTokenManager(jj_input_stream);
415: token = new Token();
416: token.next = jj_nt = token_source.getNextToken();
417: jj_gen = 0;
418: for (int i = 0; i < 13; i++) jj_la1[i] = -1;
419: }
420:
421: public void ReInit(java.io.InputStream stream) {
422: ReInit(stream, null);
423: }
424: public void ReInit(java.io.InputStream stream, String encoding) {
425: try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
426: token_source.ReInit(jj_input_stream);
427: token = new Token();
428: token.next = jj_nt = token_source.getNextToken();
429: jj_gen = 0;
430: for (int i = 0; i < 13; i++) jj_la1[i] = -1;
431: }
432:
433: public GeneratedFormulaParser(java.io.Reader stream) {
434: jj_input_stream = new JavaCharStream(stream, 1, 1);
435: token_source = new GeneratedFormulaParserTokenManager(jj_input_stream);
436: token = new Token();
437: token.next = jj_nt = token_source.getNextToken();
438: jj_gen = 0;
439: for (int i = 0; i < 13; i++) jj_la1[i] = -1;
440: }
441:
442: public void ReInit(java.io.Reader stream) {
443: jj_input_stream.ReInit(stream, 1, 1);
444: token_source.ReInit(jj_input_stream);
445: token = new Token();
446: token.next = jj_nt = token_source.getNextToken();
447: jj_gen = 0;
448: for (int i = 0; i < 13; i++) jj_la1[i] = -1;
449: }
450:
451: public GeneratedFormulaParser(GeneratedFormulaParserTokenManager tm) {
452: token_source = tm;
453: token = new Token();
454: token.next = jj_nt = token_source.getNextToken();
455: jj_gen = 0;
456: for (int i = 0; i < 13; i++) jj_la1[i] = -1;
457: }
458:
459: public void ReInit(GeneratedFormulaParserTokenManager tm) {
460: token_source = tm;
461: token = new Token();
462: token.next = jj_nt = token_source.getNextToken();
463: jj_gen = 0;
464: for (int i = 0; i < 13; i++) jj_la1[i] = -1;
465: }
466:
467: final private Token jj_consume_token(int kind) throws ParseException {
468: Token oldToken = token;
469: if ((token = jj_nt).next != null) jj_nt = jj_nt.next;
470: else jj_nt = jj_nt.next = token_source.getNextToken();
471: if (token.kind == kind) {
472: jj_gen++;
473: return token;
474: }
475: jj_nt = token;
476: token = oldToken;
477: jj_kind = kind;
478: throw generateParseException();
479: }
480:
481: final public Token getNextToken() {
482: if ((token = jj_nt).next != null) jj_nt = jj_nt.next;
483: else jj_nt = jj_nt.next = token_source.getNextToken();
484: jj_gen++;
485: return token;
486: }
487:
488: final public Token getToken(int index) {
489: Token t = token;
490: for (int i = 0; i < index; i++) {
491: if (t.next != null) t = t.next;
492: else t = t.next = token_source.getNextToken();
493: }
494: return t;
495: }
496:
497: private java.util.Vector jj_expentries = new java.util.Vector();
498: private int[] jj_expentry;
499: private int jj_kind = -1;
500:
501: public ParseException generateParseException() {
502: jj_expentries.removeAllElements();
503: boolean[] la1tokens = new boolean[49];
504: for (int i = 0; i < 49; i++) {
505: la1tokens[i] = false;
506: }
507: if (jj_kind >= 0) {
508: la1tokens[jj_kind] = true;
509: jj_kind = -1;
510: }
511: for (int i = 0; i < 13; i++) {
512: if (jj_la1[i] == jj_gen) {
513: for (int j = 0; j < 32; j++) {
514: if ((jj_la1_0[i] & (1<<j)) != 0) {
515: la1tokens[j] = true;
516: }
517: if ((jj_la1_1[i] & (1<<j)) != 0) {
518: la1tokens[32+j] = true;
519: }
520: }
521: }
522: }
523: for (int i = 0; i < 49; i++) {
524: if (la1tokens[i]) {
525: jj_expentry = new int[1];
526: jj_expentry[0] = i;
527: jj_expentries.addElement(jj_expentry);
528: }
529: }
530: int[][] exptokseq = new int[jj_expentries.size()][];
531: for (int i = 0; i < jj_expentries.size(); i++) {
532: exptokseq[i] = (int[])jj_expentries.elementAt(i);
533: }
534: return new ParseException(token, exptokseq, tokenImage);
535: }
536:
537: final public void enable_tracing() {
538: }
539:
540: final public void disable_tracing() {
541: }
542:
543: }