# 无限制文法

无限制文法是一种形式文法，其中每条产生式都具有 \( u \to v \) 的形式，这里 \( u \) 是由变元和终结符组成的非空串，而 \( v \) 是由变元和终结符组成的任意串，包括空串。它是[乔姆斯基层级](https://www.edgepedia.org/zh/chomsky-hierarchy)中限制最少的类别，称为0型，它所生成的语言恰好是[递归可枚举语言](https://www.edgepedia.org/zh/recursively-enumerable-language)，与图灵机所识别的语言属于同一类。<sup>[1](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_CH11_02.xhtml)</sup><sup> • </sup><sup>[2](https://john.cs.olemiss.edu/~hcc/docs/LinzNotes/chap11/ch11.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 产生式形式 | \( u \to v \)，其中 \( u \in (V \cup T)^{+} \)，\( v \in (V \cup T)^{*} \)；两侧均可出现任意数量的变元和终结符，顺序不限<sup>[1](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_CH11_02.xhtml)</sup> |
| 唯一限制 | 左部不能是空串 \( \lambda \)<sup>[3](https://opendsa-server.cs.vt.edu/OpenDSA/Books/PIFLA/html/TuringMachinesAdv.html)</sup> |
| 生成的语言 | 恰好是递归可枚举语言<sup>[2](https://john.cs.olemiss.edu/~hcc/docs/LinzNotes/chap11/ch11.html)</sup> |
| 对应的自动机 | 图灵机，在乔姆斯基层级中<sup>[4](https://jjcweb.jjay.cuny.edu/jwkim/class/csci374-summer-25/Chomsky_Hierarchy.pdf)</sup> |
| 其他名称 | 0型文法、短语结构文法、半图厄系统<sup>[5](https://www.rose-hulman.edu/class/cs/csse474/textbook/Part4-%28Chapters_17-26%29.pdf)</sup> |
| 成员问题 | 不可判定：不存在一种算法，能对任意输入串判定它是否属于某个给定无限制文法的语言<sup>[6](https://asaparov.org/assets/cs577_fall2025/lecture23.pdf)</sup> |
| 下一层级 | 上下文敏感（1型）文法，要求每条产生式满足 \( |u| \le |v| \)<sup>[3](https://opendsa-server.cs.vt.edu/OpenDSA/Books/PIFLA/html/TuringMachinesAdv.html)</sup> |

## 定义与推导

这一定义回到了文法最一般的形式，除左部非空之外不施加任何条件。一个文法 \( G = (V, T, S, P) \) 由有穷变元集 \( V \)、有穷终结符集 \( T \)、开始符号 \( S \) 以及有穷产生式集 \( P \) 组成，每条产生式具有 \( u \to v \) 的形式，其中 \( u \in (V \cup T)^{+} \)，\( v \in (V \cup T)^{*} \)。<sup>[1](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_CH11_02.xhtml)</sup> 推导过程与上下文无关文法相同：从 \( S \) 出发，将匹配某条产生式左部的子串替换为其右部，语言 \( L(G) \) 便是从 \( S \) 可推导出的终结符串的集合。<sup>[5](https://www.rose-hulman.edu/class/cs/csse474/textbook/Part4-%28Chapters_17-26%29.pdf)</sup>

由于终结符和变元都可以出现在左部，一般情况下无法仅凭阅读产生式列表来判断哪些符号是终结符、哪些是变元。<sup>[7](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Foundations_of_Computation_%28Critchlow_and_Eck%29/04%3A_Grammars/4.06%3A_General_Grammars)</sup> 右部短于左部的产生式可以删除符号；例如 \( aAB \to aB \) 在上下文 \( aAB \) 中删去了 \( A \)。<sup>[8](https://www.cs.ru.ac.za/compilerbook/CsharpAndJava/book2017/book2017text/chap06.htm)</sup>

## 在乔姆斯基层级中的位置

[诺姆·乔姆斯基](https://www.edgepedia.org/zh/noam-chomsky)（Noam Chomsky）于1956年描述了这一层级，按产生式规则的形式对生成文法进行分类。<sup>[9](https://arato.inf.unideb.hu/horvath.geza/book/out/html/book.html)</sup> 0型是无限制层级；对产生式施加限制便得到较低的型别。上下文敏感（1型）文法要求每条产生式满足 \( |u| \le |v| \)，因此推导过程中句型永远不会缩短；上下文无关（2型）文法要求左部为单个变元；正则（3型）文法对右部施加进一步限制。<sup>[3](https://opendsa-server.cs.vt.edu/OpenDSA/Books/PIFLA/html/TuringMachinesAdv.html)</sup><sup> • </sup><sup>[9](https://arato.inf.unideb.hu/horvath.geza/book/out/html/book.html)</sup> 这些类别层层包含：每个正则语言都是上下文无关的，每个上下文无关语言都是上下文敏感的，而每个上下文敏感语言都包含在无限制的递归可枚举类中。<sup>[10](https://journals.sagepub.com/doi/10.1177/147470491301100302)</sup>

0型对应的自动机是[图灵机](https://www.edgepedia.org/zh/turing-machine)，1型对应线性有界自动机，2型对应下推自动机，3型对应有穷自动机。<sup>[4](https://jjcweb.jjay.cuny.edu/jwkim/class/csci374-summer-25/Chomsky_Hierarchy.pdf)</sup><sup> • </sup><sup>[11](https://ocw.uc3m.es/pluginfile.php/3257/mod_page/content/14/guide4.pdf)</sup>

## 与图灵机的等价性

有两个定理将无限制文法与图灵机联系起来。第一，任何由无限制文法生成的语言都是递归可枚举的：该文法定义了一种枚举过程，先列出一步可推导出的所有串，再列出两步可推导出的所有串，依此类推，于是语言中的每个串最终都会出现。<sup>[2](https://john.cs.olemiss.edu/~hcc/docs/LinzNotes/chap11/ch11.html)</sup> 第二，对于每个递归可枚举语言 \( L \)，都存在一个无限制文法 \( G \) 使得 \( L = L(G) \)；其构造模拟一台接受 \( L \) 的图灵机，使得该文法恰好推导出机器所接受的串。<sup>[2](https://john.cs.olemiss.edu/~hcc/docs/LinzNotes/chap11/ch11.html)</sup> 两者合起来说明：无限制文法所生成的语言集合与图灵机所识别的语言集合相同。<sup>[3](https://opendsa-server.cs.vt.edu/OpenDSA/Books/PIFLA/html/TuringMachinesAdv.html)</sup>

## 例子

语言 \( \{ a^{n} b^{n} c^{n} : n > 0 \} \) 不是上下文无关的，它有一个标准的无限制文法：<sup>[12](https://www.cs.utexas.edu/~cline/ear/automata/CS341-Fall-2004-Packet/1-LectureNotes.pdf)</sup>

\[ S \to aBSc \mid aBc, \quad Ba \to aB, \quad Bc \to bc, \quad Bb \to bb \]

规则 \( Ba \to aB \) 和 \( Bb \to bb \) 将标记 \( B \) 向右移过 \( a \) 并将其转换为 \( b \)，而 \( Bc \to bc \) 终止推导，同时保持三种字母的数目相等。类似的构造可以生成 \( \{a,b,c\} \) 上 \( a \)、\( b \)、\( c \) 数目相等的串构成的语言，所用产生式让标记符号 \( A \)、\( B \)、\( C \) 彼此超越移动，然后再将它们转换为终结符。<sup>[12](https://www.cs.utexas.edu/~cline/ear/automata/CS341-Fall-2004-Packet/1-LectureNotes.pdf)</sup>

## 计算限制

无限制文法的威力是有代价的。由于它们等价于图灵机，成员问题是不可判定的：不存在一种算法，对任意给定的无限制文法和输入串总能判定该串是否在该文法的语言中。<sup>[6](https://asaparov.org/assets/cs577_fall2025/lecture23.pdf)</sup> 涉及无限制文法的问题都是不可判定的，这意味着在这些问题上运行的算法不保证会终止。<sup>[13](https://citeseerx.ist.psu.edu/document?doi=0ab95dc9f6e750597b10ed77e5dc973fdacf495d&repid=rep1&type=pdf)</sup> 这也是该形式体系在描述编程语言时鲜有实际应用的原因之一——人们更倾向于使用限制更多的文法类型，以便在其上构建翻译器。<sup>[8](https://www.cs.ru.ac.za/compilerbook/CsharpAndJava/book2017/book2017text/chap06.htm)</sup>

## 术语

无限制文法也称为0型文法（因其在乔姆斯基层级中的位置）和短语结构文法。<sup>[5](https://www.rose-hulman.edu/class/cs/csse474/textbook/Part4-%28Chapters_17-26%29.pdf)</sup> 有些文献将半图厄系统用作同义词，尽管这两种形式体系建模的是不同的计算过程，通常分开处理。<sup>[5](https://www.rose-hulman.edu/class/cs/csse474/textbook/Part4-%28Chapters_17-26%29.pdf)</sup> 该形式体系背后的重写系统早于乔姆斯基将其改造用于语言学；它们最初是作为逻辑中推理规则形式化项目的一部分而被定义的。<sup>[14](https://benjamins.com/catalog/hl.00186.pul)</sup>

## References

1. [11.2 Unrestricted Grammars, An Introduction to Formal Languages and Automata, 7th Edition](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_CH11_02.xhtml)
2. [Notes on Models of Computation, Chapter 11, H. Conrad Cunningham, University of Mississippi](https://john.cs.olemiss.edu/~hcc/docs/LinzNotes/chap11/ch11.html)
3. [9.2. Turing Machines: Advanced Topics, CS4114 Formal Languages and Automata, OpenDSA](https://opendsa-server.cs.vt.edu/OpenDSA/Books/PIFLA/html/TuringMachinesAdv.html)
4. [The Chomsky Hierarchy, course notes, John Jay College of Criminal Justice](https://jjcweb.jjay.cuny.edu/jwkim/class/csci374-summer-25/Chomsky_Hierarchy.pdf)
5. [Chapter 23: Unrestricted Grammars, CSSE 474 textbook, Rose-Hulman Institute of Technology](https://www.rose-hulman.edu/class/cs/csse474/textbook/Part4-%28Chapters_17-26%29.pdf)
6. [Unrestricted Grammars, lecture notes, CS 577, Fall 2025](https://asaparov.org/assets/cs577_fall2025/lecture23.pdf)
7. [4.6: General Grammars, Foundations of Computation, Critchlow and Eck, Engineering LibreTexts](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Foundations_of_Computation_%28Critchlow_and_Eck%29/04%3A_Grammars/4.06%3A_General_Grammars)
8. [Chapter 6, Compilers and Compiler Generators](https://www.cs.ru.ac.za/compilerbook/CsharpAndJava/book2017/book2017text/chap06.htm)
9. [Formal Languages and Automata Theory, Géza Horváth and Benedek Nagy, University of Debrecen](https://arato.inf.unideb.hu/horvath.geza/book/out/html/book.html)
10. [A Framework for the Comparative Study of Language, Juan Uriagereka and James A. Reggia, 2013](https://journals.sagepub.com/doi/10.1177/147470491301100302)
11. [Unit 4. Languages and Formal Grammars, Universidad Carlos III de Madrid](https://ocw.uc3m.es/pluginfile.php/3257/mod_page/content/14/guide4.pdf)
12. [Lecture Notes 25: Grammars and Turing Machines, CS 341, University of Texas at Austin](https://www.cs.utexas.edu/~cline/ear/automata/CS341-Fall-2004-Packet/1-LectureNotes.pdf)
13. [Formal language theory background, University of Nebraska–Lincoln](https://citeseerx.ist.psu.edu/document?doi=0ab95dc9f6e750597b10ed77e5dc973fdacf495d&repid=rep1&type=pdf)
14. [The prehistory of generative grammar and Chomsky's debt to Emil Post, Historiographia Linguistica](https://benjamins.com/catalog/hl.00186.pul)

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

Topic: 社会与历史 › 语言与语言学 › 语言学 › Formal and computational linguistics › Formal grammar classes and the Chomsky hierarchy

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/unrestricted-grammar

English original: https://www.edgepedia.org/unrestricted-grammar
