First set of methods:
the first collection is ultimately the string for the right side 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: to form as u-a ... (where A is terminator) and the income from A to first (U)
2. repeated transmission: to the shape into the u-p ... (where p is non-terminator), the entire contents of first (p) should be transmitted to first (U).
the method of follow collection:
the follow collection is for non-Terminator, and follow (U) is expressed as a 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. To receive directly: to form as "... Up ... "(P is a non-terminator) combination, the first (p) in addition to the ε direct income into follow (U).
3. To transmit repeatedly: to form as 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 directly derived 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} is follow (b) ={c}.
originating from: http://blog.sina.com.cn/s/blog_a1132bf901011ylj.html
Compiling principles frist and follow