Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2003Costas Busch - RPI1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:

Similar presentations


Presentation on theme: "Fall 2003Costas Busch - RPI1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:"— Presentation transcript:

1 Fall 2003Costas Busch - RPI1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:

2 Fall 2003Costas Busch - RPI2 A Non-Linear Grammar Grammar : Number of in string

3 Fall 2003Costas Busch - RPI3 Another Linear Grammar Grammar :

4 Fall 2003Costas Busch - RPI4 Right-Linear Grammars All productions have form: Example: or string of terminals

5 Fall 2003Costas Busch - RPI5 Left-Linear Grammars All productions have form: Example: or string of terminals

6 Fall 2003Costas Busch - RPI6 Regular Grammars

7 Fall 2003Costas Busch - RPI7 Regular Grammars A regular grammar is any right-linear or left-linear grammar Examples:

8 Fall 2003Costas Busch - RPI8 Observation Regular grammars generate regular languages Examples:

9 Fall 2003Costas Busch - RPI9 Regular Grammars Generate Regular Languages

10 Fall 2003Costas Busch - RPI10 Theorem Languages Generated by Regular Grammars Regular Languages

11 Fall 2003Costas Busch - RPI11 Theorem - Part 1 Languages Generated by Regular Grammars Regular Languages Any regular grammar generates a regular language

12 Fall 2003Costas Busch - RPI12 Theorem - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by a regular grammar

13 Fall 2003Costas Busch - RPI13 Proof – Part 1 Languages Generated by Regular Grammars Regular Languages The language generated by any regular grammar is regular

14 Fall 2003Costas Busch - RPI14 The case of Right-Linear Grammars Let be a right-linear grammar We will prove: is regular Proof idea: We will construct NFA with

15 Fall 2003Costas Busch - RPI15 Grammar is right-linear Example:

16 Fall 2003Costas Busch - RPI16 Construct NFA such that every state is a grammar variable: special final state

17 Fall 2003Costas Busch - RPI17 Add edges for each production:

18 Fall 2003Costas Busch - RPI18

19 Fall 2003Costas Busch - RPI19

20 Fall 2003Costas Busch - RPI20

21 Fall 2003Costas Busch - RPI21

22 Fall 2003Costas Busch - RPI22

23 Fall 2003Costas Busch - RPI23 Grammar NFA

24 Fall 2003Costas Busch - RPI24 In General A right-linear grammar has variables: and productions: or

25 Fall 2003Costas Busch - RPI25 We construct the NFA such that: each variable corresponds to a node: special final state

26 Fall 2003Costas Busch - RPI26 For each production: we add transitions and intermediate nodes ………

27 Fall 2003Costas Busch - RPI27 For each production: we add transitions and intermediate nodes ………

28 Fall 2003Costas Busch - RPI28 Resulting NFA looks like this: It holds that:

29 Fall 2003Costas Busch - RPI29 The case of Left-Linear Grammars Let be a left-linear grammar We will prove: is regular Proof idea: We will construct a right-linear grammar with

30 Fall 2003Costas Busch - RPI30 Since is left-linear grammar the productions look like:

31 Fall 2003Costas Busch - RPI31 Construct right-linear grammar Left linear Right linear

32 Fall 2003Costas Busch - RPI32 Construct right-linear grammar Left linear Right linear

33 Fall 2003Costas Busch - RPI33 It is easy to see that: Since is right-linear, we have: Regular Language Regular Language Regular Language

34 Fall 2003Costas Busch - RPI34 Proof - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by some regular grammar

35 Fall 2003Costas Busch - RPI35 Proof idea: Let be the NFA with. Construct from a regular grammar such that Any regular language is generated by some regular grammar

36 Fall 2003Costas Busch - RPI36 Since is regular there is an NFA such that Example:

37 Fall 2003Costas Busch - RPI37 Convert to a right-linear grammar

38 Fall 2003Costas Busch - RPI38

39 Fall 2003Costas Busch - RPI39

40 Fall 2003Costas Busch - RPI40

41 Fall 2003Costas Busch - RPI41 In General For any transition: Add production: variableterminalvariable

42 Fall 2003Costas Busch - RPI42 For any final state: Add production:

43 Fall 2003Costas Busch - RPI43 Since is right-linear grammar is also a regular grammar with


Download ppt "Fall 2003Costas Busch - RPI1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:"

Similar presentations


Ads by Google