COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University pursuant to Part VB of the Copyright Act 1968 (the Act). The material in this communication may be subject to copyright under the Act. Any further reproduction or communication of this material by you may be the subject of copyright protection under the Act. Do not remove this notice.
Pushdown Automata and Chomsky Normal Form CSE2303 Formal Methods I Lecture 13
Overview Pushdown Automaton Constructing PDA to accept a Regular Grammar Chomsky Normal Form Constructing PDA to accept a Context Free Grammar Pumping Lemma for CFG Non-Context Free Languages
Pushdown Automaton A NFA with Stack. Can be used to represent Context Free Languages. The parsers generated by bison are implemented by a Pushdown Automaton.
Example START READ PUSH X READPOP ACCEPT a b b X
A Pushdown Automaton is a collection of: An alphabet of possible input letters An alphabet of possible stack letters An INPUT TAPE and a STACK A finite set of states –One called the Start State (have only out edges) –Accept States and Reject States (have only in edges) –Read States - which read the next letter from the INPUT TAPE. –Push States - which put a letter on top of the STACK. –Pop States - which take a letter off the top of the STACK. A set of transitions between states
INPUT TAPE Where the input lives ... Finite String (input) All Blanks iiiiiiiv
States START STATE –Like the START STATE in a NFA –Not allowed to have any incoming edges. ACCEPT STATE –Like a FINAL STATE in a NFA –Not allowed any outgoing edges. REJECT STATE –Not allowed any outgoing edges. READ STATE –Read the next input letter from the INPUT TAPE.
State Representations START STATE ACCEPT STATE REJECT STATE READ STATE START ACCEPT REJECT READ a b b Note: PDA are NONDETERMINISTIC
STACK Store for letters –Serves as a memory Two Operations Push –Puts a letter at the top of the stack Pop –Takes a letter off the top of the stack.
START READ PUSH X READPOP ACCEPT a b b X
Definitions A string is accepted by a PDA –If there exists at least one path through the PDA for this string that ends in a Accept State A string is rejected by a PDA –If for all paths through the PDA for this string the PDA either crashes or ends in a Reject State The set of strings accepted by the PDA is called the language accepted by the PDA.
S aS | bY | bX X bY | Y aY | START READ PUSH S READ POP ACCEPT b Y X a READ PUSH SPUSH YPUSH X PUSH Y S a b b Regular Language PDA
Chomsky Normal Form A CFG is said to be in Chomsky Normal Form if all the productions are in the form Nonterminal Nonterminal Nonterminal or Nonterminal terminal For any context-free language L, the non-empty words in L can be generated by a grammar in Chomsky Normal Form.
Consider the CFG S bA | aB A a | aS | bAA B b | bS | aBB Can be written in Chomsky Normal Form as: S YA | XB A a | XS | YR 1 B b | YS | XR 2 X a Y b R 1 AA R 2 BB
Consequences CFG PDA –Every context free language can be defined by a PDA. Pumping Lemma for CFG –Is used to show there exists non-context free languages.
CFG PDA S AB A a | BB B a | b | AB START PUSH S PUSH APUSH BPUSH A PUSH B ACCEPT POP READ S A B A B B aab
CFG = PDA Given a CFG that generates a language, there is a PDA which accepts this language. Given a PDA that accepts a language, there exists a CFG that generates this language.
Terminology Live Production Nonterminal Nonterminal Nonterminal Dead Production Nonterminal terminal
Pumping Lemma Let G be any CFG in CNF with p live productions and w is any word generated by G with length greater than 2 p. Then there exists strings u, v, x , y, and z Such that –w = uvxyz –y and v are not both , and –uv 2 xy 2 z, …, uv n xy n z are generated by G.
Proof S P P uvxyz w
L = {a n b n a n } Assume L is a context free language. Then there exists a CFG which generates L. Convert this CFG to CNF. Suppose it has p live productions. Take N > 2 p /3 Let w = a N b N a N. Then length(w) > 2 p
So, by the Pumping Lemma, there exists Strings u, v, x , y, and z Such that –w = uvxyz –v and y are not both , and –uv 2 xy 2 z, …, uv n xy n z are all in L. Case 1: ab is in v or y. Case 2: ba is in v or y. Case 3: v and y are all a’s or all b’s or one of them is . Consider: uv 2 xy 2 z. Contradiction Therefore L is a non-context free language.
Revision Pushdown Automaton –Definition and how they work. Chomsky Normal Form –Definition Pumping Lemma. –What it is used to show. CFG = PDA –Understand what this means. Know some examples of Non-Context free languages. Preparation Read –Chapter 19 in the Text Book