yylloc在此范围内未定义 [英] yylloc undefined in this scope
问题描述
编译文件时出现以下问题.我已经按照如下方式覆盖了YYLTYPE的定义(尽管它与默认值相同,但是我将对其进行扩展
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;
,当我在lex文件中添加以下内容时,出现在此范围内未定义的yylloc"错误.
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:
- 弹性文件
- 野牛文件
- makefile
- flex file
- bison file
- makefile
Pastebin:
推荐答案
您需要将YYLTYPE
和YYLTYPE_IS_DECLARED
的定义放入#include
在.y
和.l
中的头文件中文件,并且需要在定义YYLTYPE
的文件的#include
之后,在.l
文件中的#include
文件中#include
.
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
.
发生上述情况的原因是,野牛不从.y
文件的顶部导出.tab.h
文件将始终具有默认的YYLTYPE
(由#ifndef YYLTYPE_IS_DECLARED
保护),因此您需要确保在定义之前可以看到您的定义.
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.
这篇关于yylloc在此范围内未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!