| 1 | // $Id: lexer.hpp 848 2006-10-29 02:14:04Z coz $ |
| 2 | // |
| 3 | // TuxKart - a fun racing game with go-kart |
| 4 | // Copyright (C) 2004 Matthias Braun <[email protected]> |
| 5 | // code in this file based on lispreader from Mark Probst |
| 6 | // |
| 7 | // This program is free software; you can redistribute it and/or |
| 8 | // modify it under the terms of the GNU General Public License |
| 9 | // as published by the Free Software Foundation; either version 2 |
| 10 | // of the License, or (at your option) any later version. |
| 11 | // |
| 12 | // This program is distributed in the hope that it will be useful, |
| 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | // GNU General Public License for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with this program; if not, write to the Free Software |
| 19 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | #ifndef __LISPLEXER_H__ |
| 21 | #define __LISPLEXER_H__ |
| 22 | |
| 23 | namespace lisp |
| 24 | { |
| 25 | |
| 26 | class Lexer |
| 27 | { |
| 28 | public: |
| 29 | enum TokenType |
| 30 | { |
| 31 | TOKEN_EOF, |
| 32 | TOKEN_OPEN_PAREN, |
| 33 | TOKEN_CLOSE_PAREN, |
| 34 | TOKEN_SYMBOL, |
| 35 | TOKEN_STRING, |
| 36 | TOKEN_INTEGER, |
| 37 | TOKEN_REAL, |
| 38 | TOKEN_TRUE, |
| 39 | TOKEN_FALSE |
| 40 | }; |
| 41 | |
| 42 | Lexer(std::istream& stream); |
| 43 | ~Lexer(); |
| 44 | |
| 45 | TokenType getNextToken(); |
| 46 | |
| 47 | const char* getString() const |
| 48 | { return m_token_string; } |
| 49 | |
| 50 | int getLineNumber() const |
| 51 | { return m_line_number; } |
| 52 | |
| 53 | private: |
| 54 | enum |
| 55 | { |
| 56 | MAX_TOKEN_LENGTH = 4096, |
| 57 | LEXER_BUFFER_SIZE = 1024 |
| 58 | }; |
| 59 | |
| 60 | inline void nextChar(); |
| 61 | |
| 62 | std::istream& m_stream; |
| 63 | bool m_is_eof; |
| 64 | int m_line_number; |
| 65 | char m_buffer[LEXER_BUFFER_SIZE+1]; |
| 66 | char* m_buffer_end; |
| 67 | char* m_c; |
| 68 | char m_token_string[MAX_TOKEN_LENGTH + 1]; |
| 69 | int m_token_length; |
| 70 | }; |
| 71 | |
| 72 | } // end of namespace lisp |
| 73 | |
| 74 | #endif |
| 75 |