001: package org.zkforge.json.simple.parser;
002:
003: class Yylex {
004: private final int YY_BUFFER_SIZE = 512;
005: private final int YY_F = -1;
006: private final int YY_NO_STATE = -1;
007: private final int YY_NOT_ACCEPT = 0;
008: private final int YY_START = 1;
009: private final int YY_END = 2;
010: private final int YY_NO_ANCHOR = 4;
011: private final int YY_BOL = 65536;
012: private final int YY_EOF = 65537;
013:
014: private StringBuffer sb = new StringBuffer();
015: private java.io.BufferedReader yy_reader;
016: private int yy_buffer_index;
017: private int yy_buffer_read;
018: private int yy_buffer_start;
019: private int yy_buffer_end;
020: private char yy_buffer[];
021: private boolean yy_at_bol;
022: private int yy_lexical_state;
023:
024: Yylex(java.io.Reader reader) {
025: this ();
026: if (null == reader) {
027: throw (new Error("Error: Bad input stream initializer."));
028: }
029: yy_reader = new java.io.BufferedReader(reader);
030: }
031:
032: Yylex(java.io.InputStream instream) {
033: this ();
034: if (null == instream) {
035: throw (new Error("Error: Bad input stream initializer."));
036: }
037: yy_reader = new java.io.BufferedReader(
038: new java.io.InputStreamReader(instream));
039: }
040:
041: private Yylex() {
042: yy_buffer = new char[YY_BUFFER_SIZE];
043: yy_buffer_read = 0;
044: yy_buffer_index = 0;
045: yy_buffer_start = 0;
046: yy_buffer_end = 0;
047: yy_at_bol = true;
048: yy_lexical_state = YYINITIAL;
049: }
050:
051: private boolean yy_eof_done = false;
052: private final int YYINITIAL = 0;
053: private final int STRING_BEGIN = 1;
054: private final int yy_state_dtrans[] = { 0, 39 };
055:
056: private void yybegin(int state) {
057: yy_lexical_state = state;
058: }
059:
060: private int yy_advance() throws java.io.IOException {
061: int next_read;
062: int i;
063: int j;
064:
065: if (yy_buffer_index < yy_buffer_read) {
066: return yy_buffer[yy_buffer_index++];
067: }
068:
069: if (0 != yy_buffer_start) {
070: i = yy_buffer_start;
071: j = 0;
072: while (i < yy_buffer_read) {
073: yy_buffer[j] = yy_buffer[i];
074: ++i;
075: ++j;
076: }
077: yy_buffer_end = yy_buffer_end - yy_buffer_start;
078: yy_buffer_start = 0;
079: yy_buffer_read = j;
080: yy_buffer_index = j;
081: next_read = yy_reader.read(yy_buffer, yy_buffer_read,
082: yy_buffer.length - yy_buffer_read);
083: if (-1 == next_read) {
084: return YY_EOF;
085: }
086: yy_buffer_read = yy_buffer_read + next_read;
087: }
088:
089: while (yy_buffer_index >= yy_buffer_read) {
090: if (yy_buffer_index >= yy_buffer.length) {
091: yy_buffer = yy_double(yy_buffer);
092: }
093: next_read = yy_reader.read(yy_buffer, yy_buffer_read,
094: yy_buffer.length - yy_buffer_read);
095: if (-1 == next_read) {
096: return YY_EOF;
097: }
098: yy_buffer_read = yy_buffer_read + next_read;
099: }
100: return yy_buffer[yy_buffer_index++];
101: }
102:
103: private void yy_move_end() {
104: if (yy_buffer_end > yy_buffer_start
105: && '\n' == yy_buffer[yy_buffer_end - 1])
106: yy_buffer_end--;
107: if (yy_buffer_end > yy_buffer_start
108: && '\r' == yy_buffer[yy_buffer_end - 1])
109: yy_buffer_end--;
110: }
111:
112: private boolean yy_last_was_cr = false;
113:
114: private void yy_mark_start() {
115: yy_buffer_start = yy_buffer_index;
116: }
117:
118: private void yy_mark_end() {
119: yy_buffer_end = yy_buffer_index;
120: }
121:
122: private void yy_to_mark() {
123: yy_buffer_index = yy_buffer_end;
124: yy_at_bol = (yy_buffer_end > yy_buffer_start)
125: && ('\r' == yy_buffer[yy_buffer_end - 1]
126: || '\n' == yy_buffer[yy_buffer_end - 1]
127: || 2028/*LS*/== yy_buffer[yy_buffer_end - 1] || 2029/*PS*/== yy_buffer[yy_buffer_end - 1]);
128: }
129:
130: private java.lang.String yytext() {
131: return (new java.lang.String(yy_buffer, yy_buffer_start,
132: yy_buffer_end - yy_buffer_start));
133: }
134:
135: private int yylength() {
136: return yy_buffer_end - yy_buffer_start;
137: }
138:
139: private char[] yy_double(char buf[]) {
140: int i;
141: char newbuf[];
142: newbuf = new char[2 * buf.length];
143: for (i = 0; i < buf.length; ++i) {
144: newbuf[i] = buf[i];
145: }
146: return newbuf;
147: }
148:
149: private final int YY_E_INTERNAL = 0;
150: private final int YY_E_MATCH = 1;
151: private java.lang.String yy_error_string[] = {
152: "Error: Internal error.\n", "Error: Unmatched input.\n" };
153:
154: private void yy_error(int code, boolean fatal) {
155: java.lang.System.out.print(yy_error_string[code]);
156: java.lang.System.out.flush();
157: if (fatal) {
158: throw new Error("Fatal Error.\n");
159: }
160: }
161:
162: private int[][] unpackFromString(int size1, int size2, String st) {
163: int colonIndex = -1;
164: String lengthString;
165: int sequenceLength = 0;
166: int sequenceInteger = 0;
167:
168: int commaIndex;
169: String workString;
170:
171: int res[][] = new int[size1][size2];
172: for (int i = 0; i < size1; i++) {
173: for (int j = 0; j < size2; j++) {
174: if (sequenceLength != 0) {
175: res[i][j] = sequenceInteger;
176: sequenceLength--;
177: continue;
178: }
179: commaIndex = st.indexOf(',');
180: workString = (commaIndex == -1) ? st : st.substring(0,
181: commaIndex);
182: st = st.substring(commaIndex + 1);
183: colonIndex = workString.indexOf(':');
184: if (colonIndex == -1) {
185: res[i][j] = Integer.parseInt(workString);
186: continue;
187: }
188: lengthString = workString.substring(colonIndex + 1);
189: sequenceLength = Integer.parseInt(lengthString);
190: workString = workString.substring(0, colonIndex);
191: sequenceInteger = Integer.parseInt(workString);
192: res[i][j] = sequenceInteger;
193: sequenceLength--;
194: }
195: }
196: return res;
197: }
198:
199: private int yy_acpt[] = {
200: /* 0 */YY_NOT_ACCEPT,
201: /* 1 */YY_NO_ANCHOR,
202: /* 2 */YY_NO_ANCHOR,
203: /* 3 */YY_NO_ANCHOR,
204: /* 4 */YY_NO_ANCHOR,
205: /* 5 */YY_NO_ANCHOR,
206: /* 6 */YY_NO_ANCHOR,
207: /* 7 */YY_NO_ANCHOR,
208: /* 8 */YY_NO_ANCHOR,
209: /* 9 */YY_NO_ANCHOR,
210: /* 10 */YY_NO_ANCHOR,
211: /* 11 */YY_NO_ANCHOR,
212: /* 12 */YY_NO_ANCHOR,
213: /* 13 */YY_NO_ANCHOR,
214: /* 14 */YY_NO_ANCHOR,
215: /* 15 */YY_NO_ANCHOR,
216: /* 16 */YY_NO_ANCHOR,
217: /* 17 */YY_NO_ANCHOR,
218: /* 18 */YY_NO_ANCHOR,
219: /* 19 */YY_NO_ANCHOR,
220: /* 20 */YY_NO_ANCHOR,
221: /* 21 */YY_NO_ANCHOR,
222: /* 22 */YY_NO_ANCHOR,
223: /* 23 */YY_NO_ANCHOR,
224: /* 24 */YY_NO_ANCHOR,
225: /* 25 */YY_NOT_ACCEPT,
226: /* 26 */YY_NO_ANCHOR,
227: /* 27 */YY_NO_ANCHOR,
228: /* 28 */YY_NOT_ACCEPT,
229: /* 29 */YY_NOT_ACCEPT,
230: /* 30 */YY_NOT_ACCEPT,
231: /* 31 */YY_NOT_ACCEPT,
232: /* 32 */YY_NOT_ACCEPT,
233: /* 33 */YY_NOT_ACCEPT,
234: /* 34 */YY_NOT_ACCEPT,
235: /* 35 */YY_NOT_ACCEPT,
236: /* 36 */YY_NOT_ACCEPT,
237: /* 37 */YY_NOT_ACCEPT,
238: /* 38 */YY_NOT_ACCEPT,
239: /* 39 */YY_NOT_ACCEPT,
240: /* 40 */YY_NOT_ACCEPT,
241: /* 41 */YY_NOT_ACCEPT,
242: /* 42 */YY_NOT_ACCEPT,
243: /* 43 */YY_NOT_ACCEPT,
244: /* 44 */YY_NOT_ACCEPT };
245: private int yy_cmap[] = unpackFromString(
246: 1,
247: 65538,
248: "11:8,27:2,28,11,27,28,11:18,27,11,2,11:8,16,25,12,14,3,13:10,26,11:6,10:4,1"
249: + "5,10,11:20,23,1,24,11:3,18,4,10:2,17,5,11:5,19,11,6,11:3,7,20,8,9,11:5,21,1"
250: + "1,22,11:65410,0:2")[0];
251:
252: private int yy_rmap[] = unpackFromString(1, 45,
253: "0,1:2,2,1:7,3,1:2,4,1:10,5,6,1,7,8,9,10,11,12,13,14,15,16,6,17,18,19,20,21,"
254: + "22")[0];
255:
256: private int yy_nxt[][] = unpackFromString(
257: 23,
258: 29,
259: "1,-1,2,-1:2,25,28,-1,29,-1:3,30,3,-1:7,4,5,6,7,8,9,10:2,-1:42,3,33,34,-1,34"
260: + ",-1:24,11,-1,34,-1,34,-1:12,16,17,18,19,20,21,22,23,40,-1:37,31,-1:23,26,-1"
261: + ":24,42,-1:26,32,-1:34,3,-1:34,35,-1:18,37,-1:32,11,-1:27,38,26,-1:2,38,-1:3"
262: + "2,37,-1:27,12,-1:26,13,-1:11,1,14,15,27:25,-1:5,44:2,-1:4,44,-1:2,44,-1,44,"
263: + "-1,44:2,-1:14,24:2,-1:4,24,-1:2,24,-1,24,-1,24:2,-1:29,36,-1:13,41:2,-1:4,4"
264: + "1,-1:2,41,-1,41,-1,41:2,-1:14,43:2,-1:4,43,-1:2,43,-1,43,-1,43:2,-1:10");
265:
266: public Yytoken yylex() throws java.io.IOException {
267: int yy_lookahead;
268: int yy_anchor = YY_NO_ANCHOR;
269: int yy_state = yy_state_dtrans[yy_lexical_state];
270: int yy_next_state = YY_NO_STATE;
271: int yy_last_accept_state = YY_NO_STATE;
272: boolean yy_initial = true;
273: int yy_this _accept;
274:
275: yy_mark_start();
276: yy_this _accept = yy_acpt[yy_state];
277: if (YY_NOT_ACCEPT != yy_this _accept) {
278: yy_last_accept_state = yy_state;
279: yy_mark_end();
280: }
281: while (true) {
282: if (yy_initial && yy_at_bol)
283: yy_lookahead = YY_BOL;
284: else
285: yy_lookahead = yy_advance();
286: yy_next_state = YY_F;
287: yy_next_state = yy_nxt[yy_rmap[yy_state]][yy_cmap[yy_lookahead]];
288: if (YY_EOF == yy_lookahead && true == yy_initial) {
289: return null;
290: }
291: if (YY_F != yy_next_state) {
292: yy_state = yy_next_state;
293: yy_initial = false;
294: yy_this _accept = yy_acpt[yy_state];
295: if (YY_NOT_ACCEPT != yy_this _accept) {
296: yy_last_accept_state = yy_state;
297: yy_mark_end();
298: }
299: } else {
300: if (YY_NO_STATE == yy_last_accept_state) {
301: throw (new Error("Lexical Error: Unmatched Input."));
302: } else {
303: yy_anchor = yy_acpt[yy_last_accept_state];
304: if (0 != (YY_END & yy_anchor)) {
305: yy_move_end();
306: }
307: yy_to_mark();
308: switch (yy_last_accept_state) {
309: case 1:
310:
311: case -2:
312: break;
313: case 2: {
314: sb.delete(0, sb.length());
315: yybegin(STRING_BEGIN);
316: }
317: case -3:
318: break;
319: case 3: {
320: Long val = Long.valueOf(yytext());
321: return new Yytoken(Yytoken.TYPE_VALUE, val);
322: }
323: case -4:
324: break;
325: case 4: {
326: return new Yytoken(Yytoken.TYPE_LEFT_BRACE,
327: null);
328: }
329: case -5:
330: break;
331: case 5: {
332: return new Yytoken(Yytoken.TYPE_RIGHT_BRACE,
333: null);
334: }
335: case -6:
336: break;
337: case 6: {
338: return new Yytoken(Yytoken.TYPE_LEFT_SQUARE,
339: null);
340: }
341: case -7:
342: break;
343: case 7: {
344: return new Yytoken(Yytoken.TYPE_RIGHT_SQUARE,
345: null);
346: }
347: case -8:
348: break;
349: case 8: {
350: return new Yytoken(Yytoken.TYPE_COMMA, null);
351: }
352: case -9:
353: break;
354: case 9: {
355: return new Yytoken(Yytoken.TYPE_COLON, null);
356: }
357: case -10:
358: break;
359: case 10: {
360: }
361: case -11:
362: break;
363: case 11: {
364: Double val = Double.valueOf(yytext());
365: return new Yytoken(Yytoken.TYPE_VALUE, val);
366: }
367: case -12:
368: break;
369: case 12: {
370: return new Yytoken(Yytoken.TYPE_VALUE, null);
371: }
372: case -13:
373: break;
374: case 13: {
375: Boolean val = Boolean.valueOf(yytext());
376: return new Yytoken(Yytoken.TYPE_VALUE, val);
377: }
378: case -14:
379: break;
380: case 14: {
381: sb.append(yytext());
382: }
383: case -15:
384: break;
385: case 15: {
386: yybegin(YYINITIAL);
387: return new Yytoken(Yytoken.TYPE_VALUE, sb
388: .toString());
389: }
390: case -16:
391: break;
392: case 16: {
393: sb.append('\\');
394: }
395: case -17:
396: break;
397: case 17: {
398: sb.append('"');
399: }
400: case -18:
401: break;
402: case 18: {
403: sb.append('/');
404: }
405: case -19:
406: break;
407: case 19: {
408: sb.append('\b');
409: }
410: case -20:
411: break;
412: case 20: {
413: sb.append('\f');
414: }
415: case -21:
416: break;
417: case 21: {
418: sb.append('\n');
419: }
420: case -22:
421: break;
422: case 22: {
423: sb.append('\r');
424: }
425: case -23:
426: break;
427: case 23: {
428: sb.append('\t');
429: }
430: case -24:
431: break;
432: case 24: {
433: int ch = Integer.parseInt(
434: yytext().substring(2), 16);
435: sb.append((char) ch);
436: }
437: case -25:
438: break;
439: case 26: {
440: Double val = Double.valueOf(yytext());
441: return new Yytoken(Yytoken.TYPE_VALUE, val);
442: }
443: case -26:
444: break;
445: case 27: {
446: sb.append(yytext());
447: }
448: case -27:
449: break;
450: default:
451: yy_error(YY_E_INTERNAL, false);
452: case -1:
453: }
454: yy_initial = true;
455: yy_state = yy_state_dtrans[yy_lexical_state];
456: yy_next_state = YY_NO_STATE;
457: yy_last_accept_state = YY_NO_STATE;
458: yy_mark_start();
459: yy_this_accept = yy_acpt[yy_state];
460: if (YY_NOT_ACCEPT != yy_this_accept) {
461: yy_last_accept_state = yy_state;
462: yy_mark_end();
463: }
464: }
465: }
466: }
467: }
468: }
|