Writing A C Compiler: Build a Real Programming Language from Scratch

Sandler, Nora

  • 出版商: No Starch Press
  • 出版日期: 2024-08-20
  • 售價: $2,520
  • 貴賓價: 9.5$2,394
  • 語言: 英文
  • 頁數: 792
  • 裝訂: Quality Paper - also called trade paper
  • ISBN: 1718500424
  • ISBN-13: 9781718500426
  • 相關分類: C 程式語言ScratchCompiler
  • 立即出貨 (庫存 < 3)

相關主題

商品描述

A hands-on, example-filled guide to the theory and practice of writing a C compiler: a computer program that translates code written by programmers into code the computer can read.

Compilers are at the heart of everything programmers do, yet even experienced developers find them intimidating. For those eager to truly grasp how compilers work, Writing a C Compiler dispels the mystery. This book guides you through a fun and engaging project where you'll learn what it takes to compile a real-world programming language to actual assembly code.

Writing a C Compiler will take you step by step through the process of building your own compiler for a significant subset of C--no prior experience with compiler construction or assembly code needed. Once you've built a working compiler for the simplest C program, you'll add new features chapter by chapter. The algorithms in the book are all in pseudocode, so you can implement your compiler in whatever language you like. Along the way, you'll explore key concepts like:

  • Lexing and parsing: Learn how to write a lexer and recursive descent parser that transform C code into an abstract syntax tree.
  • Program analysis: Discover how to analyze a program to understand its behavior and detect errors.
  • Code generation: Learn how to translate C language constructs like arithmetic operations, function calls, and control-flow statements into x64 assembly code.
  • Optimization techniques: Improve performance with methods like constant folding, dead store elimination, and register allocation.

Compilers aren't terrifying beasts--and with help from this hands-on, accessible guide, you might even turn them into your friends for life.

商品描述(中文翻譯)

一本實例豐富的實踐指南,介紹了編寫 C 編譯器的理論和實踐:一個將程序員編寫的代碼轉換為計算機可讀代碼的計算機程序。

編譯器是程序員工作的核心,然而即使是有經驗的開發人員也會覺得它們令人生畏。對於那些渴望真正理解編譯器工作原理的人來說,《編寫 C 編譯器》將揭開神秘的面紗。本書將引導您進行一個有趣而引人入勝的項目,您將學習將現實世界的編程語言編譯為實際的組合語言所需的一切。

《編寫 C 編譯器》將逐步引導您完成構建自己的編譯器的過程,該編譯器可以處理 C 語言的一個重要子集,無需具備編譯器構建或組合語言的先前經驗。一旦您為最簡單的 C 程序構建了一個可運行的編譯器,您將逐章添加新功能。本書中的算法都是以偽代碼形式呈現,因此您可以使用任何您喜歡的語言來實現您的編譯器。

在此過程中,您將探索以下關鍵概念:
- 词法分析和语法分析:學習如何編寫一個將 C 代碼轉換為抽象語法樹的詞法分析器和遞歸下降解析器。
- 程序分析:了解如何分析程序以理解其行為並檢測錯誤。
- 代碼生成:學習如何將 C 語言結構(如算術運算、函數調用和控制流語句)轉換為 x64 組合語言代碼。
- 優化技術:通過常量折疊、無效存儲消除和寄存器分配等方法提高性能。

編譯器並不可怕,有了這本實踐性、易於理解的指南,您甚至可能將它們視為終身的朋友。

作者簡介

Nora Sandler is a software engineer based in Seattle. She holds a BS in computer science from the University of Chicago, where she researched the implementation of parallel programming languages. More recently, she's worked on domain-specific languages at an endpoint security company. You can find her blog on pranks, compilers, and other computer science topics at https: //norasandler.com.

作者簡介(中文翻譯)

Nora Sandler 是一位位於西雅圖的軟體工程師。她擁有芝加哥大學的計算機科學學士學位,並在該校研究並實現了並行程式語言。最近,她在一家端點安全公司從事領域特定語言的工作。您可以在她的部落格 https: //norasandler.com 上找到她關於惡作劇、編譯器和其他計算機科學主題的文章。