First collection Follow set

Source: Internet
Author: User

Recently to step into the exam week, compiling the principle of this follow set has made my head big ah, today Baidu down, find an article, see after I instantly understand how to solve follow set ~ ~ Haha, if you do not know how to solve follow set, please look at the following this log it, In fact, I found that for the follow set, I do not understand the first place in the VN can launch ε when, it will need to consider a character:)

Grammar:

S→abc
a→a|ε
b→b|ε

First set seeking method:
All the opening symbols that can be rolled out by non-terminating symbols or possible ε, but require that the opening symbol is the Terminator symbol. 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 method of follow collection:
Immediately following the end symbol or #. 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) ={#}
For 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}

Tomorrow will be the exam, here tangled up this problem.

One, to know what are Terminator and non-Terminators.

Terminator: In layman's words, it is not possible to appear alone in the derivation of the left side of the symbol, that is terminator can not be deduced.

Non-Terminator: not Terminator are non-terminating characters. (not male or female, hehe)

For example: A-->b, A is A non-terminating character.

(The general book is terminator in lowercase, not terminator in uppercase.) )

Second, the grammar produces the basic idea of the language sentence: Starting from the recognition symbol (the starting character), the non-terminator in the currently generated symbol string is replaced with the symbol string in the right part of the corresponding rule until it is all composed of Terminator.

Third, first set seeking method

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, since the first collection of Terminator is itself, so it is very straightforward to get the first collection of each string after finding the first set of non-terminator.

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 ... Production (where p is non-terminator), the entire contents of first (p) should be transmitted to "U", meaning that it is only necessary to pass the initial set of non-Terminator to the past-this place is a place to pay attention to, but also difficult.

Four, the method of follow set

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. Note that the follow collection is derived from the start sign S.

1. Direct charge: Pay attention to the production of the right side of each shape, such as "... Ua ... "A direct income to follow (U). Because A is a terminator immediately after U.

2. To receive directly: to form as "... Up ... "(P is a non-terminator), the first (p) proceeds directly to follow (U)" Here, if there is a null character in first (p), then the left (assuming s) follow (s) is fed into follow (U). There is no empty character in the follow concentration.

3. Direct charge: if s-> U, which ends with u, then #∈follow (u)

4. * Repeated transmission: to form as u-> The production of P (where p is non-terminator), the entire contents of follow (U) should be transmitted to follow (P).

Ps:follow set is a little more complicated than first, but remembering that algorithms do more exercises is a small case.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.