Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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;
     }
 }
Ejemplo n.º 3
0
 // make sure that peeking starts at the current scan position
 public void ResetPeek()
 {
     pt = tokens;
 }
Ejemplo n.º 4
0
        Token NextToken()
        {
            while (ch == ' ' ||
            ch >= 9 && ch <= 10 || ch == 13
            ) NextCh();

            int recKind = noSym;
            int recEnd = pos;
            t = new Token();
            t.pos = pos; t.col = col; t.line = line; t.charPos = charPos;
            int state;
            if (start.ContainsKey(ch)) { state = (int) start[ch]; }
            else { state = 0; }
            tlen = 0; AddCh();
            /*old way
            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
            <--scan3
            }
            old way*/
            //new way begin
            bool done = false;
            while(!done) {
            switch (state) {
            case -1: { t.kind = eofSym; done = true; break; } // NextCh already done
            case 0: {
                if (recKind != noSym) {
                    tlen = recEnd - t.pos;
                    SetScannerBehindT();
                }
                t.kind = recKind; done = true; break;
            } // NextCh already done
            case 1:
                recEnd = pos; recKind = 1;
                if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') { AddCh(); state = 1; break; }
                else {t.kind = 1; done = true; break;}
            case 2:
                if (ch >= '0' && ch <= '9') { AddCh(); state = 3; break; }
                else { state = 0; break; }
            case 3:
                recEnd = pos; recKind = 3;
                if (ch >= '0' && ch <= '9') { AddCh(); state = 3; break; }
                else {t.kind = 3; done = true; break;}
            case 4:
                recEnd = pos; recKind = 2;
                if (ch >= '0' && ch <= '9') { AddCh(); state = 4; break; }
                else if (ch == '.') { AddCh(); state = 2; break; }
                else {t.kind = 2; done = true; break;}
            case 5:
                {t.kind = 4; done = true; break;}
            case 6:
                {t.kind = 5; done = true; break;}
            case 7:
                {t.kind = 6; done = true; break;}
            case 8:
                {t.kind = 7; done = true; break;}
            case 9:
                {t.kind = 8; done = true; break;}
            case 10:
                {t.kind = 9; done = true; break;}
            case 11:
                {t.kind = 10; done = true; break;}
            case 12:
                {t.kind = 11; done = true; break;}
            case 13:
                {t.kind = 12; done = true; break;}

            }
            }
            //new way end
            t.val = string.Empty;//TODO performance!!!
            for(int i = 0; i < tlen; i++) {
            t.val += tval[i];
            }
            //t.val = new String(tval, 0, tlen);
            return t;
        }
Ejemplo n.º 5
0
 void Init()
 {
     pos = -1; line = 1; col = 0; charPos = -1;
     oldEols = 0;
     NextCh();
     pt = tokens = new Token();  // first token is a dummy
 }