Beispiel #1
0
 static State lexWhitespace(Lexer l)
 {
     switch (getType(l.read()))
     {
     case CharType.Whitespace:
         l.discard();
         return lexWhitespace;
     case CharType.OpenParanthesis:
         l.next();
         l.emit(Token.OpenParanthesis);
         l.reset();
         return lexWhitespace;
     case CharType.CloseParanthesis:
         l.next();
         l.emit(Token.CloseParanthesis);
         l.reset();
         return lexWhitespace;
     case CharType.Number:
         l.reset();
         return lexNumber;
     case CharType.Operator:
         l.reset();
         return lexOperator;
     case CharType.Letter:
         l.reset();
         return lexWord;
     case CharType.EOF:
         return null;
     default:
         throw new Exception("Invalid input.");
     }
 }
Beispiel #2
0
 static State lexWord(Lexer l)
 {
     switch (getType(l.read()))
     {
     case CharType.Letter:
         l.next();
         return lexWord;
     case CharType.EOF:
         l.emit(Token.Word);
         return null;
     default:
         l.emit(Token.Word);
         l.reset();
         return lexWhitespace;
     }
 }
Beispiel #3
0
 static State lexOperator(Lexer l)
 {
     switch (getType(l.read()))
     {
     case CharType.Operator:
         l.next();
         return lexOperator;
     case CharType.EOF:
         l.emit(Token.Operator);
         return null;
     default:
         l.emit(Token.Operator);
         l.reset();
         return lexWhitespace;
     }
 }