1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 /* This file was generated by SableCC (http://www.sablecc.org/). */
\r
14 package org.simantics.spreadsheet.common.expression.lexer;
\r
17 import org.simantics.spreadsheet.common.expression.node.*;
\r
19 @SuppressWarnings("nls")
\r
22 protected Token token;
\r
23 protected State state = State.INITIAL;
\r
25 private PushbackReader in;
\r
29 private boolean eof;
\r
30 private final StringBuffer text = new StringBuffer();
\r
32 @SuppressWarnings("unused")
\r
33 protected void filter() throws LexerException, IOException
\r
38 public Lexer(@SuppressWarnings("hiding") PushbackReader in)
\r
43 public Token peek() throws LexerException, IOException
\r
45 while(this.token == null)
\r
47 this.token = getToken();
\r
54 public Token next() throws LexerException, IOException
\r
56 while(this.token == null)
\r
58 this.token = getToken();
\r
62 Token result = this.token;
\r
67 protected Token getToken() throws IOException, LexerException
\r
71 int start_pos = this.pos;
\r
72 int start_line = this.line;
\r
74 int accept_state = -1;
\r
75 int accept_token = -1;
\r
76 int accept_length = -1;
\r
77 int accept_pos = -1;
\r
78 int accept_line = -1;
\r
80 @SuppressWarnings("hiding") int[][][] gotoTable = Lexer.gotoTable[this.state.id()];
\r
81 @SuppressWarnings("hiding") int[] accept = Lexer.accept[this.state.id()];
\r
82 this.text.setLength(0);
\r
114 this.text.append((char) c);
\r
118 int oldState = (dfa_state < -1) ? (-2 -dfa_state) : dfa_state;
\r
122 int[][] tmp1 = gotoTable[oldState];
\r
124 int high = tmp1.length - 1;
\r
128 int middle = (low + high) / 2;
\r
129 int[] tmp2 = tmp1[middle];
\r
135 else if(c > tmp2[1])
\r
141 dfa_state = tmp2[2];
\r
145 }while(dfa_state < -1);
\r
154 if(accept[dfa_state] != -1)
\r
156 accept_state = dfa_state;
\r
157 accept_token = accept[dfa_state];
\r
158 accept_length = this.text.length();
\r
159 accept_pos = this.pos;
\r
160 accept_line = this.line;
\r
165 if(accept_state != -1)
\r
167 switch(accept_token)
\r
171 @SuppressWarnings("hiding") Token token = new0(
\r
174 pushBack(accept_length);
\r
175 this.pos = accept_pos;
\r
176 this.line = accept_line;
\r
181 @SuppressWarnings("hiding") Token token = new1(
\r
184 pushBack(accept_length);
\r
185 this.pos = accept_pos;
\r
186 this.line = accept_line;
\r
191 @SuppressWarnings("hiding") Token token = new2(
\r
194 pushBack(accept_length);
\r
195 this.pos = accept_pos;
\r
196 this.line = accept_line;
\r
201 @SuppressWarnings("hiding") Token token = new3(
\r
204 pushBack(accept_length);
\r
205 this.pos = accept_pos;
\r
206 this.line = accept_line;
\r
211 @SuppressWarnings("hiding") Token token = new4(
\r
214 pushBack(accept_length);
\r
215 this.pos = accept_pos;
\r
216 this.line = accept_line;
\r
221 @SuppressWarnings("hiding") Token token = new5(
\r
224 pushBack(accept_length);
\r
225 this.pos = accept_pos;
\r
226 this.line = accept_line;
\r
231 @SuppressWarnings("hiding") Token token = new6(
\r
234 pushBack(accept_length);
\r
235 this.pos = accept_pos;
\r
236 this.line = accept_line;
\r
241 @SuppressWarnings("hiding") Token token = new7(
\r
244 pushBack(accept_length);
\r
245 this.pos = accept_pos;
\r
246 this.line = accept_line;
\r
251 @SuppressWarnings("hiding") Token token = new8(
\r
254 pushBack(accept_length);
\r
255 this.pos = accept_pos;
\r
256 this.line = accept_line;
\r
261 @SuppressWarnings("hiding") Token token = new9(
\r
264 pushBack(accept_length);
\r
265 this.pos = accept_pos;
\r
266 this.line = accept_line;
\r
271 @SuppressWarnings("hiding") Token token = new10(
\r
274 pushBack(accept_length);
\r
275 this.pos = accept_pos;
\r
276 this.line = accept_line;
\r
281 @SuppressWarnings("hiding") Token token = new11(
\r
284 pushBack(accept_length);
\r
285 this.pos = accept_pos;
\r
286 this.line = accept_line;
\r
291 @SuppressWarnings("hiding") Token token = new12(
\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 = new13(
\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 = new14(
\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 = new15(
\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 = new16(
\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 = new17(
\r
347 getText(accept_length),
\r
350 pushBack(accept_length);
\r
351 this.pos = accept_pos;
\r
352 this.line = accept_line;
\r
359 if(this.text.length() > 0)
\r
361 throw new LexerException(
\r
362 "[" + (start_line + 1) + "," + (start_pos + 1) + "]" +
\r
363 " Unknown token: " + this.text);
\r
366 @SuppressWarnings("hiding") EOF token = new EOF(
\r
375 Token new0(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLessThan(line, pos); }
\r
376 Token new1(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TGreaterThan(line, pos); }
\r
377 Token new2(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TEqual(line, pos); }
\r
378 Token new3(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TPlus(line, pos); }
\r
379 Token new4(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TMinus(line, pos); }
\r
380 Token new5(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TMult(line, pos); }
\r
381 Token new6(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TDiv(line, pos); }
\r
382 Token new7(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TAmpersand(line, pos); }
\r
383 Token new8(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TComma(line, pos); }
\r
384 Token new9(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TColon(line, pos); }
\r
385 Token new10(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLPar(line, pos); }
\r
386 Token new11(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TRPar(line, pos); }
\r
387 Token new12(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TFunc(text, line, pos); }
\r
388 Token new13(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TCell(text, line, pos); }
\r
389 Token new14(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TNumber(text, line, pos); }
\r
390 Token new15(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TString(text, line, pos); }
\r
391 Token new16(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TNewLine(text, line, pos); }
\r
392 Token new17(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TBlank(text, line, pos); }
\r
394 private int getChar() throws IOException
\r
401 int result = this.in.read();
\r
411 private void pushBack(int acceptLength) throws IOException
\r
413 int length = this.text.length();
\r
414 for(int i = length - 1; i >= acceptLength; i--)
\r
418 this.in.unread(this.text.charAt(i));
\r
422 protected void unread(@SuppressWarnings("hiding") Token token) throws IOException
\r
424 @SuppressWarnings("hiding") String text = token.getText();
\r
425 int length = text.length();
\r
427 for(int i = length - 1; i >= 0; i--)
\r
431 this.in.unread(text.charAt(i));
\r
434 this.pos = token.getPos() - 1;
\r
435 this.line = token.getLine() - 1;
\r
438 private String getText(int acceptLength)
\r
440 StringBuffer s = new StringBuffer(acceptLength);
\r
441 for(int i = 0; i < acceptLength; i++)
\r
443 s.append(this.text.charAt(i));
\r
446 return s.toString();
\r
449 private static int[][][][] gotoTable;
\r
452 {{10, 10, 1}, {13, 13, 2}, {32, 32, 3}, {34, 34, 4}, {38, 38, 5}, {39, 39, 6}, {40, 40, 7}, {41, 41, 8}, {42, 42, 9}, {43, 43, 10}, {44, 44, 11}, {45, 45, 12}, {47, 47, 13}, {48, 57, 14}, {58, 58, 15}, {60, 60, 16}, {61, 61, 17}, {62, 62, 18}, {65, 90, 19}, {95, 95, 20}, {97, 122, 19}, },
\r
456 {{32, 33, 22}, {34, 34, 23}, {35, 38, 22}, {39, 39, 24}, {40, 91, 22}, {93, 127, 22}, },
\r
458 {{32, 33, 25}, {34, 34, 26}, {35, 38, 25}, {39, 39, 27}, {40, 91, 25}, {93, 127, 25}, },
\r
466 {{46, 46, 28}, {48, 57, 29}, },
\r
471 {{40, 40, 30}, {48, 57, 31}, {65, 90, 32}, {97, 122, 32}, },
\r
472 {{65, 90, 33}, {97, 122, 33}, },
\r
480 {{46, 46, 28}, {48, 57, 34}, },
\r
483 {{40, 57, -21}, {65, 90, 35}, {97, 122, 35}, },
\r
484 {{40, 122, -21}, },
\r
485 {{48, 57, 36}, {65, 122, -22}, },
\r
487 {{40, 40, 30}, {48, 57, 37}, {65, 122, -33}, },
\r
489 {{40, 122, -37}, },
\r
493 private static int[][] accept;
\r
496 {17, 16, 16, 17, -1, 7, -1, 10, 11, 5, 3, 8, 4, 6, 14, 9, 0, 2, 1, -1, -1, 16, -1, 15, -1, -1, -1, 15, 14, 14, 12, 13, -1, -1, 14, -1, 13, -1, },
\r
500 public static class State
\r
502 public final static State INITIAL = new State(0);
\r
506 private State(@SuppressWarnings("hiding") int id)
\r
521 DataInputStream s = new DataInputStream(
\r
522 new BufferedInputStream(
\r
523 Lexer.class.getResourceAsStream("lexer.dat")));
\r
526 int length = s.readInt();
\r
527 gotoTable = new int[length][][][];
\r
528 for(int i = 0; i < gotoTable.length; i++)
\r
530 length = s.readInt();
\r
531 gotoTable[i] = new int[length][][];
\r
532 for(int j = 0; j < gotoTable[i].length; j++)
\r
534 length = s.readInt();
\r
535 gotoTable[i][j] = new int[length][3];
\r
536 for(int k = 0; k < gotoTable[i][j].length; k++)
\r
538 for(int l = 0; l < 3; l++)
\r
540 gotoTable[i][j][k][l] = s.readInt();
\r
547 length = s.readInt();
\r
548 accept = new int[length][];
\r
549 for(int i = 0; i < accept.length; i++)
\r
551 length = s.readInt();
\r
552 accept[i] = new int[length];
\r
553 for(int j = 0; j < accept[i].length; j++)
\r
555 accept[i][j] = s.readInt();
\r
563 throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted.");
\r