【问题标题】:lextestpass.l:384: error: expected expression before ‘int’lextestpass.l:384:错误:“int”之前的预期表达式
【发布时间】:2011-04-20 22:54:26
【问题描述】:

所以我在头文件(实际上是 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’ 

是因为类型转换吗?

【问题讨论】:

    标签: c compiler-construction yacc lex flex-lexer


    【解决方案1】:
    int(t)
    

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

    (int)t
    

    【讨论】:

    • 你先生,太棒了。我忽略的小事。 尴尬时刻谢谢。
    • 不,我并不聪明。我只是又一个经常犯这种错误的傻瓜。
    猜你喜欢
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 2021-08-18
    相关资源
    最近更新 更多