- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 .l
文件中,我有以下内容:
<some include files....>
#include "SymbolInfo.h"
#include "y.tab.h"
using namespace std;
int line_count = 1;
int TOTAL_ERROR = 0;
extern SymbolTable symbolTable;
extern FILE *yyin,*yyout;
extern YYSTYPE yylval;
<further declarations...>
%%
"int" {
SymbolInfo* s = new SymbolInfo(string(yytext),"INT");
yylval = (YYSTYPE)s;
return INT;
}
<more patterns....>
%%
在我的 .y
文件中,我定义了 YYSTYPE
:
#include "SymbolInfo.h"
int SymbolTable::id = 0;
#define YYSTYPE SymbolInfo*
但是当我尝试编译它时,它给出了以下错误:
Lexical Analyzer.l: In function ‘int yylex()’:
Lexical Analyzer.l:162:27: error: cast from ‘SymbolInfo*’ to ‘YYSTYPE {aka int}’ loses precision [-fpermissive]
yylval = (YYSTYPE)res;
^
我的问题是,为什么即使在将 YYSTYPE
定义为 SymbolInfo*
之后仍会出现编译错误?我该如何处理这个错误?
最佳答案
why is it giving a compilation error even after defining
YYSTYPE
asSymbolInfo*
?
因为正如您所说,您在解析器定义中定义了 YYSTYPE。错误发生在扫描仪定义中。这些是单独的文件,其中定义的宏在另一个文件中不可见。
您可以将 #define YYSTYPE
行放在 .l
文件中,在包含由 bison 生成的头文件之前。或者你可以把它放在 %code requires
中bison 文件中的部分,以便将其插入到 bison 生成的 header 中。
但是你应该做的是避免宏并使用 bison declaration :
%define api.value.type { SymbolInfo* }
这不仅会正确定义语义类型,它还会被放入 bison 生成的头文件中,这样您就不必担心在其他源文件中定义 YYSTYPE
(如只要他们#include
Bison 头文件)。
请不要使用 bison 的 -y
选项。它只适用于遗留代码。应该将新代码写入 bison 接口(interface)。除非另有说明,否则 bison(没有 -y
标志)会将生成的代码放在
--output
(或
-o
)指定输出文件名,并在必要时使用
- 指定头文件名-defines
(而不是
-d
;
--defines
允许您指定文件名)。参见
Bison options了解详情。
关于c++ - 从 ‘SymbolInfo*’ 转换为 ‘YYSTYPE {aka int}’ 失去精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50768162/
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
我目前正在修改 Dennis Bush 的 UFTP ( http://uftp-multicast.sourceforge.net ) 以满足我的需要。我目前正在尝试做的是更改客户端发送 COMPL
我试图在我的应用程序中实现导航功能。当我尝试构建应用程序时,输出显示: Android resource linking failed /home/mateusz/AndroidStudioProje
我在 Xcode 5.1 中收到警告,如下所述 AFNetworking 2.2.0: AFURLConnectionOperation.m Implicit conversion loses int
我写了一个程序来交换数组中的两个结构,我的代码如下 #include struct a { char *name; int id; char *department;
我一直在尝试让 Glew 和 opengl 3.2 在 win32 上下文中使用代码块 (minGW)。我找到了一个不错的小教程 here 因为我一直在努力弄清楚在代码块中编译 glew 是否真的可行
这个问题在这里已经有了答案: how to pass 2 dimensional array if both dimensions are unknown at compile time (5 个答
这个问题在这里已经有了答案: Objective-C implicit conversion loses integer precision 'NSUInteger' (aka 'unsigned
我似乎遇到了一些与 Xcode 8 beta 和 64 位迁移相关的成长烦恼。在搜索中,我发现了一些相关问题,但没有一个专门与解决“NSInteger”(又名“long”)到“CGSWindow”(又
我不知道为什么 g++ 编译器在编译这段代码时给我错误: typedef unsigned char BYTE; typedef BYTE* BYTE_PTR; const BYTE myByte[]
你能告诉我这段代码有什么问题吗?关于如何修复的任何想法? JNIEXPORT jstring JNICALL Java_COM_DEMO_TEST_SEND (JNIEnv *env, jclass
背景:我目前正在为“Uncanny Eyes”开发 Adafruit 程序。我的目的是能够有几个瞬时开关,将静态图像绘制到一对 1.5 英寸 OLED 上。 该程序使用 Teensy 3.1 或 3.
我正在尝试将地址添加到模块基址 HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pId); MODULEENTRY3
我们的项目是使用我们大学的一位教授开发的机器人和软件来制作一部电影。该库称为 MyroC,机器人利用该库实现许多功能。理想情况下,我们让机器人拍摄用户输入的许多帧(图片)。用户还可以选择将“场景”或小
所以我是编程新手,这是大学工程类(class)的一部分。我决定找点乐子,在课外写点东西。我正在尝试用 C++ 编写一个程序,允许用户输入 3 个矩形棱柱的长度、宽度和高度值,程序将使用这 3 个值来计
我需要一个简单的代码,说明如何从移动应用程序连接到安全 WIFI (EAP-AKA)。我有以下代码,但我不知道它是否正确,也不知道如何使用它。如果有人有示例代码,那就太好了。 // Initial
NSString* lat,*longi; lat= [[deliveryInfo objectAtIndex:0]valueForKey:@"latitude"]; NSLog(@"LATITUDE
我已经学习和练习 sql 大约 6 个月了。我已经准备好投入其中,只是承认我对此很愚蠢,而且我的大脑无法理解它的大部分模式。我正在尝试创建一个数据透视表。关于这个主题的简单文献并不多,我找到的一个来源
我被指派为 Basic programming language 编写编译器.在基本情况下,代码用换行符或 : 标记分隔。例如,以下代码是有效的。 型号#1 10 PRINT "Hello Worl
我之前问过一个 similar question在这个主题上,我最终得出了几个有效的解决方案,一个基于布隆过滤器 + ngrams,另一个基于哈希表 + ngrams。这两种解决方案在小数据集(<10
我是一名优秀的程序员,十分优秀!