【问题标题】:Pushdown automata to accept the following language下推自动机接受以下语言
【发布时间】:2020-08-06 20:32:21
【问题描述】:

我需要为以下语言构建一个下推自动化:L = {a^n b^m | 2n>=m } 有人可以帮我吗?

【问题讨论】:

  • 到目前为止,您尝试了哪些方法,您的实施在哪里卡住了?如果您不确定从哪里开始,请考虑语言L = { a^n b^m | n = m },然后考虑L = { a^n b^m | n >= m }。如何将接受第一个的 PDA 修改为接受第二个的 PDA?那么,将约束更改为2n >= m 怎么样?如果这没有帮助,请更具体地说明您需要帮助的内容。

标签: formal-languages pushdown-automaton


【解决方案1】:

想到了两种方法:

  1. 尝试以合理的方式使用堆栈从头开始编写 PDA
  2. 编写一个 CFG,然后依靠显示 PDA 接受所有 CFG 语言的结构

要采用方法 1,请认识到 PDA 就像 NFA 一样,可以将符号压入堆栈并将它们弹出。如果我们想要 2n >= m,这意味着我们希望 a 的数量至少是 b 的数量的一半。也就是说,我们希望每两个 b 至少有一个 a。这意味着如果我们将所有 a 压入堆栈,我们需要为堆栈上的每个 a 读取不超过两个 b。这表明 PDA 的工作方式如下:

1. read all the a's, pushing into the stack
2. read b's, popping an a for every two b's you see
3. if you run out of stack but still have b's to process, reject
4. if you run out of input at the same time or sooner than you run out of stack, accept

在状态和转换方面:

Q    S    E    Q'    S'

q0   Z    a    q0    aZ   // these transitions read all the a's and 
q0   a    a    q0    aa   // push them onto the stack

q0   a    b    q1    a    // these transitions read all the b's and
q1   a    b    q2    -    // pop a's off the stack for every complete
q2   a    b    q1    a    // pair of b's we see. if we run out of a's
                          // it will crash and reject

q0   Z    -    q3    Z    // these transitions just let us guess at any
q0   a    -    q3    a    // point that we have read all the input and
q1   Z    -    q3    Z    // go to the accepting state. note that if
q1   a    -    q3    a    // we guessed wrong the PDA will crash there
q2   Z    -    q3    Z    // since we have no transitions defined.
q2   a    -    q3    a    // crashing rejects the input.

这里,接受条件处于状态 q3,没有更多堆栈。

要执行第二个选项,您可以这样编写 CFG:

S -> aSbb | aS | e

那么您的 PDA 可以执行以下操作:

push S onto the stack
pop from the stack and push onto the stack one of the productions for S
if you pop a terminal off the stack, consume the nonterminal from input
if you pop a nonterminal off the stack, replace it with some production for that nonterminal

这种不确定性会根据 CFG 生成所有可能的推导。如果输入是语言中的字符串,那么这些派生之一将消耗所有输入并将堆栈留空,这就是停止/接受条件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 2015-01-20
    • 1970-01-01
    • 2019-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多