pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / standard / parser / StandardSyntaxParser.java
1 /* Generated By:JavaCC: Do not edit this line. StandardSyntaxParser.java */
2 package org.apache.lucene.queryParser.standard.parser;
3
4 /**
5  * Licensed to the Apache Software Foundation (ASF) under one or more
6  * contributor license agreements.  See the NOTICE file distributed with
7  * this work for additional information regarding copyright ownership.
8  * The ASF licenses this file to You under the Apache License, Version 2.0
9  * (the "License"); you may not use this file except in compliance with
10  * the License.  You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 import java.io.StringReader;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Vector;
25
26 import org.apache.lucene.messages.Message;
27 import org.apache.lucene.messages.MessageImpl;
28 import org.apache.lucene.queryParser.core.QueryNodeError;
29 import org.apache.lucene.queryParser.core.QueryNodeException;
30 import org.apache.lucene.queryParser.core.QueryNodeParseException;
31 import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
32 import org.apache.lucene.queryParser.core.nodes.AndQueryNode;
33 import org.apache.lucene.queryParser.core.nodes.BooleanQueryNode;
34 import org.apache.lucene.queryParser.core.nodes.BoostQueryNode;
35 import org.apache.lucene.queryParser.core.nodes.FieldQueryNode;
36 import org.apache.lucene.queryParser.core.nodes.FuzzyQueryNode;
37 import org.apache.lucene.queryParser.core.nodes.ModifierQueryNode;
38 import org.apache.lucene.queryParser.core.nodes.GroupQueryNode;
39 import org.apache.lucene.queryParser.core.nodes.OpaqueQueryNode;
40 import org.apache.lucene.queryParser.core.nodes.OrQueryNode;
41 import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode;
42 import org.apache.lucene.queryParser.core.nodes.ParametricRangeQueryNode;
43 import org.apache.lucene.queryParser.core.nodes.SlopQueryNode;
44 import org.apache.lucene.queryParser.core.nodes.ProximityQueryNode;
45 import org.apache.lucene.queryParser.core.nodes.QueryNode;
46 import org.apache.lucene.queryParser.core.nodes.QueryNodeImpl;
47 import org.apache.lucene.queryParser.core.nodes.QuotedFieldQueryNode;
48 import org.apache.lucene.queryParser.core.parser.SyntaxParser;
49
50 public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserConstants {
51
52         private static final int CONJ_NONE =0;
53         private static final int CONJ_AND =2;
54         private static final int CONJ_OR =2;
55
56
57    // syntax parser constructor
58    public StandardSyntaxParser() {
59         this(new StringReader(""));
60   }
61      /** Parses a query string, returning a {@link org.apache.lucene.queryParser.core.nodes.QueryNode}.
62      *  @param query  the query string to be parsed.
63      *  @throws ParseException if the parsing fails
64      */
65     public QueryNode parse(CharSequence query, CharSequence field) throws QueryNodeParseException {
66       ReInit(new StringReader(query.toString()));
67       try {
68         // TopLevelQuery is a Query followed by the end-of-input (EOF)
69         QueryNode querynode = TopLevelQuery(field);
70         return querynode;
71       }
72       catch (ParseException tme) {
73             tme.setQuery(query);
74             throw tme;
75       }
76       catch (Error tme) {
77           Message message = new MessageImpl(QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, query, tme.getMessage());
78           QueryNodeParseException e = new QueryNodeParseException(tme);
79             e.setQuery(query);
80             e.setNonLocalizedMessage(message);
81             throw e;
82       }
83     }
84
85 // *   Query  ::= ( Clause )*
86 // *   Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )
87   final public int Conjunction() throws ParseException {
88   int ret = CONJ_NONE;
89     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
90     case AND:
91     case OR:
92       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
93       case AND:
94         jj_consume_token(AND);
95             ret = CONJ_AND;
96         break;
97       case OR:
98         jj_consume_token(OR);
99               ret = CONJ_OR;
100         break;
101       default:
102         jj_la1[0] = jj_gen;
103         jj_consume_token(-1);
104         throw new ParseException();
105       }
106       break;
107     default:
108       jj_la1[1] = jj_gen;
109       ;
110     }
111     {if (true) return ret;}
112     throw new Error("Missing return statement in function");
113   }
114
115   final public ModifierQueryNode.Modifier Modifiers() throws ParseException {
116   ModifierQueryNode.Modifier ret = ModifierQueryNode.Modifier.MOD_NONE;
117     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
118     case NOT:
119     case PLUS:
120     case MINUS:
121       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
122       case PLUS:
123         jj_consume_token(PLUS);
124               ret = ModifierQueryNode.Modifier.MOD_REQ;
125         break;
126       case MINUS:
127         jj_consume_token(MINUS);
128                  ret = ModifierQueryNode.Modifier.MOD_NOT;
129         break;
130       case NOT:
131         jj_consume_token(NOT);
132                ret = ModifierQueryNode.Modifier.MOD_NOT;
133         break;
134       default:
135         jj_la1[2] = jj_gen;
136         jj_consume_token(-1);
137         throw new ParseException();
138       }
139       break;
140     default:
141       jj_la1[3] = jj_gen;
142       ;
143     }
144     {if (true) return ret;}
145     throw new Error("Missing return statement in function");
146   }
147
148 // This makes sure that there is no garbage after the query string
149   final public QueryNode TopLevelQuery(CharSequence field) throws ParseException {
150         QueryNode q;
151     q = Query(field);
152     jj_consume_token(0);
153                 {if (true) return q;}
154     throw new Error("Missing return statement in function");
155   }
156
157 // These changes were made to introduce operator precedence:
158 // - Clause() now returns a QueryNode. 
159 // - The modifiers are consumed by Clause() and returned as part of the QueryNode Object
160 // - Query does not consume conjunctions (AND, OR) anymore. 
161 // - This is now done by two new non-terminals: ConjClause and DisjClause
162 // The parse tree looks similar to this:
163 //       Query ::= DisjQuery ( DisjQuery )*
164 //   DisjQuery ::= ConjQuery ( OR ConjQuery )* 
165 //   ConjQuery ::= Clause ( AND Clause )*
166 //      Clause ::= [ Modifier ] ... 
167   final public QueryNode Query(CharSequence field) throws ParseException {
168   Vector<QueryNode> clauses = null;
169   QueryNode c, first=null;
170     first = DisjQuery(field);
171     label_1:
172     while (true) {
173       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
174       case NOT:
175       case PLUS:
176       case MINUS:
177       case LPAREN:
178       case QUOTED:
179       case TERM:
180       case RANGEIN_START:
181       case RANGEEX_START:
182       case NUMBER:
183         ;
184         break;
185       default:
186         jj_la1[4] = jj_gen;
187         break label_1;
188       }
189       c = DisjQuery(field);
190              if (clauses == null) {
191                  clauses = new Vector<QueryNode>();
192                  clauses.addElement(first);
193              }
194          clauses.addElement(c);
195     }
196         if (clauses != null) {
197                 {if (true) return new BooleanQueryNode(clauses);}
198         } else {
199                 {if (true) return first;}
200         }
201     throw new Error("Missing return statement in function");
202   }
203
204   final public QueryNode DisjQuery(CharSequence field) throws ParseException {
205         QueryNode first, c;
206         Vector<QueryNode> clauses = null;
207     first = ConjQuery(field);
208     label_2:
209     while (true) {
210       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
211       case OR:
212         ;
213         break;
214       default:
215         jj_la1[5] = jj_gen;
216         break label_2;
217       }
218       jj_consume_token(OR);
219       c = ConjQuery(field);
220      if (clauses == null) {
221          clauses = new Vector<QueryNode>();
222          clauses.addElement(first);
223      }
224      clauses.addElement(c);
225     }
226     if (clauses != null) {
227             {if (true) return new OrQueryNode(clauses);}
228     } else {
229         {if (true) return first;}
230     }
231     throw new Error("Missing return statement in function");
232   }
233
234   final public QueryNode ConjQuery(CharSequence field) throws ParseException {
235         QueryNode first, c;
236         Vector<QueryNode> clauses = null;
237     first = ModClause(field);
238     label_3:
239     while (true) {
240       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
241       case AND:
242         ;
243         break;
244       default:
245         jj_la1[6] = jj_gen;
246         break label_3;
247       }
248       jj_consume_token(AND);
249       c = ModClause(field);
250      if (clauses == null) {
251          clauses = new Vector<QueryNode>();
252          clauses.addElement(first);
253      }
254      clauses.addElement(c);
255     }
256     if (clauses != null) {
257             {if (true) return new AndQueryNode(clauses);}
258     } else {
259         {if (true) return first;}
260     }
261     throw new Error("Missing return statement in function");
262   }
263
264 // QueryNode Query(CharSequence field) :
265 // {
266 // List clauses = new ArrayList();
267 //   List modifiers = new ArrayList();
268 //   QueryNode q, firstQuery=null;
269 //   ModifierQueryNode.Modifier mods;
270 //   int conj;
271 // }
272 // {
273 //   mods=Modifiers() q=Clause(field)
274 //   {
275 //     if (mods == ModifierQueryNode.Modifier.MOD_NONE) firstQuery=q;
276 //     
277 //     // do not create modifier nodes with MOD_NONE
278 //      if (mods != ModifierQueryNode.Modifier.MOD_NONE) {
279 //              q = new ModifierQueryNode(q, mods);
280 //      }
281 //      clauses.add(q);
282 //   }
283 //   (
284 //     conj=Conjunction() mods=Modifiers() q=Clause(field)
285 //     { 
286 //          // do not create modifier nodes with MOD_NONE
287 //              if (mods != ModifierQueryNode.Modifier.MOD_NONE) {
288 //                      q = new ModifierQueryNode(q, mods);
289 //              }
290 //              clauses.add(q);
291 //              //TODO: figure out what to do with AND and ORs
292 //   }
293 //   )*
294 //     {
295 //      if (clauses.size() == 1 && firstQuery != null)
296 //         return firstQuery;
297 //       else {
298 //              return new BooleanQueryNode(clauses);
299 //       }
300 //     }
301 // }
302   final public QueryNode ModClause(CharSequence field) throws ParseException {
303   QueryNode q;
304   ModifierQueryNode.Modifier mods;
305     mods = Modifiers();
306     q = Clause(field);
307                 if (mods != ModifierQueryNode.Modifier.MOD_NONE) {
308                         q = new ModifierQueryNode(q, mods);
309                 }
310                 {if (true) return q;}
311     throw new Error("Missing return statement in function");
312   }
313
314   final public QueryNode Clause(CharSequence field) throws ParseException {
315   QueryNode q;
316   Token fieldToken=null, boost=null;
317   boolean group = false;
318     if (jj_2_1(2)) {
319       fieldToken = jj_consume_token(TERM);
320       jj_consume_token(COLON);
321                                field=EscapeQuerySyntaxImpl.discardEscapeChar(fieldToken.image);
322     } else {
323       ;
324     }
325     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
326     case QUOTED:
327     case TERM:
328     case RANGEIN_START:
329     case RANGEEX_START:
330     case NUMBER:
331       q = Term(field);
332       break;
333     case LPAREN:
334       jj_consume_token(LPAREN);
335       q = Query(field);
336       jj_consume_token(RPAREN);
337       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
338       case CARAT:
339         jj_consume_token(CARAT);
340         boost = jj_consume_token(NUMBER);
341         break;
342       default:
343         jj_la1[7] = jj_gen;
344         ;
345       }
346                                                                  group=true;
347       break;
348     default:
349       jj_la1[8] = jj_gen;
350       jj_consume_token(-1);
351       throw new ParseException();
352     }
353       if (boost != null) {
354                   float f = (float)1.0;
355                   try {
356                     f = Float.valueOf(boost.image).floatValue();
357                     // avoid boosting null queries, such as those caused by stop words
358                 if (q != null) {
359                         q = new BoostQueryNode(q, f);
360                 }
361                   } catch (Exception ignored) {
362                         /* Should this be handled somehow? (defaults to "no boost", if
363              * boost number is invalid)
364              */
365                   }
366       }
367       if (group) { q = new GroupQueryNode(q);}
368       {if (true) return q;}
369     throw new Error("Missing return statement in function");
370   }
371
372   final public QueryNode Term(CharSequence field) throws ParseException {
373   Token term, boost=null, fuzzySlop=null, goop1, goop2;
374   boolean fuzzy = false;
375   QueryNode q =null;
376   ParametricQueryNode qLower, qUpper;
377   float defaultMinSimilarity = 0.5f;
378     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
379     case TERM:
380     case NUMBER:
381       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
382       case TERM:
383         term = jj_consume_token(TERM);
384                          q = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn);
385         break;
386       case NUMBER:
387         term = jj_consume_token(NUMBER);
388         break;
389       default:
390         jj_la1[9] = jj_gen;
391         jj_consume_token(-1);
392         throw new ParseException();
393       }
394       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
395       case FUZZY_SLOP:
396         fuzzySlop = jj_consume_token(FUZZY_SLOP);
397                                 fuzzy=true;
398         break;
399       default:
400         jj_la1[10] = jj_gen;
401         ;
402       }
403       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
404       case CARAT:
405         jj_consume_token(CARAT);
406         boost = jj_consume_token(NUMBER);
407         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
408         case FUZZY_SLOP:
409           fuzzySlop = jj_consume_token(FUZZY_SLOP);
410                                                          fuzzy=true;
411           break;
412         default:
413           jj_la1[11] = jj_gen;
414           ;
415         }
416         break;
417       default:
418         jj_la1[12] = jj_gen;
419         ;
420       }
421        if (fuzzy) {
422           float fms = defaultMinSimilarity;
423           try {
424             fms = Float.valueOf(fuzzySlop.image.substring(1)).floatValue();
425           } catch (Exception ignored) { }
426          if(fms < 0.0f || fms > 1.0f){
427            {if (true) throw new ParseException(new MessageImpl(QueryParserMessages.INVALID_SYNTAX_FUZZY_LIMITS));}
428          }
429          q = new FuzzyQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), fms, term.beginColumn, term.endColumn);
430        }
431       break;
432     case RANGEIN_START:
433       jj_consume_token(RANGEIN_START);
434       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
435       case RANGEIN_GOOP:
436         goop1 = jj_consume_token(RANGEIN_GOOP);
437         break;
438       case RANGEIN_QUOTED:
439         goop1 = jj_consume_token(RANGEIN_QUOTED);
440         break;
441       default:
442         jj_la1[13] = jj_gen;
443         jj_consume_token(-1);
444         throw new ParseException();
445       }
446       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
447       case RANGEIN_TO:
448         jj_consume_token(RANGEIN_TO);
449         break;
450       default:
451         jj_la1[14] = jj_gen;
452         ;
453       }
454       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
455       case RANGEIN_GOOP:
456         goop2 = jj_consume_token(RANGEIN_GOOP);
457         break;
458       case RANGEIN_QUOTED:
459         goop2 = jj_consume_token(RANGEIN_QUOTED);
460         break;
461       default:
462         jj_la1[15] = jj_gen;
463         jj_consume_token(-1);
464         throw new ParseException();
465       }
466       jj_consume_token(RANGEIN_END);
467       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
468       case CARAT:
469         jj_consume_token(CARAT);
470         boost = jj_consume_token(NUMBER);
471         break;
472       default:
473         jj_la1[16] = jj_gen;
474         ;
475       }
476           if (goop1.kind == RANGEIN_QUOTED) {
477             goop1.image = goop1.image.substring(1, goop1.image.length()-1);
478           }
479           if (goop2.kind == RANGEIN_QUOTED) {
480             goop2.image = goop2.image.substring(1, goop2.image.length()-1);
481           }
482
483           qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GE,
484                                                EscapeQuerySyntaxImpl.discardEscapeChar(goop1.image), goop1.beginColumn, goop1.endColumn);
485                   qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LE,
486                                                EscapeQuerySyntaxImpl.discardEscapeChar(goop2.image), goop2.beginColumn, goop2.endColumn);
487           q = new ParametricRangeQueryNode(qLower, qUpper);
488       break;
489     case RANGEEX_START:
490       jj_consume_token(RANGEEX_START);
491       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
492       case RANGEEX_GOOP:
493         goop1 = jj_consume_token(RANGEEX_GOOP);
494         break;
495       case RANGEEX_QUOTED:
496         goop1 = jj_consume_token(RANGEEX_QUOTED);
497         break;
498       default:
499         jj_la1[17] = jj_gen;
500         jj_consume_token(-1);
501         throw new ParseException();
502       }
503       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
504       case RANGEEX_TO:
505         jj_consume_token(RANGEEX_TO);
506         break;
507       default:
508         jj_la1[18] = jj_gen;
509         ;
510       }
511       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
512       case RANGEEX_GOOP:
513         goop2 = jj_consume_token(RANGEEX_GOOP);
514         break;
515       case RANGEEX_QUOTED:
516         goop2 = jj_consume_token(RANGEEX_QUOTED);
517         break;
518       default:
519         jj_la1[19] = jj_gen;
520         jj_consume_token(-1);
521         throw new ParseException();
522       }
523       jj_consume_token(RANGEEX_END);
524       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
525       case CARAT:
526         jj_consume_token(CARAT);
527         boost = jj_consume_token(NUMBER);
528         break;
529       default:
530         jj_la1[20] = jj_gen;
531         ;
532       }
533           if (goop1.kind == RANGEEX_QUOTED) {
534             goop1.image = goop1.image.substring(1, goop1.image.length()-1);
535           }
536           if (goop2.kind == RANGEEX_QUOTED) {
537             goop2.image = goop2.image.substring(1, goop2.image.length()-1);
538           }
539           qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GT,
540                                                EscapeQuerySyntaxImpl.discardEscapeChar(goop1.image), goop1.beginColumn, goop1.endColumn);
541                   qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LT,
542                                                EscapeQuerySyntaxImpl.discardEscapeChar(goop2.image), goop2.beginColumn, goop2.endColumn);
543           q = new ParametricRangeQueryNode(qLower, qUpper);
544       break;
545     case QUOTED:
546       term = jj_consume_token(QUOTED);
547                       q = new QuotedFieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image.substring(1, term.image.length()-1)), term.beginColumn + 1, term.endColumn - 1);
548       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
549       case FUZZY_SLOP:
550         fuzzySlop = jj_consume_token(FUZZY_SLOP);
551         break;
552       default:
553         jj_la1[21] = jj_gen;
554         ;
555       }
556       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
557       case CARAT:
558         jj_consume_token(CARAT);
559         boost = jj_consume_token(NUMBER);
560         break;
561       default:
562         jj_la1[22] = jj_gen;
563         ;
564       }
565          int phraseSlop = 0;
566
567          if (fuzzySlop != null) {
568            try {
569              phraseSlop = Float.valueOf(fuzzySlop.image.substring(1)).intValue();
570              q = new SlopQueryNode(q, phraseSlop);
571            }
572            catch (Exception ignored) {
573             /* Should this be handled somehow? (defaults to "no PhraseSlop", if
574                  * slop number is invalid)
575                  */
576            }
577          }
578       break;
579     default:
580       jj_la1[23] = jj_gen;
581       jj_consume_token(-1);
582       throw new ParseException();
583     }
584           if (boost != null) {
585                   float f = (float)1.0;
586                   try {
587                     f = Float.valueOf(boost.image).floatValue();
588                     // avoid boosting null queries, such as those caused by stop words
589                 if (q != null) {
590                         q = new BoostQueryNode(q, f);
591                 }
592                   } catch (Exception ignored) {
593                         /* Should this be handled somehow? (defaults to "no boost", if
594                  * boost number is invalid)
595                  */
596                   }
597           }
598       {if (true) return q;}
599     throw new Error("Missing return statement in function");
600   }
601
602   private boolean jj_2_1(int xla) {
603     jj_la = xla; jj_lastpos = jj_scanpos = token;
604     try { return !jj_3_1(); }
605     catch(LookaheadSuccess ls) { return true; }
606     finally { jj_save(0, xla); }
607   }
608
609   private boolean jj_3_1() {
610     if (jj_scan_token(TERM)) return true;
611     if (jj_scan_token(COLON)) return true;
612     return false;
613   }
614
615   /** Generated Token Manager. */
616   public StandardSyntaxParserTokenManager token_source;
617   JavaCharStream jj_input_stream;
618   /** Current token. */
619   public Token token;
620   /** Next token. */
621   public Token jj_nt;
622   private int jj_ntk;
623   private Token jj_scanpos, jj_lastpos;
624   private int jj_la;
625   private int jj_gen;
626   final private int[] jj_la1 = new int[24];
627   static private int[] jj_la1_0;
628   static {
629       jj_la1_init_0();
630    }
631    private static void jj_la1_init_0() {
632       jj_la1_0 = new int[] {0x300,0x300,0x1c00,0x1c00,0x763c00,0x200,0x100,0x10000,0x762000,0x440000,0x80000,0x80000,0x10000,0x6000000,0x800000,0x6000000,0x10000,0x60000000,0x8000000,0x60000000,0x10000,0x80000,0x10000,0x760000,};
633    }
634   final private JJCalls[] jj_2_rtns = new JJCalls[1];
635   private boolean jj_rescan = false;
636   private int jj_gc = 0;
637
638   /** Constructor with InputStream. */
639   public StandardSyntaxParser(java.io.InputStream stream) {
640      this(stream, null);
641   }
642   /** Constructor with InputStream and supplied encoding */
643   public StandardSyntaxParser(java.io.InputStream stream, String encoding) {
644     try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
645     token_source = new StandardSyntaxParserTokenManager(jj_input_stream);
646     token = new Token();
647     jj_ntk = -1;
648     jj_gen = 0;
649     for (int i = 0; i < 24; i++) jj_la1[i] = -1;
650     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
651   }
652
653   /** Reinitialise. */
654   public void ReInit(java.io.InputStream stream) {
655      ReInit(stream, null);
656   }
657   /** Reinitialise. */
658   public void ReInit(java.io.InputStream stream, String encoding) {
659     try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
660     token_source.ReInit(jj_input_stream);
661     token = new Token();
662     jj_ntk = -1;
663     jj_gen = 0;
664     for (int i = 0; i < 24; i++) jj_la1[i] = -1;
665     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
666   }
667
668   /** Constructor. */
669   public StandardSyntaxParser(java.io.Reader stream) {
670     jj_input_stream = new JavaCharStream(stream, 1, 1);
671     token_source = new StandardSyntaxParserTokenManager(jj_input_stream);
672     token = new Token();
673     jj_ntk = -1;
674     jj_gen = 0;
675     for (int i = 0; i < 24; i++) jj_la1[i] = -1;
676     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
677   }
678
679   /** Reinitialise. */
680   public void ReInit(java.io.Reader stream) {
681     jj_input_stream.ReInit(stream, 1, 1);
682     token_source.ReInit(jj_input_stream);
683     token = new Token();
684     jj_ntk = -1;
685     jj_gen = 0;
686     for (int i = 0; i < 24; i++) jj_la1[i] = -1;
687     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
688   }
689
690   /** Constructor with generated Token Manager. */
691   public StandardSyntaxParser(StandardSyntaxParserTokenManager tm) {
692     token_source = tm;
693     token = new Token();
694     jj_ntk = -1;
695     jj_gen = 0;
696     for (int i = 0; i < 24; i++) jj_la1[i] = -1;
697     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
698   }
699
700   /** Reinitialise. */
701   public void ReInit(StandardSyntaxParserTokenManager tm) {
702     token_source = tm;
703     token = new Token();
704     jj_ntk = -1;
705     jj_gen = 0;
706     for (int i = 0; i < 24; i++) jj_la1[i] = -1;
707     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
708   }
709
710   private Token jj_consume_token(int kind) throws ParseException {
711     Token oldToken;
712     if ((oldToken = token).next != null) token = token.next;
713     else token = token.next = token_source.getNextToken();
714     jj_ntk = -1;
715     if (token.kind == kind) {
716       jj_gen++;
717       if (++jj_gc > 100) {
718         jj_gc = 0;
719         for (int i = 0; i < jj_2_rtns.length; i++) {
720           JJCalls c = jj_2_rtns[i];
721           while (c != null) {
722             if (c.gen < jj_gen) c.first = null;
723             c = c.next;
724           }
725         }
726       }
727       return token;
728     }
729     token = oldToken;
730     jj_kind = kind;
731     throw generateParseException();
732   }
733
734   static private final class LookaheadSuccess extends java.lang.Error { }
735   final private LookaheadSuccess jj_ls = new LookaheadSuccess();
736   private boolean jj_scan_token(int kind) {
737     if (jj_scanpos == jj_lastpos) {
738       jj_la--;
739       if (jj_scanpos.next == null) {
740         jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
741       } else {
742         jj_lastpos = jj_scanpos = jj_scanpos.next;
743       }
744     } else {
745       jj_scanpos = jj_scanpos.next;
746     }
747     if (jj_rescan) {
748       int i = 0; Token tok = token;
749       while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
750       if (tok != null) jj_add_error_token(kind, i);
751     }
752     if (jj_scanpos.kind != kind) return true;
753     if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
754     return false;
755   }
756
757
758 /** Get the next Token. */
759   final public Token getNextToken() {
760     if (token.next != null) token = token.next;
761     else token = token.next = token_source.getNextToken();
762     jj_ntk = -1;
763     jj_gen++;
764     return token;
765   }
766
767 /** Get the specific Token. */
768   final public Token getToken(int index) {
769     Token t = token;
770     for (int i = 0; i < index; i++) {
771       if (t.next != null) t = t.next;
772       else t = t.next = token_source.getNextToken();
773     }
774     return t;
775   }
776
777   private int jj_ntk() {
778     if ((jj_nt=token.next) == null)
779       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
780     else
781       return (jj_ntk = jj_nt.kind);
782   }
783
784   private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
785   private int[] jj_expentry;
786   private int jj_kind = -1;
787   private int[] jj_lasttokens = new int[100];
788   private int jj_endpos;
789
790   private void jj_add_error_token(int kind, int pos) {
791     if (pos >= 100) return;
792     if (pos == jj_endpos + 1) {
793       jj_lasttokens[jj_endpos++] = kind;
794     } else if (jj_endpos != 0) {
795       jj_expentry = new int[jj_endpos];
796       for (int i = 0; i < jj_endpos; i++) {
797         jj_expentry[i] = jj_lasttokens[i];
798       }
799       jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) {
800         int[] oldentry = (int[])(it.next());
801         if (oldentry.length == jj_expentry.length) {
802           for (int i = 0; i < jj_expentry.length; i++) {
803             if (oldentry[i] != jj_expentry[i]) {
804               continue jj_entries_loop;
805             }
806           }
807           jj_expentries.add(jj_expentry);
808           break jj_entries_loop;
809         }
810       }
811       if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
812     }
813   }
814
815   /** Generate ParseException. */
816   public ParseException generateParseException() {
817     jj_expentries.clear();
818     boolean[] la1tokens = new boolean[31];
819     if (jj_kind >= 0) {
820       la1tokens[jj_kind] = true;
821       jj_kind = -1;
822     }
823     for (int i = 0; i < 24; i++) {
824       if (jj_la1[i] == jj_gen) {
825         for (int j = 0; j < 32; j++) {
826           if ((jj_la1_0[i] & (1<<j)) != 0) {
827             la1tokens[j] = true;
828           }
829         }
830       }
831     }
832     for (int i = 0; i < 31; i++) {
833       if (la1tokens[i]) {
834         jj_expentry = new int[1];
835         jj_expentry[0] = i;
836         jj_expentries.add(jj_expentry);
837       }
838     }
839     jj_endpos = 0;
840     jj_rescan_token();
841     jj_add_error_token(0, 0);
842     int[][] exptokseq = new int[jj_expentries.size()][];
843     for (int i = 0; i < jj_expentries.size(); i++) {
844       exptokseq[i] = jj_expentries.get(i);
845     }
846     return new ParseException(token, exptokseq, tokenImage);
847   }
848
849   /** Enable tracing. */
850   final public void enable_tracing() {
851   }
852
853   /** Disable tracing. */
854   final public void disable_tracing() {
855   }
856
857   private void jj_rescan_token() {
858     jj_rescan = true;
859     for (int i = 0; i < 1; i++) {
860     try {
861       JJCalls p = jj_2_rtns[i];
862       do {
863         if (p.gen > jj_gen) {
864           jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
865           switch (i) {
866             case 0: jj_3_1(); break;
867           }
868         }
869         p = p.next;
870       } while (p != null);
871       } catch(LookaheadSuccess ls) { }
872     }
873     jj_rescan = false;
874   }
875
876   private void jj_save(int index, int xla) {
877     JJCalls p = jj_2_rtns[index];
878     while (p.gen > jj_gen) {
879       if (p.next == null) { p = p.next = new JJCalls(); break; }
880       p = p.next;
881     }
882     p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
883   }
884
885   static final class JJCalls {
886     int gen;
887     Token first;
888     int arg;
889     JJCalls next;
890   }
891
892 }