GCC说“数字常数之前的语法错误”来自bison的生成头文件 [英] GCC says "syntax error before numeric constant" in generated header file from bison

查看:216
本文介绍了GCC说“数字常数之前的语法错误”来自bison的生成头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用bison parser.y -d -t编译我的.y文件,然后在我的flex文件中包含parser.tab.h文件,gcc在数字常量之前显示error:syntax error。它是引用行32,它是yytokentype枚举中的第一行。

 枚举yytokentype {
BREAK = 258,
...}

错误是关于BREAK = 258的行。我真的不知道为什么会发生这种情况 - 我真的想使用生成的yylval,我需要它从这个头文件。即使我在flex文件中声明了这样的yytokentype,我也会得到同样的错误。我可能做错了什么?

解决方案

是否在其他地方定义 BREAK 在你的代码中?我从以下玩具示例中得到类似的错误:

  #define BREAK 10 
枚举yytokentype {
BREAK = 258
};

构建示例:

  $ cc -c file.c 
file.c:4:错误:数字常量之前的预期标识符


When I compile my .y file with bison parser.y -d -t and then include the parser.tab.h file in my flex file, gcc says "error: syntax error before numeric constant." It's referencing line 32, which is the first line in the enum of yytokentype.

enum yytokentype {
   BREAK = 258,
   ... }

The error is about the line "BREAK = 258." I honestly don't know why this is happening--I would really like to use the generated yylval and I need it from this header file. Even if I declared yytokentype like this in my flex file, I would get the same error. Anything I could be doing wrong?

解决方案

Is BREAK defined somewhere else in your code? I get a similar error from the following toy example:

#define BREAK 10
enum yytokentype {
    BREAK = 258
};

Build example:

$ cc -c file.c 
file.c:4: error: expected identifier before numeric constant

这篇关于GCC说“数字常数之前的语法错误”来自bison的生成头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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