/* This file was generated by SableCC (http://www.sablecc.org/). */ package org.uva.student.calinwouter.qlqls.generated.lexer; import java.io.*; import org.uva.student.calinwouter.qlqls.generated.node.*; @SuppressWarnings("nls") public class Lexer { protected Token token; protected State state = State.INITIAL; private IPushbackReader 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") final PushbackReader in) { this.in = new IPushbackReader() { private PushbackReader pushbackReader = in; @Override public void unread(int c) throws IOException { pushbackReader.unread(c); } @Override public int read() throws IOException { return pushbackReader.read(); } }; } public Lexer(@SuppressWarnings("hiding") IPushbackReader 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 middle = (low + high) >>> 1; 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( getText(accept_length), 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( getText(accept_length), 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( 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( 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( 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( 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( 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( 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( 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( start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 20: { @SuppressWarnings("hiding") Token token = new20( start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 21: { @SuppressWarnings("hiding") Token token = new21( start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 22: { @SuppressWarnings("hiding") Token token = new22( start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 23: { @SuppressWarnings("hiding") Token token = new23( getText(accept_length), start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 24: { @SuppressWarnings("hiding") Token token = new24( start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 25: { @SuppressWarnings("hiding") Token token = new25( start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 26: { @SuppressWarnings("hiding") Token token = new26( start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 27: { @SuppressWarnings("hiding") Token token = new27( start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 28: { @SuppressWarnings("hiding") Token token = new28( start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 29: { @SuppressWarnings("hiding") Token token = new29( start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 30: { @SuppressWarnings("hiding") Token token = new30( getText(accept_length), start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 31: { @SuppressWarnings("hiding") Token token = new31( getText(accept_length), start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 32: { @SuppressWarnings("hiding") Token token = new32( getText(accept_length), start_line + 1, start_pos + 1); pushBack(accept_length); this.pos = accept_pos; this.line = accept_line; return token; } case 33: { @SuppressWarnings("hiding") Token token = new33( 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( new InvalidToken(this.text.substring(0, 1), start_line + 1, start_pos + 1), "[" + (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") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TComment(text, line, pos); } Token new1(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenNot(line, pos); } Token new2(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TNumber(text, line, pos); } Token new3(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TOr(line, pos); } Token new4(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TAnd(line, pos); } Token new5(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TAdd(line, pos); } Token new6(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TSubtract(line, pos); } Token new7(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TMultiply(line, pos); } Token new8(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TDivide(line, pos); } Token new9(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TModulo(line, pos); } Token new10(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLeftParenthesis(line, pos); } Token new11(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TRightParenthesis(line, pos); } Token new12(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenForm(line, pos); } Token new13(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLeftBrace(line, pos); } Token new14(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TRightBrace(line, pos); } Token new15(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TColon(line, pos); } Token new16(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TIf(line, pos); } Token new17(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TElse(line, pos); } Token new18(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenBoolean(line, pos); } Token new19(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenTrue(line, pos); } Token new20(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenFalse(line, pos); } Token new21(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenString(line, pos); } Token new22(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenInteger(line, pos); } Token new23(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TString(text, line, pos); } Token new24(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenEquals(line, pos); } Token new25(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenNotEquals(line, pos); } Token new26(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenLesserThan(line, pos); } Token new27(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenGreaterThan(line, pos); } Token new28(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenLesserThanOrEquals(line, pos); } Token new29(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokenGreaterThanOrEquals(line, pos); } Token new30(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TBlank(text, line, pos); } Token new31(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TIdentifier(text, line, pos); } Token new32(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new THex(text, line, pos); } Token new33(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TComma(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 {{9, 9, 1}, {10, 10, 2}, {13, 13, 3}, {32, 32, 4}, {33, 33, 5}, {34, 34, 6}, {35, 35, 7}, {37, 37, 8}, {38, 38, 9}, {40, 40, 10}, {41, 41, 11}, {42, 42, 12}, {43, 43, 13}, {44, 44, 14}, {45, 45, 15}, {47, 47, 16}, {48, 57, 17}, {58, 58, 18}, {60, 60, 19}, {61, 61, 20}, {62, 62, 21}, {65, 90, 22}, {97, 97, 22}, {98, 98, 23}, {99, 100, 22}, {101, 101, 24}, {102, 102, 25}, {103, 104, 22}, {105, 105, 26}, {106, 114, 22}, {115, 115, 27}, {116, 116, 28}, {117, 122, 22}, {123, 123, 29}, {124, 124, 30}, {125, 125, 31}, }, {{9, 32, -2}, }, {{9, 32, -2}, }, {{9, 9, 1}, {10, 10, 32}, {13, 32, -2}, }, {{9, 32, -2}, }, {{61, 61, 33}, }, {{0, 9, 34}, {11, 12, 34}, {14, 33, 34}, {34, 34, 35}, {35, 65535, 34}, }, {{48, 57, 36}, {65, 90, 36}, {97, 122, 36}, }, {}, {{38, 38, 37}, }, {}, {}, {}, {}, {}, {}, {{47, 47, 38}, }, {{46, 46, 39}, {48, 57, 17}, }, {}, {{61, 61, 40}, }, {{61, 61, 41}, }, {{61, 61, 42}, }, {{48, 57, 43}, {65, 90, 44}, {97, 122, 44}, }, {{48, 90, -24}, {97, 110, 44}, {111, 111, 45}, {112, 122, 44}, }, {{48, 90, -24}, {97, 107, 44}, {108, 108, 46}, {109, 122, 44}, }, {{48, 90, -24}, {97, 97, 47}, {98, 110, 44}, {111, 111, 48}, {112, 122, 44}, }, {{48, 90, -24}, {97, 101, 44}, {102, 102, 49}, {103, 109, 44}, {110, 110, 50}, {111, 122, 44}, }, {{48, 90, -24}, {97, 115, 44}, {116, 116, 51}, {117, 122, 44}, }, {{48, 90, -24}, {97, 113, 44}, {114, 114, 52}, {115, 122, 44}, }, {}, {{124, 124, 53}, }, {}, {{9, 32, -2}, }, {}, {{0, 65535, -8}, }, {}, {{48, 122, -9}, }, {}, {{0, 9, 54}, {11, 12, 54}, {14, 65535, 54}, }, {{48, 57, 55}, }, {}, {}, {}, {{48, 122, -24}, }, {{48, 122, -24}, }, {{48, 110, -25}, {111, 111, 56}, {112, 122, 44}, }, {{48, 90, -24}, {97, 114, 44}, {115, 115, 57}, {116, 122, 44}, }, {{48, 107, -26}, {108, 108, 58}, {109, 122, 44}, }, {{48, 113, -30}, {114, 114, 59}, {115, 122, 44}, }, {{48, 122, -24}, }, {{48, 115, -29}, {116, 116, 60}, {117, 122, 44}, }, {{48, 113, -30}, {114, 114, 61}, {115, 122, 44}, }, {{48, 90, -24}, {97, 116, 44}, {117, 117, 62}, {118, 122, 44}, }, {}, {{10, 10, 63}, {13, 13, 64}, }, {{48, 57, 55}, }, {{48, 107, -26}, {108, 108, 65}, {109, 122, 44}, }, {{48, 90, -24}, {97, 100, 44}, {101, 101, 66}, {102, 122, 44}, }, {{48, 114, -48}, {115, 115, 67}, {116, 122, 44}, }, {{48, 90, -24}, {97, 108, 44}, {109, 109, 68}, {110, 122, 44}, }, {{48, 122, -24}, }, {{48, 90, -24}, {97, 104, 44}, {105, 105, 69}, {106, 122, 44}, }, {{48, 100, -59}, {101, 101, 70}, {102, 122, 44}, }, {}, {{10, 10, 71}, }, {{48, 100, -59}, {101, 101, 72}, {102, 122, 44}, }, {{48, 122, -24}, }, {{48, 100, -59}, {101, 101, 73}, {102, 122, 44}, }, {{48, 122, -24}, }, {{48, 90, -24}, {97, 109, 44}, {110, 110, 74}, {111, 122, 44}, }, {{48, 122, -24}, }, {}, {{48, 90, -24}, {97, 97, 75}, {98, 122, 44}, }, {{48, 122, -24}, }, {{48, 90, -24}, {97, 102, 44}, {103, 103, 76}, {104, 122, 44}, }, {{48, 109, -71}, {110, 110, 77}, {111, 122, 44}, }, {{48, 122, -24}, }, {{48, 122, -24}, }, } };*/ private static int[][] accept; /* { // INITIAL {-1, 30, 30, 30, 30, 1, -1, -1, 9, -1, 10, 11, 7, 5, 33, 6, 8, 2, 15, 26, -1, 27, 31, 31, 31, 31, 31, 31, 31, 13, -1, 14, 30, 25, -1, 23, 32, 4, -1, -1, 28, 24, 29, 31, 31, 31, 31, 31, 31, 16, 31, 31, 31, 3, 0, 2, 31, 31, 31, 31, 22, 31, 31, 0, 0, 31, 17, 31, 12, 31, 19, 0, 31, 20, 31, 31, 21, 18, }, };*/ 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."); } } }