예제 #1
0
	void Get () {
		for (;;) {
			t = la;
			la = scanner.Scan();
			if (la.kind <= maxT) { ++errDist; break; }
				if (la.kind == 64) {
				}
				if (la.kind == 65) {
				}
				if (la.kind == 66) {
				}

			la = t;
		}
	}
예제 #2
0
 private CodePragma GetPragma(Token tok)
 {
     return new CodePragma(doc, filename, tok.line, tok.col);
 }
예제 #3
0
 void Typename(out Type t)
 {
     t = typeof(void);
     if (la.kind == 50) {
     Get();
     t = typeof(bool);
     } else if (la.kind == 51) {
     Get();
     t = typeof(int);
     } else if (la.kind == 52) {
     Get();
     t = typeof(float);
     } else if (la.kind == 53) {
     Get();
     t = typeof(string);
     } else SynErr(70);
 }
예제 #4
0
        public void Parse()
        {
            la = new Token();
            la.val = "";
            Get();
            LOLCode();

            Expect(0);
        }
예제 #5
0
        Token NextToken()
        {
            while (ch == ' ' || ch == 9 || 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 >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || 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:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 2;}
                else if (ch == 'E' || ch == 'e') {AddCh(); goto case 3;}
                else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 3:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 5;}
                else if (ch == '+' || ch == '-') {AddCh(); goto case 4;}
                else {t.kind = noSym; break;}
            case 4:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 5;}
                else {t.kind = noSym; break;}
            case 5:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 5;}
                else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            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' || ch == 'e') {AddCh(); goto case 8;}
                else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            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 = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 11:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 13;}
                else if (ch == '+' || ch == '-') {AddCh(); goto case 12;}
                else {t.kind = noSym; break;}
            case 12:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 13;}
                else {t.kind = noSym; break;}
            case 13:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 13;}
                else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 14:
                if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= 65535) {AddCh(); goto case 14;}
                else if (ch == '"') {AddCh(); goto case 22;}
                else if (ch == ':') {AddCh(); goto case 35;}
                else {t.kind = noSym; break;}
            case 15:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 16;}
                else {t.kind = noSym; break;}
            case 16:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 36;}
                else if (ch == ')') {AddCh(); goto case 14;}
                else {t.kind = noSym; break;}
            case 17:
                if (ch == ')') {AddCh(); goto case 14;}
                else {t.kind = noSym; break;}
            case 18:
                if (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 19;}
                else {t.kind = noSym; break;}
            case 19:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 19;}
                else if (ch == '}') {AddCh(); goto case 14;}
                else {t.kind = noSym; break;}
            case 20:
                if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= 65535) {AddCh(); goto case 21;}
                else {t.kind = noSym; break;}
            case 21:
                if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= 92 || ch >= '^' && ch <= 65535) {AddCh(); goto case 21;}
                else if (ch == ']') {AddCh(); goto case 38;}
                else {t.kind = noSym; break;}
            case 22:
                {t.kind = 4; break;}
            case 23:
                {t.kind = 5; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 24:
                if (ch == 10) {apx++; AddCh(); goto case 25;}
                else if (ch <= 9 || ch >= 11 && ch <= 65535) {AddCh(); goto case 24;}
                else {t.kind = noSym; break;}
            case 25:
                {
                    tlen -= apx;
                    buffer.Pos = t.pos; NextCh(); line = t.line; col = t.col;
                    for (int i = 0; i < tlen; i++) NextCh();
                    t.kind = 64; break;}
            case 26:
                if (ch <= 'S' || ch >= 'U' && ch <= 65535) {AddCh(); goto case 26;}
                else if (ch == 'T') {AddCh(); goto case 39;}
                else {t.kind = noSym; break;}
            case 27:
                {t.kind = 65; break;}
            case 28:
                if (ch == '.') {AddCh(); goto case 29;}
                else {t.kind = noSym; break;}
            case 29:
                if (ch == 10) {AddCh(); goto case 30;}
                else if (ch <= 9 || ch >= 11 && ch <= 65535) {AddCh(); goto case 29;}
                else {t.kind = noSym; break;}
            case 30:
                {t.kind = 66; break;}
            case 31:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 31;}
                else if (ch == '.') {AddCh(); goto case 6;}
                else if (ch == 'E' || ch == 'e') {AddCh(); goto case 11;}
                else {t.kind = 2; break;}
            case 32:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 2;}
                else if (ch == '.') {AddCh(); goto case 28;}
                else {t.kind = 5; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 33:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'S' || ch >= 'U' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
                else if (ch == 'T') {AddCh(); goto case 40;}
                else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 34:
                if (ch >= '0' && ch <= '9' || ch == 'A' || ch >= 'C' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
                else if (ch == 'B') {AddCh(); goto case 41;}
                else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 35:
                if (ch == '"' || ch == ')' || ch == ':' || ch == '>' || ch == 'o') {AddCh(); goto case 14;}
                else if (ch == '(') {AddCh(); goto case 15;}
                else if (ch == '{') {AddCh(); goto case 18;}
                else if (ch == '[') {AddCh(); goto case 20;}
                else {t.kind = noSym; break;}
            case 36:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 37;}
                else if (ch == ')') {AddCh(); goto case 14;}
                else {t.kind = noSym; break;}
            case 37:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 17;}
                else if (ch == ')') {AddCh(); goto case 14;}
                else {t.kind = noSym; break;}
            case 38:
                if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '9' || ch >= ';' && ch <= 65535) {AddCh(); goto case 38;}
                else if (ch == '"') {AddCh(); goto case 22;}
                else if (ch == ':') {AddCh(); goto case 35;}
                else {t.kind = noSym; break;}
            case 39:
                if (ch <= 'K' || ch >= 'M' && ch <= 65535) {AddCh(); goto case 26;}
                else if (ch == 'L') {AddCh(); goto case 42;}
                else {t.kind = noSym; break;}
            case 40:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'V' || ch >= 'X' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
                else if (ch == 'W') {AddCh(); goto case 43;}
                else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 41:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'S' || ch >= 'U' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
                else if (ch == 'T') {AddCh(); goto case 44;}
                else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 42:
                if (ch <= 'C' || ch >= 'E' && ch <= 65535) {AddCh(); goto case 26;}
                else if (ch == 'D') {AddCh(); goto case 45;}
                else {t.kind = noSym; break;}
            case 43:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 43;}
                else if (ch == 10) {apx++; AddCh(); goto case 25;}
                else if (ch <= 9 || ch >= 11 && ch <= '/' || ch >= ':' && ch <= '@' || ch >= '[' && ch <= '^' || ch == '`' || ch >= '{' && ch <= 65535) {AddCh(); goto case 24;}
                else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 44:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'V' || ch >= 'X' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
                else if (ch == 'W') {AddCh(); goto case 46;}
                else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 45:
                if (ch <= 'Q' || ch >= 'S' && ch <= 65535) {AddCh(); goto case 26;}
                else if (ch == 'R') {AddCh(); goto case 27;}
                else {t.kind = noSym; break;}
            case 46:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
                else if (ch == 9 || ch >= 11 && ch <= 12 || ch == ' ') {AddCh(); goto case 26;}
                else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 47:
                {t.kind = 23; break;}
            case 48:
                {t.kind = 45; break;}

            }
            t.val = new String(tval, 0, tlen);
            return t;
        }
예제 #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();
            }
            start = new Dictionary<int, int>(128);
            for (int i = 65; i <= 65; ++i) start[i] = 1;
            for (int i = 67; i <= 78; ++i) start[i] = 1;
            for (int i = 80; i <= 90; ++i) start[i] = 1;
            for (int i = 97; i <= 122; ++i) start[i] = 1;
            for (int i = 48; i <= 57; ++i) start[i] = 31;
            for (int i = 10; i <= 10; ++i) start[i] = 23;
            for (int i = 44; i <= 44; ++i) start[i] = 23;
            start[46] = 32;
            start[34] = 14;
            start[66] = 33;
            start[79] = 34;
            start[8230] = 29;
            start[63] = 47;
            start[33] = 48;
            start[Buffer.EOF] = -1;

            pt = tokens = new Token();  // first token is a dummy
        }
예제 #7
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;
     }
 }
예제 #8
0
 // make sure that peeking starts at the current scan position
 public void ResetPeek()
 {
     pt = tokens;
 }
예제 #9
0
 // 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;
 }