Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
This book is a hands-on guide to building a real compiler for C♭, a C-like language, on x86 Linux, covering everything from parsing to code generation and linking. It’s for developers who want to understand how compilers and runtime environments actually work by building one from scratch.
【Book Arc】
- **Opening (~0%–11%)**: Introduces the book’s philosophy—building a practical compiler rather than a toy—and outlines the full toolchain (compiler, assembler, linker, hardware, runtime). It sets expectations for the reader’s prerequisites (Java, C, Linux basics) and explains why the author chose x86 and Linux for concreteness.
- **Early (~11%–25%)**: Covers the C♭ language and the structure of the cbc compiler, then dives into lexical analysis using JavaCC. You learn how to define tokens, handle whitespace and comments, and scan structured words like strings and numbers.
- **Early (~25%–36%)**: Moves to parser construction with JavaCC, using EBNF notation to describe grammar. It addresses ambiguity, token lookahead, and how to structure rules for statements, expressions, and terms.
- **Middle (~36%–50%)**: Transitions to abstract syntax trees (ASTs) and intermediate code. You see how JavaCC actions build ASTs for declarations, statements, and expressions, then start semantic analysis—specifically resolving variable references using a scope tree and Visitor pattern.
- **Late (~50%–end)**: Continues semantic analysis (type checking, etc.), then moves to code generation, assembly, linking, and runtime considerations. The book concludes with producing executable ELF files and understanding the full program execution pipeline.
【Key Takeaways】
- **Build a real compiler, not a toy** (Opening): The book’s core value is implementing a working compiler for C♭, a C subset with pointers, that generates executable ELF files on x86 Linux. This gives you practical insight into how C programs are compiled and run.
- **Concrete platforms beat abstract theory** (Early): By fixing the environment (x86, Linux, JavaCC), the author makes the entire toolchain explainable end-to-end. This approach is more intuitive than generic discussions and lets you trace every step from source to binary.
- **JavaCC is the workhorse for lexing and parsing** (Early): You learn to describe tokens and grammar using JavaCC’s regular expressions and EBNF notation. This includes handling ambiguity, longest-match rules, and state-based scanning for structured tokens like comments and strings.
- **ASTs are the bridge between parsing and semantics** (Middle): JavaCC actions build abstract syntax trees for declarations, statements, and expressions. Understanding AST structure is essential for the next phase—semantic analysis—where you resolve references and check types.
- **Semantic analysis uses Visitor patterns and scope trees** (Middle): The book shows how to traverse ASTs using Visitor patterns and manage variable scopes with a tree structure. This is where you resolve variable references and prepare for code generation.
- **The full pipeline includes assembler, linker, and runtime** (Late): Beyond the compiler, the book covers how generated code is assembled, linked, and loaded on Linux. This holistic view is rare in compiler books and helps you understand program execution from start to finish.
- **Open-source tools are leveraged, not reinvented** (Throughout): The author uses GCC, GNU Assembler, JavaCC, and Linux, showing that “self-made” doesn’t mean writing every line yourself. This teaches you to build on existing tools while understanding their roles.
【Reading Tips】
- **Skim the early chapters on JavaCC basics** if you’re already familiar with lexers and parsers; focus instead on how C♭’s grammar is structured and where the author makes design choices.
- **Deep-read the semantic analysis and code generation sections**—these are the most complex and where the book’s unique value lies. Pay attention to how the scope tree and Visitor pattern are implemented.
- **Follow along with the code** by setting up the cbc compiler on your own Linux machine. The book is practical, so running examples and modifying them will solidify your understanding.
- **Brush up on Java 5 features** (generics, foreach) and basic C pointers before starting, as the book assumes this knowledge and doesn’t explain them in detail.
- **Use the book as a reference for the full toolchain**—if you get stuck on linking or ELF format, revisit the later chapters rather than jumping to external resources.
【Coverage Limits】
This guide covers the book’s structure and key concepts through the semantic analysis stage (~50% of the book). The later chapters on code generation, assembly, and runtime are summarized based on the book’s stated scope but not detailed from the excerpts.
...................................... 121 if 语句的抽象语法树●.........................................................................................................
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
自制编译器 = How to develop a compiler ([日] 青木峰郎 著 严圣逸, 绝云 译)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share to WeChat Moments
自制编译器 = How to develop a compiler ([日] 青木峰郎 著 严圣逸, 绝云 译)(Z-Library)
Scan the QR code with WeChat to open this book
Tap the ··· menu in the top-right corner
Choose Share to Moments
You are already in WeChat. Tap ··· in the top-right corner and choose Share to Moments.
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
自制编译器 = How to develop a compiler ([日] 青木峰郎 著 严圣逸, 绝云 译)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment