private void escapeChar() { nextChar(); switch (c) { case 34: // '"' case 39: // '\'' case 92: // '\\' case 98: // 'b' case 102: // 'f' case 110: // 'n' case 114: // 'r' case 116: // 't' lastLiteral = c; nextChar(); return; } int i = Character.digit((char) c, 8); if (i >= 0) { lastLiteral = 0; int j = i >= 4 ? 2 : 3; do { lastLiteral = (lastLiteral << 3) + i; nextChar(); i = Character.digit((char) c, 8); } while (i >= 0 && --j > 0); return; } else { report(new Failure(getPos(), "Syntax error in escape sequence")); return; } }
private int number() { int i = col; int j = 0; int k = Character.digit((char) c, 10); do { j = 10 * j + k; nextChar(); k = Character.digit((char) c, 10); } while (k >= 0); lexemeText = line.substring(i, col); lastLiteral = j; return token = 6; }
private int identifier() { int i = col; do nextChar(); while (c != -1 && Character.isJavaIdentifierPart((char) c)); lexemeText = line.substring(i, col); return token = 3; }
private int directive() { nextChar(); if (c == 37) { nextChar(); return token = 1; } if (Character.isJavaIdentifierStart((char) c)) { identifier(); if (lexemeText.equals("token")) return token = 8; if (lexemeText.equals("type")) return token = 9; if (lexemeText.equals("prec")) return token = 10; if (lexemeText.equals("left")) return token = 11; if (lexemeText.equals("right")) return token = 12; if (lexemeText.equals("nonassoc")) return token = 13; if (lexemeText.equals("start")) return token = 14; if (lexemeText.equals("package")) return token = 15; if (lexemeText.equals("extends")) return token = 18; if (lexemeText.equals("implements")) return token = 19; if (lexemeText.equals("semantic")) return token = 20; if (lexemeText.equals("get")) return token = 21; if (lexemeText.equals("next")) return token = 22; if (lexemeText.equals("class")) return token = 16; if (lexemeText.equals("interface")) { return token = 17; } else { report(new Failure(getPos(), "Unrecognized directive")); return -1; } } if (c == 123) { nextChar(); return code(); } else { report(new Failure(getPos(), "Illegal directive syntax")); return -1; } }
public int nextToken() { do { skipWhitespace(); markPosition(); lexemeText = null; switch (c) { case -1: return token = 0; case 58: // ':' nextChar(); return token = 58; case 59: // ';' nextChar(); return token = 59; case 124: // '|' nextChar(); return token = 124; case 60: // '<' nextChar(); return token = 60; case 62: // '>' nextChar(); return token = 62; case 91: // '[' nextChar(); return token = 91; case 93: // ']' nextChar(); return token = 93; case 46: // '.' nextChar(); return token = 46; case 37: // '%' if (directive() != -1) return token; break; case 34: // '"' if (string() != -1) return token; break; case 39: // '\'' if (literal() != -1) return token; break; case 123: // '{' if (action() != -1) return token; break; case 47: // '/' skipComment(); break; default: if (Character.isJavaIdentifierStart((char) c)) return identifier(); if (Character.isDigit((char) c)) return number(); illegalCharacter(); nextChar(); break; } } while (true); }