1

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?

Community
  • 1
  • 1
Dragos
  • 107
  • 8

1 Answers1

1

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.
rici
  • 234,347
  • 28
  • 237
  • 341
  • I did that and it worked. But always all properties are 1. I have tried to modify the line/colum like explained [here](http://stackoverflow.com/questions/656703/how-does-flex-support-bison-location-exactly) but I get 'yyg': undeclared variable – Dragos Jun 29 '15 at 02:03
  • @dragos: That's too complicated a question to answer in a comment. Also, the question you link to has six answers, which are subtly different; you'll need to show an example of your code (as small as possible, but still self-contained). Please ask a new question with this information. Thanks. – rici Jun 29 '15 at 02:36
  • I actually tried all of them - in the end the same error. But I figure it out: I changed in their examples the yyloc with the function **yyget_lloc** and it worked.Thank you for your answers. – Dragos Jun 29 '15 at 09:53