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
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: All the input is consumed The last state is a final state 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
55 Input Time 4 Stack
56 Input Time 5 Stack
57 Input Time 6 Stack accept