00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 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 2, or (at your option) 00007 // 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, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: Lexer.hpp,v 1.6 2007/06/09 10:37:08 delpinux Exp $ 00019 00020 // This is the Lexer replacement to Flex. The reason for changing flex 00021 // is the portability: it is not available at this very moment using CodeWarrior 6. 00022 // This is a base class. Its derived classes will be used for different languages. 00023 00024 #ifndef LEXER_HPP 00025 #define LEXER_HPP 00026 00027 #include <cstring> 00028 #include <map> 00029 00030 #include <StreamCenter.hpp> 00031 00032 #include <cstddef> 00033 00044 class Lexer 00045 { 00046 private: 00048 size_t WordMaxLenght; 00049 00050 struct eqstr 00051 { 00052 bool operator()(const char* s1, const char* s2) const 00053 { 00054 return std::strcmp(s1, s2) < 0; 00055 } 00056 }; 00057 00058 protected: 00060 std::istream& in; 00061 00063 std::ostream& out; 00064 00066 size_t linenumber; 00067 00069 std::string yytext; 00070 00071 public: 00074 typedef std::map<const char*, int, 00075 Lexer::eqstr> KeyWordList; 00076 00077 protected: 00078 KeyWordList __keyWordList; 00079 00083 int declarationToken; 00084 public: 00085 00087 Lexer(std::istream& In, 00088 std::ostream& Out = std::cout, 00089 const size_t WMaxL = 255) 00090 : WordMaxLenght(WMaxL), 00091 in(In), 00092 out(Out) 00093 { 00094 // yytext = new char[WMaxL+1]; 00095 linenumber = 1; 00096 } 00097 00099 virtual ~Lexer() 00100 { 00101 ; 00102 } 00103 00105 virtual int yylex() = 0; 00106 00108 const size_t& lineno() const 00109 { 00110 return linenumber; 00111 } 00112 00114 const char* YYText() const 00115 { 00116 return yytext.c_str(); 00117 } 00118 }; 00119 00120 #endif // LEXER_HPP
1.5.6