void Get () { for (;;) { t = la; la = scanner.Scan(); if (la.kind <= maxT) { ++errDist; break; } if (la.kind == 79) { } if (la.kind == 80) { } if (la.kind == 81) { } la = t; } }
Token NextToken() { while (ch == ' ' || ch == 9 || ch == 13) NextCh(); int apx = 0; t = new Token(); t.pos = pos; t.col = col; t.line = line; int state; try { state = start[ch]; } catch (KeyNotFoundException) { state = 0; } tlen = 0; AddCh(); switch (state) { case -1: { t.kind = eofSym; break; } // NextCh already done case 0: { t.kind = noSym; break; } // NextCh already done case 1: if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 2: if (ch >= '0' && ch <= '9') {AddCh(); goto case 2;} else if (ch == 'E' || ch == 'e') {AddCh(); goto case 3;} else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 3: if (ch >= '0' && ch <= '9') {AddCh(); goto case 5;} else if (ch == '+' || ch == '-') {AddCh(); goto case 4;} else {t.kind = noSym; break;} case 4: if (ch >= '0' && ch <= '9') {AddCh(); goto case 5;} else {t.kind = noSym; break;} case 5: if (ch >= '0' && ch <= '9') {AddCh(); goto case 5;} else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 6: if (ch >= '0' && ch <= '9') {AddCh(); goto case 7;} else {t.kind = noSym; break;} case 7: if (ch >= '0' && ch <= '9') {AddCh(); goto case 7;} else if (ch == 'E' || ch == 'e') {AddCh(); goto case 8;} else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 8: if (ch >= '0' && ch <= '9') {AddCh(); goto case 10;} else if (ch == '+' || ch == '-') {AddCh(); goto case 9;} else {t.kind = noSym; break;} case 9: if (ch >= '0' && ch <= '9') {AddCh(); goto case 10;} else {t.kind = noSym; break;} case 10: if (ch >= '0' && ch <= '9') {AddCh(); goto case 10;} else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 11: if (ch >= '0' && ch <= '9') {AddCh(); goto case 13;} else if (ch == '+' || ch == '-') {AddCh(); goto case 12;} else {t.kind = noSym; break;} case 12: if (ch >= '0' && ch <= '9') {AddCh(); goto case 13;} else {t.kind = noSym; break;} case 13: if (ch >= '0' && ch <= '9') {AddCh(); goto case 13;} else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 14: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 14;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 28;} else {t.kind = noSym; break;} case 15: {t.kind = 4; break;} case 16: {t.kind = 5; break;} case 17: if (ch == 10) {apx++; AddCh(); goto case 18;} else if (ch <= 9 || ch >= 11 && ch <= 65535) {AddCh(); goto case 17;} else {t.kind = noSym; break;} case 18: { tlen -= apx; buffer.Pos = t.pos; NextCh(); line = t.line; col = t.col; for (int i = 0; i < tlen; i++) NextCh(); t.kind = 79; break;} case 19: if (ch <= 'S' || ch >= 'U' && ch <= 65535) {AddCh(); goto case 19;} else if (ch == 'T') {AddCh(); goto case 30;} else {t.kind = noSym; break;} case 20: {t.kind = 80; break;} case 21: if (ch == '.') {AddCh(); goto case 22;} else {t.kind = noSym; break;} case 22: if (ch == 10) {AddCh(); goto case 23;} else if (ch <= 9 || ch >= 11 && ch <= 65535) {AddCh(); goto case 22;} else {t.kind = noSym; break;} case 23: {t.kind = 81; break;} case 24: if (ch >= '0' && ch <= '9') {AddCh(); goto case 24;} else if (ch == '.') {AddCh(); goto case 6;} else if (ch == 'E' || ch == 'e') {AddCh(); goto case 11;} else {t.kind = 2; break;} case 25: if (ch >= '0' && ch <= '9') {AddCh(); goto case 2;} else if (ch == '.') {AddCh(); goto case 21;} else {t.kind = 5; break;} case 26: if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'S' || ch >= 'U' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;} else if (ch == 'T') {AddCh(); goto case 31;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 27: if (ch >= '0' && ch <= '9' || ch == 'A' || ch >= 'C' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;} else if (ch == 'B') {AddCh(); goto case 32;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 28: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= 39 || ch >= ')' && ch <= '9' || ch >= ';' && ch <= 'Z' || ch >= ']' && ch <= 'z' || ch >= '|' && ch <= 65535) {AddCh(); goto case 14;} else if (ch == '"') {AddCh(); goto case 33;} else if (ch == ':') {AddCh(); goto case 28;} else if (ch == '(') {AddCh(); goto case 34;} else if (ch == '{') {AddCh(); goto case 35;} else if (ch == '[') {AddCh(); goto case 36;} else {t.kind = noSym; break;} case 29: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 29;} else if (ch == ':') {AddCh(); goto case 37;} else if (ch == '"') {AddCh(); goto case 15;} else {t.kind = noSym; break;} case 30: if (ch <= 'K' || ch >= 'M' && ch <= 65535) {AddCh(); goto case 19;} else if (ch == 'L') {AddCh(); goto case 38;} else {t.kind = noSym; break;} case 31: if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'V' || ch >= 'X' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;} else if (ch == 'W') {AddCh(); goto case 39;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 32: if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'S' || ch >= 'U' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;} else if (ch == 'T') {AddCh(); goto case 40;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 33: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 14;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 28;} else {t.kind = 4; break;} case 34: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ';' && ch <= '@' || ch >= 'G' && ch <= '[' || ch >= ']' && ch <= '`' || ch >= 'g' && ch <= 65535) {AddCh(); goto case 14;} else if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 41;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 28;} else {t.kind = noSym; break;} case 35: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= '@' || ch == '[' || ch >= ']' && ch <= '^' || ch == '`' || ch >= '{' && ch <= 65535) {AddCh(); goto case 14;} else if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 42;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 28;} else {t.kind = noSym; break;} case 36: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 29;} else if (ch == ':') {AddCh(); goto case 37;} else if (ch == '"') {AddCh(); goto case 15;} else {t.kind = noSym; break;} case 37: if (ch == '[') {AddCh(); goto case 43;} else if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= 39 || ch >= ')' && ch <= '9' || ch >= ';' && ch <= 'Z' || ch >= ']' && ch <= 'z' || ch >= '|' && ch <= 65535) {AddCh(); goto case 29;} else if (ch == '"') {AddCh(); goto case 33;} else if (ch == ':') {AddCh(); goto case 37;} else if (ch == '(') {AddCh(); goto case 44;} else if (ch == '{') {AddCh(); goto case 45;} else {t.kind = noSym; break;} case 38: if (ch <= 'C' || ch >= 'E' && ch <= 65535) {AddCh(); goto case 19;} else if (ch == 'D') {AddCh(); goto case 46;} else {t.kind = noSym; break;} case 39: if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 39;} else if (ch == 10) {apx++; AddCh(); goto case 18;} else if (ch <= 9 || ch >= 11 && ch <= '/' || ch >= ':' && ch <= '@' || ch >= '[' && ch <= '^' || ch == '`' || ch >= '{' && ch <= 65535) {AddCh(); goto case 17;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 40: if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'V' || ch >= 'X' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;} else if (ch == 'W') {AddCh(); goto case 47;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 41: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ';' && ch <= '@' || ch >= 'G' && ch <= '[' || ch >= ']' && ch <= '`' || ch >= 'g' && ch <= 65535) {AddCh(); goto case 14;} else if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 48;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 28;} else {t.kind = noSym; break;} case 42: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ';' && ch <= '@' || ch == '[' || ch >= ']' && ch <= '^' || ch == '`' || ch >= '{' && ch <= 65535) {AddCh(); goto case 14;} else if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 42;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 28;} else {t.kind = noSym; break;} case 43: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 29;} else if (ch == ':') {AddCh(); goto case 37;} else if (ch == '"') {AddCh(); goto case 15;} else {t.kind = noSym; break;} case 44: if (ch == ':') {AddCh(); goto case 37;} else if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ';' && ch <= '@' || ch >= 'G' && ch <= '[' || ch >= ']' && ch <= '`' || ch >= 'g' && ch <= 65535) {AddCh(); goto case 29;} else if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 49;} else if (ch == '"') {AddCh(); goto case 15;} else {t.kind = noSym; break;} case 45: if (ch == ':') {AddCh(); goto case 37;} else if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= '@' || ch == '[' || ch >= ']' && ch <= '^' || ch == '`' || ch >= '{' && ch <= 65535) {AddCh(); goto case 29;} else if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 50;} else if (ch == '"') {AddCh(); goto case 15;} else {t.kind = noSym; break;} case 46: if (ch <= 'Q' || ch >= 'S' && ch <= 65535) {AddCh(); goto case 19;} else if (ch == 'R') {AddCh(); goto case 20;} else {t.kind = noSym; break;} case 47: if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;} else if (ch == 9 || ch >= 11 && ch <= 12 || ch == ' ') {AddCh(); goto case 19;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 48: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ';' && ch <= '@' || ch >= 'G' && ch <= '[' || ch >= ']' && ch <= '`' || ch >= 'g' && ch <= 65535) {AddCh(); goto case 14;} else if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 51;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 28;} else {t.kind = noSym; break;} case 49: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ';' && ch <= '@' || ch >= 'G' && ch <= '[' || ch >= ']' && ch <= '`' || ch >= 'g' && ch <= 65535) {AddCh(); goto case 29;} else if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 52;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 37;} else {t.kind = noSym; break;} case 50: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ';' && ch <= '@' || ch == '[' || ch >= ']' && ch <= '^' || ch == '`' || ch >= '{' && ch <= 65535) {AddCh(); goto case 29;} else if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 50;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 37;} else {t.kind = noSym; break;} case 51: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ';' && ch <= '@' || ch >= 'G' && ch <= '[' || ch >= ']' && ch <= '`' || ch >= 'g' && ch <= 65535) {AddCh(); goto case 14;} else if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 53;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 28;} else {t.kind = noSym; break;} case 52: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ';' && ch <= '@' || ch >= 'G' && ch <= '[' || ch >= ']' && ch <= '`' || ch >= 'g' && ch <= 65535) {AddCh(); goto case 29;} else if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 54;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 37;} else {t.kind = noSym; break;} case 53: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 14;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 28;} else {t.kind = noSym; break;} case 54: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ';' && ch <= '@' || ch >= 'G' && ch <= '[' || ch >= ']' && ch <= '`' || ch >= 'g' && ch <= 65535) {AddCh(); goto case 29;} else if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 55;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 37;} else {t.kind = noSym; break;} case 55: if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 29;} else if (ch == '"') {AddCh(); goto case 15;} else if (ch == ':') {AddCh(); goto case 37;} else {t.kind = noSym; break;} case 56: {t.kind = 26; break;} case 57: {t.kind = 44; break;} case 58: if (ch == '!') {AddCh(); goto case 57;} else {t.kind = 56; break;} } t.val = new String(tval, 0, tlen); return t; }
void Init() { pos = -1; line = 1; col = 0; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2)); } buffer = new UTF8Buffer(buffer); col = 0; NextCh(); } start = new Dictionary<int, int>(128); for (int i = 65; i <= 65; ++i) start[i] = 1; for (int i = 67; i <= 78; ++i) start[i] = 1; for (int i = 80; i <= 90; ++i) start[i] = 1; for (int i = 95; i <= 95; ++i) start[i] = 1; for (int i = 97; i <= 122; ++i) start[i] = 1; for (int i = 48; i <= 57; ++i) start[i] = 24; for (int i = 10; i <= 10; ++i) start[i] = 16; for (int i = 44; i <= 44; ++i) start[i] = 16; start[46] = 25; start[34] = 14; start[66] = 26; start[79] = 27; start[8230] = 22; start[63] = 56; start[33] = 58; start[Buffer.EOF] = -1; pt = tokens = new Token(); // first token is a dummy }
// get the next token (possibly a token already seen during peeking) public Token Scan() { if (tokens.next == null) { return NextToken(); } else { pt = tokens = tokens.next; return tokens; } }
// make sure that peeking starts at the current scan position public void ResetPeek() { pt = tokens; }
// peek for the next token, ignore pragmas public Token Peek() { if (pt.next == null) { do { pt = pt.next = NextToken(); } while (pt.kind > maxT); // skip pragmas } else { do { pt = pt.next; } while (pt.kind > maxT); } return pt; }
public void Parse() { la = new Token(); la.val = ""; Get(); LOLCode(); Expect(0); }