Rule (rewrite rule, production or formula)
- The form α → β or α :: = β 's (α, β) ordered pair, wherein [alpha] is called the right part of the left portion of the rule, the rule known as beta], where the symbol → (:: =) reading " is defined as "A → a, for example, read as" A is defined as a "
- Grammar G is defined as a four-tuple (V N, V T , P, S)
- Wherein V N non-terminal symbol set (or variable Syntax entity); V T terminator set; P rule (α → β) is set, ae (V N ∪V T ) * , and comprising at least one nonterminal , β∈ (V N∪ V T ) * , V N , V T and P are nonempty finite set
- S or identifier called the start symbol , which is a non-terminal, left to occur at least as a rule
- V N and V T does not contain a common element, i.e., V N ∩ V T = Ø
- Usually represented by V V N ∪ V T , V G, called grammar alphabet or vocabulary
= 2.1 Example There grammar G <V N , V T , P, S>, where, V N = {S}, V T = {0,1}, P = {S → 0S1, S → 01}, where the non- terminator concentrate containing only one element S, a termination symbol set composed of two elements 0,1, there are two production, is the start symbol S
This example can also be written as
G: S→0S1
S→01
or
G[S]:S→0S1
S→01
Example 2.2 have grammar = G (V N , V T , P, S), where V N = {identifier, letters, numbers}, V T = {A, B, C, ..., X, Y, Z , 0,1, ..., 9}
P = {<identifier> → <letter>
<Identifier> → <identifier> <letter>
<Identifier> → <identifier> <number>
<Letter> → a
<Letter> → b
...
<Letter> → z
<Number> → 0
<Number> → 1
...
<Number> → 9
}
S = <identifier>
Language definition is generated by the grammar, but also need to introduce derived concept, definition of V * relationships between symbols, is derived directly => a length of n (n≥1) derivation and a length of n (n≥0) derivation
DERIVATION / direct reduction definition
- Grammar is disposed α → β = G (V N , V T , P, S) of the rules (or a production in P), γ and δ is V * of any symbol
- If symbol string v, [omega] meet, v = γαδ, ω = γβδ , said that v (apply rule α → β) produced directly [omega], or that [omega] is a direct derivation of v , or that [omega] v directly to the reduction , referred to for v => ω
For example, for Example 2.1 grammar G, can be given some examples
- v = 0S1, ω = 0011, is derived directly: 0S1 => 0011, using the rules: S → 01, where γ = 0, δ = 1
- v = S, ω = 0S1, directly derived: S => 0S1, using rules: S → 0S1, where [epsilon] = gamma], [delta] = [epsilon], [epsilon] group which is similar to the identity element
- v = 0S1, ω = 00S11, deduced directly: 0S1 => 00S11, using rules, S → 0S1, where γ = 0, δ = 1
For Example 2.1 grammar G, the following example is derived directly
- V = <identifier>, [omega] = <identifier> <letter> directly derived: <identifier> => <identifier> <letter>, using the rule: <identifier> → <identifier> <letter> , where γ = δ = ε
- V = <identifier> <letter> <number>, [omega] = <letter> <letter> <number>, derived directly: <identifier> <letter> <number> => <letter> <letter> <number>, use rules: <identifier> → <letter>, where γ = ε, δ = <letters> <numeric>
- v = abc <number>, ω = abc5, deduced directly: ABC <number> => abc5, using the rule: <number> → 5, where γ = abc, δ = ε
Defined sequence deduced
- If the presence of the sequence derived directly: v = [omega] 0 => [omega] . 1 => [omega] 2 => ... => [omega] n- = [omega] (n-> 0) called v derived (generated) [omega] (derivation of length n) , also known as ω reduces to v , denoted v ω
- If V [omega], or v = ω, is referred to as V [omega] Example 2.1 of grammar, there is a direct sequence deduced v = S1 => 00S11 => 000S11 => 00001111 = ω, i.e. 0S1 00001111, also referred to as 0S1 00001111
- 2.2 Example of grammar, there is a direct sequence deduced V = <identifier> => <identifier> <number> => <letter> <number> => X <number> => x1 = ω, i.e. <identifier> x1
Sentence (deduced from the results), and sentence (sentence consisting only of terminal symbols) is defined
- Set G [S] is a grammar, if the symbol string x is derived from the identification code , i.e., there are S x, called x is grammar G [S] sentence
- If only the end of the symbols x, i.e., S x, x∈V * T , x is called G [S] sentences
- For example, in the embodiment 2.1, S, 0S1,000111 sentence is grammar G of Example 2.1, wherein G is 000,111 sentences
- In the embodiment 2.2, <identifier> <letter>, <letter> <number>, Example 2.2 are a1 sentence grammar G, wherein G is a1 sentences
Language definition generated grammar G
- Language grammar G is defined as a set of generated X {| S X, wherein S is the recognition grammar symbols and x∈V * T }, available L (G) of the set represents
Language grammar describes grammar all the sentence (sentence consisting only of terminal symbols) set
Example Consider the grammar G 2.1, there are two production (rule): S → 0S1 and S → 01, by using the n-1 times to generate a first type, and then use a formula to generate a second, to give S => = 0S1> 00S11 => ... => 0 n-. 1- Sl n--. 1 => 0 n- . 1 n-
L(G)={0n1n|n≥1}
Example 2.3
Set = G (V N , V T , P, S), V N = {S, B, E}, V T = {A, B, E}, P generated by the following composition formula
- S→aSBE
- S→aBE
- EB→BE
- aB→ab
- bB→bb
- bE→be
- eE→ee
If L (G1) = L (G2), G1 and G2 are called grammatical equivalent
For example grammar G [A]:
- A→0R
- A→01
- R→A1