[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Usage of C++ parser with C++ flex scanner
From: |
Michael Brandt |
Subject: |
Re: Usage of C++ parser with C++ flex scanner |
Date: |
Wed, 24 May 2006 23:18:40 +0200 |
Hi,
2006/5/23, Toly Kournik <address@hidden>:
I'm trying to integrate generated C++ Bison parser with generated C++
Flex scanner.
The goal is to do it without generated code intervention.
There are several questions:
1. How can I cause generated Parser::parse() method to call
Lexer::yylex() instead of yylex() ?
You could try the following (untestet). Write a global yylex-Function
that is called from bison. Use the bison directive %lex-param to pass
your Flexer:
%lex-param {MyFlexLexer* lexer}
Then call the lexer->yylex() method from this function:
int yylex(MyFlexLexer* lexer) {
return lexer->yylex();
}
When you have more arguments use more %lex-params and just pass them
through the global yylex-Function.
2. How can I tell Lexer::yylex() to receive parameters?
in your derived class from yyFlexLexer declare the yylex-Function as
you like it:
class MyFlexLexer : public yyFlexLexer {
// ...
public:
int yylex(int foo, std::string& bar);
// ...
}
then redefine YY_DECL to MyFlexLexer::yylex(int foo, std::string& bar);
Regards,
Michael