1 /* This file was generated by SableCC (http://www.sablecc.org/). */
3 package org.simantics.basicexpression.lexer;
6 import org.simantics.basicexpression.node.*;
8 @SuppressWarnings("nls")
11 protected Token token;
12 protected State state = State.INITIAL;
14 private PushbackReader in;
19 private final StringBuffer text = new StringBuffer();
21 @SuppressWarnings("unused")
22 protected void filter() throws LexerException, IOException
27 public Lexer(@SuppressWarnings("hiding") PushbackReader in)
32 public Token peek() throws LexerException, IOException
34 while(this.token == null)
36 this.token = getToken();
43 public Token next() throws LexerException, IOException
45 while(this.token == null)
47 this.token = getToken();
51 Token result = this.token;
56 protected Token getToken() throws IOException, LexerException
60 int start_pos = this.pos;
61 int start_line = this.line;
63 int accept_state = -1;
64 int accept_token = -1;
65 int accept_length = -1;
69 @SuppressWarnings("hiding") int[][][] gotoTable = Lexer.gotoTable[this.state.id()];
70 @SuppressWarnings("hiding") int[] accept = Lexer.accept[this.state.id()];
71 this.text.setLength(0);
103 this.text.append((char) c);
107 int oldState = (dfa_state < -1) ? (-2 -dfa_state) : dfa_state;
111 int[][] tmp1 = gotoTable[oldState];
113 int high = tmp1.length - 1;
117 int middle = (low + high) / 2;
118 int[] tmp2 = tmp1[middle];
134 }while(dfa_state < -1);
143 if(accept[dfa_state] != -1)
145 accept_state = dfa_state;
146 accept_token = accept[dfa_state];
147 accept_length = this.text.length();
148 accept_pos = this.pos;
149 accept_line = this.line;
154 if(accept_state != -1)
160 @SuppressWarnings("hiding") Token token = new0(
163 pushBack(accept_length);
164 this.pos = accept_pos;
165 this.line = accept_line;
170 @SuppressWarnings("hiding") Token token = new1(
173 pushBack(accept_length);
174 this.pos = accept_pos;
175 this.line = accept_line;
180 @SuppressWarnings("hiding") Token token = new2(
183 pushBack(accept_length);
184 this.pos = accept_pos;
185 this.line = accept_line;
190 @SuppressWarnings("hiding") Token token = new3(
193 pushBack(accept_length);
194 this.pos = accept_pos;
195 this.line = accept_line;
200 @SuppressWarnings("hiding") Token token = new4(
203 pushBack(accept_length);
204 this.pos = accept_pos;
205 this.line = accept_line;
210 @SuppressWarnings("hiding") Token token = new5(
213 pushBack(accept_length);
214 this.pos = accept_pos;
215 this.line = accept_line;
220 @SuppressWarnings("hiding") Token token = new6(
223 pushBack(accept_length);
224 this.pos = accept_pos;
225 this.line = accept_line;
230 @SuppressWarnings("hiding") Token token = new7(
233 pushBack(accept_length);
234 this.pos = accept_pos;
235 this.line = accept_line;
240 @SuppressWarnings("hiding") Token token = new8(
243 pushBack(accept_length);
244 this.pos = accept_pos;
245 this.line = accept_line;
250 @SuppressWarnings("hiding") Token token = new9(
253 pushBack(accept_length);
254 this.pos = accept_pos;
255 this.line = accept_line;
260 @SuppressWarnings("hiding") Token token = new10(
263 pushBack(accept_length);
264 this.pos = accept_pos;
265 this.line = accept_line;
270 @SuppressWarnings("hiding") Token token = new11(
273 pushBack(accept_length);
274 this.pos = accept_pos;
275 this.line = accept_line;
280 @SuppressWarnings("hiding") Token token = new12(
281 getText(accept_length),
284 pushBack(accept_length);
285 this.pos = accept_pos;
286 this.line = accept_line;
291 @SuppressWarnings("hiding") Token token = new13(
292 getText(accept_length),
295 pushBack(accept_length);
296 this.pos = accept_pos;
297 this.line = accept_line;
302 @SuppressWarnings("hiding") Token token = new14(
303 getText(accept_length),
306 pushBack(accept_length);
307 this.pos = accept_pos;
308 this.line = accept_line;
313 @SuppressWarnings("hiding") Token token = new15(
314 getText(accept_length),
317 pushBack(accept_length);
318 this.pos = accept_pos;
319 this.line = accept_line;
324 @SuppressWarnings("hiding") Token token = new16(
325 getText(accept_length),
328 pushBack(accept_length);
329 this.pos = accept_pos;
330 this.line = accept_line;
335 @SuppressWarnings("hiding") Token token = new17(
336 getText(accept_length),
339 pushBack(accept_length);
340 this.pos = accept_pos;
341 this.line = accept_line;
346 @SuppressWarnings("hiding") Token token = new18(
347 getText(accept_length),
350 pushBack(accept_length);
351 this.pos = accept_pos;
352 this.line = accept_line;
357 @SuppressWarnings("hiding") Token token = new19(
358 getText(accept_length),
361 pushBack(accept_length);
362 this.pos = accept_pos;
363 this.line = accept_line;
370 if(this.text.length() > 0)
372 throw new LexerException(
373 "[" + (start_line + 1) + "," + (start_pos + 1) + "]" +
374 " Unknown token: " + this.text);
377 @SuppressWarnings("hiding") EOF token = new EOF(
386 Token new0(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLessThan(line, pos); }
387 Token new1(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TGreaterThan(line, pos); }
388 Token new2(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TEqual(line, pos); }
389 Token new3(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TPlus(line, pos); }
390 Token new4(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TMinus(line, pos); }
391 Token new5(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TMult(line, pos); }
392 Token new6(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TDiv(line, pos); }
393 Token new7(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TAmpersand(line, pos); }
394 Token new8(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TComma(line, pos); }
395 Token new9(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TColon(line, pos); }
396 Token new10(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLPar(line, pos); }
397 Token new11(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TRPar(line, pos); }
398 Token new12(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TVariable(text, line, pos); }
399 Token new13(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TFunc(text, line, pos); }
400 Token new14(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TCell(text, line, pos); }
401 Token new15(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TRvi(text, line, pos); }
402 Token new16(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TNumber(text, line, pos); }
403 Token new17(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TString(text, line, pos); }
404 Token new18(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TNewLine(text, line, pos); }
405 Token new19(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TBlank(text, line, pos); }
407 private int getChar() throws IOException
414 int result = this.in.read();
424 private void pushBack(int acceptLength) throws IOException
426 int length = this.text.length();
427 for(int i = length - 1; i >= acceptLength; i--)
431 this.in.unread(this.text.charAt(i));
435 protected void unread(@SuppressWarnings("hiding") Token token) throws IOException
437 @SuppressWarnings("hiding") String text = token.getText();
438 int length = text.length();
440 for(int i = length - 1; i >= 0; i--)
444 this.in.unread(text.charAt(i));
447 this.pos = token.getPos() - 1;
448 this.line = token.getLine() - 1;
451 private String getText(int acceptLength)
453 StringBuffer s = new StringBuffer(acceptLength);
454 for(int i = 0; i < acceptLength; i++)
456 s.append(this.text.charAt(i));
462 private static int[][][][] gotoTable;
465 {{10, 10, 1}, {13, 13, 2}, {32, 32, 3}, {34, 34, 4}, {35, 35, 5}, {38, 38, 6}, {39, 39, 7}, {40, 40, 8}, {41, 41, 9}, {42, 42, 10}, {43, 43, 11}, {44, 44, 12}, {45, 45, 13}, {46, 46, 14}, {47, 47, 15}, {48, 57, 16}, {58, 58, 17}, {60, 60, 18}, {61, 61, 19}, {62, 62, 20}, {65, 90, 21}, {95, 95, 22}, {97, 122, 21}, },
469 {{32, 33, 24}, {34, 34, 25}, {35, 38, 24}, {39, 39, 26}, {40, 91, 24}, {93, 255, 24}, },
470 {{35, 35, 27}, {46, 46, 28}, {47, 47, 29}, {48, 57, 30}, {65, 90, 31}, {95, 95, 32}, {97, 122, 31}, },
472 {{32, 33, 33}, {34, 34, 34}, {35, 38, 33}, {39, 39, 35}, {40, 91, 33}, {93, 255, 33}, },
479 {{35, 35, 5}, {46, 46, 14}, {47, 47, 36}, },
481 {{46, 46, 37}, {48, 57, 38}, },
486 {{40, 40, 39}, {48, 57, 40}, {65, 90, 41}, {95, 95, 41}, {97, 122, 41}, },
502 {{46, 46, 37}, {48, 57, 42}, },
505 {{40, 57, -23}, {65, 90, 43}, {95, 95, 43}, {97, 122, 43}, },
508 {{40, 40, 39}, {48, 57, 44}, {65, 122, -42}, },
513 private static int[][] accept;
516 {19, 18, 18, 19, -1, 15, 7, -1, 10, 11, 5, 3, 8, 4, -1, 6, 16, 9, 0, 2, 1, 12, 12, 18, -1, 17, -1, 15, 15, 15, 15, 15, 15, -1, -1, 17, 15, 16, 16, 13, 12, 12, 16, 12, 12, },
520 public static class State
522 public final static State INITIAL = new State(0);
526 private State(@SuppressWarnings("hiding") int id)
541 DataInputStream s = new DataInputStream(
542 new BufferedInputStream(
543 Lexer.class.getResourceAsStream("lexer.dat")));
546 int length = s.readInt();
547 gotoTable = new int[length][][][];
548 for(int i = 0; i < gotoTable.length; i++)
550 length = s.readInt();
551 gotoTable[i] = new int[length][][];
552 for(int j = 0; j < gotoTable[i].length; j++)
554 length = s.readInt();
555 gotoTable[i][j] = new int[length][3];
556 for(int k = 0; k < gotoTable[i][j].length; k++)
558 for(int l = 0; l < 3; l++)
560 gotoTable[i][j][k][l] = s.readInt();
567 length = s.readInt();
568 accept = new int[length][];
569 for(int i = 0; i < accept.length; i++)
571 length = s.readInt();
572 accept[i] = new int[length];
573 for(int j = 0; j < accept[i].length; j++)
575 accept[i][j] = s.readInt();
583 throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted.");