Skip to Content
深入理解運算原理|從簡單的機器到無所不能的程式
book

深入理解運算原理|從簡單的機器到無所不能的程式

by Tom Stuart
November 2017
Beginner to intermediate
344 pages
7h 2m
Chinese
GoTop Information, Inc.
Content preview from 深入理解運算原理|從簡單的機器到無所不能的程式
只想加入運算能力
|
137
狀態 接受與否? 堆疊內容 剩下的輸入 動作
2 M}$ n} 提出 M, 推入 T
2 T}$ n} 提出 T, 推入 n
2 n}$ n} 讀取 n, 提出 n
這項執行追蹤讓我們知道機器如何在符號和符記規則之間不斷來回:符號規則重複展開
堆疊頂端的符號,直到符記換掉它,然後符記規則處理堆疊(和輸入)裡的資料,直
到它們命中符號。只要文法規則可以產生輸入字串,這樣的來來回回最終會導致空的堆
8
PDA 如何知道在每個執行步驟要選擇哪條規則?沒錯,這就是非決定論的威力:我們
NPDA 模擬物會嘗試所有可能的規則,所以只要出現能獲得空堆疊的方式,我們就
會找到它。
實踐
這種解析過程雖然依賴非決定論,但在實際應用最好避免非決定論,因為決定論 PDA
比非決定論的版本快很多,而且更容易模擬。所幸只要使用輸入符記本身來決定每個階
段要套用哪一項符號規則,幾乎可以完全排除非決定論(一種稱為
前看
[
lookahead
]
技巧),但是這會讓 CFG 轉換到 PDA 的過程更加複雜。
它也不是真的好到只能識別有效的程式。如同我們在第 61 頁的『實現解析器』所見,
解析程式的整個重點是將它轉換成接著我們可以做些益事的結構化表示方式。在實踐的
過程,只要將我們的 PDA 模擬物工具化,並且記錄它所遵循的一組規則,進而達到接
受狀態,就可以建立這種表示方式,這提供了構造解析樹的足夠資訊。舉例來說,以上
的執行追蹤告訴我們如何展開堆疊裡的符號,進而形成所需要的符記序列,並且也告訴 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JSON實務手冊

JSON實務手冊

Tom Marrs

Publisher Resources

ISBN: 9789864766000