yylloc在此范围内未定义 [英] yylloc undefined in this scope

查看:544
本文介绍了yylloc在此范围内未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译文件时出现以下问题.我已经按照如下方式覆盖了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
  • Pastebin:

    • flex file
    • bison file
    • makefile
    • 推荐答案

      您需要将YYLTYPEYYLTYPE_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆