1 / 10

Context-Free Languages: Design, Proof , Structure

MA/CSSE 474 Theory of Computation. Context-Free Languages: Design, Proof , Structure. Your Questions?. Previous class days' material Reading Assignments. HW 9 problems Exam 2 Anything else. Designing Context-Free Grammars. ● Generate related regions together. A n B n

keiran
Download Presentation

Context-Free Languages: Design, Proof , Structure

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. MA/CSSE 474 Theory of Computation Context-Free Languages:Design, Proof, Structure

  2. Your Questions? • Previous class days' material • Reading Assignments • HW 9 problems • Exam 2 • Anything else

  3. Designing Context-Free Grammars ● Generate related regions together. AnBn ● Generate concatenated regions: ABC ●Generate outside in: A aAb

  4. Concatenating Independent Languages Let L = {anbncm : n, m 0}. The cm portion of any string in L is completely independent of the anbn portion, so we should generate the two portions separately and concatenate them together. G = ({S, N, C, a, b, c}, {a, b, c}, R, S} where: R = { }.

  5. L = { : k 0 and i≤k (ni 0)} Examples of strings in L: , abab, aabbaaabbbabab Note that L = {anbn : n 0}*. G = ({S, M, a, b}, {a, b}, R, S} where: R = { }

  6. Another Example: Unequal a’s and b’s L = {anbm: nm} G = (V, , R, S), where V = {a, b, S, },  = {a, b}, R =

  7. Simplifying Context-Free Grammars Remove non-productive and unreachable non-terminals.

  8. Remove Unproductive Nonterminals removeunproductive(G: CFG) = • G = G. • Mark every nonterminal symbol in G as unproductive. • Mark every terminal symbol in G as productive. • Until one entire pass has been made without any new nonterminal symbol being marked do: For each rule X  in R do: If every symbol in  has been marked as productive and X has not yet been marked as productive then: Mark X as productive. • Remove from G every unproductive symbol. • Remove from G every rule that contains an unproductive symbol. • Return G.

  9. Remove Unreachable Nonterminals removeunreachable(G: CFG) = • G = G. • Mark S as reachable. • Mark every other nonterminal symbol as unreachable. • Until one entire pass has been made without any new symbol being marked do: For each rule X A (where A V - ) in R do: If X has been marked as reachable and A has not then: Mark A as reachable. • Remove from G every unreachable symbol. • Remove from G every rule with an unreachable symbol on the left-hand side. • Return G.

  10. Proving the Correctness of a Grammar L: AnBn= {anbn : n 0} G = ({S, a, b}, {a, b}, R, S), R = { S aSb S  } ● Prove that G generates only strings in L. ● Prove that G generates all the strings in L.

More Related