yylloc undefined in this scope

情到浓时终转凉″ 提交于 2019-12-04 05:30:53

问题


I have the following problem while compiling the files. I have overwritten the definition of YYLTYPE as follows(though it is the same as default but I will extend it

typedef struct YYLTYPE  
{  
  int first_line;  
  int first_column;  
  int last_line;  
  int last_column;  
} YYLTYPE;

and when I add the following in the lex file I get the "yylloc undefined in this scope" error.

#define YY_USER_INIT yylloc.first_line = yylloc.first_column = 1;

Pastebin:

  • flex file
  • bison file
  • makefile

回答1:


You need to put the definition of YYLTYPE and YYLTYPE_IS_DECLARED into a header file that you #include in both your .y and .l files, and you need to #include the .tab.h file in your .l file AFTER the #include of the file that defines YYLTYPE.

The reason for the above is that bison DOES NOT export your definition of YYLTYPE from the top of your .y file, so if you want it somewhere else, you need to arrange that it be available. Worse, the .tab.h file will always have the default YYLTYPE (guarded by #ifndef YYLTYPE_IS_DECLARED) so you need to ensure that your definition is seen before it.



来源:https://stackoverflow.com/questions/10386567/yylloc-undefined-in-this-scope

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!