Question

In: Computer Science

Give a CFG and (natural) PDA for the language { ai bj ck ef: i +...

Give a CFG and (natural) PDA for the language { ai bj ck ef: i + j = k + f, i, j, k, f ≥ 0 }

Solutions

Expert Solution

CFG (context-free grammar) for the language  { a^ i b^ j c ^k | i, j, k ≥ 0 and i + j = k } is :

G = (V, Σ, R, S)

set of variables V = {S, X}, where S is the start variable;

set of terminals Σ = {a, b, c};

rules S → aSc | X X → bXc | ε

PDA (Pushdown Automata) for the language { a^ i b^ j c ^k | i, j, k ≥ 0 and i + j = k }:

For every a and b read in the first part of the string, the PDA pushes an x onto the stack. Then it must read c for each x out of the stack.

We show the PDA as a 6-tuple (Q, Σ, Γ, δ, q1, F), where

Q = {q1, q2, . . . , q5}

Σ = {a, b, c}

Γ = {x, $} (use $ to bottom of stack)

Transition function δ : Q × Σε × Γε → P(Q × Γε) is as follows:

Input

a

b

c

ε

Stack

X            $           ε

X            $           ε

X            $           ε

X            $           ε

q1

                  

                   {(q2, $)}

q2

                   {(q2, x)}

                   {(q3, ε )}

q3

                   {(q3, x)}

                   {(q4, ε )}

q4

{(q4, ε )}

q8

          {(q5, ε )}

Blank entries are ∅.

q1 is the start state

F = {q5}

Similarly, write for the given language with small changes as follows:


Related Solutions

Prove by construction that the language An = { ai | i is a multiple of...
Prove by construction that the language An = { ai | i is a multiple of n } is regular. In other words the language An contains all strings composed of the letter a some multiple of n times
give a PDA for the language {a1a2: where the length of a1 equals the length of...
give a PDA for the language {a1a2: where the length of a1 equals the length of a2, a1 contains an odd amount of 0’s and a2 contains an odd amount of 0′s} a1, a2 ∈ {0, 1}*
Java language please Problem There are N houses for sale. The i-th house costs Ai dollars...
Java language please Problem There are N houses for sale. The i-th house costs Ai dollars to buy. You have a budget of B dollars to spend. What is the maximum number of houses you can buy? Input The first line of the input gives the number of test cases, T. T test cases follow. Each test case begins with a single line containing the two integers N and B. The second line contains N integers. The i-th integer is...
This assignment will give you practice in Handling Exceptions and using File I/O. Language for this...
This assignment will give you practice in Handling Exceptions and using File I/O. Language for this program is JAVA Part One A hotel salesperson enters sales in a text file. Each line contains the following, separated by semicolons: The name of the client, the service sold (such as Dinner, Conference, Lodging, and so on), the amount of the sale, and the date of that event. Prompt the user for data to write the file. Part Two Write a program that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT