Download presentation
Presentation is loading. Please wait.
Published byMarlene Small Modified over 9 years ago
1
cs466(Prasad)L8Norm1 Normal Forms Chomsky Normal Form Griebach Normal Form
2
cs466(Prasad)L8Norm2 Language preserving transformations Improve parsing efficiency Prove properties about languages and derivations Shorter derivations
3
cs466(Prasad)L8Norm3 Elimination of rules Reduces the length of the derivation
4
cs466(Prasad)L8Norm4 Aim: Restrict the grammar such that Approach: –Introduce S’
5
cs466(Prasad)L8Norm5 –Add rules to capture the effect of -rules to be deleted. – (Ensures non-contracting rules)
6
cs466(Prasad)L8Norm6 Example
7
cs466(Prasad)L8Norm7 Determination of nullable non-terminals Bottom-up flow of information
8
cs466(Prasad)L8Norm8 Algorithm Nullable Nonterminals NULL := {A | A -> P}; repeat PREV := NULL ; foreach A V do if there is an A-rule A -> w and w PREV* then NULL := NULL U {A} until NULL = PREV;
9
cs466(Prasad)L8Norm9 Proof of correctness Soundness –If A NULL (final) then A=>*. Induction on the number of iterations of the loop. Completeness –If A=>* then A NULL (final). Induction on the minimal derivation of the null string from a non-terminal. Termination Bounded by the number of non-terminals.
10
cs466(Prasad)L8Norm10 Elimination of Chain rules Removing renaming rules: redundant procedure calls. Top-down flow of information
11
cs466(Prasad)L8Norm11 Construction of Chain (A) Chain (A) := {A}; PREV := ; repeat NEW := Chain (A) - PREV; PREV := Chain (A); foreach B NEW do if there is a rule B -> C then Chain (A) := Chain (A) U {C} until Chain (A) = PREV;
12
cs466(Prasad)L8Norm12 Examples
13
cs466(Prasad)L8Norm13 Elimination of useless symbols usefulA variable is useful if it occurs in a derivation that begins with the start symbol and generates a terminal string. Reachable from S Derives terminal string
14
cs466(Prasad)L8Norm14 Construction of the set of variables that derive terminal string. –Bottom-up flow of information Similar to the computation of nullable variables. Construction of the set of variables that are reachable –Top-down flow of information Similar to the computation of chained variables.
15
cs466(Prasad)L8Norm15 Examples B does not derive terminal string; C unreachable. A unreachable. Empty set of productions “Non-termination”
16
cs466(Prasad)L8Norm16 A CFG is in Chomsky Normal Form if each rule is of the form: Theorem: There is an algorithm to construct a grammar G’ in CNF that is equivalent to a CFG G. Chomsky Normal Form
17
cs466(Prasad)L8Norm17 Construction Obtain an equivalent grammar that does not contain -rules, chain rules, and useless variables. Apply following conversion on rules of the form:
18
cs466(Prasad)L8Norm18 Significance of CNF Length of derivation of a string of length n in CNF = (2n-1) (Cf. Number of nodes of a strictly binary tree with n-leaves) Maximum depth of a parse tree = n Minimum depth of a parse tree =
19
cs466(Prasad)L8Norm19 Removal of direct left recursion Causes infinite loop in top-down (depth- first) parsers. Approach: Generate string from left to right.
20
cs466(Prasad)L8Norm20 Note that absence of direct left recursion does not imply absence of left recursion.
21
cs466(Prasad)L8Norm21 (Cf. Gaussian Elimination)
22
cs466(Prasad)L8Norm22 Griebach Normal Form (* Constructs terminal prefixes that facilitates discovery of dead-ends *) A CFG is in Griebach Normal Form if each rule is of the form Theorem: There is an algorithm to construct a grammar G’ in GNF that is equivalent to a CFG G.
23
cs466(Prasad)L8Norm23 Analogy: solving linear simultaneous equations What are the values of x,y, and z? (Solving for z and then back substituiting.)
24
cs466(Prasad)L8Norm24 Example: conversion to GNF Eliminating left recursion Introducing terminals as first element on RHS
25
cs466(Prasad)L8Norm25 The size of the equivalent GNF can be large compared to the original grammar. Example CFG has 5 rules, but the corresponding GNF has 24 rules!! Length of the derivation in GNF = Length of the string. GNF is useful in relating CFGs (“generators”) to pushdown automata (“recognizers”/”acceptors”).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.