Exemplo n.º 1
0
	void Get () {
		for (;;) {
			t = la;
			la = scanner.Scan();
			if (la.kind <= maxT) { ++errDist; break; }

			la = t;
		}
	}
Exemplo n.º 2
0
	// make sure that peeking starts at the current scan position
	public void ResetPeek () { pt = tokens; }
Exemplo n.º 3
0
	// peek for the next token, ignore pragmas
	public Token Peek () {
		do {
			if (pt.next == null) {
				pt.next = NextToken();
			}
			pt = pt.next;
		} while (pt.kind > maxT); // skip pragmas
	
		return pt;
	}
Exemplo n.º 4
0
	// 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;
		}
	}
Exemplo n.º 5
0
	Token NextToken() {
		while (ch == ' ' ||
			ch >= 9 && ch <= 10 || ch == 13
		) NextCh();

		int recKind = noSym;
		int recEnd = pos;
		t = new Token();
		t.pos = pos; t.col = col; t.line = line; t.charPos = charPos;
		int state;
		if (start.ContainsKey(ch)) { state = (int) start[ch]; }
		else { state = 0; }
		tlen = 0; AddCh();
		
		switch (state) {
			case -1: { t.kind = eofSym; break; } // NextCh already done
			case 0: {
				if (recKind != noSym) {
					tlen = recEnd - t.pos;
					SetScannerBehindT();
				}
				t.kind = recKind; break;
			} // NextCh already done
			case 1:
				if (ch == 'n') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 2:
				if (ch == 'b') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 3:
				if (ch == 'r') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 4:
				if (ch == 'r') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 5:
				if (ch == 'i') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 6:
				if (ch == 'g') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 7:
				if (ch == 'p') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 8:
				if (ch == 'k') {AddCh(); goto case 9;}
				else {goto case 0;}
			case 9:
				if (ch == 't') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 10:
				if (ch == 'o') {AddCh(); goto case 11;}
				else {goto case 0;}
			case 11:
				if (ch == 'v') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 12:
				if (ch == 'z') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 13:
				{t.kind = 1; break;}
			case 14:
				if (ch == 'n') {AddCh(); goto case 15;}
				else {goto case 0;}
			case 15:
				if (ch == 't') {AddCh(); goto case 16;}
				else {goto case 0;}
			case 16:
				if (ch == 'a') {AddCh(); goto case 17;}
				else {goto case 0;}
			case 17:
				if (ch == 'g') {AddCh(); goto case 52;}
				else {goto case 0;}
			case 18:
				if (ch == 'e') {AddCh(); goto case 19;}
				else {goto case 0;}
			case 19:
				if (ch == 'n') {AddCh(); goto case 20;}
				else {goto case 0;}
			case 20:
				if (ch == 's') {AddCh(); goto case 21;}
				else {goto case 0;}
			case 21:
				if (ch == 't') {AddCh(); goto case 22;}
				else {goto case 0;}
			case 22:
				if (ch == 'a') {AddCh(); goto case 23;}
				else {goto case 0;}
			case 23:
				if (ch == 'g') {AddCh(); goto case 52;}
				else {goto case 0;}
			case 24:
				if (ch == 't') {AddCh(); goto case 25;}
				else {goto case 0;}
			case 25:
				if (ch == 'w') {AddCh(); goto case 26;}
				else {goto case 0;}
			case 26:
				if (ch == 'o') {AddCh(); goto case 27;}
				else {goto case 0;}
			case 27:
				if (ch == 'c') {AddCh(); goto case 28;}
				else {goto case 0;}
			case 28:
				if (ch == 'h') {AddCh(); goto case 52;}
				else {goto case 0;}
			case 29:
				if (ch == 'n') {AddCh(); goto case 30;}
				else {goto case 0;}
			case 30:
				if (ch == 'n') {AddCh(); goto case 31;}
				else {goto case 0;}
			case 31:
				if (ch == 'e') {AddCh(); goto case 32;}
				else {goto case 0;}
			case 32:
				if (ch == 'r') {AddCh(); goto case 33;}
				else {goto case 0;}
			case 33:
				if (ch == 's') {AddCh(); goto case 34;}
				else {goto case 0;}
			case 34:
				if (ch == 't') {AddCh(); goto case 35;}
				else {goto case 0;}
			case 35:
				if (ch == 'a') {AddCh(); goto case 36;}
				else {goto case 0;}
			case 36:
				if (ch == 'g') {AddCh(); goto case 52;}
				else {goto case 0;}
			case 37:
				if (ch == 'e') {AddCh(); goto case 38;}
				else {goto case 0;}
			case 38:
				if (ch == 'i') {AddCh(); goto case 39;}
				else {goto case 0;}
			case 39:
				if (ch == 't') {AddCh(); goto case 40;}
				else {goto case 0;}
			case 40:
				if (ch == 'a') {AddCh(); goto case 41;}
				else {goto case 0;}
			case 41:
				if (ch == 'g') {AddCh(); goto case 52;}
				else {goto case 0;}
			case 42:
				if (ch == 'm') {AddCh(); goto case 43;}
				else {goto case 0;}
			case 43:
				if (ch == 's') {AddCh(); goto case 44;}
				else {goto case 0;}
			case 44:
				if (ch == 't') {AddCh(); goto case 45;}
				else {goto case 0;}
			case 45:
				if (ch == 'a') {AddCh(); goto case 46;}
				else {goto case 0;}
			case 46:
				if (ch == 'g') {AddCh(); goto case 52;}
				else {goto case 0;}
			case 47:
				if (ch == 'n') {AddCh(); goto case 48;}
				else {goto case 0;}
			case 48:
				if (ch == 'n') {AddCh(); goto case 49;}
				else {goto case 0;}
			case 49:
				if (ch == 't') {AddCh(); goto case 50;}
				else {goto case 0;}
			case 50:
				if (ch == 'a') {AddCh(); goto case 51;}
				else {goto case 0;}
			case 51:
				if (ch == 'g') {AddCh(); goto case 52;}
				else {goto case 0;}
			case 52:
				{t.kind = 2; break;}
			case 53:
				if (ch == 'd') {AddCh(); goto case 54;}
				else {goto case 0;}
			case 54:
				{t.kind = 3; break;}
			case 55:
				recEnd = pos; recKind = 4;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 55;}
				else {t.kind = 4; break;}
			case 56:
				recEnd = pos; recKind = 3;
				if (ch == 'a') {AddCh(); goto case 1;}
				else if (ch == 'u') {AddCh(); goto case 62;}
				else {t.kind = 3; break;}
			case 57:
				if (ch == 'e') {AddCh(); goto case 2;}
				else if (ch == 'r') {AddCh(); goto case 37;}
				else {goto case 0;}
			case 58:
				recEnd = pos; recKind = 3;
				if (ch == 228) {AddCh(); goto case 3;}
				else if (ch == 'a') {AddCh(); goto case 5;}
				else if (ch == 'o') {AddCh(); goto case 14;}
				else if (ch == 'i') {AddCh(); goto case 63;}
				else {t.kind = 3; break;}
			case 59:
				if (ch == 'p') {AddCh(); goto case 4;}
				else if (ch == 'u') {AddCh(); goto case 6;}
				else {goto case 0;}
			case 60:
				if (ch == 'e') {AddCh(); goto case 7;}
				else if (ch == 'a') {AddCh(); goto case 42;}
				else if (ch == 'o') {AddCh(); goto case 47;}
				else if (ch == 't') {AddCh(); goto case 53;}
				else {goto case 0;}
			case 61:
				if (ch == 'e') {AddCh(); goto case 12;}
				else if (ch == 'i') {AddCh(); goto case 18;}
				else if (ch == 'o') {AddCh(); goto case 29;}
				else {goto case 0;}
			case 62:
				if (ch == 'l' || ch == 'n') {AddCh(); goto case 13;}
				else {goto case 0;}
			case 63:
				if (ch == 't') {AddCh(); goto case 24;}
				else if (ch == 'n') {AddCh(); goto case 54;}
				else {goto case 0;}
			case 64:
				{t.kind = 5; break;}
			case 65:
				{t.kind = 6; break;}

		}
		t.val = new String(tval, 0, tlen);
		return t;
	}
Exemplo n.º 6
0
	void Init() {
		pos = -1; line = 1; col = 0; charPos = -1;
		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; charPos = -1;
			NextCh();
		}
		pt = tokens = new Token();  // first token is a dummy
	}
Exemplo n.º 7
0
	public void Parse() {
		la = new Token();
		la.val = "";		
		Get();
		Followup();
		Expect(0);

	}