# 格雷巴赫范式

**格雷巴赫范式**（Greibach normal form，GNF）是上下文无关文法的一种范式，其中每条产生式都以终结符开头：每条产生式形如 A → aα，a 是终结符，α 是由变元组成的、可以为空的串。一种常见的表述允许唯一的例外 S → ε，条件是空串属于该语言，且开始符号 S 不出现在任何右部中。<sup>[1](https://alphabetamath.cc/item/def-greibach-normal-form)</sup><sup> • </sup><sup>[2](https://www.munotes.in/notes/BSc-Computer-Science/SY-BSc-Computer-Science/Semester-3/Theory-of-Computation/greibach-normal-form/)</sup>

| 关键事实 | 细节 |
|---|---|
| 产生式形式 | A → aα，a 为终结符，α 为变元组成的（可为空的）串；当 ε 属于该语言且 S 不出现在任何右部时，可额外允许 S → ε<sup>[1](https://alphabetamath.cc/item/def-greibach-normal-form)</sup> |
| 覆盖范围 | 每个上下文无关语言都可由某个处于格雷巴赫范式的文法生成<sup>[2](https://www.munotes.in/notes/BSc-Computer-Science/SY-BSc-Computer-Science/Semester-3/Theory-of-Computation/greibach-normal-form/)</sup> |
| 起源 | 由希拉·格雷巴赫（Sheila Greibach）证明，见《美国计算机学会杂志》1965 年 1 月第 12 卷第 1 期第 42–52 页，《上下文无关短语结构文法的一个新范式定理》<sup>[3](https://projects.csail.mit.edu/jacm/Authors/greibachsheilaa.html)</sup> |
| 推导长度 | 长度为 n 的串的推导恰需 n 步；在乔姆斯基范式中需 2n − 1 步<sup>[2](https://www.munotes.in/notes/BSc-Computer-Science/SY-BSc-Computer-Science/Semester-3/Theory-of-Computation/greibach-normal-form/)</sup> |
| 左递归 | GNF 中不允许出现；转换过程中必须消除<sup>[2](https://www.munotes.in/notes/BSc-Computer-Science/SY-BSc-Computer-Science/Semester-3/Theory-of-Computation/greibach-normal-form/)</sup> |
| 主要用途 | 构造模拟上下文无关文法最左推导的下推自动机<sup>[4](https://opendsa-server.cs.vt.edu/ODSA/Books/CS4114S22notes/html/PDACFL.html)</sup> |
| 转换代价 | 霍普克罗夫特与厄尔曼算法已通过形式验证，复杂度可达指数级，对 n 个非终结符，膨胀最坏可达 \( 2^{n^2} \)<sup>[5](https://isa-afp.org/browser_info/current/AFP/Greibach_Normal_Form/Greibach_Normal_Form.html)</sup> |

## 定义与直接推论

上下文无关文法 G = (V, Σ, P, S) 处于格雷巴赫范式，当且仅当 P 中每条产生式都形如 A → aα，其中 A 是变元，a 是终结符，α 是由变元组成的（可为空的）串。当空串属于该语言时，这种表述额外加入唯一一条产生式 S → ε，且 S 不出现在任何右部中。<sup>[1](https://alphabetamath.cc/item/def-greibach-normal-form)</sup> 某些教材的处理会进一步限制 α，例如至多含两个变元，但标准表述允许任意多个变元，包括零个。<sup>[6](https://cs.wellesley.edu/~cs235/fall05/lectures/tr16.pdf)</sup>

每一步推导都在最左位置恰好产生一个终结符，因此长度为 n 的串的推导恰需 n 步。这与乔姆斯基范式形成对照：那里产生式要么是 A → BC，要么是 A → a，长度为 n 的串的推导需 2n − 1 步，其中有些步骤根本不产生终结符。<sup>[2](https://www.munotes.in/notes/BSc-Computer-Science/SY-BSc-Computer-Science/Semester-3/Theory-of-Computation/greibach-normal-form/)</sup>

GNF 与乔姆斯基范式的约束方式不同，因此二者互不为特例。乔姆斯基范式限制右部的长度，并让终结符单独出现；格雷巴赫范式限制终结符与变元出现的*位置*，允许在打头的终结符之后跟任意多个变元。此外，GNF 排除左递归，而乔姆斯基范式允许左递归。<sup>[2](https://www.munotes.in/notes/BSc-Computer-Science/SY-BSc-Computer-Science/Semester-3/Theory-of-Computation/greibach-normal-form/)</sup>

这种范式也不同于更严格的 s 文法（简单文法）：一个 GNF 文法中可以有多条规则共享同一对 (A, a)，而 s 文法中每一对这样的组合至多出现在一条规则里，因此语法分析永远不需要回溯。<sup>[7](https://www.cs.sjsu.edu/~pollett/154.1.20s/Lec20200325.html)</sup><sup> • </sup><sup>[8](https://opendsa.cs.vt.edu/ODSA/Books/CS4114S22notes/html/CFLSimp.html)</sup>

## 范式定理

奠基性的结果是希拉·格雷巴赫的定理，1965 年 1 月发表于《美国计算机学会杂志》，题为《上下文无关短语结构文法的一个新范式定理》；当时格雷巴赫在哈佛大学任职。<sup>[3](https://projects.csail.mit.edu/jacm/Authors/greibachsheilaa.html)</sup><sup> • </sup><sup>[9](https://cir.nii.ac.jp/crid/1361418520582366592)</sup> 该定理指出，每个上下文无关文法都等价于某个处于格雷巴赫范式的文法；对于包含空串的语言，等价的 GNF 文法生成的是该语言去掉 ε 之后的部分，S → ε 规则另行加入。<sup>[2](https://www.munotes.in/notes/BSc-Computer-Science/SY-BSc-Computer-Science/Semester-3/Theory-of-Computation/greibach-normal-form/)</sup><sup> • </sup><sup>[10](https://www.cs.csustan.edu/~xliang/Courses2/CS4410-24F/NewLectureSlides/PDF/Ch06REC.pdf)</sup>

**转换算法。** 霍普克罗夫特与厄尔曼给出的经典转换分阶段进行：<sup>[11](https://www.iitg.ac.in/gkd/ma513/oct/oct18/note.pdf)</sup>

1. 消除空产生式、单位产生式和无用符号，并把文法转换为生成该语言去掉 ε 之后部分的乔姆斯基范式。
2. 把变元重命名为 A1, A2, ..., An，令 S = A1，并修改规则，使得 Ai → Ajγ 蕴含 j > i。
3. 从 A1 到 An 依次处理，把较前变元的产生式体代入较后的变元，直到每条规则都形如 Ak → Apγ 且 p ≥ k；然后对每个左递归变元引入一个新变元，以消除左递归。
4. 从 An−1 倒推回 A1，逐一代换，使每个右部都以终结符开头。

证明依赖两条代换引理。第一，产生式 A → α1Bα2 可以替换为 A → α1β1α2, ..., A → α1βrα2，其中 B → β1 | ... | βr 是 B 的全部产生式，而语言不变。第二，左递归 A → Aα1 | ... | Aαr 连同 A → β1 | ... | βs，可以通过引入新变元 Z（Z → αi | αiZ）并把 A 的产生式替换为 A → βi | βiZ 来消除。<sup>[11](https://www.iitg.ac.in/gkd/ma513/oct/oct18/note.pdf)</sup><sup> • </sup><sup>[12](https://www.cs.mun.ca/courses/cs4741/hopcroft-book.pdf)</sup> 伊莎贝尔/HOL 形式证明档案（Isabelle/HOL Archive of Formal Proofs）形式化了这一霍普克罗夫特–厄尔曼算法，并报告说：对于含 n 个非终结符、4n 条产生式的初始文法，膨胀最坏可达 \( 2^{n^2} \)；文献中也存在其他多项式时间的做法。<sup>[5](https://isa-afp.org/browser_info/current/AFP/Greibach_Normal_Form/Greibach_Normal_Form.html)</sup> 1986 年《理论计算机科学》上的一篇论文给出了从任意不含 ε、不含链式产生式的上下文无关文法直接转换到等价 GNF 文法的算法。<sup>[13](https://www.sciencedirect.com/science/article/pii/0304397586901209)</sup>

## 范式的意义：下推自动机

GNF 的核心应用，是证明每个上下文无关语言都能被一台非确定性下推自动机（pushdown automaton，PDA）接受——那是一台带栈的有限自动机。<sup>[4](https://opendsa-server.cs.vt.edu/ODSA/Books/CS4114S22notes/html/PDACFL.html)</sup><sup> • </sup><sup>[14](https://john.cs.olemiss.edu/~hcc/csci311/notes/chap07/ch07.html)</sup> 由于 GNF 文法的每条产生式都以终结符开头，PDA 可以直接模拟最左推导：对于每条产生式 A → aX1X2...Xn，自动机从栈中弹出 A，从输入中读入 a，再把 X1X2...Xn 压入栈中。在推导的任何时刻，句型都由两部分构成：与迄今读入的输入相匹配的终结符前缀，以及存放在栈上的变元。<sup>[4](https://opendsa-server.cs.vt.edu/ODSA/Books/CS4114S22notes/html/PDACFL.html)</sup><sup> • </sup><sup>[15](https://www-alg.ist.hokudai.ac.jp/~thomas/ToC/SLIDES/toc_lec10.pdf)</sup>

非确定性用来在首终结符相同的多条产生式之间作出选择，这正是该构造使用非确定性下推自动机（NPDA）而非确定性机器的原因。这一构造构成了上下文无关文法与下推自动机经典等价性的基础。<sup>[4](https://opendsa-server.cs.vt.edu/ODSA/Books/CS4114S22notes/html/PDACFL.html)</sup>

## 与语法分析实践的关系

除了 PDA 构造之外，GNF 还为分析由上下文无关文法生成的串所需的时间与空间给出了另一种界，因为每一步推导都消耗一个输入符号。<sup>[7](https://www.cs.sjsu.edu/~pollett/154.1.20s/Lec20200325.html)</sup> 左递归的非终结符会使自顶向下的确定性分析器陷入死循环，而 GNF 提供了避开这一问题的途径，因为 GNF 文法中的每个非终结符都不是左递归的。<sup>[16](https://www.cis.upenn.edu/~cis2620/notes/tcbook-u.pdf)</sup> 乔姆斯基范式则承担互补的用途，为 CYK 分析算法和上下文无关泵引理提供基础。<sup>[2](https://www.munotes.in/notes/BSc-Computer-Science/SY-BSc-Computer-Science/Semester-3/Theory-of-Computation/greibach-normal-form/)</sup>

## 推广

这种范式已被推广到若干更宽泛的框架中。摩尔（Moore）与克拉奇菲尔德（Crutchfield）在发展量子自动机与量子文法时，在他们所推广的一批经典定理（连同泵引理与闭包性质）中找到了格雷巴赫范式的对应物。<sup>[17](https://arxiv.org/abs/quant-ph/9707031)</sup> 德罗斯特（Droste）、杰亚德克（Dziadek）与库伊希（Kuich）（2020）证明，描述无限字的加权上下文无关语言的混合 ω-代数系统可以转换为格雷巴赫范式，并借此证明简单的 ω-重置下推自动机可识别所有 ω-代数级数；这类自动机不使用 ε-转移，且每次移动最多改变栈中一个符号。<sup>[18](https://arxiv.org/abs/2007.08866)</sup> 对于超图文法，普申尼岑（Pshenitsyn）（2020）引入了弱格雷巴赫范式，它对应于串文法的词汇化范式，并证明除了一些非本质的例外，每个上下文无关超图语言都可由处于这种范式的文法生成。<sup>[19](https://arxiv.org/abs/2012.01660)</sup>

## References

1. [Greibach normal form, Alphabeta Math](https://alphabetamath.cc/item/def-greibach-normal-form)
2. [Greibach Normal Form notes, B.Sc. Computer Science Sem 3, munotes](https://www.munotes.in/notes/BSc-Computer-Science/SY-BSc-Computer-Science/Semester-3/Theory-of-Computation/greibach-normal-form/)
3. [Sheila A. Greibach publication list, MIT CSAIL JACM author pages](https://projects.csail.mit.edu/jacm/Authors/greibachsheilaa.html)
4. [Equivalence of NPDA and CFG, CS4114 Coursenotes, Virginia Tech](https://opendsa-server.cs.vt.edu/ODSA/Books/CS4114S22notes/html/PDACFL.html)
5. [Theory Greibach_Normal_Form, Archive of Formal Proofs](https://isa-afp.org/browser_info/current/AFP/Greibach_Normal_Form/Greibach_Normal_Form.html)
6. [Standardized tests: Chomsky and Greibach normal forms, CS235, Wellesley College](https://cs.wellesley.edu/~cs235/fall05/lectures/tr16.pdf)
7. [Chris Pollett, CS154 lecture of 25 March 2020, San Jose State University](https://www.cs.sjsu.edu/~pollett/154.1.20s/Lec20200325.html)
8. [Simplifying CFGs and Normal Forms, CS4114 Coursenotes, Virginia Tech](https://opendsa.cs.vt.edu/ODSA/Books/CS4114S22notes/html/CFLSimp.html)
9. [A New Normal-Form Theorem for Context-Free Phrase Structure Grammars, CiNii Research](https://cir.nii.ac.jp/crid/1361418520582366592)
10. [Automata, Computability, and Formal Language, lecture slides, CSUSTan](https://www.cs.csustan.edu/~xliang/Courses2/CS4410-24F/NewLectureSlides/PDF/Ch06REC.pdf)
11. [MA513 Formal Languages and Automata Theory, lecture notes, IIT Guwahati](https://www.iitg.ac.in/gkd/ma513/oct/oct18/note.pdf)
12. [Hopcroft and Ullman, section 4.3, Greibach Normal Form](https://www.cs.mun.ca/courses/cs4741/hopcroft-book.pdf)
13. [On Greibach normal form construction, Theoretical Computer Science](https://www.sciencedirect.com/science/article/pii/0304397586901209)
14. [CSci 311, Models of Computation, Chapter 7 Pushdown Automata, University of Mississippi](https://john.cs.olemiss.edu/~hcc/csci311/notes/chap07/ch07.html)
15. [Thomas Zeugmann, Theory of Computation, Lecture 10, Hokkaido University](https://www-alg.ist.hokudai.ac.jp/~thomas/ToC/SLIDES/toc_lec10.pdf)
16. [Jean Gallier, Introduction to the Theory of Computation, University of Pennsylvania](https://www.cis.upenn.edu/~cis2620/notes/tcbook-u.pdf)
17. [Cristopher Moore and James P. Crutchfield (1997), Quantum Automata and Quantum Grammars, arXiv](https://arxiv.org/abs/quant-ph/9707031)
18. [Manfred Droste, Sven Dziadek, Werner Kuich (2020), Greibach Normal Form for ω-Algebraic Systems and Weighted Simple ω-Pushdown Automata, arXiv](https://arxiv.org/abs/2007.08866)
19. [Tikhon Pshenitsyn (2020), Weak Greibach Normal Form for Hyperedge Replacement Grammars, arXiv](https://arxiv.org/abs/2012.01660)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 25, 2026 · Edited: Sep 30, 2026; Oct 11, 2026; Oct 25, 2026 · Last review: Oct 25, 2026*

Topic: 社会与历史 › 语言与语言学 › 语言学 › 形式与计算语言学 › 语法范式与转换

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/greibach-normal-form

English original: https://www.edgepedia.org/greibach-normal-form
