Chomsky hierarchy
来源:互联网 发布:淘宝联盟没绑定支付宝 编辑:程序博客网 时间:2024/05/07 21:56
The Chomsky hierarchy consists of the following levels:
- Type-3 grammars (regular grammars) generate the regular languages. Such a grammar restricts its rules to a single nonterminal on the left-hand side and a right-hand side consisting of a single terminal, possibly followed (or preceded, but not both in the same grammar) by a single nonterminal. The rule is also allowed here if S does not appear on the right side of any rule. These languages are exactly all languages that can be decided by a finite state automaton. Additionally, this family of formal languages can be obtained by regular expressions. Regular languages are commonly used to define search patterns and the lexical structure of programming languages.
Strictly regular grammars
In computer science, a right regular grammar (also called right linear grammar) is a formal grammar (N, Σ, P, S) such that all the production rules in P are of one of the following forms:
- B → a - where B is a non-terminal in N and a is a terminal in Σ
- B → aC - where B and C are in N and a is in Σ
- B → ε - where B is in N and ε denotes the empty string, i.e. the string of length 0.
In a left regular grammar (also called left linear grammar), all rules obey the forms
- A → a - where A is a non-terminal in N and a is a terminal in Σ
- A → Ba - where A and B are in N and a is in Σ
- A → ε - where A is in N and ε is the empty string.
An example of a right regular grammar G with N = {S, A}, Σ = {a, b, c}, P consists of the following rules
S → aSS → bAA → εA → cAand S is the start symbol. This grammar describes the same language as the regular expression a*bc*.
A regular grammar is a left regular or right regular grammar.
Some textbooks and articles disallow empty production rules, and assume that the empty string is not present in languages.
[edit]Extended regular grammarsAn extended right regular grammar is one in which all rules obey one of
- B → a - where B is a non-terminal in N and a is a terminal in Σ
- A → wB - where A and B are in N and w is in Σ*
- A → ε - where A is in N and ε is the empty string.
Some authors call this type of grammar a right regular grammar (or right linear grammar) and the type above a strictly right regular grammar (or strictly right linear grammar).
An extended left regular grammar is one in which all rules obey one of
- A → a - where A is a non-terminal in N and a is a terminal in Σ
- A → Bw - where A and B are in N and w is in Σ*
- A → ε - where A is in N and ε is the empty string.
Some authors call this type of grammar a left regular grammar and the type above a strictly left regular grammar.
[edit]Expressive powerThere is a direct one-to-one correspondence between the rules of a (strictly) left regular grammar and those of a nondeterministic finite state automaton, such that the grammar generates exactly the language the automaton accepts. Hence, the left regular grammars generate exactly all regular languages. The right regular grammars describe the reverses of all such languages, that is, exactly the regular languages as well.
Every strict right regular grammar is extended right regular, while every extended right regular grammar can be made strict by inserting new nonterminals, such that the result generates the same language; hence, extended right regular grammars generate the regular languages as well. Analogously, so do the extended left regular grammars.
If empty productions are disallowed, only all regular languages that do not include the empty string can be generated.
[edit]Mixing left and right regular rulesIf mixing of left-regular and right-regular rules is allowed, we still have a linear grammar, but not necessarily a regular one. What is more, such a grammar need not generate a regular language: all linear grammars can be easily brought into this form, and hence, such grammars can generate exactly all linear languages, including nonregular ones.
For instance, the grammar G with N = {S, A}, Σ = {a, b}, P with start symbol S and rules
S → aAA → SbS → εgenerates , the paradigmatic non-regular linear language.
- Chomsky hierarchy
- Hierarchy
- hierarchy
- Chomsky 文法分类
- Chomsky文法类型判断
- 语法的Chomsky层级
- Chomsky文法类型判断
- 《Chomsky: ideas and ideals》笔记
- 编译原理(一) Chomsky文法
- 【编译原理】乔姆斯基(chomsky)文法分类
- Hierarchy Viewer
- CF17B Hierarchy
- Hierarchy Viewer
- pyscreenshot hierarchy
- View Hierarchy
- Hierarchy Viewer
- Exception hierarchy
- Memory Hierarchy
- 寒假该看C++了
- 【多核程序设计】蒙特卡洛算法求pi
- 两整型变量的数据交换
- 12
- 131313
- Chomsky hierarchy
- 基于java的数据结构学习手记11--递归法数组归并排序
- SQL Server 中查询非中文,非英文,非数字的特殊列
- 代码是我生命中不可或缺的一部分
- 判断目录是否为空
- 电脑问题,求解决方法!
- 2010年1月12日
- Timer in Java
- 我的日志