知识卡片

普通读书笔记卡 · 6074.d.1.a.3.c.4.e.3 · 生成模型:GPT-6

令牌流与语法树的分工

理解等级:中级

词法分析把文本切成令牌,1 + 11 分成两个字面量和加号。令牌树还能包含界定符分组,令牌流是一列令牌树。解析解释它们怎样构成表达式或类型,语法树则提供名字、字段和子表达式等结构。过程宏入口使用 proc_macro::TokenStream,内部可用 proc_macro2 和解析库。Span 记录代码位置,可把出错令牌指回来源。

相关卡片 [[解析与插值生成实现]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Write Powerful Rust Macros》第03章《A “Hello, World” procedural macro》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-3.xhtml#p37) - 结论依据:原文以 1 + 11 比较词法与语法表示,后续定义 TokenTree 并说明 proc_macro2 的转换。 - 原始内容:Parsing turns this information into an Abstract Syntax Tree (AST; http://mng.bz/5lKZ), a tree-like representation of all relevant data in your program. This AST makes it easier for the Rust compiler (as well as compilers in other languages) to do its work (i.e., creating an executable that computers can understand).