Compiler theory (Tsinghua University Press) - The type of grammar - grammar and language

Type 0 grammar

  • Set = G (V N , V T , P, S) is a grammar, if each of its production α → β is a structure: ae (V N  ∪ V T ) * and containing at least one non-terminal Fu , while β∈ (V N  ∪ V T ) * , then G is a  0-type grammar
  • Also known phrase grammar, ability to type 0 grammar is equivalent to a Turing machine (Turing machine); any type 0 languages are recursively enumerable ; on the contrary, must be recursively enumerable set a language 0

Type 1 or context sensitive (context-sensitive)

  • Setting G = (V N , V T , P, S) is a grammar, if each of P in the production α → β both satisfying  | β | ≥ | α | except only S → [epsilon] , then the grammar G is  1 type or context-related
  • In some definitions, the form of context-sensitive grammar productions described as [alpha] . 1 Aa 2  → [alpha] . 1 βα , wherein [alpha] . 1 , [alpha] 2  and beta] are (V N  ∪ V T ) *    beta] ≠ [epsilon], A in V N
  • Better reflect the "context-sensitive" because only A occurs in the [alpha] . 1  and [alpha] 2  context of , allowed substituted with A β

Type 2 or contextual (context-free)

  • Set = G (V N , V T , P, S) is a grammar, if P in each of the production α → β satisfy the  [alpha] is a terminator , β∈ (V N  ∪ V T ) * , grammars G is a  type 2 or a context-free
  • 2 indicating the type sometimes generative grammar in the form A → β, where A∈V N , i.e., when substituted with nonterminal beta] A, where A is independent of the context, the context is irrelevant named

Example 2.4 G = ({S, A, B}, {a, b}, P, S), where P is generated by the following composition formula:

  • S→aB
  • A→aAA
  • S→bA
  • B→b
  • A→a
  • B→bS
  • A→aS
  • B→aBB

Can produce the same type of a left portion, abbreviated as [alpha] → A . 1 | [alpha] 2  | ... | [alpha] n-   ,  the pivot symbol |  pronounced "or"

2.4 examples of P can be written as 

  • S → aB | bA
  • A → a | aS | Bar
  • B → b | AA | aBB

Type 3 grammar or regular grammar

Set = G (V N , V T , P, S), if the production of each of the form P is A → aB or A → a, wherein A and B are nonterminals, a∈V * T , G is the type 3 grammar or regular grammar

Example 2.5 grammar G = ({S, A, B}, {0,1}, P, S), where P is generated by the following composition formula:

  • S→0A
  • S→1B
  • S→0
  • S→0
  • A→0A
  • A→1B
  • B→1B
  • B→1
  • B→0

G is a regular grammar

Guess you like

Origin www.cnblogs.com/YC-L/p/12175804.html