[Compilation Principle] Formal Language Classification

to sum up

This is based on "Compilation Principles Tutorial (Fourth Edition)" Hu Yuanyi
(I have read other teachers, and they are a bit different . I will explain the different points in the points of attention)
Formal language classification

The difference between the 4 types of grammar

Type 0

The only restriction : there must be a non-terminal symbol in the left part of the production

Type 1

The only difference with Type 0 : the right part of the production cannot be empty (in order to ensure that the length of the right part is not shorter than the length of the left)

Type 2

The only restriction : the left part of the production has exactly one nonterminal

Type 3

The only difference with Type 2 : There is at most one non-terminal symbol on the right of the production

important point

About Type 2

α A δ → α β δ \ alpha A \ delta → \ alpha \ beta \ delta α A δαβδ
A A A must be inα \alphaαδ \ deltaIn the context of δ can it beβ \betareplaced by β , which is certain

Then the book says that there must be at least one non-terminal symbol in the right part of the production, that is, the type 1 grammar cannot appear S → ε S → \varepsilonSA production in the form of ε .

There is another saying:
(1) If there is S → ε S→\varepsilonSε , thenSSS must not appear in the right part of the production
(2) generally not allowed to be replaced withε \varepsilonε unless the start symbol producesε \varepsilonε
Then this statement, the right part of the production allows no non-terminal symbols
[the two are essentially the same:∣ α ∣ |\alpha|α ≤ \leq | b | | \ beta |β

If you follow this statement, then the relationship between grammars is:
Grammatical relations
otherwise, as the summary table says, type 2 grammars may not necessarily belong to type 1 grammars , because type 2 grammars may have S → ε S→\varepsilonSe

What kind of statement is based on what the teacher teaches.

Guess you like

Origin blog.csdn.net/qq_44714521/article/details/106982208