30 likes | 139 Views
Example:. Given the following CFG S X | Y X aXb | aX | a Y aYb | Yb | b (1) L(G) = ? (2) Design an equivalent PDA for it. Σ ={a, b}. Solution: L(S). S X | Y X a X b | a X | a Y a Y b | Y b | b.
E N D
Example: • Given the following CFG S X | Y X aXb | aX | a Y aYb | Yb | b • (1) L(G) = ? • (2) Design an equivalent PDA for it. Σ={a, b}
Solution: L(S) S X |Y X aXb | aX | a Y aYb | Yb | b Try to write some strings generated by it: SXaXbaaXbbaaaXbbaaaabb SYaYbaYbbaaYbbbaabbbb more a’s than b’s more b’s than a’s • Observations: • Start from S, we can enter two States X & Y, and X, Y are “independent”; • In X state, always more a are generated; • In Y state, always more b are generated. Ls = Lx U Ly L(S) = { aibj; i≠j } Lx = { aibj; i>j } Lx = { aibj; i<j }
a,e/A b,A/e b,$/$ a,e/A b,A/e e,A/e e,$/e e,$/e e,e/e e,e/$ e,e/$ e,e/e e,A/e b,$/$ q0 q’0 q1 q’1 q2 q’2 q3 q’3 Solution: PDA L(S) = { aibj; i≠j } S X | Y X aXb | aX | a Y aYb | Yb | b = { aibj; i>j } U { aibj; i<j } PDA = NFA + a stack (infinite memory) A possible way: “divide and conquer” Lx = { aibj; i>j } LY = { aibj; i<j } e, e /e Combine both …