Download presentation

Presentation is loading. Please wait.

Published byAileen Higgins Modified over 2 years ago

1
Prof. Busch - LSU1 Simplifications of Context-Free Grammars

2
Prof. Busch - LSU2 A Substitution Rule Substitute Equivalent grammar

3
Prof. Busch - LSU3 Equivalent grammar Substitute

4
Prof. Busch - LSU4 In general: Substitute equivalent grammar

5
Prof. Busch - LSU5 Nullable Variables Nullable Variable: Example: Nullable variable

6
Prof. Busch - LSU6 Substitute Removing After we remove all the all the nullable variables disappear (except for the start variable)

7
Prof. Busch - LSU7 Unit-Productions Unit Production: (a single variable in both sides) Example: Unit Productions

8
Prof. Busch - LSU8 Substitute Removal of unit productions:

9
Prof. Busch - LSU9 Remove can be removed immediately Unit productions of form

10
Prof. Busch - LSU10 Substitute

11
Prof. Busch - LSU11 Remove repeated productions Final grammar

12
Prof. Busch - LSU12 Useless Productions Some derivations never terminate... Useless Production

13
Prof. Busch - LSU13 Another grammar: Not reachable from S Useless Production

14
Prof. Busch - LSU14 In general: If there is a derivation Then variable is useful Otherwise, variable is useless consists of terminals

15
Prof. Busch - LSU15 A production is useless if any of its variables is useless Productions useless Variables useless

16
Prof. Busch - LSU16 Example Grammar: Removing Useless Variables and Productions

17
Prof. Busch - LSU17 First: find all variables that can produce strings with only terminals or Round 1: Round 2: (possible useful variables) (the right hand side of production that has only terminals) (the right hand side of a production has terminals and variables of previous round) This process can be generalized

18
Prof. Busch - LSU18 Then, remove productions that use variables other than

19
Prof. Busch - LSU19 Second: Find all variables reachable from Use a Dependency Graph where nodes are variables unreachable

20
Prof. Busch - LSU20 Keep only the variables reachable from S Final Grammar Contains only useful variables

21
Prof. Busch - LSU21 Removing All Step 1: Remove Nullable Variables Step 2: Remove Unit-Productions Step 3: Remove Useless Variables This sequence guarantees that unwanted variables and productions are removed

22
Prof. Busch - LSU22 Normal Forms for Context-free Grammars

23
Prof. Busch - LSU23 Chomsky Normal Form Each production has form: variable or terminal

24
Prof. Busch - LSU24 Examples: Not Chomsky Normal Form Chomsky Normal Form

25
Prof. Busch - LSU25 Conversion to Chomsky Normal Form Example: Not Chomsky Normal Form We will convert it to Chomsky Normal Form

26
Prof. Busch - LSU26 Introduce new variables for the terminals:

27
Prof. Busch - LSU27 Introduce new intermediate variable to break first production:

28
Prof. Busch - LSU28 Introduce intermediate variable:

29
Prof. Busch - LSU29 Final grammar in Chomsky Normal Form: Initial grammar

30
Prof. Busch - LSU30 From any context-free grammar (which doesn’t produce ) not in Chomsky Normal Form we can obtain: an equivalent grammar in Chomsky Normal Form In general:

31
Prof. Busch - LSU31 The Procedure First remove: Nullable variables Unit productions (Useless variables optional)

32
Prof. Busch - LSU32 Then, for every symbol : In productions with length at least 2 replace with Add production New variable: Productions of form do not need to change!

33
Prof. Busch - LSU33 Replace any production with New intermediate variables:

34
Prof. Busch - LSU34 Observations Chomsky normal forms are good for parsing and proving theorems It is easy to find the Chomsky normal form for any context-free grammar (which doesn’t generate )

35
Prof. Busch - LSU35 Greinbach Normal Form All productions have form: symbolvariables

36
Prof. Busch - LSU36 Examples: Greinbach Normal Form Not Greinbach Normal Form

37
Prof. Busch - LSU37 Conversion to Greinbach Normal Form: Greinbach Normal Form

38
Prof. Busch - LSU38 Observations Greinbach normal forms are very good for parsing strings (better than Chomsky Normal Forms) However, it is difficult to find the Greinbach normal of a grammar

Similar presentations

OK

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

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

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on viruses and bacteria pictures Ppt on duty roster sample Ppt on kinetic theory of matter/gas laws Ppt on conceptual art galleries Ppt on waves tides and ocean currents of the world Ppt on applied operational research definition Ppt on mumbai as financial capital of india Ppt on power sharing in belgium and sri lanka Ppt on van de graaff generator definition Show ppt on french revolution