1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.

Slides:



Advertisements
Similar presentations
Simplifications of Context-Free Grammars
Advertisements

Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
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,
Fall 2004COMP 3351 Simplifications of Context-Free Grammars.
Prof. Busch - LSU1 Simplifications of Context-Free Grammars.
Pushdown Automata Part II: PDAs and CFG Chapter 12.
Introduction to Computability Theory
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.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
Courtesy Costas Buch - RPI1 Simplifications of Context-Free Grammars.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Costas Buch - RPI1 Simplifications of Context-Free Grammars.
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
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.
1 Simplifications of Context-Free Grammars. 2 A Substitution Rule substitute B equivalent grammar.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
1 Simplifications of Context-Free Grammars. 2 A Substitution Rule Substitute Equivalent grammar.
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:
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Pushdown Automata (PDAs)
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.
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.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
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.
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.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
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 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
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.
Formal Languages, Automata and Models of Computation
PDAs Accept Context-Free Languages
NPDAs Accept Context-Free Languages
Simplifications of Context-Free Grammars
Simplifications of Context-Free Grammars
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
Theory of Computation Lecture #27-28.
Chapter 7 PUSHDOWN AUTOMATA.
Pushdown Automata PDAs
NPDAs Accept Context-Free Languages
Principles of Computing – UFCFA3-30-1
Chapter 2 Context-Free Language - 01
… NPDAs continued.
Pushdown automata The Chinese University of Hong Kong Fall 2011
Normal Forms for Context-free Grammars
Context-Free Languages
Presentation transcript:

1 Normal Forms for Context-free Grammars

2 Chomsky Normal Form All productions have form: variable and terminal

3 Examples: Not Chomsky Normal Form Chomsky Normal Form

4 Convertion to Chomsky Normal Form Example: Not Chomsky Normal Form

5 Introduce variables for terminals:

6 Introduce intermediate variable:

7

8 Final grammar in Chomsky Normal Form: Initial grammar

9 From any context-free grammar not in Chomsky Normal Form we can obtain: An equivalent grammar in Chomsky Normal Form In general:

10 The Procedure First remove: Nullable variables Unit productions

11 For every symbol : In productions: replace with Add production New variable:

12 Replace any production with New intermediate variables:

13 Theorem: For any context-free grammar there is an equivalent grammar in Chomsky Normal Form

14 Observations Chomsky normal forms are good for parsing and proving theorems It is very easy to find the Chomsky normal form of any context-free grammar

15 Greinbach Normal Form All productions have form: symbolvariables

16 Examples: Greinbach Normal Form Not Greinbach Normal Form

17 Conversion to Greinbach Normal Form: Greinbach Normal Form

18 Theorem: For any context-free grammar there is an equivalent grammar in Greinbach Normal Form

19 Observations Greinbach normal forms are very good for parsing It is hard to find the Greinbach normal form of any context-free grammar

20 An Application of Chomsky Normal Forms

21 The CYK Membership Algorithm Input: Grammar in Chomsky Normal Form String Output: find if

22 The Algorithm Grammar : String : Input example:

23

24

25

26

27 Therefore: Time Complexity: The CYK algorithm can be easily converted to a parser Observation:

28 Pushdown Automata PDAs

29 Pushdown Automaton -- PDA Input String Stack States

30 Initial Stack Symbol Stack bottom special symbol

31 The States Input symbol Pop symbol Push symbol

32 top input stack Replace

33 Push top input stack

34 Pop top input stack

35 No Change top input stack

36 Non-Determinism These are allowed transitions in a Non-deterministic PDA (NPDA)

37 NPDA: Non-Deterministic PDA Example:

38 Execution Example: Input current state Time 0 Stack

39 Input Time 1 Stack

40 Input Stack Time 2

41 Input Stack Time 3

42 Input Stack Time 4

43 Input Stack Time 5

44 Input Stack Time 6

45 Input Stack Time 7

46 Input Time 8 accept Stack

47 A string is accepted if there is a computation such that: All the input is consumed The last state is a final state At the end of the computation, we do not care about the stack contents

48 The input string is accepted by the NPDA:

49 is the language accepted by the NPDA: In general,

50 Another NPDA example NPDA

51 Execution Example: Input Time 0 Stack

52 Input Time 1 Stack

53 Input Time 2 Stack

54 Input Time 3 Stack Guess the middle of string

55 Input Time 4 Stack

56 Input Time 5 Stack

57 Input Time 6 Stack accept

58 Rejection Example: Input Time 0 Stack

59 Input Time 1 Stack

60 Input Time 2 Stack

61 Input Time 3 Stack Guess the middle of string

62 Input Time 4 Stack

63 Input Time 5 Stack There is no possible transition. Input is not consumed

64 Another computation on same string: Input Time 0 Stack

65 Input Time 1 Stack

66 Input Time 2 Stack

67 Input Time 3 Stack

68 Input Time 4 Stack

69 Input Time 5 Stack No final state is reached

70 There is no computation that accepts string