簡體   English   中英

CFG到PDA(無上下文語法下推自動機)

[英]CFG to PDA (Context free grammar to Push Down Automata)

如何將下一個CFG轉換為PDA?

S-> abScB | e

B-> bB | b

首先,我將看一下CFG生成的語言。 實際上,這是一種非常復雜的語言。 僅擴展S,它將是abc(b(b*)) 對於兩個,您將得到ab[abc(b(b*))]c(b(b*)) ,三個將是ab[ab[abc(b(b*))]c(b(b*))]c(b(b*))等。 我已經在S過渡中添加了方括號。 這種語言似乎是{(ab)^n (c(b(b^x_i)))^m} ,其中x_i是大於或等於0的整數,並且每個x_1, x_2, ... , x_i可以是不同。 nm都是大於或等於0的整數。

要轉換為PDA,我們可以從簡單的零件開始。 您的字母是{a,b,c},“ ab”部分需要一個狀態,“ c(b(b ^ b_x_i)”部分則需要一個狀態。讓我們將第一個狀態稱為p ,將第二個狀態稱為q 。您的堆棧字母為{bottom,A,C}。底部只是表示我們已經到達堆棧底部的符號,現在最困難的部分是增量,假設被空堆棧接受:

(p,e,bottom),(p,e) - this is for "m" = 0, accepting the empty string "e" or the case (ab)^n (this is an accepting state)
(p,a,bottom),(p, A bottom) - if we read an "a" and the stack is empty, push an A to the stack
(p,b,A),(p,e) - if we get a "b" and there was already an A on the stack, remove it
(p,c,bottom),(q,C bottom) - if we get a "c" and the stack was empty (i.e. we've finished the (ab)^n section), go to state q and push a C onto the stack
(q,b,C),(q,e) - if we get a "b" after a c, remove the C from the stack
(q,b,bottom),(q,bottom) - if we get a "b" in the b^x_i section, pop then immediately push bottom onto the stack
(q,c,bottom),(q,C bottom) - if we get a "c" after the b^x_i section, push a C onto the stack
(q,e,bottom),(q,e) - if we finish our string and our stack is empty (as it should be), then this is an accepting state

上面的讀取空字符串並生成空堆棧的轉換是接受狀態。 不包括所有不允許的轉換(例如,當堆棧中已經有C時獲得“ c”)。

希望有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM