/* * Copyright (C) 2008 Dynare Team * * This file is part of Dynare. * * Dynare is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Dynare is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Dynare. If not, see . */ #ifndef _MACRO_DRIVER_HH #define _MACRO_DRIVER_HH #ifdef _PARSING_DRIVER_HH # error Impossible to include both ParsingDriver.hh and MacroDriver.hh #endif #include #include #include #include "MacroBison.hh" using namespace std; // Declare MacroFlexLexer class #ifndef __FLEX_LEXER_H # define yyFlexLexer MacroFlexLexer # include # undef yyFlexLexer #endif //! The lexer class /*! Actually it was necessary to subclass the MacroFlexLexer class generated by Flex, since the prototype for MacroFlexLexer::yylex() was not convenient. */ class MacroFlex : public MacroFlexLexer { private: //! The stack of scanner states /*! We could have used instead yypush_buffer_state() and yypop_buffer_state(), but those functions do not exist in Flex 2.5.4 */ stack state_stack; public: MacroFlex(istream* in = 0, ostream* out = 0); //! The main lexing function Macro::parser::token_type lex(Macro::parser::semantic_type *yylval, Macro::parser::location_type *yylloc, MacroDriver &driver); }; //! Implements the macro expansion using a Flex scanner and a Bison parser class MacroDriver { public: //! Constructor MacroDriver(); //! Destructor virtual ~MacroDriver(); //! Starts parsing a file, returns output in out void parse(const string &f, ostream &out); //! Pointer to keep track of the input file stream currently scanned ifstream *ifs; //! Stack of locations used for (possibly nested) includes stack loc_stack; //! Name of main file being parsed string file; //! Reference to the lexer class MacroFlex *lexer; //! Trace scanning ? /*! If set to true before calling parse(), the flex scanner will dump a lot of debugging information. Defaults to false. */ bool trace_scanning; //! Trace parsing ? /*! If set to true before calling parse(), the bison parser will dump debugging information. Defaults to false. */ bool trace_parsing; //! Error handler void error(const Macro::parser::location_type &l, const string &m); }; #endif // ! MACRO_DRIVER_HH