Back to index

supertuxkart  0.5+dfsg1
lexer.hpp
Go to the documentation of this file.
00001 //  $Id: lexer.hpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  TuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de>
00005 //  code in this file based on lispreader from Mark Probst
00006 //
00007 //  This program is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU General Public License
00009 //  as published by the Free Software Foundation; either version 2
00010 //  of the License, or (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 #ifndef __LISPLEXER_H__
00021 #define __LISPLEXER_H__
00022 
00023 namespace lisp
00024 {
00025 
00026     class Lexer
00027     {
00028     public:
00029         enum TokenType
00030         {
00031             TOKEN_EOF,
00032             TOKEN_OPEN_PAREN,
00033             TOKEN_CLOSE_PAREN,
00034            TOKEN_TRANSLATION,
00035             TOKEN_SYMBOL,
00036             TOKEN_STRING,
00037             TOKEN_INTEGER,
00038             TOKEN_REAL,
00039             TOKEN_TRUE,
00040             TOKEN_FALSE
00041         };
00042 
00043         Lexer(std::istream& stream);
00044         ~Lexer();
00045 
00046         TokenType getNextToken();
00047 
00048         const char* getString() const
00049             { return m_token_string; }
00050 
00051         int getLineNumber() const
00052             { return m_line_number; }
00053 
00054     private:
00055         enum
00056         {
00057             MAX_TOKEN_LENGTH = 4096,
00058             LEXER_BUFFER_SIZE = 1024
00059         };
00060 
00061         inline void nextChar();
00062 
00063         std::istream& m_stream;
00064         bool m_is_eof;
00065         int m_line_number;
00066         char m_buffer[LEXER_BUFFER_SIZE+1];
00067         char* m_buffer_end;
00068         char* m_c;
00069         char m_token_string[MAX_TOKEN_LENGTH + 1];
00070         int m_token_length;
00071     };
00072 
00073 } // end of namespace lisp
00074 
00075 #endif
00076