46 Slides--More on Context-Free Languages

46 Slides--More on Context-Free Languages - CS103 HO#46...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS103 HO#46 Slides--More on Context-Free Languages May 12, 2010 1 Context-Free Languages There may be more than one way to derive a given string. Consider: S aS | Sa | a Here are four parse trees for "aaa" S S S S S S S S S S S S a a a a a a a a a a a a This grammar is ambiguous , since it has at least one string with more than one parse tree. Why Ambiguity Matters E E + E | E * E | (E) | int 2 + 3 * 4 2 + 3 * 4 E E E E E E E E E E An Unambiguous Grammar E E + T E T T T * F T F F ( E ) F int 2 + 3 * 4 2 + 3 * 4 T E E T F E E T T F T F F F T F E An inherently ambiguous language L = {a i b j c k | i = j or j = k} S S 1 | S 2 S 1 S 1 c | A A aAb | S 2 aS 2 | B B bBc | A string like a n b n c n has one derivation through A and one through B. It can be shown that for any grammar that generates L, there is a least one string in L with two derivations. Closure Properties for Context-Free Languages Context-free languages are closed under • Union • Concatenation • Star • Reverse but not under • Intersection • Complement • Difference Examples Context-Free {a n b n | n 0} {a n b 2n | n 0} {ww R | w {a, b}*} {w {a, b}* | number of a's = number of b's} Not Context-Free {a n b n c n | n 0} {ww | w {a, b}*} {wcw | w {a, b}*}
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS103 HO#46 Slides--More on Context-Free Languages May 12, 2010 2 Pushdown Automaton state control abbabbbaa... x y a z b . . . $ input stack The machine has a pushdown stack of unlimited capacity. It can push symbols onto the stack or pop them off and read them. The stack is initially empty. The machine cannot explicitly test for an empty stack, so we often push a special symbol on first. A pushdown automaton is a 6-tuple (Q, , , , q 0 , F) where 1. Q is a finite set of states, 2. is the finite input alphabet, 3. is the finite stack alphabet, 4. : Q     P (Q   ) is the transition function, 5. q 0 Q is the start state, and 6. F Q is the set of accept states. Transitions depend on the current state, the input symbol, and the top symbol on the stack. Thus the domain of is Q     . When a transition occurs, the machine may enter a new state and write a new symbol on the top of the stack. Since the machine is nondeterministic, the range of the transition function is P (Q   ) . a , b c We label transitions like this: which means: read a , pop b , push c state control a ademrjk b f g h q j q k If the machine is in state q j , reading a , with b on top of the stack We label transitions like this: which means: read a , pop b , push c state control b f g h If the machine is in state q j , reading a , with b on top of the stack state control c f g h Then it pops the b , pushes c onto the top of the stack, and goes to state q k a , b c q j q k a
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern