예제 #1
0
파일: Token.cs 프로젝트: SealedSun/prx
 public Token(Token next)
 {
     this.next = next;
 }
예제 #2
0
파일: Scanner.cs 프로젝트: SealedSun/prx
	// make sure that peeking starts at the current scan position
	public void ResetPeek () { pt = tokens; }
예제 #3
0
파일: Scanner.cs 프로젝트: SealedSun/prx
	// 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;
	}
예제 #4
0
파일: Scanner.cs 프로젝트: SealedSun/prx
	// 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 프로젝트: SealedSun/prx
	Token NextToken() {
		while (false || ch >= 9 && ch <= 10 || 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 == '$' || ch >= '0' && ch <= '9' || ch == 92 || 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:
				{t.kind = 2; break;}
			case 3:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 4;}
				else {t.kind = noSym; break;}
			case 4:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 4;}
				else {t.kind = 5; break;}
			case 5:
				{
					tlen -= apx;
					buffer.Pos = t.pos; NextCh(); line = t.line; col = t.col;
					for (int i = 0; i < tlen; i++) NextCh();
					t.kind = 5; break;}
			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') {AddCh(); goto case 8;}
				else {t.kind = 6; break;}
			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 = 6; break;}
			case 11:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 11;}
				else if (ch == 'e') {AddCh(); goto case 12;}
				else {t.kind = 6; break;}
			case 12:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 14;}
				else if (ch == '+' || ch == '-') {AddCh(); goto case 13;}
				else {t.kind = noSym; break;}
			case 13:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 14;}
				else {t.kind = noSym; break;}
			case 14:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 14;}
				else {t.kind = 6; break;}
			case 15:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 17;}
				else if (ch == '+' || ch == '-') {AddCh(); goto case 16;}
				else {t.kind = noSym; break;}
			case 16:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 17;}
				else {t.kind = noSym; break;}
			case 17:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 17;}
				else {t.kind = 6; break;}
			case 18:
				if (ch <= 9 || ch >= 11 && ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 18;}
				else if (ch == '"') {AddCh(); goto case 34;}
				else if (ch == 92) {AddCh(); goto case 37;}
				else {t.kind = noSym; break;}
			case 19:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 20;}
				else {t.kind = noSym; break;}
			case 20:
				if (ch <= 9 || ch >= 11 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ':' && ch <= '[' || ch >= ']' && ch <= '`' || ch >= 'g' && ch <= 65535) {AddCh(); goto case 18;}
				else if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 38;}
				else if (ch == '"') {AddCh(); goto case 34;}
				else if (ch == 92) {AddCh(); goto case 37;}
				else {t.kind = noSym; break;}
			case 21:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 22;}
				else {t.kind = noSym; break;}
			case 22:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 23;}
				else {t.kind = noSym; break;}
			case 23:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 18;}
				else {t.kind = noSym; break;}
			case 24:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 25;}
				else {t.kind = noSym; break;}
			case 25:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 26;}
				else {t.kind = noSym; break;}
			case 26:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 27;}
				else {t.kind = noSym; break;}
			case 27:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 28;}
				else {t.kind = noSym; break;}
			case 28:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 29;}
				else {t.kind = noSym; break;}
			case 29:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 30;}
				else {t.kind = noSym; break;}
			case 30:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 31;}
				else {t.kind = noSym; break;}
			case 31:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 18;}
				else {t.kind = noSym; break;}
			case 32:
				if (ch == '"') {AddCh(); goto case 33;}
				else {t.kind = noSym; break;}
			case 33:
				if (ch <= '!' || ch >= '#' && ch <= 65535) {AddCh(); goto case 33;}
				else if (ch == '"') {AddCh(); goto case 40;}
				else {t.kind = noSym; break;}
			case 34:
				{t.kind = 7; break;}
			case 35:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 35;}
				else if (ch == '.') {apx++; AddCh(); goto case 41;}
				else if (ch == 'e') {AddCh(); goto case 15;}
				else {t.kind = 5; break;}
			case 36:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 35;}
				else if (ch == '.') {apx++; AddCh(); goto case 41;}
				else if (ch == 'x') {AddCh(); goto case 3;}
				else if (ch == 'e') {AddCh(); goto case 15;}
				else {t.kind = 5; break;}
			case 37:
				if (ch == '"' || ch == '$' || ch == 39 || ch == '0' || ch == 92 || ch >= 'a' && ch <= 'b' || ch == 'f' || ch == 'n' || ch == 'r' || ch == 't' || ch == 'v') {AddCh(); goto case 18;}
				else if (ch == 'x') {AddCh(); goto case 19;}
				else if (ch == 'u') {AddCh(); goto case 42;}
				else {t.kind = noSym; break;}
			case 38:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 39;}
				else if (ch <= 9 || ch >= 11 && ch <= '!' || ch >= '#' && ch <= '/' || ch >= ':' && ch <= '[' || ch >= ']' && ch <= '`' || ch >= 'g' && ch <= 65535) {AddCh(); goto case 18;}
				else if (ch == '"') {AddCh(); goto case 34;}
				else if (ch == 92) {AddCh(); goto case 37;}
				else {t.kind = noSym; break;}
			case 39:
				if (ch <= 9 || ch >= 11 && ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 18;}
				else if (ch == '"') {AddCh(); goto case 34;}
				else if (ch == 92) {AddCh(); goto case 37;}
				else {t.kind = noSym; break;}
			case 40:
				if (ch == '"') {AddCh(); goto case 33;}
				else {t.kind = 7; break;}
			case 41:
				if (ch <= '/' || ch >= ':' && ch <= 65535) {apx++; AddCh(); goto case 5;}
				else if (ch >= '0' && ch <= '9') {apx = 0; AddCh(); goto case 11;}
				else {t.kind = noSym; break;}
			case 42:
				if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 21;}
				else if (ch == 'l') {AddCh(); goto case 24;}
				else {t.kind = noSym; break;}
			case 43:
				{t.kind = 8; break;}
			case 44:
				{t.kind = 9; break;}
			case 45:
				{t.kind = 10; break;}

		}
		t.val = new String(tval, 0, tlen);
		return t;
	}
예제 #6
0
파일: Scanner.cs 프로젝트: SealedSun/prx
	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 = 36; i <= 36; ++i) start[i] = 1;
		for (int i = 92; i <= 92; ++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 = 49; i <= 57; ++i) start[i] = 35;
		start[126] = 2; 
		start[48] = 36; 
		start[46] = 6; 
		start[34] = 18; 
		start[64] = 32; 
		start[40] = 43; 
		start[44] = 44; 
		start[41] = 45; 
		start[Buffer.EOF] = -1;

		pt = tokens = new Token();  // first token is a dummy
	}