4 grammar and language work summary and comb

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

(1) basic grammar concepts involved, and are not familiar with the concept of their own

L={A,B, … ,Z,a,b, … ,z}

D={0,1, … ,9}

LUD: full set of letters and numbers

LD: the set of all strings of symbols consisting of a letter followed by a number composed of

L4: All of the symbol string 4 letters in the set

The set of all symbol string of letters (including [epsilon]) of: L *

D +: the set of all strings of symbols by one or several digits

The set of all strings beginning with the letter symbol, followed by the letter, numbers of: L (LUD) *

 Grammar rules are described in the form of the grammatical structure of the language (ie syntax rules). Refers to how a bunch of symbols a meaningful sentence rules and agreements. And is a context-free grammar.

Grammar examples:

The above rules define the English sentence can be said to be a context-free grammar. Wherein <Sentence> is called the start symbol , <Subject> <predicate> <Pronoun> or the like is called nonterminal , He, gave the like is referred to as terminal symbols .

To sum up, a context-free grammar G consists of four parts: terminal symbols, nonterminal symbols start, production .

More precise definition:

(2) the parse tree and ambiguity

  •  Rightmost derivation, each derivation are starting to replace nonterminals rightmost
  •  Leftmost derivation, each derivation are starting to replace nonterminals leftmost

A grammar can uniquely identify a language, but a language is not necessarily unique to a grammar

Diagrammatically represented by a tree of the derivation of this sentence, the tree is called "parse tree", referred to as "syntax tree."

Column such as:

 For a grammar, if it's some of the sentences correspond to two different syntax tree, this grammar belongs to " ambiguous grammar ."

2. Try to write grammar PL / 0 language.

整数n    <数字> ::= 0 | 1 | 2 | … | 8 | 9

标识符i   <标识符>::=<字母>{<字母>|<数字>}

表达式e   <表达式>::=[+ | -] <项> { <加法运算符><项>}

条件语句   <条件语句>  ::= IF <条件> THEN <语句>

赋值语句   <赋值语句> -> <标识符> := <表达式>

复合语句   <复合语句> ::= BEGIN <语句> {;<语句>} END

函数  <函数定义> := <类型说明><函数名><复合语句>

程序   <程序> ::= <分程序>

...

 

Guess you like

Origin www.cnblogs.com/zhengjieting/p/11583681.html