c++ - C++ 编译中有哪些不同的标记类型?

标签 c++ parsing compiler-construction compilation lexer

Walter Bright 的 C++ Compilation 文章谈到了这两个词组

“转换为预处理标记。”
什么是初始 token ?预处理 token 是什么样的?

“预处理标记到 C++ 标记的转换” 这个 C++ Token 是什么,为什么一开始不转换成它?

引用: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.

所以“转换为预处理标记”是对翻译单元进行词法分析和识别单个标记的过程。

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

token:

  • identifier
  • keyword
  • literal
  • operator
  • punctuator

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

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

关于c++ - C++ 编译中有哪些不同的标记类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11074073/

相关文章:

c++ - Qt (4.8.2) GUI - 自己的主循环而不是 QApplication::exec()

c++ - 模板和依赖注入(inject)

c++ - 你如何告诉 pyximport 使用 cython --cplus 选项?

c++ - 使用 DHCP 获取 IP 地址、网关、掩码和广播信息

javascript - JQuery.parseJSON 不适用于字符串

java - 从 CSV 读取字符串并解析到日期

performance - Perl6 : What is the best way for dealing with very big files?

c# - 在.net 中编译成.exe 的注释?

c - 编译器如何为变量分配内存地址?

c - `:>`(冒号,大于,又名笑脸)在 C 编程语言中是什么意思?