Exemplo n.º 1
0
        Token NextToken()
        {
            while (ch == ' ' ||
            ch == 9
            ) NextCh();

            int apx = 0;
            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:
                recEnd = pos; recKind = 1;
                if (ch == 39 || 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:
                recEnd = pos; recKind = 1;
                if (ch == 39 || ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || 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:
                if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 51;}
                else if (ch >= '0' && ch <= '9') {AddCh(); goto case 52;}
                else if (ch == 39) {AddCh(); goto case 3;}
                else {goto case 0;}
            case 4:
                recEnd = pos; recKind = 2;
                if (ch == 39 || ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 4;}
                else {t.kind = 2; break;}
            case 5:
                {
                    tlen -= apx;
                    SetScannerBehindT();
                    t.kind = 3; break;}
            case 6:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 7;}
                else {goto case 0;}
            case 7:
                recEnd = pos; recKind = 3;
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 7;}
                else if (ch == 'L' || ch == 'l') {AddCh(); goto case 8;}
                else {t.kind = 3; break;}
            case 8:
                {t.kind = 3; break;}
            case 9:
                recEnd = pos; recKind = 4;
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
                else if (ch == 'D' || ch == 'F' || ch == 'd' || ch == 'f') {AddCh(); goto case 20;}
                else if (ch == 'E' || ch == 'e') {AddCh(); goto case 10;}
                else {t.kind = 4; break;}
            case 10:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 12;}
                else if (ch == '+' || ch == '-') {AddCh(); goto case 11;}
                else {goto case 0;}
            case 11:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 12;}
                else {goto case 0;}
            case 12:
                recEnd = pos; recKind = 4;
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 12;}
                else if (ch == 'D' || ch == 'F' || ch == 'd' || ch == 'f') {AddCh(); goto case 20;}
                else {t.kind = 4; break;}
            case 13:
                recEnd = pos; recKind = 4;
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 13;}
                else if (ch == 'D' || ch == 'F' || ch == 'd' || ch == 'f') {AddCh(); goto case 20;}
                else if (ch == 'E' || ch == 'e') {AddCh(); goto case 14;}
                else {t.kind = 4; break;}
            case 14:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 16;}
                else if (ch == '+' || ch == '-') {AddCh(); goto case 15;}
                else {goto case 0;}
            case 15:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 16;}
                else {goto case 0;}
            case 16:
                recEnd = pos; recKind = 4;
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 16;}
                else if (ch == 'D' || ch == 'F' || ch == 'd' || ch == 'f') {AddCh(); goto case 20;}
                else {t.kind = 4; break;}
            case 17:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 19;}
                else if (ch == '+' || ch == '-') {AddCh(); goto case 18;}
                else {goto case 0;}
            case 18:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 19;}
                else {goto case 0;}
            case 19:
                recEnd = pos; recKind = 4;
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 19;}
                else if (ch == 'D' || ch == 'F' || ch == 'd' || ch == 'f') {AddCh(); goto case 20;}
                else {t.kind = 4; break;}
            case 20:
                {t.kind = 4; break;}
            case 21:
                if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 21;}
                else if (ch == '"') {AddCh(); goto case 31;}
                else if (ch == 92) {AddCh(); goto case 53;}
                else {goto case 0;}
            case 22:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 23;}
                else {goto case 0;}
            case 23:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 24;}
                else {goto case 0;}
            case 24:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 25;}
                else {goto case 0;}
            case 25:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 21;}
                else {goto case 0;}
            case 26:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 27;}
                else {goto case 0;}
            case 27:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 28;}
                else {goto case 0;}
            case 28:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 29;}
                else {goto case 0;}
            case 29:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 30;}
                else {goto case 0;}
            case 30:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 21;}
                else {goto case 0;}
            case 31:
                {t.kind = 5; break;}
            case 32:
                if (ch == 39) {AddCh(); goto case 42;}
                else {goto case 0;}
            case 33:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 34;}
                else {goto case 0;}
            case 34:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 35;}
                else {goto case 0;}
            case 35:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 36;}
                else {goto case 0;}
            case 36:
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F' || ch >= 'a' && ch <= 'f') {AddCh(); goto case 32;}
                else {goto case 0;}
            case 37:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 38;}
                else {goto case 0;}
            case 38:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 39;}
                else {goto case 0;}
            case 39:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 40;}
                else {goto case 0;}
            case 40:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 41;}
                else {goto case 0;}
            case 41:
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 32;}
                else {goto case 0;}
            case 42:
                {t.kind = 6; break;}
            case 43:
                recEnd = pos; recKind = 7;
                if (ch == '!' || ch >= '$' && ch <= '&' || ch == '+' || ch >= '-' && ch <= '.' || ch == ':' || ch >= '<' && ch <= '@' || ch == 92 || ch == '^' || ch == '`' || ch == '|' || ch == '~') {AddCh(); goto case 43;}
                else {t.kind = 7; break;}
            case 44:
                recEnd = pos; recKind = 8;
                if (ch >= '(' && ch <= ')' || ch == '[' || ch == ']' || ch == '{' || ch == '}') {AddCh(); goto case 44;}
                else {t.kind = 8; break;}
            case 45:
                {t.kind = 9; break;}
            case 46:
                recEnd = pos; recKind = 3;
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 46;}
                else if (ch == 'L' || ch == 'l') {AddCh(); goto case 8;}
                else if (ch == '.') {apx++; AddCh(); goto case 55;}
                else if (ch == 'E' || ch == 'e') {AddCh(); goto case 17;}
                else if (ch == 'D' || ch == 'F' || ch == 'M' || ch == 'd' || ch == 'f' || ch == 'm') {AddCh(); goto case 20;}
                else {t.kind = 3; break;}
            case 47:
                if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 56;}
                else if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '&' || ch >= '(' && ch <= '@' || ch == '[' || ch >= ']' && ch <= '^' || ch == '`' || ch >= '{' && ch <= 65535) {AddCh(); goto case 32;}
                else if (ch == 92) {AddCh(); goto case 54;}
                else {goto case 0;}
            case 48:
                recEnd = pos; recKind = 3;
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 46;}
                else if (ch == 'L' || ch == 'l') {AddCh(); goto case 8;}
                else if (ch == '.') {apx++; AddCh(); goto case 55;}
                else if (ch == 'X' || ch == 'x') {AddCh(); goto case 6;}
                else if (ch == 'E' || ch == 'e') {AddCh(); goto case 17;}
                else if (ch == 'D' || ch == 'F' || ch == 'M' || ch == 'd' || ch == 'f' || ch == 'm') {AddCh(); goto case 20;}
                else {t.kind = 3; break;}
            case 49:
                recEnd = pos; recKind = 7;
                if (ch >= '1' && ch <= '9') {AddCh(); goto case 46;}
                else if (ch == '0') {AddCh(); goto case 48;}
                else if (ch == '!' || ch >= '$' && ch <= '&' || ch == '+' || ch == '-' || ch == ':' || ch >= '<' && ch <= '@' || ch == 92 || ch == '^' || ch == '`' || ch == '|' || ch == '~') {AddCh(); goto case 43;}
                else if (ch == '.') {AddCh(); goto case 50;}
                else {t.kind = 7; break;}
            case 50:
                recEnd = pos; recKind = 7;
                if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
                else if (ch == '!' || ch >= '$' && ch <= '&' || ch == '+' || ch >= '-' && ch <= '.' || ch == ':' || ch >= '<' && ch <= '@' || ch == 92 || ch == '^' || ch == '`' || ch == '|' || ch == '~') {AddCh(); goto case 43;}
                else {t.kind = 7; break;}
            case 51:
                recEnd = pos; recKind = 1;
                if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 51;}
                else if (ch >= '0' && ch <= '9') {AddCh(); goto case 52;}
                else if (ch == 39) {AddCh(); goto case 3;}
                else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 52:
                recEnd = pos; recKind = 1;
                if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 51;}
                else if (ch >= '0' && ch <= '9') {AddCh(); goto case 52;}
                else if (ch == 39) {AddCh(); goto case 3;}
                else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 53:
                if (ch == '"' || ch == 39 || ch == '0' || ch == 92 || ch == 'b' || ch == 'n' || ch == 'r' || ch == 't') {AddCh(); goto case 21;}
                else if (ch == 'u') {AddCh(); goto case 22;}
                else if (ch == 'x') {AddCh(); goto case 26;}
                else {goto case 0;}
            case 54:
                if (ch == '"' || ch == 39 || ch == '0' || ch == 92 || ch == 'b' || ch == 'n' || ch == 'r' || ch == 't') {AddCh(); goto case 32;}
                else if (ch == 'u') {AddCh(); goto case 33;}
                else if (ch == 'x') {AddCh(); goto case 37;}
                else {goto case 0;}
            case 55:
                if (ch <= '/' || ch >= ':' && ch <= 65535) {apx++; AddCh(); goto case 5;}
                else if (ch >= '0' && ch <= '9') {apx = 0; AddCh(); goto case 13;}
                else {goto case 0;}
            case 56:
                recEnd = pos; recKind = 1;
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 3;}
                else if (ch == 39) {AddCh(); goto case 57;}
                else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
            case 57:
                recEnd = pos; recKind = 6;
                if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 51;}
                else if (ch >= '0' && ch <= '9') {AddCh(); goto case 52;}
                else if (ch == 39) {AddCh(); goto case 3;}
                else {t.kind = 6; break;}
            case 58:
                {t.kind = 10; break;}
            case 59:
                {t.kind = 11; break;}
            case 60:
                {t.kind = 12; break;}
            case 61:
                {t.kind = 13; break;}
            case 62:
                {t.kind = 14; break;}
            case 63:
                {t.kind = 20; break;}
            case 64:
                {t.kind = 21; break;}
            case 65:
                {t.kind = 22; break;}
            case 66:
                recEnd = pos; recKind = 19;
                if (ch == 39 || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 2;}
                else {t.kind = 19; break;}
            case 67:
                recEnd = pos; recKind = 16;
                if (ch == '*') {AddCh(); goto case 58;}
                else if (ch == '/') {AddCh(); goto case 60;}
                else {t.kind = 16; break;}
            case 68:
                recEnd = pos; recKind = 15;
                if (ch == '/') {AddCh(); goto case 59;}
                else {t.kind = 15; break;}
            case 69:
                recEnd = pos; recKind = 7;
                if (ch == '!' || ch >= '$' && ch <= '&' || ch == '+' || ch >= '-' && ch <= '.' || ch == ':' || ch >= '<' && ch <= '@' || ch == 92 || ch == '^' || ch == '`' || ch == '|' || ch == '~') {AddCh(); goto case 43;}
                else if (ch == '[') {AddCh(); goto case 61;}
                else {t.kind = 7; break;}
            case 70:
                recEnd = pos; recKind = 8;
                if (ch >= '(' && ch <= ')' || ch == '[' || ch == ']' || ch == '{' || ch == '}') {AddCh(); goto case 44;}
                else if (ch == '>') {AddCh(); goto case 62;}
                else {t.kind = 8; break;}

            }
            t.val = new String(tval, 0, tlen);
            return t;
        }
Exemplo n.º 2
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.º 3
0
 // make sure that peeking starts at the current scan position
 public void ResetPeek()
 {
     pt = tokens;
 }
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
        // 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;
        }