编译原理
编译原理课程的第一章,介绍了编译器的基本概念、模块化设计以及常用工具。编译器是将一种语言转换为另一种语言的程序,分为多个阶段,每个阶段处理不同的抽象表示形式。课程还介绍了正则表达式和上下文无关文法,以及相应的工具Lex和Yacc,用于词法分析和语法分析。


Phase 指的是编译过程中的一个“工作步骤”,比如如下所示:
| Phase | Description |
|---|---|
| Lex | Break source file into tokens |
| Parse | Analyze the phrase structure of the program |
| Parsing Actions | Build abstract syntax tree (AST) for each phrase |
| Semantic Analysis | Determine meaning; check types; resolve variable bindings |
| Frame Layout | Organize variables and parameters into stack frames |
| Translate | Produce intermediate representation (IR trees) |
| Canonicalize | Simplify IR; hoist side effects; clean conditionals |
| Instruction Selection | Map IR nodes to target machine instructions |
| Control Flow Analysis | Build control flow graph (CFG) |
| Dataflow Analysis | Analyze flow of values (e.g., liveness analysis) |
| Register Allocation | Assign variables to machine registers |
| Code Emission | Generate final assembly code |
Interfaces 指的是 phases 之间如何交换数据。比如 Phase 拿到 token:
Token getNextToken(); 有两种非常有用的概念供我们使用:
相应的,有两个工具供使用,来进行编译:
Written by
Comments