--- /dev/null
+/* This file was generated by SableCC (http://www.sablecc.org/). */\r
+\r
+package org.simantics.basicexpression.lexer;\r
+\r
+import java.io.*;\r
+import org.simantics.basicexpression.node.*;\r
+\r
+@SuppressWarnings("nls")\r
+public class Lexer\r
+{\r
+ protected Token token;\r
+ protected State state = State.INITIAL;\r
+\r
+ private PushbackReader in;\r
+ private int line;\r
+ private int pos;\r
+ private boolean cr;\r
+ private boolean eof;\r
+ private final StringBuffer text = new StringBuffer();\r
+\r
+ @SuppressWarnings("unused")\r
+ protected void filter() throws LexerException, IOException\r
+ {\r
+ // Do nothing\r
+ }\r
+\r
+ public Lexer(@SuppressWarnings("hiding") PushbackReader in)\r
+ {\r
+ this.in = in;\r
+ }\r
+ \r
+ public Token peek() throws LexerException, IOException\r
+ {\r
+ while(this.token == null)\r
+ {\r
+ this.token = getToken();\r
+ filter();\r
+ }\r
+\r
+ return this.token;\r
+ }\r
+\r
+ public Token next() throws LexerException, IOException\r
+ {\r
+ while(this.token == null)\r
+ {\r
+ this.token = getToken();\r
+ filter();\r
+ }\r
+\r
+ Token result = this.token;\r
+ this.token = null;\r
+ return result;\r
+ }\r
+\r
+ protected Token getToken() throws IOException, LexerException\r
+ {\r
+ int dfa_state = 0;\r
+\r
+ int start_pos = this.pos;\r
+ int start_line = this.line;\r
+\r
+ int accept_state = -1;\r
+ int accept_token = -1;\r
+ int accept_length = -1;\r
+ int accept_pos = -1;\r
+ int accept_line = -1;\r
+\r
+ @SuppressWarnings("hiding") int[][][] gotoTable = Lexer.gotoTable[this.state.id()];\r
+ @SuppressWarnings("hiding") int[] accept = Lexer.accept[this.state.id()];\r
+ this.text.setLength(0);\r
+\r
+ while(true)\r
+ {\r
+ int c = getChar();\r
+\r
+ if(c != -1)\r
+ {\r
+ switch(c)\r
+ {\r
+ case 10:\r
+ if(this.cr)\r
+ {\r
+ this.cr = false;\r
+ }\r
+ else\r
+ {\r
+ this.line++;\r
+ this.pos = 0;\r
+ }\r
+ break;\r
+ case 13:\r
+ this.line++;\r
+ this.pos = 0;\r
+ this.cr = true;\r
+ break;\r
+ default:\r
+ this.pos++;\r
+ this.cr = false;\r
+ break;\r
+ }\r
+\r
+ this.text.append((char) c);\r
+\r
+ do\r
+ {\r
+ int oldState = (dfa_state < -1) ? (-2 -dfa_state) : dfa_state;\r
+\r
+ dfa_state = -1;\r
+\r
+ int[][] tmp1 = gotoTable[oldState];\r
+ int low = 0;\r
+ int high = tmp1.length - 1;\r
+\r
+ while(low <= high)\r
+ {\r
+ int middle = (low + high) / 2;\r
+ int[] tmp2 = tmp1[middle];\r
+\r
+ if(c < tmp2[0])\r
+ {\r
+ high = middle - 1;\r
+ }\r
+ else if(c > tmp2[1])\r
+ {\r
+ low = middle + 1;\r
+ }\r
+ else\r
+ {\r
+ dfa_state = tmp2[2];\r
+ break;\r
+ }\r
+ }\r
+ }while(dfa_state < -1);\r
+ }\r
+ else\r
+ {\r
+ dfa_state = -1;\r
+ }\r
+\r
+ if(dfa_state >= 0)\r
+ {\r
+ if(accept[dfa_state] != -1)\r
+ {\r
+ accept_state = dfa_state;\r
+ accept_token = accept[dfa_state];\r
+ accept_length = this.text.length();\r
+ accept_pos = this.pos;\r
+ accept_line = this.line;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if(accept_state != -1)\r
+ {\r
+ switch(accept_token)\r
+ {\r
+ case 0:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new0(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 1:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new1(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 2:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new2(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 3:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new3(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 4:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new4(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 5:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new5(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 6:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new6(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 7:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new7(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 8:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new8(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 9:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new9(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 10:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new10(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 11:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new11(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 12:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new12(\r
+ getText(accept_length),\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 13:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new13(\r
+ getText(accept_length),\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 14:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new14(\r
+ getText(accept_length),\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 15:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new15(\r
+ getText(accept_length),\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 16:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new16(\r
+ getText(accept_length),\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 17:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new17(\r
+ getText(accept_length),\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 18:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new18(\r
+ getText(accept_length),\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ case 19:\r
+ {\r
+ @SuppressWarnings("hiding") Token token = new19(\r
+ getText(accept_length),\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ pushBack(accept_length);\r
+ this.pos = accept_pos;\r
+ this.line = accept_line;\r
+ return token;\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if(this.text.length() > 0)\r
+ {\r
+ throw new LexerException(\r
+ "[" + (start_line + 1) + "," + (start_pos + 1) + "]" +\r
+ " Unknown token: " + this.text);\r
+ }\r
+\r
+ @SuppressWarnings("hiding") EOF token = new EOF(\r
+ start_line + 1,\r
+ start_pos + 1);\r
+ return token;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ Token new0(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLessThan(line, pos); }\r
+ Token new1(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TGreaterThan(line, pos); }\r
+ Token new2(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TEqual(line, pos); }\r
+ Token new3(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TPlus(line, pos); }\r
+ Token new4(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TMinus(line, pos); }\r
+ Token new5(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TMult(line, pos); }\r
+ Token new6(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TDiv(line, pos); }\r
+ Token new7(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TAmpersand(line, pos); }\r
+ Token new8(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TComma(line, pos); }\r
+ Token new9(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TColon(line, pos); }\r
+ Token new10(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLPar(line, pos); }\r
+ Token new11(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TRPar(line, pos); }\r
+ Token new12(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TVariable(text, line, pos); }\r
+ Token new13(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TFunc(text, line, pos); }\r
+ Token new14(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TCell(text, line, pos); }\r
+ Token new15(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TRvi(text, line, pos); }\r
+ Token new16(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TNumber(text, line, pos); }\r
+ Token new17(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TString(text, line, pos); }\r
+ Token new18(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TNewLine(text, line, pos); }\r
+ Token new19(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TBlank(text, line, pos); }\r
+\r
+ private int getChar() throws IOException\r
+ {\r
+ if(this.eof)\r
+ {\r
+ return -1;\r
+ }\r
+\r
+ int result = this.in.read();\r
+\r
+ if(result == -1)\r
+ {\r
+ this.eof = true;\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ private void pushBack(int acceptLength) throws IOException\r
+ {\r
+ int length = this.text.length();\r
+ for(int i = length - 1; i >= acceptLength; i--)\r
+ {\r
+ this.eof = false;\r
+\r
+ this.in.unread(this.text.charAt(i));\r
+ }\r
+ }\r
+\r
+ protected void unread(@SuppressWarnings("hiding") Token token) throws IOException\r
+ {\r
+ @SuppressWarnings("hiding") String text = token.getText();\r
+ int length = text.length();\r
+\r
+ for(int i = length - 1; i >= 0; i--)\r
+ {\r
+ this.eof = false;\r
+\r
+ this.in.unread(text.charAt(i));\r
+ }\r
+\r
+ this.pos = token.getPos() - 1;\r
+ this.line = token.getLine() - 1;\r
+ }\r
+\r
+ private String getText(int acceptLength)\r
+ {\r
+ StringBuffer s = new StringBuffer(acceptLength);\r
+ for(int i = 0; i < acceptLength; i++)\r
+ {\r
+ s.append(this.text.charAt(i));\r
+ }\r
+\r
+ return s.toString();\r
+ }\r
+\r
+ private static int[][][][] gotoTable;\r
+/* {\r
+ { // INITIAL\r
+ {{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
+ {},\r
+ {{10, 10, 23}, },\r
+ {{32, 32, 3}, },\r
+ {{32, 33, 24}, {34, 34, 25}, {35, 38, 24}, {39, 39, 26}, {40, 91, 24}, {93, 255, 24}, },\r
+ {{35, 35, 27}, {46, 46, 28}, {47, 47, 29}, {48, 57, 30}, {65, 90, 31}, {95, 95, 32}, {97, 122, 31}, },\r
+ {},\r
+ {{32, 33, 33}, {34, 34, 34}, {35, 38, 33}, {39, 39, 35}, {40, 91, 33}, {93, 255, 33}, },\r
+ {},\r
+ {},\r
+ {},\r
+ {},\r
+ {},\r
+ {},\r
+ {{35, 35, 5}, {46, 46, 14}, {47, 47, 36}, },\r
+ {{35, 122, -7}, },\r
+ {{46, 46, 37}, {48, 57, 38}, },\r
+ {},\r
+ {},\r
+ {},\r
+ {},\r
+ {{40, 40, 39}, {48, 57, 40}, {65, 90, 41}, {95, 95, 41}, {97, 122, 41}, },\r
+ {{40, 122, -23}, },\r
+ {},\r
+ {{32, 255, -6}, },\r
+ {},\r
+ {{32, 255, -6}, },\r
+ {{35, 122, -7}, },\r
+ {{35, 122, -7}, },\r
+ {{35, 122, -7}, },\r
+ {{35, 122, -7}, },\r
+ {{35, 122, -7}, },\r
+ {{35, 122, -7}, },\r
+ {{32, 255, -9}, },\r
+ {{32, 255, -9}, },\r
+ {},\r
+ {{35, 122, -7}, },\r
+ {{46, 46, 37}, {48, 57, 42}, },\r
+ {{46, 57, -18}, },\r
+ {},\r
+ {{40, 57, -23}, {65, 90, 43}, {95, 95, 43}, {97, 122, 43}, },\r
+ {{40, 122, -23}, },\r
+ {{48, 57, 42}, },\r
+ {{40, 40, 39}, {48, 57, 44}, {65, 122, -42}, },\r
+ {{40, 122, -45}, },\r
+ }\r
+ };*/\r
+\r
+ private static int[][] accept;\r
+/* {\r
+ // INITIAL\r
+ {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
+\r
+ };*/\r
+\r
+ public static class State\r
+ {\r
+ public final static State INITIAL = new State(0);\r
+\r
+ private int id;\r
+\r
+ private State(@SuppressWarnings("hiding") int id)\r
+ {\r
+ this.id = id;\r
+ }\r
+\r
+ public int id()\r
+ {\r
+ return this.id;\r
+ }\r
+ }\r
+\r
+ static \r
+ {\r
+ try\r
+ {\r
+ DataInputStream s = new DataInputStream(\r
+ new BufferedInputStream(\r
+ Lexer.class.getResourceAsStream("lexer.dat")));\r
+\r
+ // read gotoTable\r
+ int length = s.readInt();\r
+ gotoTable = new int[length][][][];\r
+ for(int i = 0; i < gotoTable.length; i++)\r
+ {\r
+ length = s.readInt();\r
+ gotoTable[i] = new int[length][][];\r
+ for(int j = 0; j < gotoTable[i].length; j++)\r
+ {\r
+ length = s.readInt();\r
+ gotoTable[i][j] = new int[length][3];\r
+ for(int k = 0; k < gotoTable[i][j].length; k++)\r
+ {\r
+ for(int l = 0; l < 3; l++)\r
+ {\r
+ gotoTable[i][j][k][l] = s.readInt();\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ // read accept\r
+ length = s.readInt();\r
+ accept = new int[length][];\r
+ for(int i = 0; i < accept.length; i++)\r
+ {\r
+ length = s.readInt();\r
+ accept[i] = new int[length];\r
+ for(int j = 0; j < accept[i].length; j++)\r
+ {\r
+ accept[i][j] = s.readInt();\r
+ }\r
+ }\r
+\r
+ s.close();\r
+ }\r
+ catch(Exception e)\r
+ {\r
+ throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted.");\r
+ }\r
+ }\r
+}\r