00001 // SuperTux 00002 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 #ifndef HEADER_SUPERTUX_LISP_LEXER_HPP 00018 #define HEADER_SUPERTUX_LISP_LEXER_HPP 00019 00020 #include <istream> 00021 00022 namespace lisp { 00023 00024 class Lexer 00025 { 00026 public: 00027 enum TokenType { 00028 TOKEN_EOF, 00029 TOKEN_OPEN_PAREN, 00030 TOKEN_CLOSE_PAREN, 00031 TOKEN_SYMBOL, 00032 TOKEN_STRING, 00033 TOKEN_INTEGER, 00034 TOKEN_REAL, 00035 TOKEN_TRUE, 00036 TOKEN_FALSE 00037 }; 00038 00039 Lexer(std::istream& stream); 00040 ~Lexer(); 00041 00042 TokenType getNextToken(); 00043 const char* getString() const 00044 { return token_string; } 00045 int getLineNumber() const 00046 { return linenumber; } 00047 00048 private: 00049 enum { 00050 MAX_TOKEN_LENGTH = 16384, 00051 BUFFER_SIZE = 1024 00052 }; 00053 00054 inline void nextChar(); 00055 inline void addChar(); 00056 00057 private: 00058 std::istream& stream; 00059 bool eof; 00060 int linenumber; 00061 char buffer[BUFFER_SIZE+1]; 00062 char* bufend; 00063 char* bufpos; 00064 int c; 00065 char token_string[MAX_TOKEN_LENGTH + 1]; 00066 int token_length; 00067 00068 private: 00069 Lexer(const Lexer&); 00070 Lexer & operator=(const Lexer&); 00071 }; 00072 00073 } // end of namespace lisp 00074 00075 #endif 00076 00077 /* EOF */