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