LectureNotes13

LectureNotes13 - ECS 120 Lesson 13 Pushdown Automata, Pt. 2...

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

View Full Document Right Arrow Icon
ECS 120 Lesson 13 – Pushdown Automata, Pt. 2 Oliver Kreylos Friday, April 27th, 2001 In the last lecture, we introduced pushdown automata as an alternative means to specify context-free languages. We still have left to prove that they are actually capable of that; in other words, we have to show that the class of languages that can be accepted by pushdown automata is exactly the class of languages that can be generated by context-free grammars. As usual, we will prove this equivalence in two directions. The first direction is a constructive proof that describes how to build a PDA that accepts the language generated by a given grammar. This construction is important in practice, because it shows how to create a parser for a given grammar. The reverse direction, building a grammar from a given PDA, is of lesser practical value. 1 Converting a Context-Free Grammar into a PDA We have to show that every context-free language is accepted by some PDA. In other words, if L is a context-free language, i. e., there exists a context- free grammar G such that L = L ( G ), there must exist a PDA P such that L = L ( P ). The basic idea for the construction of P is to simulate the leftmost derivations in G , and to accept a word iff there exists a leftmost derivation that generates it. The PDA will use its stack to store and manipulate the intermediate strings in the derivation it simulates, and after all variables have been replaced by characters, the resulting string will be compared to the input string. The PDA will use its nondeterminism to “guess” which rule to apply to the leftmost variable in each step. If the input word can be generated 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
by the grammar, at least one of the resulting branches of computation will succeed in matching the word and the PDA will accept. When looking at leftmost derivations S s 1 ⇒ ··· ⇒ s n - 1 w in G , every intermediate string s i can be written as s i = xAα , where A V is the leftmost variable, x Σ * is a string of only characters, and α ( V Σ) * is a string of variables and characters. Since the PDA needs to access the leftmost variable A in any derivation step, it is not possible to store the entire string s i on the stack – a PDA can only access the topmost stack symbol. But we know that the symbols to the left of A (the word x ) will never change during further derivations, and in the end they have to match the beginning characters in the input string. Therefore, it is not necessary to store the character-only prefix of s i , but only all symbols from the first variable on. The suffix of an intermediate string including the leftmost variable, , is called a tail . Whenever during derivation the intermediate string has a prefix of only characters, that prefix is going to be matched against input characters immediately. Using this strategy, the leftmost variable of all intermediate strings is always the topmost stack symbol, and can be accessed by the PDA.
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.

Page1 / 8

LectureNotes13 - ECS 120 Lesson 13 Pushdown Automata, Pt. 2...

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