46 Slides--More on Context-Free Languages

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

Info iconThis 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 SS 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 EE 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 ET 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 •S tar •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}*}
Background image of page 1

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

View Full DocumentRight 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 ademrjk a ademrjk a , b c
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/08/2011.

Page1 / 5

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online