Nfa
1. (a| b )* the NFA of AB
2. aa*|bb* 's NFA
Dfa
1. (a|b) *ab's DFA ?
NFA-to-DFA transformation
The general idea of an equivalent DFA constructed from the NFA is to let each state of the newly constructed DFA represent a set of states of the NFA, which uses its state to remember all the states that the NFA can reach after reading the symbol.
Write a grammarso that its language is an odd set, and each odd number does not start with 0.
Solution: Grammar g (N):
n→ab| B
a→ac| D
B→1|3|5|7|9
D→b|2|4|6|8
c→0| D
first collection of the method the
first collection is ultimately the string for the right part of the production, but the key is to find the first set of non-Terminator, because Terminator's first collection is itself, Therefore, after finding the first collection of non-terminator, it is very straightforward to get the first collection of each string.
1. Direct charge: The form of u-a (where A is terminator), the income from A to first (U) 2. Repeat: The production of the form into U-p, where p is non-terminator, the first (p) To the first (U). Follow: the
Follow collection is for non-Terminator, and follow (U) is the set of all possible post-finalization symbols that are not terminator u, in particular, "#" is the post-attendant character of the recognition symbol. 1. Direct charge: Pay attention to the production of the right side of each shape such as "? Ua? " A direct income to follow (U). 2. Direct charge: To form like "? Up? " (P is a non-terminator), and the first (p) is directly generated in follow (U) except ε.
3. Repeated transmission: To form like P-? U's production (where U is non-terminator), the entire contents of follow (P) should be transferred to follow (U). (or P-?) UB and First (b) contains ε, the first (b) is derived directly from the follow (U), and the entire contents of follow (P) are transferred to follow (U)
Example 1: Judge if the grammar is ll (1) grammar, stating the reason S→abc a→a|εb→b|ε?
The first set is a method of all the opening symbols or possible ε that can be introduced by non-terminating symbols, but requires that the opening symbol be a terminator. So the question a can be pushed to export a and ε, so first (A) ={a,ε}; same as first (B) ={b,ε}; S can deduce the ABC, also can deduce the BC, can also push export C, so first (S) ={a,b,c}.
The follow collection is followed by the end symbol or #, immediately following it. But the grammatical identification symbol contains #, when asked to consider the ε. The practice is to find out all the symbols that contain your requirements and see which ones are useful. Follow (S) ={#} If you are seeking a, the resulting formula: S→abc a→a|ε, but only s→abc useful. The final symbol following the end of A is first (b) ={b,ε}, when the element of first (b) is ε, the symbol following a is C, so follow (a) ={b,c} follow (b) ={c}
Examples of elimination of left recursion:
Extract public left factor:
LL (1) Grammar:
LL (1) Grammar prediction Analysis Method:
Grammar (4 1) '
1e→te′
2e′→ate′|ε
3t→ft′
4t′→mft′|ε
5f→ (E) |i
6a→+|-
7m→*|/
Considering grammar (4 1), the first and follow sets are respectively calculated as shown in table 41, and the corresponding LL (1) Analysis table is shown in table 42. Now take the input symbol string i+i*i as an example, listing the process of identifying this symbol string as shown in table 43.
The above algorithm corresponds to the obscure explanation on the textbook:
(1) if A∈first (γi), then m[a,a]= "A→γi";
(2) if Ε∈first (Γj), and A∈follow (A), then m[a,a]= "A→γj";
(3) In addition to the above two cases, all the remaining table elements are set to "error".
Note: M is ll (1) Analysis table
One more example to deepen the impression:
Grammar:
The first collection of each non-terminator:
About follow collections we only consider non-terminator that are likely to become empty conversions:
You can generate a ll (1) Grammar prediction Analysis table based on the first set and the follow set:
Analytical process of the Predictive Analysis table method:
To list the change, input, and output actions of the analysis stack in tabular form:
The following is the parsing process of the above grammar for the Id+id*id string
Compiling principle inductive learning--removing obscure