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