330 likes | 457 Views
Erik Jonsson School of Engineering and Computer Science. CS 5349 – 001 CS 4384 – 0 01. Automata Theory. http://www.utdallas.edu/~pervin. Tue sday : Sections 3.1-3.3. Thurs day 10-09-14. FEARLESS Engineering. Context-free Languages. Chapter Three.
E N D
Erik Jonsson School of Engineering and Computer Science CS 5349 – 001 CS 4384– 001 Automata Theory http://www.utdallas.edu/~pervin Tuesday: Sections 3.1-3.3 Thursday10-09-14 FEARLESS Engineering
Context-free Languages Chapter Three
G = ({S}, {0,1}, {S → 0S1 | ε }, S) • ε in L(G) because S ε . • 01 in L(G) because S 0S1 01. • 0011 in L(G) because S 0S1 00S11 0011. • 0 1 in L(G) because S * 0 1 . • L(G) = {0 1 | n > 0} n n n n n n Example
For every regular language L, there exists a CFG G such that L=L(G). Theorem
G = (V, ∑, R, E) V = {E, T, F} ∑= {x, 1, 2, +, *, (, )} R = { E -> E + T | T; T -> T * F | F; F -> (E) | x1 | x2 } Expressions, Terms, Factors Parsing Expressions
For every regular language L, there exists a CFG G such that L=L(G). Proof. Let L=L(M) for a DFA M=(Q, Σ, δ, s, F). Construct a CFG G=(V, Σ, R, S) as follows. V = Q, Σ = Σ, R = { q → ap | δ(q, a) = p } U { f → ε | f in F}, S = q0. Theorem x1 xn S x1q1 x1x2q2 ··· x1…xnf x1…xn f=qn s q1
Note that (ab)* instead does not work since that allows any number of a’s without any b’s.