Compilation Principle: first set and follow set

Source: Internet
Author: User
Http://www.hackchina.com /? Q = ll % 281% 29

GRAMMAR:

S → ABC
A → A | ε
B → B | ε

 

First set method:

All the starting symbols or possible ε that can be introduced by non-ending symbols, but this starting symbol is required to be an ending symbol. In this case, question a can deduce a and ε, so first (A) = {A, ε}; similarly, first (B) = {B, ε}; s can deduce ABC, you can also export BC and C, so first (S) = {a, B, c}

   The first set is ultimately for the right string of the form, but the key is to find the first set of non-Terminator, because the first set of Terminator is its own, therefore, after finding the first set of non-Terminator, you can obtain the first set of each string intuitively.
1.Directly charged: pairs such as U-... Generate (where a is the terminator), and send a's revenue to first (u)
2.Repeated transmission: the object is in the u-p... (P is not a terminator), and all content in first (p) should be transmitted to first (u.

Method of follow set:
Follow the terminator or # following it #. However, the recognition symbols of grammar include #, which must be considered in the query. The specific method is to find out all the production types that contain the symbols you require, and then see which one is useful. Follow (S) = {#}

For example, for a, the formula is S → abc a → A | ε, but only S → ABC is useful. The ending symbol following a is first (B) = {B, ε}. When the first (B) element is ε, the symbol following a is C, so follow (A) = {B, c} is the same as follow (B) = {c}

The follow set is for non-Terminator. Follow (u) expresses the set of all possible terminologies with non-terminator U in a sentence. In particular, "#" is the suffix of the identifier.
1.Charge directly: Pay attention to each of the right parts of the generative formula, such as "... UA ..." To directly generate a to follow (u.
2. direct charge: The pair is like "... Up ..." (P) is a combination of non-terminologies, and first (P) is directly included in follow (u.
3. Repeated transmission: pairs such as U -... P (where p is not a terminator), all content in follow (u) should be transmitted to follow (P ).

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.