Dragos
Dragos

Reputation: 107

Flex/Bison 'yylex' : function does not take 3 arguments

I have the following Lexer.l and Parser.y files.

Lexer.l

%{
#include "Parser.h"
%}

%option yylineno
%option outfile="Lexer.cpp" header-file="Lexer.h"
%option warn nodefault
%option reentrant noyywrap never-interactive nounistd
%option bison-bridge

Parser.y

%{
#include "Parser.h"
#include "Lexer.h"

extern int yyerror(yyscan_t scanner, const char *msg) 
{printf("\r\nError: %s", msg); return 1;}

%}
 
%code requires {     
#ifndef YY_TYPEDEF_YY_SCANNER_T
#define YY_TYPEDEF_YY_SCANNER_T
typedef void* yyscan_t;
#endif
}
 
%output  "Parser.cpp"
%defines "Parser.h"     
%define api.pure
%pure-parser
%lex-param   { yyscan_t scanner }
%parse-param {yyscan_t scanner }
 

Everything works fine.

Now I am trying to get the column and line for a token; when I use @1.first_line I get the following errors:

'yylex' : function does not take 3 arguments

'yyerror' : function does not take 3 arguments

For the yyerror I looked at the compiler requirements for it and implemented it.

But, for yylex I have no idea what to return. I've tried to look at the yylex with 2 parameters implementation to make something similar, but it seems to be no implementation for yylex at all.

Any thoughts?

Upvotes: 1

Views: 1127

Answers (1)

rici
rici

Reputation: 241931

If you use option bison-bridge and your parser has @ references, you need to add

%option bison-locations

to your flex file. (You can use it instead of bison-bridge, but I think it is tidier to have both.) From the flex manual:

  • --bison-locations, %option bison-locations
    • instruct flex that GNU bison %locations are being used. This means yylex will be passed an additional parameter, yylloc. This option implies %option bison-bridge.

Upvotes: 1

Related Questions