其他分享
首页 > 其他分享> > C编译中有哪些不同的令牌类型?

C编译中有哪些不同的令牌类型?

作者:互联网

Walter Bright关于C编译的文章讨论了这两个短语

“转换为预处理令牌.”
什么是初始令牌?预处理令牌是什么样的?

“将预处理令牌转换为C令牌”
什么是这个C令牌,为什么它最初没有转换成它?

参考:http://www.drdobbs.com/blogs/cpp/228701711

解决方法:

预处理标记是预处理器语法的一个元素.来自C标准中的[lex.pptoken]:

preprocessing-token:

  • header-name
  • identifier
  • pp-number
  • character-literal
  • user-defined-character-literal
  • string-literal
  • user-defined-string-literal
  • preprocessing-op-or-punc
  • each non-white-space character that cannot be one of the above

A preprocessing token is the minimal lexical element of the language in translation phases 3 through 6.

因此,“转换为预处理令牌”是翻译单元和识别单个令牌的过程.

[lex.token]中列出了C标记(实际上只是“标记”):

token:

  • identifier
  • keyword
  • literal
  • operator
  • punctuator

这些仅在所有其他翻译阶段发生后才存在(宏扩展等).

有关整个过程的更多信息,我建议阅读C标准中的[lex.phases].

标签:lexer,c,compilation,parsing,compiler-construction
来源: https://codeday.me/bug/20190826/1728461.html