1 / 5

1   文法 G : E→E+T|T T→T×F|F F→(E ) |i 句子 i+i×i 的推导过程如下: 最左推导:

1   文法 G : E→E+T|T T→T×F|F F→(E ) |i 句子 i+i×i 的推导过程如下: 最左推导: E => E +T => T +T=> F +T=> i + T =>i+ T ×F =>i+ F ×F =>i+ i × F =>i+i× i 最右推导: E => E+ T =>E+ T× F =>E+ T × i =>E+ F ×i=> E + i ×i => T +i×i=> F +i×i=> i +i×i. 例 构造一个文法 G3 使 L(G3)={a n b n |n≥1} 解 ; S→aSb|ab

nonnie
Download Presentation

1   文法 G : E→E+T|T T→T×F|F F→(E ) |i 句子 i+i×i 的推导过程如下: 最左推导:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 1   文法G:E→E+T|T T→T×F|F F→(E)|i 句子i+i×i的推导过程如下: 最左推导: E=>E+T=>T+T=>F+T=>i+T=>i+T×F=>i+F×F =>i+i×F=>i+i×i 最右推导: E=>E+T=>E+T×F=>E+T×i=>E+F×i=>E+i×i => T+i×i=>F+i×i=>i+i×i

  2. 例 构造一个文法G3使 L(G3)={anbn|n≥1} 解; S→aSb|ab 例 试构造生成语言L={anbnci|n1, i 0}的文法 解:G(Z): ZAB A aAb|ab B cB| • (1) { an bn am bm | n,m>=0 } S→AA A→aAb|ε 或者 S→AB A→aAb|ε B→aBb|ε • (2) {1n 0m 1m 0n | n,m>=0 } S→1S0|A A→0A1|ε

  3. 因为句型 QbRae 可由文法开始符S经过规范推导产生,推导过程如下: S => SaQ => SaR => Sae => Qae => QbRae 所以句型 QbRae 是规范句型。 • 2.给出句型 QbRae 的短语,直接短语和句柄: 短语:QbR e QbRae 直接短语:QbR e 句柄:QbR

  4. E E + T T F T × F i . 因为E=>* T+i 且 T=>T×F,所以T×F 是句型相对于T的短语,且是相对 于T→T×F的直接短语 . 因为E=>* T×F+F 且 F=>i,所以i是句 型相对于F的短语,且是相对于F→i 的直接短语 . 因为E=>* E 且E=>+ T×F+i,所以 T×F+i是句型相对于E的短语 . T×F是最左直接短语,即句柄 例:文法G[E]: E→E+T|T T→T×F|F F→(E)| i 的一个句型是 T×F+i,相应的语法树见右图:

  5. 文法G[S]: • (1)S→aSBE • (2)S→aBE • (3)EB→BE • (4)aB→ab • (5)bB→bb • (6)bE→be • (7)eE→ee Sa S BE (S→aSBE) a aBEBE (S→aBE) aabEBE (aB→ab ) aabBEE ( EB→BE ) aabbEE (bB→bb) aabbeE (bE→be) aabbee (eE→ee) Sa S BE aaSBEBE aaaBEBEBE L(G)={ anbnen | n≥1 }

More Related