Job four - grammar and language summary and comb

1. carding second chapter, this chapter has been summarized.

Syntax refers to a set of rules, which may be formed and used to generate an appropriate program, is now widely used means of context-free grammars, context-free grammar that is used as a tool described in a programming language syntax.

Use grammar as a tool, not only for strictly defined structure of the sentence, but also to all the rules of appropriate sentence paragraphs to describe it, it can be said grammar is a tool infinite set of finite set of characterization.

Type 0 grammar definition:

0 type grammar (PSG): α∈ (VN∪VT) *, and containing at least one the VN

β∈ (VN∪VT) *

Type 1 grammar:
  for any production α → β, both | β |> = | α |, excluding only S → ε
  forms described production: α1Aα2 → α1βα2
  (wherein, α1, α2, β∈ (VN∪VT ) *, β ≠ ε, A∈VN)
  namely: a only α1α2 appears in the context, allowed replaced by β.
  Language production called "context-sensitive language" but S does not appear in the right part of the production.

Type 2 grammar: for any production α → β, there α∈VN, β∈ (VN∪VT) *
  in the form of production is described: A → β (A∈VN)
  i.e. substituted beta] A, and the A nothing to do at the context.
  Language production called "context-free languages"

 

2. Try to write grammar PL / 0 language. (Or do you think the better language rules)

Integer: n → 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

Identifier: i → <letters> <letters> | <number>

Expression: e → [+ | -] <item> {<subtraction operator> <term>}

Conditional statements: <conditional statement> → if <condition> the then <statement execution>

Assignment: <assignment statement> → <identifier>: = <expression>

Compound statement: <compound statement> → begin <statement> {; <statement>} end

Function: <function> → <main function> <Other functions> | <main function>

Program: will not do (No results)

Guess you like

Origin www.cnblogs.com/WEJACKSI/p/11599803.html