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