The fourth work - grammar and language summary and comb

  1. Carding second chapter, understand and write a summary.

 

Syntax: Syntax called a language refers to a set of rules, which may be formed by a well-formed and the generator. Some of these rules is called a lexical rules, the other part is called syntax rules (or rule generation).

Semantics: For a language is not only to give its lexical, grammatical rules, but also to define the meaning of its words and grammar symbol units. This is a semantic problem. Leave semantics, language is just a collection of a bunch of symbols.

Grammar G = (Vn, Vt, P, S), wherein the non-terminator Vn set; Vt of the terminator is set; P is the set of productions, comprising at least one non-terminal symbol; S or an identifier for the start symbol.

       Type 0 grammar (grammar phrases): a left portion and a right portion α 0 type beta] production are all grammar symbol string, without any limitation thereof. I.e., production of the left portion to the right of the at least one nonterminal freely. If the production of the 0-type grammar for certain limits, can be given other three types of grammar.

  Type 1 grammars (context-sensitive grammar): Type 1 All grammar productions left portion may contain one, two or more characters, but must have at least one non-terminal symbol. The length of the symbol string production must be greater than the right portion of the left side of the symbol string length. For production "S → ε" is a special case of the type 1 grammar. 

  Type 2 grammar (context-free grammar | left linear grammar): the left part of all production to a single type 2 grammar nonterminals, a right portion by a terminator sequence and nonterminal symbols thereof.

  Type 3 grammar (grammar of Linear | regular grammar): type 3 grammar all right portion is the production of a single or unitary terminator terminator followed by a single non-terminal symbol. Right production unit symbol sequence length is less than or equal to 2.

 

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

Integer n n-> 0 | 1 | 2 | 3 | ...... | 8 | 9

Identifier i i-> a | b | c | ...... | y | z | A | B | C | ...... | Y | Z (<letter> {<letters> | <number>})

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

Conditional statement :: = if <condition> then <statement>

Assignment :: = <id>: = <expression>

Compound statement :: = begin <statement> {; <statement>} end

= Function :: = <main function>

Program :: = <Block> :: = [<Constant Description section>] [<Variable Description section>] [<Process Description section>] <statement>

Guess you like

Origin www.cnblogs.com/Fishmark/p/11595280.html