世界は優しい
首页博客关于

Site

世界は優しい

世界很温柔,我们都在努力变得更好。

Navigation

  • 首页
  • 博客
  • 关于

Connect

  • GitHub
  • 作者

© 2026 ZZC. 本站内容以 CC BY-NC-SA 4.0 协议发布。

Built with Next.js · Tailwind CSS

Folders

课程介绍与评分Lec1: IntroductionLec2: Lexical AnalysisLec3: ParsingLec4: Abstract SyntaxLec5: Semantic AnalysisLec6: Activation RecordsLec7: Translate to Intermediate CodeLec8: Basic Blocks and TracesLec9: 指令选择Lec10: Liveness Analysis
Lec0: 课程介绍与成绩Lec1: IntroductionLec2: Operating-System StructuresLec3: ProcessesLec4: Threads(多线程编程)Lec5: CPU SchedulingLec6: 进程同步Lec7: DeadlocksLec8: Main MemoryLec9: Virtual MemoryLec10: File-System InterfaceLec11: File System ImplementationLec12: Mass-Storage System
Lec1: Basic Concepts in Reinforcement LearningLec2: Bellman EquationLec3: Bellman Optimality EquationLec4: Value Iteration & Policy IterationLec5: Monte Carlo Learning
首页
ManiGaussian 论文笔记ManiGaussian++ 论文笔记
AMP: 对抗动作先验替代复杂奖励函数DeepMimic: 从动作捕捉数据学习物理仿真角色技能DreamWaQ: 纯本体感知的四足鲁棒行走Imitating Animals: 从动物模仿到真实四足敏捷运动MoE-Loco: 多任务腿足运动的专家混合架构Multi-AMP: 多重对抗动作先验学习高级技能PIE: Proprioception with Imagination for ParkourRMA: Rapid Motor Adaptation for Legged Robots
论文阅读
Lec1: 五十音Lec2: 日语声调Lec3: 浊音和长音
Callout 语法速查
Hello World - 我的第一篇博客
Typora 语法兼容性测试
首页博客Coure-NotebookCompiler_PrincipleLec1: Introduction

编译原理

Lec1: Introduction

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

2026 年 03 月 13 日/3 min read/ZZCZZC
#编译原理#课程笔记#计算机科学

编译器

  1. 什么是编译器:编译器实际上就是一个可以将一个语言(source language)转化成另一个语言(target language)的程序(equivalent program)。

image-20260302141910891

Modules and Interfaces: Overview

image-20260302142201915

  • 两个重要概念:
    • Phases:one or more modules operating on the different abstract “languages” during compiling process
      • 每一个阶段中,处理一种表示形式,输出另一种表示形式,相当于在不同“语言层次”之间转换。
    • Interfaces:Describe the information exchanged between modules of the compiler
      • 编译器各个阶段之间传递的信息格式
      • 上一个阶段的输出,必须符合下一个阶段的输入格式

Phases

​ Phase 指的是编译过程中的一个“工作步骤”,比如如下所示:

PhaseDescription
LexBreak source file into tokens
ParseAnalyze the phrase structure of the program
Parsing ActionsBuild abstract syntax tree (AST) for each phrase
Semantic AnalysisDetermine meaning; check types; resolve variable bindings
Frame LayoutOrganize variables and parameters into stack frames
TranslateProduce intermediate representation (IR trees)
CanonicalizeSimplify IR; hoist side effects; clean conditionals
Instruction SelectionMap IR nodes to target machine instructions
Control Flow AnalysisBuild control flow graph (CFG)
Dataflow AnalysisAnalyze flow of values (e.g., liveness analysis)
Register AllocationAssign variables to machine registers
Code EmissionGenerate final assembly code

Modularization

  • Several modules maybe combined into one phase
  • 有些模块会被整合在一个阶段中
  • Simple compilers may omit the Control Flow Analysis, Data Flow Analysis, and Register Allocation phases
  • 简单的编译器会省略 CFA、DFA、RA 这些优化阶段

Interfaces

​ Interfaces 指的是 phases 之间如何交换数据。比如 Phase 拿到 token:

Token getNextToken();

Tools and Software

​ 有两种非常有用的概念供我们使用:

  • Regular expression: for lexical analysis
  • Context-free grammers: for parsing

​ 相应的,有两个工具供使用,来进行编译:

  • Lex converts a declarative specification into a lexical analysis program
  • Yacc converts a grammar into a parsing program
ZZC

Written by

ZZC
每天研究怎么摸鱼的神人

Comments

评论功能即将上线

On this page

  • 编译器
  • Modules and Interfaces: Overview
  • Phases
  • Modularization
  • Interfaces
  • Tools and Software