Exemplo n.º 1
0
	// make sure that peeking starts at the current scan position
	public void ResetPeek () { pt = tokens; }
Exemplo n.º 2
0
	void Get () {
		for (;;) {
			t = la;
			la = scanner.Scan();
			if (la.kind <= maxT) { ++errDist; break; }

			la = t;
		}
	}
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 == 10 || ch == 13
		) NextCh();

		int recKind = noSym;
		int recEnd = pos;
		t = new Token();
		t.pos = pos; t.col = col; t.line = line; 
		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 >= '0' && ch <= '9') {AddCh(); goto case 2;}
				else {goto case 0;}
			case 2:
				recEnd = pos; recKind = 5;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 2;}
				else {t.kind = 5; break;}
			case 3:
				{t.kind = 7; break;}
			case 4:
				{t.kind = 8; break;}
			case 5:
				{t.kind = 9; break;}
			case 6:
				{t.kind = 10; break;}
			case 7:
				{t.kind = 17; break;}
			case 8:
				{t.kind = 18; break;}
			case 9:
				{t.kind = 31; break;}
			case 10:
				if (ch == '.') {AddCh(); goto case 11;}
				else {goto case 0;}
			case 11:
				if (ch == '"') {AddCh(); goto case 12;}
				else if (ch == '#' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 13;}
				else if (ch >= '0' && ch <= '9') {AddCh(); goto case 15;}
				else if (ch == '-') {AddCh(); goto case 14;}
				else {goto case 0;}
			case 12:
				if (ch == '"') {AddCh(); goto case 18;}
				else if (ch >= ' ' && ch <= '!' || ch >= '#' && ch <= '+' || ch >= '-' && ch <= ':' || ch == '@' || ch >= '[' && ch <= '_' || ch >= 'a' && ch <= '{' || ch == '}') {AddCh(); goto case 12;}
				else {goto case 0;}
			case 13:
				recEnd = pos; recKind = 35;
				if (ch == '#' || ch >= '0' && ch <= '9' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 13;}
				else {t.kind = 35; break;}
			case 14:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 15;}
				else {goto case 0;}
			case 15:
				recEnd = pos; recKind = 35;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 15;}
				else if (ch == '.') {AddCh(); goto case 16;}
				else {t.kind = 35; break;}
			case 16:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 17;}
				else {goto case 0;}
			case 17:
				recEnd = pos; recKind = 35;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 17;}
				else {t.kind = 35; break;}
			case 18:
				{t.kind = 35; break;}
			case 19:
				recEnd = pos; recKind = 1;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 19;}
				else if (ch == '.') {AddCh(); goto case 22;}
				else {t.kind = 1; break;}
			case 20:
				recEnd = pos; recKind = 3;
				if (ch == '#' || ch >= '0' && ch <= '9' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 20;}
				else if (ch == '.') {AddCh(); goto case 10;}
				else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
			case 21:
				if (ch == '"') {AddCh(); goto case 23;}
				else if (ch >= ' ' && ch <= '!' || ch >= '#' && ch <= '+' || ch >= '-' && ch <= ':' || ch == '@' || ch >= '[' && ch <= '_' || ch >= 'a' && ch <= '{' || ch == '}') {AddCh(); goto case 21;}
				else {goto case 0;}
			case 22:
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 24;}
				else if (ch == '.') {AddCh(); goto case 11;}
				else {goto case 0;}
			case 23:
				recEnd = pos; recKind = 4;
				if (ch == '.') {AddCh(); goto case 10;}
				else {t.kind = 4; break;}
			case 24:
				recEnd = pos; recKind = 2;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 24;}
				else if (ch == '.') {AddCh(); goto case 10;}
				else {t.kind = 2; break;}
			case 25:
				{t.kind = 37; break;}
			case 26:
				{t.kind = 38; break;}
			case 27:
				{t.kind = 39; break;}
			case 28:
				{t.kind = 40; break;}
			case 29:
				{t.kind = 41; break;}
			case 30:
				{t.kind = 42; break;}
			case 31:
				recEnd = pos; recKind = 36;
				if (ch >= '0' && ch <= '9') {AddCh(); goto case 19;}
				else {t.kind = 36; break;}

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

    Expect(0);
	}