Difference between LR and SLR (follow set and search operator)

Source: Internet
Author: User

Difference between LR and SLR (follow set and search operator)

In syntax analysis, slr uses follow sets and LR uses search characters, which is the root cause of different functions.

The follow set calculation method is as follows:

1.
For method start character S, set # To follow (s;

2.
If a-> α B Beta is a production formula, the first (Beta )/{
ε} is added to follow (B;

3.
If a-> α B is a production formula, add follow (a) to follow (B.

For Article 2, the operation to remove ε in the first set is explained as follows: it does not make sense to follow an empty input. If nothing really follows, then at least there is a # bottom, therefore, it is not necessary to add ε.

Search operator calculation method:

The textbooks (Chen huowang, National Defense Industry Press) do not directly provide search operators. However, when constructing the LR (1) project set family, the computation of search operators is involved. The process for finding the closure of the LR (1) project set is as follows:

1.
Any project of I belongs to closure (I );

2.
If project [A-> α · B β, A] belongs to closure (I), and B-> E is a production formula, for each Terminator B in first (β, if [B-> · ε, B] is not in closure (I), add it;

3.
Repeat Step 2 until the closure (I) does not increase.

Difference.Obviously, step 2 involves the calculation of search characters. When using a project's search operator, we are actually examining multiple search operators, that is, first (βA ). So we call first (βA) A search operator set. It is a bit like a follow set. It is also the terminator following the method symbol.


From the calculation process of the search operator set, it is a stricter follow set. Because it only uses 1st and 2 of the follow set calculation methods (Steps 1st are not shown here ). The consequence of this is that the search operator set will certainly appear in a certain sentence pattern, followed by a non-Terminator that generates the left part of the formula in the project. But the elements of the follow set are not necessarily.


Step 2 ensures that the request is followed by a non-Terminator. In grammar language, if a-> α B Beta is a production formula, there must be a sentence pattern containing α B Beta, and then B is decomposed. At this time, first (Beta) must follow.


Step 3 is not the case. It can be understood that the terminator following a must be behind B. There is no error in this reasoning, but the problem is that we need to convert B to A, and B must have α before B. If there is no α, even after B, follow (B) appears) it cannot be reduced to.

Example of referencing a textbook.Considerations:

(1) S-> L = r

(2) S-> r

(3) L-> * R

(4) L-> I

(5) r-> L


It can be calculated that follow (r) contains "=", but when r = is encountered, it cannot be reduced. Because there is no "*" before R, and the syntax does not contain a sentence pattern prefixed with r =. After calculating follow (B), we will find that "=" is calculated by step 3. That is to say, through (1) and (3) it is considered that the terminator after l must be behind R, but (3) it requires "*" before R.

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.