Commit e1238b58 authored by sebastien's avatar sebastien
Browse files

v4 parser: adapted macro processor for compatibility with Flex 2.5.4


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1675 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 79a4e8c8
......@@ -45,6 +45,12 @@ using namespace std;
*/
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<struct yy_buffer_state *> state_stack;
public:
MacroFlex(istream* in = 0, ostream* out = 0);
......@@ -54,8 +60,7 @@ public:
MacroDriver &driver);
};
//! Drives the scanning and parsing of the .mod file, and constructs its abstract representation
/*! It is built along the guidelines given in Bison 2.3 manual. */
//! Implements the macro expansion using a Flex scanner and a Bison parser
class MacroDriver
{
public:
......
......@@ -80,7 +80,11 @@ typedef Macro::parser::token token;
// Display @line
*yyout << "@line \"" << *yylloc->begin.filename << "\" 1" << endl;
// Switch to new buffer
yypush_buffer_state(yy_create_buffer(driver.ifs, YY_BUF_SIZE));
/* We don't use yypush_buffer_state(), since it doesn't exist in
Flex 2.5.4 (see Flex 2.5.33 info file - section 11 - for code
example with yypush_buffer_state()) */
state_stack.push(YY_CURRENT_BUFFER);
yy_switch_to_buffer(yy_create_buffer(driver.ifs, YY_BUF_SIZE));
BEGIN(INITIAL);
}
......@@ -93,14 +97,19 @@ typedef Macro::parser::token token;
}
<<EOF>> {
// Try to restore old flex buffer
yypop_buffer_state();
if (!YY_CURRENT_BUFFER)
/* We don't use yypop_buffer_state(), since it doesn't exist in
Flex 2.5.4 (see Flex 2.5.33 info file - section 11 - for code
example with yypop_buffer_state()) */
// Quit lexer if end of main file
if (state_stack.empty())
{
// Quit lexer if end of main file
yyterminate();
}
// Else restore old location
// Else restore old flex buffer
yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(state_stack.top());
state_stack.pop();
// And restore old location
delete yylloc->begin.filename;
*yylloc = driver.loc_stack.top();
driver.loc_stack.pop();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment