编辑从 lex 和 bison 文件生成的 C 文件
我在从 .c
文件中删除警告时遇到了麻烦,这些文件是由 .l(lex)
和 .y(bison)
。我在 lex
和 bison
文件中没有任何编译器警告。但我在生成的 C 文件中收到以下类型的警告。
parser.c:1772:34: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result
这是来自 parser.c
的警告。这个parser.c是从parser.y生成的。您能否让我知道如何永久删除这些警告,因为在 parser.c 中进行编辑对下一次编译没有任何意义。
提前致谢。
I have been in trouble of removing warning from .c
files which are generated by.l(lex)
and .y(bison)
. I don't have any compiler warning in lex
and bison
files. But I get following type of warning in the generated C
file.
parser.c:1772:34: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result
This is the warning from the parser.c
. This parser.c is generated from parser.y
. Could you please let me know how can i permanently remove those warning as editing in the parser.c does not make any sense for next compilation.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果警告与 bison/lex 代码的生成部分相关(不是您的操作)。
也许唯一的解决办法就是修改骨架。
但最有可能的警告与您的 bison/lex 源代码中的操作部分有关,您只需修改该操作即可。请记住,bison 不会分析您的操作的内容(即大括号内的所有代码)。
假设您正在使用一个返回
unsigned int
的函数,并在一个操作中使用它,如下所示:如果规则的预期标记类型是 int,您将收到 ac 警告,
如果没有源代码行 (1772:34) 和上下文,则很难对您的问题给出准确的答案。
If the warning is related to generated part of the bison/lex code (not your action).
Probably the only solution is to modify the skeleton.
But most likely the warning is related to the action part in your bison/lex source code, you simply have to modify the action. Keep in mind that bison does not analyze the content of your action (ie. all the code inside braces.
Suppose that your are using a function returning an
unsigned int
and that use it in one action like that :If the expected token type for rule is an int you will have a c warning.
Without the source line (1772:34) and the context it is hard to give a precise answer to your question.
您的 Flex/Lex 和 Bison/Yacc 文件将告诉我有关此问题的更多信息。 Flex 和 Bison 在生成代码时不向您发出警告的原因是它们将您的代码视为文本块并且不尝试理解它。这就是 C 编译器的工作。
c 代码是从您的文件生成的。调整生成的代码并不是一个好主意,因为它相当复杂。最好从源头解决问题。
Your Flex/Lex and Bison/Yacc files will tell me more about this problem. The reason why Flex and Bison don't give you warnings when they are generating the code is because they treat your code as a block of text and don't attempt to make sense of it. That is the C compilers job.
The c code is generated from your files. It is not a good idea to tweek the generated code since it is fairly complex. Much better to get it right at the source.