我们可以将预处理器指令视为 token 吗?

标签 c token lexer

对于以下代码,我们可以将'#define'视为 token 吗?

#define int char 
 main(){
   int i=65;               // i is initialized  
   printf("sizeof(i)=%d",sizeof(i)); 
}

最佳答案

ISO C 标准明确指出存在哪些标记,例如 c11 6.4 :

token:
    keyword
    identifier
    constant
    string-literal
    punctuator
preprocessing-token:
    header-name
    identifier
    pp-number
    character-constant
    string-literal
    punctuator
    each non-white-space character that cannot be one of the above

所以,不,#define不是一个标记,它是两个预处理标记,#define标识符。

这是一个标识符,如 6.4.2.1它的定义基本上为 [_A-Za-z][_A-Za-z0-9]* .

关于我们可以将预处理器指令视为 token 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41583056/

相关文章:

iphone - 验证从移动 (iPhone) 应用程序到 ASP.Net Web API 的请求(对我的设计请求反馈)

java - 如何将 token 添加到 HttpPost Json 消息

python - ply 中的特殊情况词法分析器规则

ANTLR:如何跳过多行注释

c++ - 在C++中修改PL/SQL语句字符串

c - 错误: a value of type "void *" cannot be assigned to an entity of type "float *"

c - 在我的 c 代码中删除重复项时出现错误

C(不是++)struct动态初始化中struct数组的struct麻烦malloc

angular2-jwt 检查组件中的 token 是否过期?

c - 如何获取用户输入的数组大小