示例#1
0
	void Get () {
		for (;;) {
			t = la;
			la = scanner.Scan();
			if (la.kind <= maxT) { ++errDist; break; }

			la = t;
		}
	}
示例#2
0
文件: Scanner.cs 项目: heran/DekiWiki
	// make sure that peeking starts at the current scan position
	public void ResetPeek () { pt = tokens; }
示例#3
0
文件: Scanner.cs 项目: heran/DekiWiki
	// 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;
	}
示例#4
0
文件: Scanner.cs 项目: heran/DekiWiki
	// 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;
		}
	}
示例#5
0
文件: Scanner.cs 项目: heran/DekiWiki
	Token NextToken() {
		while (ch == ' ' ||
			ch >= 9 && ch <= 10 || ch == 13 || ch == 160 || ch == 173
		) NextCh();
		if (ch == '/' && Comment0() ||ch == '/' && Comment1()) return NextToken();
		int recKind = noSym;
		int recEnd = pos;
		t = new Token();
		t.pos = pos; t.col = col; t.line = line; t.origin = origin;
		int state;
		start.TryGetValue(ch, out state);
		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:
				recEnd = pos; recKind = 1;
				if (ch >= '0' && ch <= '9' || 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:
				recEnd = pos; recKind = 1;
				if (ch >= '0' && ch <= '9' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 2;}
				else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
			case 3:
				recEnd = pos; recKind = 1;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 3;}
				else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
			case 4:
				recEnd = pos; recKind = 1;
				if (ch >= '0' && ch <= '9' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 4;}
				else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
			case 5:
				if (ch >= 'a' && ch <= 'z') {AddCh(); goto case 6;}
				else {goto case 0;}
			case 6:
				recEnd = pos; recKind = 2;
				if (ch >= '0' && ch <= '9' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 6;}
				else {t.kind = 2; break;}
			case 7:
				if (ch <= '!' || ch >= '#' && ch <= 65535) {AddCh(); goto case 7;}
				else if (ch == '"') {AddCh(); goto case 37;}
				else {goto case 0;}
			case 8:
				if (ch <= '&' || ch >= '(' && ch <= 65535) {AddCh(); goto case 8;}
				else if (ch == 39) {AddCh(); goto case 38;}
				else {goto case 0;}
			case 9:
				if (ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 9;}
				else if (ch == '"') {AddCh(); goto case 11;}
				else if (ch == 92) {AddCh(); goto case 39;}
				else {goto case 0;}
			case 10:
				if (ch <= '&' || ch >= '(' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 10;}
				else if (ch == 39) {AddCh(); goto case 11;}
				else if (ch == 92) {AddCh(); goto case 40;}
				else {goto case 0;}
			case 11:
				{t.kind = 4; break;}
			case 12:
				recEnd = pos; recKind = 5;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 12;}
				else if (ch == 'e') {AddCh(); goto case 13;}
				else {t.kind = 5; break;}
			case 13:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 15;}
				else if (ch == '+' || ch == '-') {AddCh(); goto case 14;}
				else {goto case 0;}
			case 14:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 15;}
				else {goto case 0;}
			case 15:
				recEnd = pos; recKind = 5;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 15;}
				else {t.kind = 5; break;}
			case 16:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 17;}
				else {goto case 0;}
			case 17:
				recEnd = pos; recKind = 5;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 17;}
				else if (ch == 'e') {AddCh(); goto case 18;}
				else {t.kind = 5; break;}
			case 18:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 20;}
				else if (ch == '+' || ch == '-') {AddCh(); goto case 19;}
				else {goto case 0;}
			case 19:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 20;}
				else {goto case 0;}
			case 20:
				recEnd = pos; recKind = 5;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 20;}
				else {t.kind = 5; break;}
			case 21:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 23;}
				else if (ch == '+' || ch == '-') {AddCh(); goto case 22;}
				else {goto case 0;}
			case 22:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 23;}
				else {goto case 0;}
			case 23:
				recEnd = pos; recKind = 5;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 23;}
				else {t.kind = 5; break;}
			case 24:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 25;}
				else {goto case 0;}
			case 25:
				recEnd = pos; recKind = 6;
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 25;}
				else {t.kind = 6; break;}
			case 26:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 26;}
				else if (ch == ';') {AddCh(); goto case 31;}
				else {goto case 0;}
			case 27:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 28;}
				else if (ch == 'x') {AddCh(); goto case 29;}
				else {goto case 0;}
			case 28:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 28;}
				else if (ch == ';') {AddCh(); goto case 31;}
				else {goto case 0;}
			case 29:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 30;}
				else {goto case 0;}
			case 30:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 30;}
				else if (ch == ';') {AddCh(); goto case 31;}
				else {goto case 0;}
			case 31:
				{t.kind = 7; break;}
			case 32:
				recEnd = pos; recKind = 5;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 32;}
				else if (ch == '.') {AddCh(); goto case 16;}
				else if (ch == 'e') {AddCh(); goto case 21;}
				else {t.kind = 5; break;}
			case 33:
				recEnd = pos; recKind = 1;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 3;}
				else if (ch >= 'a' && ch <= 'z') {AddCh(); goto case 4;}
				else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
			case 34:
				if (ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 9;}
				else if (ch == '"') {AddCh(); goto case 41;}
				else if (ch == 92) {AddCh(); goto case 39;}
				else {goto case 0;}
			case 35:
				if (ch <= '&' || ch >= '(' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 10;}
				else if (ch == 39) {AddCh(); goto case 42;}
				else if (ch == 92) {AddCh(); goto case 40;}
				else {goto case 0;}
			case 36:
				recEnd = pos; recKind = 5;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 32;}
				else if (ch == '.') {AddCh(); goto case 16;}
				else if (ch == 'e') {AddCh(); goto case 21;}
				else if (ch == 'x') {AddCh(); goto case 24;}
				else {t.kind = 5; break;}
			case 37:
				if (ch <= '!' || ch >= '#' && ch <= 65535) {AddCh(); goto case 7;}
				else if (ch == '"') {AddCh(); goto case 43;}
				else {goto case 0;}
			case 38:
				if (ch <= '&' || ch >= '(' && ch <= 65535) {AddCh(); goto case 8;}
				else if (ch == 39) {AddCh(); goto case 44;}
				else {goto case 0;}
			case 39:
				if (ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 9;}
				else if (ch == '"') {AddCh(); goto case 45;}
				else if (ch == 92) {AddCh(); goto case 39;}
				else {goto case 0;}
			case 40:
				if (ch <= '&' || ch >= '(' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 10;}
				else if (ch == 39) {AddCh(); goto case 46;}
				else if (ch == 92) {AddCh(); goto case 40;}
				else {goto case 0;}
			case 41:
				recEnd = pos; recKind = 4;
				if (ch == '"') {AddCh(); goto case 7;}
				else {t.kind = 4; break;}
			case 42:
				recEnd = pos; recKind = 4;
				if (ch == 39) {AddCh(); goto case 8;}
				else {t.kind = 4; break;}
			case 43:
				if (ch <= '!' || ch >= '#' && ch <= 65535) {AddCh(); goto case 7;}
				else if (ch == '"') {AddCh(); goto case 47;}
				else {goto case 0;}
			case 44:
				if (ch <= '&' || ch >= '(' && ch <= 65535) {AddCh(); goto case 8;}
				else if (ch == 39) {AddCh(); goto case 48;}
				else {goto case 0;}
			case 45:
				recEnd = pos; recKind = 4;
				if (ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 9;}
				else if (ch == '"') {AddCh(); goto case 11;}
				else if (ch == 92) {AddCh(); goto case 39;}
				else {t.kind = 4; break;}
			case 46:
				recEnd = pos; recKind = 4;
				if (ch <= '&' || ch >= '(' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 10;}
				else if (ch == 39) {AddCh(); goto case 11;}
				else if (ch == 92) {AddCh(); goto case 40;}
				else {t.kind = 4; break;}
			case 47:
				recEnd = pos; recKind = 3;
				if (ch <= '!' || ch >= '#' && ch <= 65535) {AddCh(); goto case 7;}
				else if (ch == '"') {AddCh(); goto case 47;}
				else {t.kind = 3; break;}
			case 48:
				recEnd = pos; recKind = 3;
				if (ch <= '&' || ch >= '(' && ch <= 65535) {AddCh(); goto case 8;}
				else if (ch == 39) {AddCh(); goto case 48;}
				else {t.kind = 3; break;}
			case 49:
				{t.kind = 8; break;}
			case 50:
				{t.kind = 9; break;}
			case 51:
				{t.kind = 10; break;}
			case 52:
				{t.kind = 13; break;}
			case 53:
				{t.kind = 14; break;}
			case 54:
				{t.kind = 15; break;}
			case 55:
				{t.kind = 16; break;}
			case 56:
				{t.kind = 17; break;}
			case 57:
				{t.kind = 18; break;}
			case 58:
				{t.kind = 20; break;}
			case 59:
				{t.kind = 22; break;}
			case 60:
				{t.kind = 23; break;}
			case 61:
				{t.kind = 31; break;}
			case 62:
				{t.kind = 36; break;}
			case 63:
				{t.kind = 38; break;}
			case 64:
				if (ch == '|') {AddCh(); goto case 65;}
				else {goto case 0;}
			case 65:
				{t.kind = 39; break;}
			case 66:
				{t.kind = 40; break;}
			case 67:
				{t.kind = 43; break;}
			case 68:
				{t.kind = 44; break;}
			case 69:
				{t.kind = 47; break;}
			case 70:
				{t.kind = 48; break;}
			case 71:
				{t.kind = 62; break;}
			case 72:
				{t.kind = 64; break;}
			case 73:
				{t.kind = 65; break;}
			case 74:
				{t.kind = 72; break;}
			case 75:
				{t.kind = 73; break;}
			case 76:
				recEnd = pos; recKind = 66;
				if (ch >= '0' && ch <= '9' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 2;}
				else {t.kind = 66; break;}
			case 77:
				recEnd = pos; recKind = 63;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 12;}
				else if (ch == '.') {AddCh(); goto case 89;}
				else {t.kind = 63; break;}
			case 78:
				recEnd = pos; recKind = 54;
				if (ch >= 'a' && ch <= 'z') {AddCh(); goto case 26;}
				else if (ch == '#') {AddCh(); goto case 27;}
				else if (ch == '&') {AddCh(); goto case 66;}
				else {t.kind = 54; break;}
			case 79:
				recEnd = pos; recKind = 12;
				if (ch == '=') {AddCh(); goto case 90;}
				else {t.kind = 12; break;}
			case 80:
				recEnd = pos; recKind = 55;
				if (ch == '=') {AddCh(); goto case 52;}
				else {t.kind = 55; break;}
			case 81:
				recEnd = pos; recKind = 56;
				if (ch == '=') {AddCh(); goto case 53;}
				else {t.kind = 56; break;}
			case 82:
				recEnd = pos; recKind = 57;
				if (ch == '=') {AddCh(); goto case 54;}
				else {t.kind = 57; break;}
			case 83:
				recEnd = pos; recKind = 58;
				if (ch == '=') {AddCh(); goto case 55;}
				else if (ch == '>') {AddCh(); goto case 75;}
				else {t.kind = 58; break;}
			case 84:
				recEnd = pos; recKind = 59;
				if (ch == '=') {AddCh(); goto case 56;}
				else {t.kind = 59; break;}
			case 85:
				recEnd = pos; recKind = 60;
				if (ch == '!') {AddCh(); goto case 62;}
				else if (ch == '=') {AddCh(); goto case 91;}
				else {t.kind = 60; break;}
			case 86:
				recEnd = pos; recKind = 37;
				if (ch == '?') {AddCh(); goto case 63;}
				else {t.kind = 37; break;}
			case 87:
				recEnd = pos; recKind = 45;
				if (ch == '=') {AddCh(); goto case 69;}
				else if (ch == '/') {AddCh(); goto case 92;}
				else {t.kind = 45; break;}
			case 88:
				recEnd = pos; recKind = 46;
				if (ch == '=') {AddCh(); goto case 70;}
				else {t.kind = 46; break;}
			case 89:
				recEnd = pos; recKind = 53;
				if (ch == '=') {AddCh(); goto case 57;}
				else {t.kind = 53; break;}
			case 90:
				recEnd = pos; recKind = 42;
				if (ch == '=') {AddCh(); goto case 68;}
				else {t.kind = 42; break;}
			case 91:
				recEnd = pos; recKind = 41;
				if (ch == '=') {AddCh(); goto case 67;}
				else {t.kind = 41; break;}
			case 92:
				recEnd = pos; recKind = 71;
				if (ch == '>') {AddCh(); goto case 74;}
				else {t.kind = 71; break;}

		}
		t.val = new String(tval, 0, tlen);
		return t;
	}
示例#6
0
文件: Scanner.cs 项目: heran/DekiWiki
	void Init(string o, int l, int c) {
		pos = -1; line = l; col = c;
		origin = o;
		oldEols = 0;
		
		// NOTE: always use UTF-8 decoding
		buffer = new UTF8Buffer(buffer);
		
		NextCh();
		pt = tokens = new Token();  // first token is a dummy
	}
示例#7
0
	public void Parse() {
		la = new Token();
		la.val = "";		
		Get();
		DekiScript();

    Expect(0);
	}