]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/parser/grammar/input/GrammarLexer.java
Moved SCL parser generator to platform repository.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / parser / grammar / input / GrammarLexer.java
1 /* The following code was generated by JFlex 1.6.1 */
2
3 package org.simantics.scl.compiler.parser.grammar.input;
4
5 import org.simantics.scl.compiler.parser.grammar.input.Token;
6
7
8 /**
9  * This class is a scanner generated by 
10  * <a href="http://www.jflex.de/">JFlex</a> 1.6.1
11  * from the specification file <tt>C:/Users/hannu/git/scl/org.simantics.parser/src/org/simantics/parser/grammar/input2/GrammarLexer.flex</tt>
12  */
13 public class GrammarLexer {
14
15   /** This character denotes the end of file */
16   public static final int YYEOF = -1;
17
18   /** initial size of the lookahead buffer */
19   private static final int ZZ_BUFFERSIZE = 16384;
20
21   /** lexical states */
22   public static final int YYINITIAL = 0;
23
24   /**
25    * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
26    * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
27    *                  at the beginning of a line
28    * l is of the form l = 2*k, k a non negative integer
29    */
30   private static final int ZZ_LEXSTATE[] = { 
31      0, 0
32   };
33
34   /** 
35    * Translates characters to character classes
36    */
37   private static final String ZZ_CMAP_PACKED = 
38     "\11\0\1\4\1\6\1\36\1\36\1\6\22\0\1\4\2\0\1\13"+
39     "\4\0\1\15\1\16\1\7\1\17\1\14\2\0\1\5\12\1\1\0"+
40     "\1\12\1\0\1\10\1\0\1\20\1\0\32\3\4\0\1\1\1\0"+
41     "\1\24\1\2\1\35\1\33\1\32\1\30\1\2\1\27\1\21\2\2"+
42     "\1\25\1\2\1\22\3\2\1\31\1\26\1\23\1\34\5\2\1\0"+
43     "\1\11\10\0\1\36\u1fa2\0\1\36\1\36\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\udfe6\0";
44
45   /** 
46    * Translates characters to character classes
47    */
48   private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
49
50   /** 
51    * Translates DFA states to action switch labels.
52    */
53   private static final int [] ZZ_ACTION = zzUnpackAction();
54
55   private static final String ZZ_ACTION_PACKED_0 =
56     "\1\0\1\1\1\2\1\3\1\4\1\1\1\5\1\6"+
57     "\1\7\1\10\1\11\1\12\1\13\1\14\1\15\1\16"+
58     "\3\2\1\4\1\0\3\2\1\0\3\2\1\4\4\2"+
59     "\1\17\2\2\1\20\1\21";
60
61   private static int [] zzUnpackAction() {
62     int [] result = new int[38];
63     int offset = 0;
64     offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
65     return result;
66   }
67
68   private static int zzUnpackAction(String packed, int offset, int [] result) {
69     int i = 0;       /* index in packed string  */
70     int j = offset;  /* index in unpacked array */
71     int l = packed.length();
72     while (i < l) {
73       int count = packed.charAt(i++);
74       int value = packed.charAt(i++);
75       do result[j++] = value; while (--count > 0);
76     }
77     return j;
78   }
79
80
81   /** 
82    * Translates a state to a row index in the transition table
83    */
84   private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
85
86   private static final String ZZ_ROWMAP_PACKED_0 =
87     "\0\0\0\37\0\76\0\135\0\174\0\233\0\37\0\37"+
88     "\0\37\0\37\0\37\0\37\0\37\0\37\0\37\0\37"+
89     "\0\272\0\331\0\370\0\u0117\0\u0136\0\u0155\0\u0174\0\u0193"+
90     "\0\u01b2\0\u01d1\0\u01f0\0\u020f\0\37\0\u022e\0\u024d\0\u026c"+
91     "\0\u028b\0\76\0\u02aa\0\u02c9\0\76\0\76";
92
93   private static int [] zzUnpackRowMap() {
94     int [] result = new int[38];
95     int offset = 0;
96     offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
97     return result;
98   }
99
100   private static int zzUnpackRowMap(String packed, int offset, int [] result) {
101     int i = 0;  /* index in packed string  */
102     int j = offset;  /* index in unpacked array */
103     int l = packed.length();
104     while (i < l) {
105       int high = packed.charAt(i++) << 16;
106       result[j++] = high | packed.charAt(i++);
107     }
108     return j;
109   }
110
111   /** 
112    * The transition table of the DFA
113    */
114   private static final int [] ZZ_TRANS = zzUnpackTrans();
115
116   private static final String ZZ_TRANS_PACKED_0 =
117     "\2\2\1\3\1\4\1\5\1\6\1\5\1\7\1\10"+
118     "\1\11\1\12\1\13\1\14\1\15\1\16\1\17\1\20"+
119     "\1\21\4\3\1\22\2\3\1\23\4\3\41\0\3\3"+
120     "\15\0\15\3\2\0\3\4\15\0\15\4\5\0\1\5"+
121     "\1\0\1\5\35\0\1\24\1\0\1\25\30\0\3\3"+
122     "\15\0\1\3\1\26\13\3\2\0\3\3\15\0\6\3"+
123     "\1\27\6\3\2\0\3\3\15\0\11\3\1\30\3\3"+
124     "\1\0\6\24\1\0\30\24\7\25\1\31\27\25\1\0"+
125     "\3\3\15\0\1\32\14\3\2\0\3\3\15\0\1\33"+
126     "\14\3\2\0\3\3\15\0\12\3\1\34\2\3\1\0"+
127     "\5\25\1\35\1\25\1\31\27\25\1\0\3\3\15\0"+
128     "\2\3\1\36\12\3\2\0\3\3\15\0\7\3\1\37"+
129     "\5\3\2\0\3\3\15\0\13\3\1\40\1\3\2\0"+
130     "\3\3\15\0\1\41\14\3\2\0\3\3\15\0\2\3"+
131     "\1\42\12\3\2\0\3\3\15\0\14\3\1\43\2\0"+
132     "\3\3\15\0\3\3\1\44\11\3\2\0\3\3\15\0"+
133     "\11\3\1\45\3\3\2\0\3\3\15\0\4\3\1\46"+
134     "\10\3\1\0";
135
136   private static int [] zzUnpackTrans() {
137     int [] result = new int[744];
138     int offset = 0;
139     offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
140     return result;
141   }
142
143   private static int zzUnpackTrans(String packed, int offset, int [] result) {
144     int i = 0;       /* index in packed string  */
145     int j = offset;  /* index in unpacked array */
146     int l = packed.length();
147     while (i < l) {
148       int count = packed.charAt(i++);
149       int value = packed.charAt(i++);
150       value--;
151       do result[j++] = value; while (--count > 0);
152     }
153     return j;
154   }
155
156
157   /* error codes */
158   private static final int ZZ_UNKNOWN_ERROR = 0;
159   private static final int ZZ_NO_MATCH = 1;
160   private static final int ZZ_PUSHBACK_2BIG = 2;
161
162   /* error messages for the codes above */
163   private static final String ZZ_ERROR_MSG[] = {
164     "Unknown internal scanner error",
165     "Error: could not match input",
166     "Error: pushback value was too large"
167   };
168
169   /**
170    * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
171    */
172   private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
173
174   private static final String ZZ_ATTRIBUTE_PACKED_0 =
175     "\1\0\1\11\4\1\12\11\4\1\1\0\3\1\1\0"+
176     "\3\1\1\11\11\1";
177
178   private static int [] zzUnpackAttribute() {
179     int [] result = new int[38];
180     int offset = 0;
181     offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
182     return result;
183   }
184
185   private static int zzUnpackAttribute(String packed, int offset, int [] result) {
186     int i = 0;       /* index in packed string  */
187     int j = offset;  /* index in unpacked array */
188     int l = packed.length();
189     while (i < l) {
190       int count = packed.charAt(i++);
191       int value = packed.charAt(i++);
192       do result[j++] = value; while (--count > 0);
193     }
194     return j;
195   }
196
197   /** the input device */
198   private java.io.Reader zzReader;
199
200   /** the current state of the DFA */
201   private int zzState;
202
203   /** the current lexical state */
204   private int zzLexicalState = YYINITIAL;
205
206   /** this buffer contains the current text to be matched and is
207       the source of the yytext() string */
208   private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
209
210   /** the textposition at the last accepting state */
211   private int zzMarkedPos;
212
213   /** the current text position in the buffer */
214   private int zzCurrentPos;
215
216   /** startRead marks the beginning of the yytext() string in the buffer */
217   private int zzStartRead;
218
219   /** endRead marks the last character in the buffer, that has been read
220       from input */
221   private int zzEndRead;
222
223   /** number of newlines encountered up to the start of the matched text */
224   private int yyline;
225
226   /** the number of characters up to the start of the matched text */
227   private int yychar;
228
229   /**
230    * the number of characters from the last newline up to the start of the 
231    * matched text
232    */
233   private int yycolumn;
234
235   /** 
236    * zzAtBOL == true <=> the scanner is currently at the beginning of a line
237    */
238   private boolean zzAtBOL = true;
239
240   /** zzAtEOF == true <=> the scanner is at the EOF */
241   private boolean zzAtEOF;
242
243   /** denotes if the user-EOF-code has already been executed */
244   private boolean zzEOFDone;
245   
246   /** 
247    * The number of occupied positions in zzBuffer beyond zzEndRead.
248    * When a lead/high surrogate has been read from the input stream
249    * into the final zzBuffer position, this will have a value of 1;
250    * otherwise, it will have a value of 0.
251    */
252   private int zzFinalHighSurrogate = 0;
253
254   /* user code: */
255     private Token sym(int id) {
256         return new Token(id, yychar, yychar+yylength(), yytext());
257     }
258
259
260   /**
261    * Creates a new scanner
262    *
263    * @param   in  the java.io.Reader to read input from.
264    */
265   public GrammarLexer(java.io.Reader in) {
266     this.zzReader = in;
267   }
268
269
270   /** 
271    * Unpacks the compressed character translation table.
272    *
273    * @param packed   the packed character translation table
274    * @return         the unpacked character translation table
275    */
276   private static char [] zzUnpackCMap(String packed) {
277     char [] map = new char[0x110000];
278     int i = 0;  /* index in packed string  */
279     int j = 0;  /* index in unpacked array */
280     while (i < 146) {
281       int  count = packed.charAt(i++);
282       char value = packed.charAt(i++);
283       do map[j++] = value; while (--count > 0);
284     }
285     return map;
286   }
287
288
289   /**
290    * Refills the input buffer.
291    *
292    * @return      <code>false</code>, iff there was new input.
293    * 
294    * @exception   java.io.IOException  if any I/O-Error occurs
295    */
296   private boolean zzRefill() throws java.io.IOException {
297
298     /* first: make room (if you can) */
299     if (zzStartRead > 0) {
300       zzEndRead += zzFinalHighSurrogate;
301       zzFinalHighSurrogate = 0;
302       System.arraycopy(zzBuffer, zzStartRead,
303                        zzBuffer, 0,
304                        zzEndRead-zzStartRead);
305
306       /* translate stored positions */
307       zzEndRead-= zzStartRead;
308       zzCurrentPos-= zzStartRead;
309       zzMarkedPos-= zzStartRead;
310       zzStartRead = 0;
311     }
312
313     /* is the buffer big enough? */
314     if (zzCurrentPos >= zzBuffer.length - zzFinalHighSurrogate) {
315       /* if not: blow it up */
316       char newBuffer[] = new char[zzBuffer.length*2];
317       System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
318       zzBuffer = newBuffer;
319       zzEndRead += zzFinalHighSurrogate;
320       zzFinalHighSurrogate = 0;
321     }
322
323     /* fill the buffer with new input */
324     int requested = zzBuffer.length - zzEndRead;
325     int numRead = zzReader.read(zzBuffer, zzEndRead, requested);
326
327     /* not supposed to occur according to specification of java.io.Reader */
328     if (numRead == 0) {
329       throw new java.io.IOException("Reader returned 0 characters. See JFlex examples for workaround.");
330     }
331     if (numRead > 0) {
332       zzEndRead += numRead;
333       /* If numRead == requested, we might have requested to few chars to
334          encode a full Unicode character. We assume that a Reader would
335          otherwise never return half characters. */
336       if (numRead == requested) {
337         if (Character.isHighSurrogate(zzBuffer[zzEndRead - 1])) {
338           --zzEndRead;
339           zzFinalHighSurrogate = 1;
340         }
341       }
342       /* potentially more input available */
343       return false;
344     }
345
346     /* numRead < 0 ==> end of stream */
347     return true;
348   }
349
350     
351   /**
352    * Closes the input stream.
353    */
354   public final void yyclose() throws java.io.IOException {
355     zzAtEOF = true;            /* indicate end of file */
356     zzEndRead = zzStartRead;  /* invalidate buffer    */
357
358     if (zzReader != null)
359       zzReader.close();
360   }
361
362
363   /**
364    * Resets the scanner to read from a new input stream.
365    * Does not close the old reader.
366    *
367    * All internal variables are reset, the old input stream 
368    * <b>cannot</b> be reused (internal buffer is discarded and lost).
369    * Lexical state is set to <tt>ZZ_INITIAL</tt>.
370    *
371    * Internal scan buffer is resized down to its initial length, if it has grown.
372    *
373    * @param reader   the new input stream 
374    */
375   public final void yyreset(java.io.Reader reader) {
376     zzReader = reader;
377     zzAtBOL  = true;
378     zzAtEOF  = false;
379     zzEOFDone = false;
380     zzEndRead = zzStartRead = 0;
381     zzCurrentPos = zzMarkedPos = 0;
382     zzFinalHighSurrogate = 0;
383     yyline = yychar = yycolumn = 0;
384     zzLexicalState = YYINITIAL;
385     if (zzBuffer.length > ZZ_BUFFERSIZE)
386       zzBuffer = new char[ZZ_BUFFERSIZE];
387   }
388
389
390   /**
391    * Returns the current lexical state.
392    */
393   public final int yystate() {
394     return zzLexicalState;
395   }
396
397
398   /**
399    * Enters a new lexical state
400    *
401    * @param newState the new lexical state
402    */
403   public final void yybegin(int newState) {
404     zzLexicalState = newState;
405   }
406
407
408   /**
409    * Returns the text matched by the current regular expression.
410    */
411   public final String yytext() {
412     return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
413   }
414
415
416   /**
417    * Returns the character at position <tt>pos</tt> from the 
418    * matched text. 
419    * 
420    * It is equivalent to yytext().charAt(pos), but faster
421    *
422    * @param pos the position of the character to fetch. 
423    *            A value from 0 to yylength()-1.
424    *
425    * @return the character at position pos
426    */
427   public final char yycharat(int pos) {
428     return zzBuffer[zzStartRead+pos];
429   }
430
431
432   /**
433    * Returns the length of the matched text region.
434    */
435   public final int yylength() {
436     return zzMarkedPos-zzStartRead;
437   }
438
439
440   /**
441    * Reports an error that occured while scanning.
442    *
443    * In a wellformed scanner (no or only correct usage of 
444    * yypushback(int) and a match-all fallback rule) this method 
445    * will only be called with things that "Can't Possibly Happen".
446    * If this method is called, something is seriously wrong
447    * (e.g. a JFlex bug producing a faulty scanner etc.).
448    *
449    * Usual syntax/scanner level error handling should be done
450    * in error fallback rules.
451    *
452    * @param   errorCode  the code of the errormessage to display
453    */
454   private void zzScanError(int errorCode) throws RuntimeException {
455     String message;
456     try {
457       message = ZZ_ERROR_MSG[errorCode];
458     }
459     catch (ArrayIndexOutOfBoundsException e) {
460       message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
461     }
462
463     throw new RuntimeException(message);
464   } 
465
466
467   /**
468    * Pushes the specified amount of characters back into the input stream.
469    *
470    * They will be read again by then next call of the scanning method
471    *
472    * @param number  the number of characters to be read again.
473    *                This number must not be greater than yylength()!
474    */
475   public void yypushback(int number)  throws RuntimeException {
476     if ( number > yylength() )
477       zzScanError(ZZ_PUSHBACK_2BIG);
478
479     zzMarkedPos -= number;
480   }
481
482
483   /**
484    * Resumes scanning until the next regular expression is matched,
485    * the end of input is encountered or an I/O-Error occurs.
486    *
487    * @return      the next token
488    * @exception   java.io.IOException  if any I/O-Error occurs
489    */
490   public Token nextToken() throws java.io.IOException, RuntimeException, RuntimeException {
491     int zzInput;
492     int zzAction;
493
494     // cached fields:
495     int zzCurrentPosL;
496     int zzMarkedPosL;
497     int zzEndReadL = zzEndRead;
498     char [] zzBufferL = zzBuffer;
499     char [] zzCMapL = ZZ_CMAP;
500
501     int [] zzTransL = ZZ_TRANS;
502     int [] zzRowMapL = ZZ_ROWMAP;
503     int [] zzAttrL = ZZ_ATTRIBUTE;
504
505     while (true) {
506       zzMarkedPosL = zzMarkedPos;
507
508       yychar+= zzMarkedPosL-zzStartRead;
509
510       zzAction = -1;
511
512       zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
513   
514       zzState = ZZ_LEXSTATE[zzLexicalState];
515
516       // set up zzAction for empty match case:
517       int zzAttributes = zzAttrL[zzState];
518       if ( (zzAttributes & 1) == 1 ) {
519         zzAction = zzState;
520       }
521
522
523       zzForAction: {
524         while (true) {
525     
526           if (zzCurrentPosL < zzEndReadL) {
527             zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL, zzEndReadL);
528             zzCurrentPosL += Character.charCount(zzInput);
529           }
530           else if (zzAtEOF) {
531             zzInput = YYEOF;
532             break zzForAction;
533           }
534           else {
535             // store back cached positions
536             zzCurrentPos  = zzCurrentPosL;
537             zzMarkedPos   = zzMarkedPosL;
538             boolean eof = zzRefill();
539             // get translated positions and possibly new buffer
540             zzCurrentPosL  = zzCurrentPos;
541             zzMarkedPosL   = zzMarkedPos;
542             zzBufferL      = zzBuffer;
543             zzEndReadL     = zzEndRead;
544             if (eof) {
545               zzInput = YYEOF;
546               break zzForAction;
547             }
548             else {
549               zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL, zzEndReadL);
550               zzCurrentPosL += Character.charCount(zzInput);
551             }
552           }
553           int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
554           if (zzNext == -1) break zzForAction;
555           zzState = zzNext;
556
557           zzAttributes = zzAttrL[zzState];
558           if ( (zzAttributes & 1) == 1 ) {
559             zzAction = zzState;
560             zzMarkedPosL = zzCurrentPosL;
561             if ( (zzAttributes & 8) == 8 ) break zzForAction;
562           }
563
564         }
565       }
566
567       // store back cached position
568       zzMarkedPos = zzMarkedPosL;
569
570       if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
571         zzAtEOF = true;
572           {     return sym(GrammarTerminals.EOF);
573  }
574       }
575       else {
576         switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
577           case 1: 
578             { throw new RuntimeException("Illegal character '" + yytext() + "'.");
579             }
580           case 18: break;
581           case 2: 
582             { return sym(GrammarTerminals.NONTERMINAL);
583             }
584           case 19: break;
585           case 3: 
586             { return sym(GrammarTerminals.TERMINAL);
587             }
588           case 20: break;
589           case 4: 
590             { 
591             }
592           case 21: break;
593           case 5: 
594             { return sym(GrammarTerminals.STAR);
595             }
596           case 22: break;
597           case 6: 
598             { return sym(GrammarTerminals.EQUALS);
599             }
600           case 23: break;
601           case 7: 
602             { return sym(GrammarTerminals.BAR);
603             }
604           case 24: break;
605           case 8: 
606             { return sym(GrammarTerminals.SEMICOLON);
607             }
608           case 25: break;
609           case 9: 
610             { return sym(GrammarTerminals.HASH);
611             }
612           case 26: break;
613           case 10: 
614             { return sym(GrammarTerminals.COMMA);
615             }
616           case 27: break;
617           case 11: 
618             { return sym(GrammarTerminals.LPAREN);
619             }
620           case 28: break;
621           case 12: 
622             { return sym(GrammarTerminals.RPAREN);
623             }
624           case 29: break;
625           case 13: 
626             { return sym(GrammarTerminals.PLUS);
627             }
628           case 30: break;
629           case 14: 
630             { return sym(GrammarTerminals.OPTIONAL);
631             }
632           case 31: break;
633           case 15: 
634             { return sym(GrammarTerminals.SHIFT);
635             }
636           case 32: break;
637           case 16: 
638             { return sym(GrammarTerminals.REDUCE);
639             }
640           case 33: break;
641           case 17: 
642             { return sym(GrammarTerminals.INITIAL);
643             }
644           case 34: break;
645           default:
646             zzScanError(ZZ_NO_MATCH);
647         }
648       }
649     }
650   }
651
652
653 }