KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > system > jdbc > parser > SqlGrammar


1 /* Generated By:JavaCC: Do not edit this line. SqlGrammar.java */
2 package org.apache.beehive.controls.system.jdbc.parser;
3 import java.io.StringReader JavaDoc;
4
5 public class SqlGrammar implements SqlGrammarConstants {
6     private StringBuilder JavaDoc buffer = new StringBuilder JavaDoc();
7     public static void main(String JavaDoc[] args) throws Exception JavaDoc
8     {
9         SqlGrammar parser = new SqlGrammar(new StringReader JavaDoc(args[0]));
10         SqlStatement statement = parser.parse();
11         System.out.println(statement.toString());
12     }
13
14 //
15
// Parse methods
16
//
17

18
19 //
20
// Main parse method
21
//
22
final public SqlStatement parse() throws ParseException {
23     SqlStatement statement = new SqlStatement();
24     SqlFragment frag;
25     Token t, sq;
26     label_1:
27     while (true) {
28       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
29       case NON_EXPRESSION_TEXT:
30       case START_EXPRESSION:
31       case SQUOTE:
32         ;
33         break;
34       default:
35         jj_la1[0] = jj_gen;
36         break label_1;
37       }
38       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
39       case NON_EXPRESSION_TEXT:
40         t = jj_consume_token(NON_EXPRESSION_TEXT);
41                                  statement.addChild(new LiteralFragment(t.image));
42         break;
43       case SQUOTE:
44         sq = jj_consume_token(SQUOTE);
45         t = jj_consume_token(STRING_LITERAL);
46                                        statement.addChild(new LiteralFragment(sq.image + t.image));
47         break;
48       case START_EXPRESSION:
49         frag = parseExpression();
50                                 statement.addChild(frag);
51         break;
52       default:
53         jj_la1[1] = jj_gen;
54         jj_consume_token(-1);
55         throw new ParseException();
56       }
57     }
58     jj_consume_token(0);
59       {if (true) return statement;}
60     throw new Error JavaDoc("Missing return statement in function");
61   }
62
63 //
64
// Parse an expression delimited by '{}'
65
//
66
final public SqlFragment parseExpression() throws ParseException {
67     Token t, tt = null;
68     SqlFragment frag = null;
69     jj_consume_token(START_EXPRESSION);
70     label_2:
71     while (true) {
72       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
73       case WHITESPACE:
74         ;
75         break;
76       default:
77         jj_la1[2] = jj_gen;
78         break label_2;
79       }
80       jj_consume_token(WHITESPACE);
81     }
82     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
83     case SQL_ESCAPE:
84     case SQL_SUBST:
85     case SQL_FN:
86       frag = parseSqlEscape();
87       break;
88     case JDBC_CALL:
89     case JDBC_RET:
90     case JDBC_DATE:
91     case JDBC_TIME:
92     case JDBC_TIMESTAMP:
93     case JDBC_FUNCTION:
94     case JDBC_ESCAPE:
95     case JDBC_OUTERJOIN:
96       frag = parseJdbcEscape();
97       break;
98     case IDENTIFIER:
99       t = jj_consume_token(IDENTIFIER);
100       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
101       case REFLECT_SEP:
102         jj_consume_token(REFLECT_SEP);
103         tt = jj_consume_token(IDENTIFIER);
104         break;
105       default:
106         jj_la1[3] = jj_gen;
107         ;
108       }
109       jj_consume_token(END_EXPRESSION);
110                                                                          frag = new ReflectionFragment(t.image,(tt == null) ? null : tt.image);
111       break;
112     default:
113       jj_la1[4] = jj_gen;
114       jj_consume_token(-1);
115       throw new ParseException();
116     }
117     label_3:
118     while (true) {
119       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
120       case WHITESPACE:
121         ;
122         break;
123       default:
124         jj_la1[5] = jj_gen;
125         break label_3;
126       }
127       jj_consume_token(WHITESPACE);
128     }
129      {if (true) return frag;}
130     throw new Error JavaDoc("Missing return statement in function");
131   }
132
133 //
134
// parse an sql: escape sequence
135
//
136
final public SqlSubstitutionFragment parseSqlEscape() throws ParseException {
137     Token id1, id2;
138     Token t = null;
139     SqlSubstitutionFragment frag;
140     String JavaDoc func = null;
141     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
142     case SQL_ESCAPE:
143     case SQL_SUBST:
144       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
145       case SQL_ESCAPE:
146         jj_consume_token(SQL_ESCAPE);
147         break;
148       case SQL_SUBST:
149         jj_consume_token(SQL_SUBST);
150         break;
151       default:
152         jj_la1[6] = jj_gen;
153         jj_consume_token(-1);
154         throw new ParseException();
155       }
156       t = jj_consume_token(IDENTIFIER);
157            if (t != null) {
158              frag = new SqlSubstitutionFragment(new ReflectionFragment(t.image));
159            } else {
160              frag = new SqlSubstitutionFragment(new LiteralFragment(func));
161            }
162       break;
163     case SQL_FN:
164       jj_consume_token(SQL_FN);
165       jj_consume_token(SQL_FN_NM);
166       jj_consume_token(SQL_FN_PAREN);
167       label_4:
168       while (true) {
169         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
170         case SQL_FN_WHITESPACE:
171           ;
172           break;
173         default:
174           jj_la1[7] = jj_gen;
175           break label_4;
176         }
177         jj_consume_token(SQL_FN_WHITESPACE);
178       }
179       id1 = jj_consume_token(SQL_FN_IDENTIFIER);
180       label_5:
181       while (true) {
182         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
183         case SQL_FN_WHITESPACE:
184           ;
185           break;
186         default:
187           jj_la1[8] = jj_gen;
188           break label_5;
189         }
190         jj_consume_token(SQL_FN_WHITESPACE);
191       }
192       jj_consume_token(SQL_FN_COMMA);
193       label_6:
194       while (true) {
195         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
196         case SQL_FN_WHITESPACE:
197           ;
198           break;
199         default:
200           jj_la1[9] = jj_gen;
201           break label_6;
202         }
203         jj_consume_token(SQL_FN_WHITESPACE);
204       }
205       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
206       case SQL_FN_PSTART:
207         t = jj_consume_token(SQL_FN_PSTART);
208         break;
209       default:
210         jj_la1[10] = jj_gen;
211         ;
212       }
213       id2 = jj_consume_token(SQL_FN_IDENTIFIER);
214       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
215       case SQL_FN_PEND:
216         jj_consume_token(SQL_FN_PEND);
217         break;
218       default:
219         jj_la1[11] = jj_gen;
220         ;
221       }
222       label_7:
223       while (true) {
224         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
225         case SQL_FN_WHITESPACE:
226           ;
227           break;
228         default:
229           jj_la1[12] = jj_gen;
230           break label_7;
231         }
232         jj_consume_token(SQL_FN_WHITESPACE);
233       }
234       jj_consume_token(SQL_FN_END);
235          if (t == null) {
236            frag = new SqlSubstitutionFragment(new LiteralFragment("(" + id1.image + " IN (" + id2.image + ")"));
237          } else {
238            frag = new SqlSubstitutionFragment(new LiteralFragment("(" + id1.image + " IN ("),
239                                         new ReflectionFragment(id2.image),
240                                         new LiteralFragment("))"));
241          }
242       break;
243     default:
244       jj_la1[13] = jj_gen;
245       jj_consume_token(-1);
246       throw new ParseException();
247     }
248     jj_consume_token(END_EXPRESSION);
249       {if (true) return frag;}
250     throw new Error JavaDoc("Missing return statement in function");
251   }
252
253 //
254
// parse a param sub inside of a jdbc escape
255
//
256
final public SqlFragment parseReflect() throws ParseException {
257    Token t, tt = null;
258    SqlFragment frag;
259     jj_consume_token(JDBC_PARAM);
260     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
261     case PARAM_IDENTIFIER:
262       t = jj_consume_token(PARAM_IDENTIFIER);
263       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
264       case PARAM_REFLECT_SEP:
265         jj_consume_token(PARAM_REFLECT_SEP);
266         tt = jj_consume_token(IDENTIFIER);
267         break;
268       default:
269         jj_la1[14] = jj_gen;
270         ;
271       }
272             frag = new ReflectionFragment(t.image, (tt == null) ? null : tt.image);
273       break;
274     case PARAM_LITERAL:
275       t = jj_consume_token(PARAM_LITERAL);
276               frag = new LiteralFragment(t.image);
277       break;
278     default:
279       jj_la1[15] = jj_gen;
280       jj_consume_token(-1);
281       throw new ParseException();
282     }
283     jj_consume_token(PARAM_END);
284       {if (true) return frag;}
285     throw new Error JavaDoc("Missing return statement in function");
286   }
287
288 //
289
// parse a jdbc escape sequence
290
//
291
final public JdbcFragment parseJdbcEscape() throws ParseException {
292   Token lit, c;
293   JdbcFragment jfrag = new JdbcFragment();
294   jfrag.addChild(new LiteralFragment("{"));
295   SqlFragment frag = null;
296     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
297     case JDBC_CALL:
298       c = jj_consume_token(JDBC_CALL);
299       break;
300     case JDBC_RET:
301       c = jj_consume_token(JDBC_RET);
302       break;
303     case JDBC_DATE:
304       c = jj_consume_token(JDBC_DATE);
305       break;
306     case JDBC_ESCAPE:
307       c = jj_consume_token(JDBC_ESCAPE);
308       break;
309     case JDBC_FUNCTION:
310       c = jj_consume_token(JDBC_FUNCTION);
311       break;
312     case JDBC_TIME:
313       c = jj_consume_token(JDBC_TIME);
314       break;
315     case JDBC_TIMESTAMP:
316       c = jj_consume_token(JDBC_TIMESTAMP);
317       break;
318     case JDBC_OUTERJOIN:
319       c = jj_consume_token(JDBC_OUTERJOIN);
320       break;
321     default:
322       jj_la1[16] = jj_gen;
323       jj_consume_token(-1);
324       throw new ParseException();
325     }
326          jfrag.addChild(new LiteralFragment(c.image));
327     label_8:
328     while (true) {
329       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
330       case JDBC_LIT:
331         lit = jj_consume_token(JDBC_LIT);
332                            jfrag.addChild(new LiteralFragment(lit.image));
333         break;
334       case JDBC_PARAM:
335         frag = parseReflect();
336                                   jfrag.addChild(frag);
337         break;
338       default:
339         jj_la1[17] = jj_gen;
340         jj_consume_token(-1);
341         throw new ParseException();
342       }
343       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
344       case JDBC_LIT:
345       case JDBC_PARAM:
346         ;
347         break;
348       default:
349         jj_la1[18] = jj_gen;
350         break label_8;
351       }
352     }
353     jj_consume_token(JDBC_END);
354       jfrag.addChild(new LiteralFragment("}"));
355       {if (true) return jfrag;}
356     throw new Error JavaDoc("Missing return statement in function");
357   }
358
359   public SqlGrammarTokenManager token_source;
360   SimpleCharStream jj_input_stream;
361   public Token token, jj_nt;
362   private int jj_ntk;
363   private int jj_gen;
364   final private int[] jj_la1 = new int[19];
365   static private int[] jj_la1_0;
366   static private int[] jj_la1_1;
367   static {
368       jj_la1_0();
369       jj_la1_1();
370    }
371    private static void jj_la1_0() {
372       jj_la1_0 = new int[] {0xe,0xe,0x100000,0x100,0x2ffe00,0x100000,0x600,0x40000000,0x40000000,0x40000000,0x10000000,0x20000000,0x40000000,0xe00,0x0,0x0,0xff000,0x0,0x0,};
373    }
374    private static void jj_la1_1() {
375       jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10,0x28,0x0,0x6,0x6,};
376    }
377
378   public SqlGrammar(java.io.InputStream JavaDoc stream) {
379     jj_input_stream = new SimpleCharStream(stream, 1, 1);
380     token_source = new SqlGrammarTokenManager(jj_input_stream);
381     token = new Token();
382     jj_ntk = -1;
383     jj_gen = 0;
384     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
385   }
386
387   public void ReInit(java.io.InputStream JavaDoc stream) {
388     jj_input_stream.ReInit(stream, 1, 1);
389     token_source.ReInit(jj_input_stream);
390     token = new Token();
391     jj_ntk = -1;
392     jj_gen = 0;
393     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
394   }
395
396   public SqlGrammar(java.io.Reader JavaDoc stream) {
397     jj_input_stream = new SimpleCharStream(stream, 1, 1);
398     token_source = new SqlGrammarTokenManager(jj_input_stream);
399     token = new Token();
400     jj_ntk = -1;
401     jj_gen = 0;
402     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
403   }
404
405   public void ReInit(java.io.Reader JavaDoc stream) {
406     jj_input_stream.ReInit(stream, 1, 1);
407     token_source.ReInit(jj_input_stream);
408     token = new Token();
409     jj_ntk = -1;
410     jj_gen = 0;
411     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
412   }
413
414   public SqlGrammar(SqlGrammarTokenManager tm) {
415     token_source = tm;
416     token = new Token();
417     jj_ntk = -1;
418     jj_gen = 0;
419     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
420   }
421
422   public void ReInit(SqlGrammarTokenManager tm) {
423     token_source = tm;
424     token = new Token();
425     jj_ntk = -1;
426     jj_gen = 0;
427     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
428   }
429
430   final private Token jj_consume_token(int kind) throws ParseException {
431     Token oldToken;
432     if ((oldToken = token).next != null) token = token.next;
433     else token = token.next = token_source.getNextToken();
434     jj_ntk = -1;
435     if (token.kind == kind) {
436       jj_gen++;
437       return token;
438     }
439     token = oldToken;
440     jj_kind = kind;
441     throw generateParseException();
442   }
443
444   final public Token getNextToken() {
445     if (token.next != null) token = token.next;
446     else token = token.next = token_source.getNextToken();
447     jj_ntk = -1;
448     jj_gen++;
449     return token;
450   }
451
452   final public Token getToken(int index) {
453     Token t = token;
454     for (int i = 0; i < index; i++) {
455       if (t.next != null) t = t.next;
456       else t = t.next = token_source.getNextToken();
457     }
458     return t;
459   }
460
461   final private int jj_ntk() {
462     if ((jj_nt=token.next) == null)
463       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
464     else
465       return (jj_ntk = jj_nt.kind);
466   }
467
468   private java.util.Vector JavaDoc jj_expentries = new java.util.Vector JavaDoc();
469   private int[] jj_expentry;
470   private int jj_kind = -1;
471
472   public ParseException generateParseException() {
473     jj_expentries.removeAllElements();
474     boolean[] la1tokens = new boolean[39];
475     for (int i = 0; i < 39; i++) {
476       la1tokens[i] = false;
477     }
478     if (jj_kind >= 0) {
479       la1tokens[jj_kind] = true;
480       jj_kind = -1;
481     }
482     for (int i = 0; i < 19; i++) {
483       if (jj_la1[i] == jj_gen) {
484         for (int j = 0; j < 32; j++) {
485           if ((jj_la1_0[i] & (1<<j)) != 0) {
486             la1tokens[j] = true;
487           }
488           if ((jj_la1_1[i] & (1<<j)) != 0) {
489             la1tokens[32+j] = true;
490           }
491         }
492       }
493     }
494     for (int i = 0; i < 39; i++) {
495       if (la1tokens[i]) {
496         jj_expentry = new int[1];
497         jj_expentry[0] = i;
498         jj_expentries.addElement(jj_expentry);
499       }
500     }
501     int[][] exptokseq = new int[jj_expentries.size()][];
502     for (int i = 0; i < jj_expentries.size(); i++) {
503       exptokseq[i] = (int[])jj_expentries.elementAt(i);
504     }
505     return new ParseException(token, exptokseq, tokenImage);
506   }
507
508   final public void enable_tracing() {
509   }
510
511   final public void disable_tracing() {
512   }
513
514 }
515
Popular Tags