FLC-Regular Grammar
2016-03-06 03:35
239 查看
本身只是一个数学对象,有四部分组成,是为了正确表达字符串的语法格式,它是任意的线性语法。线性语法:是文本自由的语法,左线性语法就是在左边最多只有一个非终止标志,右线性语法相反。左右是同等的。A regular grammar is a mathematical object, G, with four components, G = (N, Σ, P, S), whereN is a nonempty, finite set of nonterminal symbols,
Σ is a finite set of terminal symbols , or alphabet, symbols,
P is a set of grammar rules, each of one having one of the forms
A → aB
A → a
A → ε, for A, B ∈ N, a ∈ Σ, and ε the empty string, and
S ∈ N is the start symbol. □
Notice that this definition captures all of the components of a regular grammar that we have heretofore identified (heretofor, how often does one get to use that word?But what does it do?
Pupose:to specify how to form grammatically correct strings in the language of the grammar reprents.
All strings in Σ* that can be produced from the start symbol by application of the rules of the grammar are in the language of this grammar, all other strings are not. Let's see how we might capture that in a definition.First we need yet another definition. We have talked about how strings in a language can be derived by applying the rules of the grammar to nonterminals, starting with the start symbol S. We now need to make that concept formal. We do this by defining the operation "derives in one step " as we have used it in our previous examples and exercises by way of the arrow. For example, we have said that010110A derives in one step 0101101Sor simply010110A 0101101Sif there is a rule A → 1S in the grammar we are using. (Notice that because of the way regular grammars are defined, all intermediate strings on the way to a string in the language have the form "zero or more terminals followed by one nonterminal".)
Σ is a finite set of terminal symbols , or alphabet, symbols,
P is a set of grammar rules, each of one having one of the forms
A → aB
A → a
A → ε, for A, B ∈ N, a ∈ Σ, and ε the empty string, and
S ∈ N is the start symbol. □
Notice that this definition captures all of the components of a regular grammar that we have heretofore identified (heretofor, how often does one get to use that word?But what does it do?
Pupose:to specify how to form grammatically correct strings in the language of the grammar reprents.
All strings in Σ* that can be produced from the start symbol by application of the rules of the grammar are in the language of this grammar, all other strings are not. Let's see how we might capture that in a definition.First we need yet another definition. We have talked about how strings in a language can be derived by applying the rules of the grammar to nonterminals, starting with the start symbol S. We now need to make that concept formal. We do this by defining the operation "derives in one step " as we have used it in our previous examples and exercises by way of the arrow. For example, we have said that010110A derives in one step 0101101Sor simply010110A 0101101Sif there is a rule A → 1S in the grammar we are using. (Notice that because of the way regular grammars are defined, all intermediate strings on the way to a string in the language have the form "zero or more terminals followed by one nonterminal".)
Definition: Derivations in a Regular Grammar
Let G = (N, Σ, P, S) be a regular grammar. We will define three different notations that we use for derivations in G: (single step derivations) k (k step derivations) * (derivations of 0 or more steps)Part 1. The definition of . We define the operation , called "derives in one step" to be the mapping from strings of the form a1...anA to strings of the form a1... anα, ora1...anA a1... anαif and only if there is a ruleA → αin P, where each of the a1 are terminal symbols in Σ and A is a nonterminal in N. (Of course, by the definition of regular grammars, α must have one of the forms bB, b, or ε since α is the right hand side of a rule or a regular grammar).Part 2. The definition of k. We further define the operation k , called a k-step derivation, to be the extension of to k consecutive single-step derivations. Thus, there is a derivationa1...anA k a1...an, an+1...an+k-1αif and only if there are k single-step derivations in Ga1...anA a1...anan+1A1 ... a1...anan+1...an+k-1Ak-1 a1...anan+1...an+k-1αfor k ≥ 0. If k = 0 this just means that no rules are applied, so the string being derived from does not change:a1...anA 0 a1...anA Part 3. The definition of * . We define * to stand for zero or more single step derivations in sequence. □Finally, we are able to give a formal definition for the set of all strings generated by a grammar G. We call this set the language of G.Definition: The Language Generated by a Regular Grammar
Let G = (N, Σ, P, S) be a regular grammar. We define the language generated by G to be L(G)L(G) = {w | S * w, where w ∈ Σ*} All this formal definition says is that the language of a regular grammar is the set of all strings over the alphabet Σ that can be derived from the start symbol by application of the grammar rules starting with S. □Although this appears to be a lot of words and unnecessary mathematical notation, it turns out to be unbelievably convenient. From now on we can simply discuss the derivation of strings in a regular grammar by way of the production rules (→) and the three notations for derivations (, k , and * ).http://www.cs.montana.edu/ross/theory/contents/chapter02/green/section05/page04.xhtml相关文章推荐
- fpc exam- foreword
- 继续探索其他不同类型Activity的属性,可以获取到所有Activity的属性
- Extjs4.x (MVC)Controller中refs以及Ext.ComponentQuery解析
- 数学符号,不常用的时候参考一下…
- xp_pcre - Regular Expressions in T-SQL
- 轻松理解正则表达式
- Undefined symbols for architecture armv7:
- what is the difference between definition and declaration in c
- A story of declaration and defintion (C++)
- Regular Expression Matching
- regular expression
- linux3.0内核KDB调试:无法获取部分符号
- C++ 防 陷阱2 重复包含头文件
- 基础正觃表示法字符汇整 (characters)
- 延伸正规表示法的符号意义
- Regular Expression Matching
- surf算法生成动态链接库使用出现crtstuff.c:(.text+0x5510): multiple definition of `main'
- XSD- XML Schema Definition模式定义
- A better way to learn regular expression
- iOS 创建静态库文件时去掉其中的Symbols