void Init() { pos = -1; line = 1; lineStart = 0; oldEols = 0; NextCh(); ignore = new BitArray(charSetSize+1); ignore[' '] = true; // blanks are always white space ignore[9] = true; ignore[10] = true; ignore[13] = true; pt = tokens = new Token(); // first token is a dummy }
Token NextToken() { while (ignore[ch]) NextCh(); t = new Token(); t.pos = pos; t.col = pos - lineStart + 1; t.line = line; int state = start[ch]; 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: {t.kind = 1; break;} case 2: if ((ch >= '0' && ch <= '9')) {AddCh(); goto case 2;} else {t.kind = 2; break;} case 3: {t.kind = 3; break;} case 4: {t.kind = 4; break;} } t.val = new String(tval, 0, tlen); return t; }
// 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; }
void Get() { for (;;) { token = la; la = scanner.Scan(); if (la.kind <= maxT) { ++errDist; break; } la = token; } }
public IDice Parse() { la = new Token(); la.val = ""; Get(); Dice(); Expect(0); return dice; }