lextestpass.l:384:错误:“int”之前的预期表达式

发布于 2024-11-02 10:58:13 字数 932 浏览 10 评论 0原文

所以我在头文件(实际上是 y.tab.h 文件)中有这个定义:

  typedef enum yytokentype {
 TOKEN_UNKNOWN = 1000,
 TOKEN_ABBREV = 1001,
 TOKEN_AT = 1002,
 TOKEN_COMMA = 1003,
 TOKEN_COMMENT = 1004,
 TOKEN_ENTRY = 1005,
 TOKEN_EQUALS = 1006,
 TOKEN_FIELD = 1007,
 TOKEN_INCLUDE = 1008,
 TOKEN_INLINE = 1009,
 TOKEN_KEY = 1010,
 TOKEN_LBRACE = 1011,
 TOKEN_LITERAL = 1012,
 TOKEN_NEWLINE = 1013,
 TOKEN_PREAMBLE = 1014,
 TOKEN_RBRACE = 1015,
 TOKEN_SHARP = 1016,
 TOKEN_SPACE = 1017,
 TOKEN_STRING = 1018,
 TOKEN_VALUE = 1019
} token_t;

这是我正在使用的函数的一部分:

static token_t out_token(token_t t)
{       
    int n;
int temp;

if (1)
{
temp = int(t);
temp = 1000-temp;
(void)printf("this is the value of the array : %d\n",temp);
(void)printf("%d\t%s\t", (int)t, type_name[temp]);
}

但它给了我以下错误:

lextestpass.l:384: error: expected expression before ‘int’ 

是因为类型转换吗?

So I have this definition in a header file (actually the y.tab.h file):

  typedef enum yytokentype {
 TOKEN_UNKNOWN = 1000,
 TOKEN_ABBREV = 1001,
 TOKEN_AT = 1002,
 TOKEN_COMMA = 1003,
 TOKEN_COMMENT = 1004,
 TOKEN_ENTRY = 1005,
 TOKEN_EQUALS = 1006,
 TOKEN_FIELD = 1007,
 TOKEN_INCLUDE = 1008,
 TOKEN_INLINE = 1009,
 TOKEN_KEY = 1010,
 TOKEN_LBRACE = 1011,
 TOKEN_LITERAL = 1012,
 TOKEN_NEWLINE = 1013,
 TOKEN_PREAMBLE = 1014,
 TOKEN_RBRACE = 1015,
 TOKEN_SHARP = 1016,
 TOKEN_SPACE = 1017,
 TOKEN_STRING = 1018,
 TOKEN_VALUE = 1019
} token_t;

and this is a part of the function that I'm using:

static token_t out_token(token_t t)
{       
    int n;
int temp;

if (1)
{
temp = int(t);
temp = 1000-temp;
(void)printf("this is the value of the array : %d\n",temp);
(void)printf("%d\t%s\t", (int)t, type_name[temp]);
}

But it gives me the following error:

lextestpass.l:384: error: expected expression before ‘int’ 

Is it because of the typecasting?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心清如水 2024-11-09 10:58:13
int(t)

这是 C++ 函数风格的转换。 C 风格的转换在类型名周围使用括号:

(int)t
int(t)

This is a C++ function-style cast. The C-style cast uses parentheses around the typename:

(int)t
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文