1 /* The following code was generated by JFlex 1.6.1 */
3 package org.simantics.scl.compiler.parser.grammar.input;
5 import org.simantics.scl.compiler.parser.grammar.input.Token;
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>
13 public class GrammarLexer {
15 /** This character denotes the end of file */
16 public static final int YYEOF = -1;
18 /** initial size of the lookahead buffer */
19 private static final int ZZ_BUFFERSIZE = 16384;
22 public static final int YYINITIAL = 0;
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
30 private static final int ZZ_LEXSTATE[] = {
35 * Translates characters to character classes
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";
46 * Translates characters to character classes
48 private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
51 * Translates DFA states to action switch labels.
53 private static final int [] ZZ_ACTION = zzUnpackAction();
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";
61 private static int [] zzUnpackAction() {
62 int [] result = new int[38];
64 offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
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();
73 int count = packed.charAt(i++);
74 int value = packed.charAt(i++);
75 do result[j++] = value; while (--count > 0);
82 * Translates a state to a row index in the transition table
84 private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
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";
93 private static int [] zzUnpackRowMap() {
94 int [] result = new int[38];
96 offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
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();
105 int high = packed.charAt(i++) << 16;
106 result[j++] = high | packed.charAt(i++);
112 * The transition table of the DFA
114 private static final int [] ZZ_TRANS = zzUnpackTrans();
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"+
136 private static int [] zzUnpackTrans() {
137 int [] result = new int[744];
139 offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
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();
148 int count = packed.charAt(i++);
149 int value = packed.charAt(i++);
151 do result[j++] = value; while (--count > 0);
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;
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"
170 * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
172 private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
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"+
178 private static int [] zzUnpackAttribute() {
179 int [] result = new int[38];
181 offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
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();
190 int count = packed.charAt(i++);
191 int value = packed.charAt(i++);
192 do result[j++] = value; while (--count > 0);
197 /** the input device */
198 private java.io.Reader zzReader;
200 /** the current state of the DFA */
203 /** the current lexical state */
204 private int zzLexicalState = YYINITIAL;
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];
210 /** the textposition at the last accepting state */
211 private int zzMarkedPos;
213 /** the current text position in the buffer */
214 private int zzCurrentPos;
216 /** startRead marks the beginning of the yytext() string in the buffer */
217 private int zzStartRead;
219 /** endRead marks the last character in the buffer, that has been read
221 private int zzEndRead;
223 /** number of newlines encountered up to the start of the matched text */
226 /** the number of characters up to the start of the matched text */
230 * the number of characters from the last newline up to the start of the
233 private int yycolumn;
236 * zzAtBOL == true <=> the scanner is currently at the beginning of a line
238 private boolean zzAtBOL = true;
240 /** zzAtEOF == true <=> the scanner is at the EOF */
241 private boolean zzAtEOF;
243 /** denotes if the user-EOF-code has already been executed */
244 private boolean zzEOFDone;
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.
252 private int zzFinalHighSurrogate = 0;
255 private Token sym(int id) {
256 return new Token(id, yychar, yychar+yylength(), yytext());
261 * Creates a new scanner
263 * @param in the java.io.Reader to read input from.
265 public GrammarLexer(java.io.Reader in) {
271 * Unpacks the compressed character translation table.
273 * @param packed the packed character translation table
274 * @return the unpacked character translation table
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 */
281 int count = packed.charAt(i++);
282 char value = packed.charAt(i++);
283 do map[j++] = value; while (--count > 0);
290 * Refills the input buffer.
292 * @return <code>false</code>, iff there was new input.
294 * @exception java.io.IOException if any I/O-Error occurs
296 private boolean zzRefill() throws java.io.IOException {
298 /* first: make room (if you can) */
299 if (zzStartRead > 0) {
300 zzEndRead += zzFinalHighSurrogate;
301 zzFinalHighSurrogate = 0;
302 System.arraycopy(zzBuffer, zzStartRead,
304 zzEndRead-zzStartRead);
306 /* translate stored positions */
307 zzEndRead-= zzStartRead;
308 zzCurrentPos-= zzStartRead;
309 zzMarkedPos-= zzStartRead;
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;
323 /* fill the buffer with new input */
324 int requested = zzBuffer.length - zzEndRead;
325 int numRead = zzReader.read(zzBuffer, zzEndRead, requested);
327 /* not supposed to occur according to specification of java.io.Reader */
329 throw new java.io.IOException("Reader returned 0 characters. See JFlex examples for workaround.");
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])) {
339 zzFinalHighSurrogate = 1;
342 /* potentially more input available */
346 /* numRead < 0 ==> end of stream */
352 * Closes the input stream.
354 public final void yyclose() throws java.io.IOException {
355 zzAtEOF = true; /* indicate end of file */
356 zzEndRead = zzStartRead; /* invalidate buffer */
358 if (zzReader != null)
364 * Resets the scanner to read from a new input stream.
365 * Does not close the old reader.
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>.
371 * Internal scan buffer is resized down to its initial length, if it has grown.
373 * @param reader the new input stream
375 public final void yyreset(java.io.Reader reader) {
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];
391 * Returns the current lexical state.
393 public final int yystate() {
394 return zzLexicalState;
399 * Enters a new lexical state
401 * @param newState the new lexical state
403 public final void yybegin(int newState) {
404 zzLexicalState = newState;
409 * Returns the text matched by the current regular expression.
411 public final String yytext() {
412 return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
417 * Returns the character at position <tt>pos</tt> from the
420 * It is equivalent to yytext().charAt(pos), but faster
422 * @param pos the position of the character to fetch.
423 * A value from 0 to yylength()-1.
425 * @return the character at position pos
427 public final char yycharat(int pos) {
428 return zzBuffer[zzStartRead+pos];
433 * Returns the length of the matched text region.
435 public final int yylength() {
436 return zzMarkedPos-zzStartRead;
441 * Reports an error that occured while scanning.
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.).
449 * Usual syntax/scanner level error handling should be done
450 * in error fallback rules.
452 * @param errorCode the code of the errormessage to display
454 private void zzScanError(int errorCode) throws RuntimeException {
457 message = ZZ_ERROR_MSG[errorCode];
459 catch (ArrayIndexOutOfBoundsException e) {
460 message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
463 throw new RuntimeException(message);
468 * Pushes the specified amount of characters back into the input stream.
470 * They will be read again by then next call of the scanning method
472 * @param number the number of characters to be read again.
473 * This number must not be greater than yylength()!
475 public void yypushback(int number) throws RuntimeException {
476 if ( number > yylength() )
477 zzScanError(ZZ_PUSHBACK_2BIG);
479 zzMarkedPos -= number;
484 * Resumes scanning until the next regular expression is matched,
485 * the end of input is encountered or an I/O-Error occurs.
487 * @return the next token
488 * @exception java.io.IOException if any I/O-Error occurs
490 public Token nextToken() throws java.io.IOException, RuntimeException, RuntimeException {
497 int zzEndReadL = zzEndRead;
498 char [] zzBufferL = zzBuffer;
499 char [] zzCMapL = ZZ_CMAP;
501 int [] zzTransL = ZZ_TRANS;
502 int [] zzRowMapL = ZZ_ROWMAP;
503 int [] zzAttrL = ZZ_ATTRIBUTE;
506 zzMarkedPosL = zzMarkedPos;
508 yychar+= zzMarkedPosL-zzStartRead;
512 zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
514 zzState = ZZ_LEXSTATE[zzLexicalState];
516 // set up zzAction for empty match case:
517 int zzAttributes = zzAttrL[zzState];
518 if ( (zzAttributes & 1) == 1 ) {
526 if (zzCurrentPosL < zzEndReadL) {
527 zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL, zzEndReadL);
528 zzCurrentPosL += Character.charCount(zzInput);
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;
549 zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL, zzEndReadL);
550 zzCurrentPosL += Character.charCount(zzInput);
553 int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
554 if (zzNext == -1) break zzForAction;
557 zzAttributes = zzAttrL[zzState];
558 if ( (zzAttributes & 1) == 1 ) {
560 zzMarkedPosL = zzCurrentPosL;
561 if ( (zzAttributes & 8) == 8 ) break zzForAction;
567 // store back cached position
568 zzMarkedPos = zzMarkedPosL;
570 if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
572 { return sym(GrammarTerminals.EOF);
576 switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
578 { throw new RuntimeException("Illegal character '" + yytext() + "'.");
582 { return sym(GrammarTerminals.NONTERMINAL);
586 { return sym(GrammarTerminals.TERMINAL);
594 { return sym(GrammarTerminals.STAR);
598 { return sym(GrammarTerminals.EQUALS);
602 { return sym(GrammarTerminals.BAR);
606 { return sym(GrammarTerminals.SEMICOLON);
610 { return sym(GrammarTerminals.HASH);
614 { return sym(GrammarTerminals.COMMA);
618 { return sym(GrammarTerminals.LPAREN);
622 { return sym(GrammarTerminals.RPAREN);
626 { return sym(GrammarTerminals.PLUS);
630 { return sym(GrammarTerminals.OPTIONAL);
634 { return sym(GrammarTerminals.SHIFT);
638 { return sym(GrammarTerminals.REDUCE);
642 { return sym(GrammarTerminals.INITIAL);
646 zzScanError(ZZ_NO_MATCH);