1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Pushdown Automata Part II: PDAs and CFG Chapter 12.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Pushdown Automata.
Chapter 7 PDA and CFLs.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2010.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
PushDown Automata. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
Formal Languages, Automata and Models of Computation
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
G. Pullaiah College of Engineering and Technology
PDAs Accept Context-Free Languages
CSE 105 theory of computation
NPDAs Accept Context-Free Languages
Pushdown Automata (PDA). Part 2
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
NPDAs Accept Context-Free Languages
فصل دوم Context-Free Languages
Chapter 2 Context-Free Language - 01
… NPDAs continued.
Pushdown automata The Chinese University of Hong Kong Fall 2011
Normal Forms for Context-free Grammars
Presentation transcript:

1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011

2 Content Context-Free Languages Push-Down Automata, PDA NPDA: Non-Deterministic PDA Formal Definitions for NPDAs NPDAs Accept Context-Free Languages Converting NPDA to Context-Free Grammar

3 Regular Languages Context-Free Languages Non-regular languages

4 Context-Free Languages

5 Pushdown Automata Context-Free Grammars stack automaton (CF grammars are defined as generalized Regular Grammars)

6 Definition: Context-Free Grammars Grammar Productions of the form: is string of variables and terminals VariablesTerminal symbols Start variables

7 Pushdown Automata PDAs

8 Pushdown Automaton - PDA Input String Stack States

9 The Stack The stack allows pushdown automata to recognize some non-regular languages. All access to the stack is only on the top! (Stack top is written leftmost in the string, e.g. yxz) A PDA can write symbols on stack and read them later on. A stack is valuable as it can hold an unlimited amount of information (but it is not random access!). POP reading symbol PUSH writing symbol

10 The States Input symbol Pop old - reading stack symbol Push new - writing stack symbol

11 top input stack Replace (An alternative is to either start and finish with empty stack or with a stack bottom symbol such as $)

12 input Push top stack

13 input Pop top stack

14 input No Change top stack

15 Input Stack Example 3.7 Salling: A PDA for simple nested parenthesis strings Time 0

16 Input Stack Example 3.7 Time 1

17 Input Stack Example 3.7 Time 2

18 Input Stack Example 3.7 Time 3

19 Input Stack Example 3.7 Time 4

20 Input Stack Example 3.7 Time 5

21 Input Stack Example 3.7 Time 6

22 Input Example 3.7 Time 7 Stack

23 NPDAs Non-deterministic Push-Down Automata

24 Non-Determinism

25 A string is accepted if: All the input is consumed The last state is a final state Stack is in the initial condition (either: empty (when we started with empty stack), or: bottom symbol reached, depending on convention)

26 is the language accepted by the NPDA: Example NPDA

27 NPDA M (Even-length palindromes) Example NPDA Example : aabaaabbb  bbbaaabaa

28 Pushing Strings Input symbol Pop symbol Push string

29 top input stack Push pushed string Example

30 Another NPDA example NPDA M

31 Time 0 Input Stack Current state Execution Example

32 Input Stack Time 1

33 Input Stack Time 2

34 Input Stack Time 3

35 Input Stack Time 4

36 Input Stack Time 5

37 Input Stack Time 6

38 Input Stack accept Time 7

39 Formal Definitions for NPDAs

40 Transition function

41 Transition function current state current input symbol current stack top new state new stack top An unspecified transition function is to the null set and represents a dead configuration for the NPDA.

42 Formal Definition Non-Deterministic Pushdown Automaton NPDA States Input alphabet Stack alphabet Transition function Final states Stack start symbol

43 Instantaneous Description Current state Remaining input Current stack contents

44 Input Stack Time 4: ExampleInstantaneous Description

45 Input Stack Time 5: ExampleInstantaneous Description

46 We write Time 4Time 5

47 A computation example

48 A computation example

49 A computation example

50 A computation example

51 A computation example

52 A computation example

53 A computation example

54 A computation example

55 For convenience we write A computation example

56 Formal Definition Language of NPDA M Initial state Final state

57 Example NPDA M

58 NPDA M

59 Therefore: NPDA M

60 NPDAs Accept Context-Free Languages

61 Context-Free Languages (Grammars) Languages Accepted by NPDAs Theorem

62 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 1: Convert any context-free grammar G to a NPDA M with L(G) = L(M)

63 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 2: Convert any NPDA M to a context-free grammar G with L(M) = L(G)

64 Converting Context-Free Grammars to NPDAs

65 An example grammar: What is the equivalent NPDA?

66 Grammar NPDA

67 The NPDA simulates the leftmost derivations of the grammar L(Grammar) = L(NPDA)

68 Grammar: A leftmost derivation:

69 NPDA execution: Input Stack Time 0 Start

70 Input Stack Time 1

71 Input Stack Time 2

72 Input Stack Time 3

73 Input Stack Time 4

74 Input Stack Time 5

75 Input Stack Time 6

76 Input Stack Time 7

77 Input Stack Time 8

78 Input Stack Time 9

79 Input Stack Time 10 accept

80 In general Given any grammar G we can construct a NPDA M with

81 For any productionFor any terminal Constructing NPDA M from grammar G Top-down parser

82 Grammar G generates string w if and only if NPDA M accepts w

83 For any context-free language there is an NPDA that accepts the same language

84 Which means Languages Accepted by NPDAs Context-Free Languages (Grammars)

85 Converting NPDAs to Context-Free Grammars

86 For any NPDA M we will construct a context-free grammar G with

87 in NPDA M Input processedStack contents terminals variables A derivation in Grammar The grammar simulates the machine

88 Some Simplifications First we modify the NPDA so that It has a single final state q f and It empties the stack when it accepts the input Original NPDAEmpty Stack

89 Second we modify the NPDA transitions. All transitions will have form: or which means that each move increases/decreases stack by a single symbol.

90 Those simplifications do not affect generality of our argument. It can be shown that for any NPDA there exists an equivalent one having the above two properties i.e. the equivalent NPDA with a single final state which empties its stack when it accepts the input, and which for each move increases/decreases stack by a single symbol.

91 The Grammar Construction In grammar G Terminals: Input symbols of NPDA states Stack symbol Variables:

92 For each transition: we add production:

93 For each transition: we add production: for all states q k, q l

94 Start Variable Stack bottom symbol Start state (Single) Final state

95 From NPDA to CFG, in short When we write a grammar, we can use any variable names we choose. As in programming languages, we like to use "meaningful" variable names. When we translate an NPDA into a CFG, we will use variable names that encode information about both the state of the NPDA and the stack contents. Variable names will have the form [qiAqj], where qi and qj are states and A is a variable. The "meaning" of the variable [qiAqj] is that the NPDA can go from state qi with Ax on the stack to state qj with x on the stack. Each transition of the form (qi, a, A) = (qj, ) results in a single grammar rule.

96 From NPDA to CFG Each transition of the form (qi, a, A) = (qj, BC) results in a multitude of grammar rules, one for each pair of states qx and qy in the NPDA. This algorithm results in a lot of useless (unreachable) productions, but the useful productions define the context-free grammar recognized by the NPDA using JFLAP

97 For any NPDA there is an context-free grammar that generates the same language

98 Context-Free Languages (Grammars) Languages Accepted by NPDAs We have the procedure to convert any NPDA M to a context-free grammar G with L(M) = L(G) which means

99 Context-Free Languages (Grammars) Languages Accepted by NPDAs Therefore END OF PROOF

100 An example of a NPDA in an appropriate form

101 Example Grammar production:

102 Grammar productions:

103 Grammar production:

104 Resulting Grammar

105 Resulting Grammar, cont.

106 Resulting Grammar, cont.

107 Derivation of string

108 In general, in grammar: if and only if is accepted by the NPDA

109 Explanation By construction of Grammar: if and only if in the NPDA going from q i to q j the stack doesn’t change below and A is removed from stack

110 Example (Sudkamp 8.1.2) Language consisting solely of a’s or an equal number of a´s and b´s.

111 JFLAP demo Concerning examination in the course: Exercises are voluntary Labs are voluntary Midterms are voluntary Lectures are voluntary… All of them are recommended!