Exemple #1
0
 public Token scan()
 {
     for (; ; peek = (char)Console.Read())
     {
         if (peek == ' ' || peek == '\t')
         {
             continue;
         }
         else if (peek == '\n')
         {
             ++line;
         }
         else
         {
             break;
         }
     }
     if (Char.IsDigit(peek))
     {
         int v = 0;
         do
         {
             v = 10 * v + int.Parse(peek.ToString()); //this is dumb is there a better way?
             peek = (char)Console.Read();
         } while (Char.IsDigit(peek));
         return new IntegerToken(v);
     }
     if (Char.IsLetter(peek))
     {
         string wordValue = "";
         do
         {
             wordValue += peek;
             peek = (char)Console.Read();
         } while (Char.IsLetterOrDigit(peek));
         if (words.ContainsKey(wordValue))
         {
             return words[wordValue];
         }
         else
         {
             Word w = new Word(Tag.IDENTIFIER, wordValue);
             words[wordValue] = w;
             return w;
         }
     }
     Token t = new Token(peek);
     peek = ' ';
     return t;
 }
Exemple #2
0
 void reserve(Word word)
 {
     words[word.lexeme] = word;
 }
Exemple #3
0
 private Token Word()
 {
     string wordValue = "";
     do
     {
         wordValue += peek;
         AdvancePeek();
     } while (Char.IsLetterOrDigit(peek));
     if (words.ContainsKey(wordValue))
     {
         return words[wordValue];
     }
     else
     {
         Word w = new Word(Tag.IDENTIFIER, wordValue);
         words[wordValue] = w;
         return w;
     }
 }
Exemple #4
0
 private void Reserve(Word word)
 {
     words[word.lexeme] = word;
 }
Exemple #5
0
 void reserve(Word word)
 {
     words[word.lexeme] = word;
 }