Computational Linguistics II: Parsing Formal Languages: Context Free Languages III Frank Richter & Jan-Philipp S¨ ohn fr@sfs.uni-tuebingen.de, jp.soehn@uni-tuebingen.de November 13th, 2006 Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 1 / 15
The Big Picture Once Again: The Big Picture hierarchy grammar machine other type 3 reg. grammar DFA reg. expressions NFA det. cf. LR(k) grammar DPDA type 2 CFG PDA type 1 CSG LBA type 0 unrestricted Turing grammar machine DFA: Deterministic finite state automaton (D)PDA: (Deterministic) Pushdown automaton CFG: Context-free grammar CSG: Context-sensitive grammar LBA: Linear bounded automaton Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 2 / 15
A Format for Context-Free Languages Chomsky Normal Form The Chomsky Normal Form: CFGs in CNF Two types of rules allowed: A → BC A → a How to do a transformation: 1 Add new variable for each terminal symbol. 2 Recursively add one new variable for each pair of variables B j B k in A → B i B j B k ... Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 3 / 15
A Format for Context-Free Languages Chomsky Normal Form The Chomsky Normal Form: CFGs in CNF Transform the following Grammar into CNF: S → AB A → aAb A → ab B → cB B → c Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 4 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF I One type of rules allowed: A → aB 1 B 2 ...B k ( k ≥ 0) Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 5 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF I One type of rules allowed: A → aB 1 B 2 ...B k ( k ≥ 0) Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 6 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF II We transform the following grammar into GNF: S → AB A → BS | b B → SA | a Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 7 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF III Step 1: Rename it! A 1 → A 2 A 3 A 2 → A 3 A 1 | b A 3 → A 1 A 2 | a Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 8 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF IV Step 2: A i → A j α | i < j A 1 → A 2 A 3 A 2 → A 3 A 1 | b A 3 → A 1 A 2 | a A 3 → A 2 A 3 A 2 | a Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 9 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF IV Step 2: A i → A j α | i < j A 1 → A 2 A 3 A 2 → A 3 A 1 | b A 3 → A 1 A 2 | a A 3 → A 2 A 3 A 2 | a A 3 → A 3 A 1 A 3 A 2 | bA 3 A 2 | a Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 10 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF IV Step 2: A i → A j α | i < j A 1 → A 2 A 3 A 2 → A 3 A 1 | b A 3 → A 1 A 2 | a A 3 → A 2 A 3 A 2 | a A 3 → A 3 A 1 A 3 A 2 | bA 3 A 2 | a A 3 → bA 3 A 2 B 3 | aB 3 | bA 3 A 2 | a B 3 → A 1 A 3 A 2 | A 1 A 3 A 2 B 3 Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 11 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF V Step 3: Replace A i → A j α with A i → βα for each A j → β A 1 → A 2 A 3 A 2 → A 3 A 1 | b A 3 → bA 3 A 2 B 3 | aB 3 | bA 3 A 2 | a B 3 → A 1 A 3 A 2 | A 1 A 3 A 2 B 3 Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 12 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF V Step 3: Replace A i → A j α with A i → βα for each A j → β A 1 → A 2 A 3 A 2 → bA 3 A 2 B 3 A 1 | aB 3 A 1 | bA 3 A 2 A 1 | aA 1 | b A 3 → bA 3 A 2 B 3 | aB 3 | bA 3 A 2 | a B 3 → A 1 A 3 A 2 | A 1 A 3 A 2 B 3 Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 13 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF V Step 3: Replace A i → A j α with A i → βα for each A j → β A 1 → bA 3 A 2 B 3 A 1 A 3 | aB 3 A 1 A 3 | bA 3 A 2 A 1 A 3 | aA 1 A 3 | bA 3 A 2 → bA 3 A 2 B 3 A 1 | aB 3 A 1 | bA 3 A 2 A 1 | aA 1 | b A 3 → bA 3 A 2 B 3 | aB 3 | bA 3 A 2 | a B 3 → A 1 A 3 A 2 | A 1 A 3 A 2 B 3 Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 14 / 15
A Format for Context-Free Languages Greibach Normal Form The Greibach Normal Form: CFGs in GNF V Step 3: Replace A i → A j α with A i → βα for each A j → β A 1 → bA 3 A 2 B 3 A 1 A 3 | aB 3 A 1 A 3 | bA 3 A 2 A 1 A 3 | aA 1 A 3 | bA 3 A 2 → bA 3 A 2 B 3 A 1 | aB 3 A 1 | bA 3 A 2 A 1 | aA 1 | b A 3 → bA 3 A 2 B 3 | aB 3 | bA 3 A 2 | a B 3 → bA 3 A 2 B 3 A 1 A 3 A 3 A 2 | aB 3 A 1 A 3 A 3 A 2 | bA 3 A 2 A 1 A 3 A 3 A 2 | aA 1 A 3 A 3 A 2 | bA 3 A 3 A 2 | bA 3 A 2 B 3 A 1 A 3 A 3 A 2 B 3 | aB 3 A 1 A 3 A 3 A 2 B 3 | bA 3 A 2 A 1 A 3 A 3 A 2 B 3 | aA 1 A 3 A 3 A 2 B 3 | bA 3 A 3 A 2 B 3 Richter/S¨ ohn (WS 2006/07) Computational Linguistics II: Parsing November 13th, 2006 15 / 15
Recommend
More recommend