public void Parse(Stream stream) { sw = new StreamWriter(stream); la = new Token(); la.val = ""; Get(); Rules(); sw.Flush(); }
public void Init(Stream s) { buffer = new Buffer(); buffer.Fill(s); pos = -1; line = 1; lineStart = 0; oldEols = 0; NextCh(); ignore = new BitArray(charSetSize + 1); ignore[9] = true; ignore[10] = true; ignore[13] = true; ignore[32] = true; //--- AW: fill token list tokens = new Token(); // first token is a dummy Token node = tokens; do { node.next = NextToken(); node = node.next; } while (node.kind != eofSym); /* AW: 0 == EOF */ node.next = node; node.val = "EOF"; t = pt = tokens; }
/* AW 2003-03-07 get the next token, ignore pragmas */ public Token Peek() { do { // skip pragmas while peeking pt = pt.next; } while (pt.kind > maxT); return pt; }
/* AW Scan() renamed to NextToken() */ private Token NextToken() { while (ignore[ch]) NextCh(); if (ch == '/' && Comment0()) return NextToken(); t = new Token(); t.pos = pos; t.col = pos - lineStart + 1; t.line = line; int state = start[ch]; StringBuilder buf = new StringBuilder(16); buf.Append(ch); NextCh(); switch (state) { case -1: { t.kind = eofSym; goto done; } // NextCh already done /* pdt */ case 0: { t.kind = noSym; goto done; } // NextCh already done case 1: {t.kind = 1; goto done;} case 2: {t.kind = 2; goto done;} case 3: {t.kind = 3; goto done;} case 4: if (ch == '>') {buf.Append(ch); NextCh(); goto case 5;} else {t.kind = noSym; goto done;} case 5: {t.kind = 4; goto done;} case 6: {t.kind = 5; goto done;} case 7: {t.kind = 6; goto done;} case 8: {t.kind = 7; goto done;} case 9: if ((ch >= '*' && ch <= '+' || ch >= '-' && ch <= ':' || ch >= 'A' && ch <= 'Z' || ch == 92 || ch == '_' || ch >= 'a' && ch <= 'z')) {buf.Append(ch); NextCh(); goto case 9;} else {t.kind = 8; goto done;} case 10: {t.kind = 9; goto done;} case 11: {t.kind = 10; goto done;} case 12: if ((ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z')) {buf.Append(ch); NextCh(); goto case 13;} else {t.kind = noSym; goto done;} case 13: if ((ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z')) {buf.Append(ch); NextCh(); goto case 13;} else {t.kind = 17; goto done;} case 14: {t.kind = 11; goto done;} case 15: {t.kind = 12; goto done;} case 16: {t.kind = 13; goto done;} case 17: {t.kind = 14; goto done;} case 18: {t.kind = 15; goto done;} } done: t.val = buf.ToString(); return t; }
/* AW 2003-03-07 get the next token, move on and synch peek token with current */ public Token Scan() { t = pt = t.next; return t; }
/* AW 2003-03-11 to make sure peek start at current scan position */ public void ResetPeek() { pt = t; }
private void Get() { for (;;) { t = la; la = scanner.Scan(); if (la.kind <= maxT) { ++errDist; break; } if (la.kind == 17) { if (la.val.Equals("#DIRECTION_FORWARD")) direction = "forward"; else if (la.val.Equals("#DIRECTION_BACKWARD")) direction = "backward"; else if (la.val.Equals("#DIRECTION_BIDIRECTIONAL")) direction = "bidirectional"; else errors.Error(t.line, t.col, "unknown pragma :" + la.val); } la = t; } }