File indexing completed on 2024-04-28 04:36:05
0001 /***************************************************************************** 0002 * Copyright (c) 2005, 2006 Jakob Petsovits <jpetso@gmx.at> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU Library General Public * 0006 * License as published by the Free Software Foundation; either * 0007 * version 2 of the License, or (at your option) any later version. * 0008 * * 0009 * This grammar is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0012 * Lesser General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU Library General Public License * 0015 * along with this library; see the file COPYING.LIB. If not, write to * 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0017 * Boston, MA 02110-1301, USA. * 0018 *****************************************************************************/ 0019 0020 #include "ccparser.h" 0021 0022 #include <iostream> 0023 0024 #ifndef DONT_INCLUDE_FLEXLEXER 0025 #include "FlexLexer.h" 0026 #endif 0027 0028 // The YY_USER_ACTION macro is called whenever a token is found by Flex 0029 #define YY_USER_ACTION \ 0030 m_tokenBegin = m_tokenEnd; \ 0031 m_tokenEnd += yyleng; 0032 0033 0034 namespace cc 0035 { 0036 0037 class Lexer : public yyFlexLexer 0038 { 0039 public: 0040 Lexer( cc::Parser *parser, char *contents ); 0041 void restart( cc::Parser *parser, char *contents ); 0042 0043 int yylex(); 0044 char *contents() { return m_contents; } 0045 std::size_t tokenBegin() { return m_tokenBegin; } 0046 std::size_t tokenEnd() { return m_tokenEnd; } 0047 0048 protected: 0049 // custom input, replacing the Flex default input stdin 0050 virtual int LexerInput( char *buf, int max_size ); 0051 0052 // dismisses any lexer output (which should not happen anyways) 0053 virtual void LexerOutput( const char * /*buf*/, int /*max_size*/ ) { return; } 0054 virtual void LexerError( const char */*msg*/ ) { return; } 0055 0056 private: 0057 cc::Parser* m_parser; 0058 char *m_contents; 0059 std::size_t m_tokenBegin, m_tokenEnd; 0060 std::size_t m_currentOffset; 0061 KDevPG::LocationTable *m_locationTable; 0062 }; 0063 0064 } // end of namespace cc 0065 0066 // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on