Skip to content

Commit 9ccbb7c

Browse files
committed
Make flex directly generate the yylex method with parameter
1 parent 124fb2b commit 9ccbb7c

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

mc_lexer.l

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
%{
22
/* C++ string header, for string ops below */
33
#include <string>
4+
45
/* Implementation of yyFlexScanner */
56
#include "mc_scanner.hpp"
7+
#undef YY_DECL
8+
#define YY_DECL int MC::MC_Scanner::yylex(MC::MC_Parser::semantic_type *lval)
69

710
/* typedef to make the returns for the tokens shorter */
811
typedef MC::MC_Parser::token token;
@@ -25,6 +28,10 @@ typedef MC::MC_Parser::token token;
2528
%option c++
2629

2730
%%
31+
%{ // Code executed at the beginning of yylex
32+
yylval = lval;
33+
%}
34+
2835
[a-z] {
2936
return( token::LOWER );
3037
}

mc_scanner.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@ class MC_Scanner : public yyFlexLexer{
1515
MC_Scanner(std::istream *in) : yyFlexLexer(in),
1616
yylval( nullptr ){};
1717

18-
int yylex(MC::MC_Parser::semantic_type *lval)
19-
{
20-
yylval = lval;
21-
return( yylex() );
22-
}
23-
18+
int yylex(MC::MC_Parser::semantic_type *lval);
19+
// YY_DECL defined in mc_lexer.l
20+
// Method body created by flex in mc_lexer.yy.cc
2421

2522
private:
26-
/* hide this one from public view */
27-
int yylex();
2823
/* yyval ptr */
2924
MC::MC_Parser::semantic_type *yylval;
3025
};

0 commit comments

Comments
 (0)