source: tags/MetisMQIDemo/src/main/java/weka/core/json/Scanner.java

Last change on this file was 29, checked in by gnappo, 15 years ago

Taggata versione per la demo e aggiunto branch.

File size: 17.9 KB
Line 
1/* The following code was generated by JFlex 1.4.2 on 22/07/09 9:31 PM */
2
3/*
4 *    This program is free software; you can redistribute it and/or modify
5 *    it under the terms of the GNU General Public License as published by
6 *    the Free Software Foundation; either version 2 of the License, or
7 *    (at your option) any later version.
8 *
9 *    This program is distributed in the hope that it will be useful,
10 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *    GNU General Public License for more details.
13 *
14 *    You should have received a copy of the GNU General Public License
15 *    along with this program; if not, write to the Free Software
16 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/*
20 * Scanner.java
21 * Copyright (C) 2009 University of Waikato, Hamilton, New Zealand
22 */
23
24package weka.core.json;
25
26import java_cup.runtime.SymbolFactory;
27import java.io.*;
28
29/**
30 * A scanner for JSON data files.
31 *
32 * @author FracPete (fracpete at waikato dot ac dot nz)
33 * @version $Revision: 5786 $
34 */
35
36public class Scanner implements java_cup.runtime.Scanner {
37
38  /** This character denotes the end of file */
39  public static final int YYEOF = -1;
40
41  /** initial size of the lookahead buffer */
42  private static final int ZZ_BUFFERSIZE = 16384;
43
44  /** lexical states */
45  public static final int STRING = 2;
46  public static final int YYINITIAL = 0;
47
48  /**
49   * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
50   * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
51   *                  at the beginning of a line
52   * l is of the form l = 2*k, k a non negative integer
53   */
54  private static final int ZZ_LEXSTATE[] = { 
55     0,  0,  1, 1
56  };
57
58  /**
59   * Translates characters to character classes
60   */
61  private static final char [] ZZ_CMAP = {
62     0,  0,  0,  0,  0,  0,  0,  0,  0, 20, 24,  0, 20, 22,  0,  0, 
63     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 
64    20,  0, 19,  0,  0,  0,  0,  0,  0,  0,  0,  0,  5, 18, 17,  0, 
65    16, 16, 16, 16, 16, 16, 16, 16, 16, 16,  6,  0,  0,  0,  0,  0, 
66     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 
67     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  3, 21,  4,  0,  0, 
68     0, 14, 23,  0,  0, 12, 13,  0,  0,  0,  0,  0,  9,  0,  7,  0, 
69     0,  0, 11, 15, 10,  8,  0,  0,  0,  0,  0,  1,  0,  2,  0,  0
70  };
71
72  /**
73   * Translates DFA states to action switch labels.
74   */
75  private static final int [] ZZ_ACTION = zzUnpackAction();
76
77  private static final String ZZ_ACTION_PACKED_0 =
78    "\2\0\1\1\1\2\1\3\1\4\1\5\1\6\1\7"+
79    "\3\1\1\10\1\1\1\11\1\12\1\13\1\14\1\15"+
80    "\3\0\2\16\1\17\1\20\1\21\1\22\1\23\1\24"+
81    "\3\0\1\25\1\26";
82
83  private static int [] zzUnpackAction() {
84    int [] result = new int[35];
85    int offset = 0;
86    offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
87    return result;
88  }
89
90  private static int zzUnpackAction(String packed, int offset, int [] result) {
91    int i = 0;       /* index in packed string  */
92    int j = offset;  /* index in unpacked array */
93    int l = packed.length();
94    while (i < l) {
95      int count = packed.charAt(i++);
96      int value = packed.charAt(i++);
97      do result[j++] = value; while (--count > 0);
98    }
99    return j;
100  }
101
102
103  /**
104   * Translates a state to a row index in the transition table
105   */
106  private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
107
108  private static final String ZZ_ROWMAP_PACKED_0 =
109    "\0\0\0\31\0\62\0\62\0\62\0\62\0\62\0\62"+
110    "\0\62\0\113\0\144\0\175\0\226\0\257\0\62\0\62"+
111    "\0\310\0\62\0\341\0\372\0\u0113\0\u012c\0\u0145\0\u015e"+
112    "\0\62\0\62\0\62\0\62\0\62\0\62\0\u0177\0\u0190"+
113    "\0\u01a9\0\62\0\62";
114
115  private static int [] zzUnpackRowMap() {
116    int [] result = new int[35];
117    int offset = 0;
118    offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
119    return result;
120  }
121
122  private static int zzUnpackRowMap(String packed, int offset, int [] result) {
123    int i = 0;  /* index in packed string  */
124    int j = offset;  /* index in unpacked array */
125    int l = packed.length();
126    while (i < l) {
127      int high = packed.charAt(i++) << 16;
128      result[j++] = high | packed.charAt(i++);
129    }
130    return j;
131  }
132
133  /**
134   * The transition table of the DFA
135   */
136  private static final int [] ZZ_TRANS = zzUnpackTrans();
137
138  private static final String ZZ_TRANS_PACKED_0 =
139    "\1\3\1\4\1\5\1\6\1\7\1\10\1\11\1\12"+
140    "\2\3\1\13\2\3\1\14\2\3\1\15\1\3\1\16"+
141    "\1\17\1\20\1\3\1\20\1\3\1\20\23\21\1\22"+
142    "\1\21\1\23\1\3\1\21\42\0\1\24\33\0\1\25"+
143    "\33\0\1\26\32\0\1\15\1\27\27\0\1\30\10\0"+
144    "\23\21\1\0\1\21\2\0\1\21\10\0\1\31\2\0"+
145    "\1\32\1\33\1\0\1\34\5\0\1\35\3\0\1\36"+
146    "\12\0\1\37\27\0\1\40\31\0\1\41\37\0\1\27"+
147    "\30\0\1\30\1\27\20\0\1\42\33\0\1\43\33\0"+
148    "\1\40\11\0";
149
150  private static int [] zzUnpackTrans() {
151    int [] result = new int[450];
152    int offset = 0;
153    offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
154    return result;
155  }
156
157  private static int zzUnpackTrans(String packed, int offset, int [] result) {
158    int i = 0;       /* index in packed string  */
159    int j = offset;  /* index in unpacked array */
160    int l = packed.length();
161    while (i < l) {
162      int count = packed.charAt(i++);
163      int value = packed.charAt(i++);
164      value--;
165      do result[j++] = value; while (--count > 0);
166    }
167    return j;
168  }
169
170
171  /* error codes */
172  private static final int ZZ_UNKNOWN_ERROR = 0;
173  private static final int ZZ_NO_MATCH = 1;
174  private static final int ZZ_PUSHBACK_2BIG = 2;
175
176  /* error messages for the codes above */
177  private static final String ZZ_ERROR_MSG[] = {
178    "Unkown internal scanner error",
179    "Error: could not match input",
180    "Error: pushback value was too large"
181  };
182
183  /**
184   * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
185   */
186  private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
187
188  private static final String ZZ_ATTRIBUTE_PACKED_0 =
189    "\2\0\7\11\5\1\2\11\1\1\1\11\1\1\3\0"+
190    "\2\1\6\11\3\0\2\11";
191
192  private static int [] zzUnpackAttribute() {
193    int [] result = new int[35];
194    int offset = 0;
195    offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
196    return result;
197  }
198
199  private static int zzUnpackAttribute(String packed, int offset, int [] result) {
200    int i = 0;       /* index in packed string  */
201    int j = offset;  /* index in unpacked array */
202    int l = packed.length();
203    while (i < l) {
204      int count = packed.charAt(i++);
205      int value = packed.charAt(i++);
206      do result[j++] = value; while (--count > 0);
207    }
208    return j;
209  }
210
211  /** the input device */
212  private java.io.Reader zzReader;
213
214  /** the current state of the DFA */
215  private int zzState;
216
217  /** the current lexical state */
218  private int zzLexicalState = YYINITIAL;
219
220  /** this buffer contains the current text to be matched and is
221      the source of the yytext() string */
222  private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
223
224  /** the textposition at the last accepting state */
225  private int zzMarkedPos;
226
227  /** the current text position in the buffer */
228  private int zzCurrentPos;
229
230  /** startRead marks the beginning of the yytext() string in the buffer */
231  private int zzStartRead;
232
233  /** endRead marks the last character in the buffer, that has been read
234      from input */
235  private int zzEndRead;
236
237  /** number of newlines encountered up to the start of the matched text */
238  private int yyline;
239
240  /** the number of characters up to the start of the matched text */
241  private int yychar;
242
243  /**
244   * the number of characters from the last newline up to the start of the
245   * matched text
246   */
247  private int yycolumn;
248
249  /**
250   * zzAtBOL == true <=> the scanner is currently at the beginning of a line
251   */
252  private boolean zzAtBOL = true;
253
254  /** zzAtEOF == true <=> the scanner is at the EOF */
255  private boolean zzAtEOF;
256
257  /* user code: */
258  // Author: FracPete (fracpete at waikato dot ac dot nz)
259  // Version: $Revision: 5786 $
260  protected SymbolFactory m_SF;
261
262  protected StringBuffer m_String = new StringBuffer();
263
264  public Scanner(InputStream r, SymbolFactory sf) {
265    this(r);
266    m_SF = sf;
267  }
268
269  public Scanner(Reader r, SymbolFactory sf) {
270    this(r);
271    m_SF = sf;
272  }
273
274
275  /**
276   * Creates a new scanner
277   * There is also a java.io.InputStream version of this constructor.
278   *
279   * @param   in  the java.io.Reader to read input from.
280   */
281  public Scanner(java.io.Reader in) {
282    this.zzReader = in;
283  }
284
285  /**
286   * Creates a new scanner.
287   * There is also java.io.Reader version of this constructor.
288   *
289   * @param   in  the java.io.Inputstream to read input from.
290   */
291  public Scanner(java.io.InputStream in) {
292    this(new java.io.InputStreamReader(in));
293  }
294
295
296  /**
297   * Refills the input buffer.
298   *
299   * @return      <code>false</code>, iff there was new input.
300   *
301   * @exception   java.io.IOException  if any I/O-Error occurs
302   */
303  private boolean zzRefill() throws java.io.IOException {
304
305    /* first: make room (if you can) */
306    if (zzStartRead > 0) {
307      System.arraycopy(zzBuffer, zzStartRead,
308                       zzBuffer, 0,
309                       zzEndRead-zzStartRead);
310
311      /* translate stored positions */
312      zzEndRead-= zzStartRead;
313      zzCurrentPos-= zzStartRead;
314      zzMarkedPos-= zzStartRead;
315      zzStartRead = 0;
316    }
317
318    /* is the buffer big enough? */
319    if (zzCurrentPos >= zzBuffer.length) {
320      /* if not: blow it up */
321      char newBuffer[] = new char[zzCurrentPos*2];
322      System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
323      zzBuffer = newBuffer;
324    }
325
326    /* finally: fill the buffer with new input */
327    int numRead = zzReader.read(zzBuffer, zzEndRead,
328                                            zzBuffer.length-zzEndRead);
329
330    if (numRead > 0) {
331      zzEndRead+= numRead;
332      return false;
333    }
334    // unlikely but not impossible: read 0 characters, but not at end of stream   
335    if (numRead == 0) {
336      int c = zzReader.read();
337      if (c == -1) {
338        return true;
339      } else {
340        zzBuffer[zzEndRead++] = (char) c;
341        return false;
342      }     
343    }
344
345        // numRead < 0
346    return true;
347  }
348
349   
350  /**
351   * Closes the input stream.
352   */
353  public final void yyclose() throws java.io.IOException {
354    zzAtEOF = true;            /* indicate end of file */
355    zzEndRead = zzStartRead;  /* invalidate buffer    */
356
357    if (zzReader != null)
358      zzReader.close();
359  }
360
361
362  /**
363   * Resets the scanner to read from a new input stream.
364   * Does not close the old reader.
365   *
366   * All internal variables are reset, the old input stream
367   * <b>cannot</b> be reused (internal buffer is discarded and lost).
368   * Lexical state is set to <tt>ZZ_INITIAL</tt>.
369   *
370   * @param reader   the new input stream
371   */
372  public final void yyreset(java.io.Reader reader) {
373    zzReader = reader;
374    zzAtBOL  = true;
375    zzAtEOF  = false;
376    zzEndRead = zzStartRead = 0;
377    zzCurrentPos = zzMarkedPos = 0;
378    yyline = yychar = yycolumn = 0;
379    zzLexicalState = YYINITIAL;
380  }
381
382
383  /**
384   * Returns the current lexical state.
385   */
386  public final int yystate() {
387    return zzLexicalState;
388  }
389
390
391  /**
392   * Enters a new lexical state
393   *
394   * @param newState the new lexical state
395   */
396  public final void yybegin(int newState) {
397    zzLexicalState = newState;
398  }
399
400
401  /**
402   * Returns the text matched by the current regular expression.
403   */
404  public final String yytext() {
405    return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
406  }
407
408
409  /**
410   * Returns the character at position <tt>pos</tt> from the
411   * matched text.
412   *
413   * It is equivalent to yytext().charAt(pos), but faster
414   *
415   * @param pos the position of the character to fetch.
416   *            A value from 0 to yylength()-1.
417   *
418   * @return the character at position pos
419   */
420  public final char yycharat(int pos) {
421    return zzBuffer[zzStartRead+pos];
422  }
423
424
425  /**
426   * Returns the length of the matched text region.
427   */
428  public final int yylength() {
429    return zzMarkedPos-zzStartRead;
430  }
431
432
433  /**
434   * Reports an error that occured while scanning.
435   *
436   * In a wellformed scanner (no or only correct usage of
437   * yypushback(int) and a match-all fallback rule) this method
438   * will only be called with things that "Can't Possibly Happen".
439   * If this method is called, something is seriously wrong
440   * (e.g. a JFlex bug producing a faulty scanner etc.).
441   *
442   * Usual syntax/scanner level error handling should be done
443   * in error fallback rules.
444   *
445   * @param   errorCode  the code of the errormessage to display
446   */
447  private void zzScanError(int errorCode) {
448    String message;
449    try {
450      message = ZZ_ERROR_MSG[errorCode];
451    }
452    catch (ArrayIndexOutOfBoundsException e) {
453      message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
454    }
455
456    throw new Error(message);
457  } 
458
459
460  /**
461   * Pushes the specified amount of characters back into the input stream.
462   *
463   * They will be read again by then next call of the scanning method
464   *
465   * @param number  the number of characters to be read again.
466   *                This number must not be greater than yylength()!
467   */
468  public void yypushback(int number)  {
469    if ( number > yylength() )
470      zzScanError(ZZ_PUSHBACK_2BIG);
471
472    zzMarkedPos -= number;
473  }
474
475
476  /**
477   * Resumes scanning until the next regular expression is matched,
478   * the end of input is encountered or an I/O-Error occurs.
479   *
480   * @return      the next token
481   * @exception   java.io.IOException  if any I/O-Error occurs
482   */
483  public java_cup.runtime.Symbol next_token() throws java.io.IOException {
484    int zzInput;
485    int zzAction;
486
487    // cached fields:
488    int zzCurrentPosL;
489    int zzMarkedPosL;
490    int zzEndReadL = zzEndRead;
491    char [] zzBufferL = zzBuffer;
492    char [] zzCMapL = ZZ_CMAP;
493
494    int [] zzTransL = ZZ_TRANS;
495    int [] zzRowMapL = ZZ_ROWMAP;
496    int [] zzAttrL = ZZ_ATTRIBUTE;
497
498    while (true) {
499      zzMarkedPosL = zzMarkedPos;
500
501      zzAction = -1;
502
503      zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
504 
505      zzState = ZZ_LEXSTATE[zzLexicalState];
506
507
508      zzForAction: {
509        while (true) {
510   
511          if (zzCurrentPosL < zzEndReadL)
512            zzInput = zzBufferL[zzCurrentPosL++];
513          else if (zzAtEOF) {
514            zzInput = YYEOF;
515            break zzForAction;
516          }
517          else {
518            // store back cached positions
519            zzCurrentPos  = zzCurrentPosL;
520            zzMarkedPos   = zzMarkedPosL;
521            boolean eof = zzRefill();
522            // get translated positions and possibly new buffer
523            zzCurrentPosL  = zzCurrentPos;
524            zzMarkedPosL   = zzMarkedPos;
525            zzBufferL      = zzBuffer;
526            zzEndReadL     = zzEndRead;
527            if (eof) {
528              zzInput = YYEOF;
529              break zzForAction;
530            }
531            else {
532              zzInput = zzBufferL[zzCurrentPosL++];
533            }
534          }
535          int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
536          if (zzNext == -1) break zzForAction;
537          zzState = zzNext;
538
539          int zzAttributes = zzAttrL[zzState];
540          if ( (zzAttributes & 1) == 1 ) {
541            zzAction = zzState;
542            zzMarkedPosL = zzCurrentPosL;
543            if ( (zzAttributes & 8) == 8 ) break zzForAction;
544          }
545
546        }
547      }
548
549      // store back cached position
550      zzMarkedPos = zzMarkedPosL;
551
552      switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
553        case 20: 
554          { m_String.append('\b');
555          }
556        case 23: break;
557        case 7: 
558          { return m_SF.newSymbol("Colon", sym.COLON);
559          }
560        case 24: break;
561        case 13: 
562          { m_String.append('\\');
563          }
564        case 25: break;
565        case 22: 
566          { return m_SF.newSymbol("Boolean", sym.BOOLEAN, new Boolean(yytext()));
567          }
568        case 26: break;
569        case 14: 
570          { return m_SF.newSymbol("Double", sym.DOUBLE, new Double(yytext()));
571          }
572        case 27: break;
573        case 17: 
574          { m_String.append('\r');
575          }
576        case 28: break;
577        case 3: 
578          { return m_SF.newSymbol("Right curly bracket", sym.RCURLY);
579          }
580        case 29: break;
581        case 19: 
582          { m_String.append('\"');
583          }
584        case 30: break;
585        case 1: 
586          { System.err.println("Illegal character: " + yytext());
587          }
588        case 31: break;
589        case 18: 
590          { m_String.append('\f');
591          }
592        case 32: break;
593        case 21: 
594          { return m_SF.newSymbol("Null", sym.NULL);
595          }
596        case 33: break;
597        case 16: 
598          { m_String.append('\t');
599          }
600        case 34: break;
601        case 4: 
602          { return m_SF.newSymbol("Left square bracket", sym.LSQUARE);
603          }
604        case 35: break;
605        case 12: 
606          { yybegin(YYINITIAL); return m_SF.newSymbol("String", sym.STRING, m_String.toString());
607          }
608        case 36: break;
609        case 15: 
610          { m_String.append('\n');
611          }
612        case 37: break;
613        case 2: 
614          { return m_SF.newSymbol("Left curly bracket", sym.LCURLY);
615          }
616        case 38: break;
617        case 6: 
618          { return m_SF.newSymbol("Comma", sym.COMMA);
619          }
620        case 39: break;
621        case 8: 
622          { return m_SF.newSymbol("Integer", sym.INTEGER, new Integer(yytext()));
623          }
624        case 40: break;
625        case 9: 
626          { m_String.setLength(0); yybegin(STRING);
627          }
628        case 41: break;
629        case 11: 
630          { m_String.append(yytext());
631          }
632        case 42: break;
633        case 10: 
634          { /* ignore white space. */
635          }
636        case 43: break;
637        case 5: 
638          { return m_SF.newSymbol("Right square bracket", sym.RSQUARE);
639          }
640        case 44: break;
641        default: 
642          if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
643            zzAtEOF = true;
644              {     return m_SF.newSymbol("EOF", sym.EOF);
645 }
646          } 
647          else {
648            zzScanError(ZZ_NO_MATCH);
649          }
650      }
651    }
652  }
653
654
655}
Note: See TracBrowser for help on using the repository browser.