fall 2003costas busch - rpi1 linear grammars grammars with at most one variable at the right side of...

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

Post on 22-Dec-2015

215 views

Category:

Documents

1 download

Embed Size (px)

TRANSCRIPT

  • Slide 1
  • Fall 2003Costas Busch - RPI1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:
  • Slide 2
  • Fall 2003Costas Busch - RPI2 A Non-Linear Grammar Grammar : Number of in string
  • Slide 3
  • Fall 2003Costas Busch - RPI3 Another Linear Grammar Grammar :
  • Slide 4
  • Fall 2003Costas Busch - RPI4 Right-Linear Grammars All productions have form: Example: or string of terminals
  • Slide 5
  • Fall 2003Costas Busch - RPI5 Left-Linear Grammars All productions have form: Example: or string of terminals
  • Slide 6
  • Fall 2003Costas Busch - RPI6 Regular Grammars
  • Slide 7
  • Fall 2003Costas Busch - RPI7 Regular Grammars A regular grammar is any right-linear or left-linear grammar Examples:
  • Slide 8
  • Fall 2003Costas Busch - RPI8 Observation Regular grammars generate regular languages Examples:
  • Slide 9
  • Fall 2003Costas Busch - RPI9 Regular Grammars Generate Regular Languages
  • Slide 10
  • Fall 2003Costas Busch - RPI10 Theorem Languages Generated by Regular Grammars Regular Languages
  • Slide 11
  • Fall 2003Costas Busch - RPI11 Theorem - Part 1 Languages Generated by Regular Grammars Regular Languages Any regular grammar generates a regular language
  • Slide 12
  • Fall 2003Costas Busch - RPI12 Theorem - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by a regular grammar
  • Slide 13
  • Fall 2003Costas Busch - RPI13 Proof Part 1 Languages Generated by Regular Grammars Regular Languages The language generated by any regular grammar is regular
  • Slide 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
  • Slide 15
  • Fall 2003Costas Busch - RPI15 Grammar is right-linear Example:
  • Slide 16
  • Fall 2003Costas Busch - RPI16 Construct NFA such that every state is a grammar variable: special final state
  • Slide 17
  • Fall 2003Costas Busch - RPI17 Add edges for each production:
  • Slide 18
  • Fall 2003Costas Busch - RPI18
  • Slide 19
  • Fall 2003Costas Busch - RPI19
  • Slide 20
  • Fall 2003Costas Busch - RPI20
  • Slide 21
  • Fall 2003Costas Busch - RPI21
  • Slide 22
  • Fall 2003Costas Busch - RPI22
  • Slide 23
  • Fall 2003Costas Busch - RPI23 Grammar NFA
  • Slide 24
  • Fall 2003Costas Busch - RPI24 In General A right-linear grammar has variables: and productions: or
  • Slide 25
  • Fall 2003Costas Busch - RPI25 We construct the NFA such that: each variable corresponds to a node: special final state
  • Slide 26
  • Fall 2003Costas Busch - RPI26 For each production: we add transitions and intermediate nodes
  • Slide 27
  • Fall 2003Costas Busch - RPI27 For each production: we add transitions and intermediate nodes
  • Slide 28
  • Fall 2003Costas Busch - RPI28 Resulting NFA looks like this: It holds that:
  • Slide 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
  • Slide 30
  • Fall 2003Costas Busch - RPI30 Since is left-linear grammar the productions look like:
  • Slide 31
  • Fall 2003Costas Busch - RPI31 Construct right-linear grammar Left linear Right linear
  • Slide 32
  • Fall 2003Costas Busch - RPI32 Construct right-linear grammar Left linear Right linear
  • Slide 33
  • Fall 2003Costas Busch - RPI33 It is easy to see that: Since is right-linear, we have: Regular Language Regular Language Regular Language
  • Slide 34
  • Fall 2003Costas Busch - RPI34 Proof - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by some regular grammar
  • Slide 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
  • Slide 36
  • Fall 2003Costas Busch - RPI36 Since is regular there is an NFA such that Example:
  • Slide 37
  • Fall 2003Costas Busch - RPI37 Convert to a right-linear grammar
  • Slide 38
  • Fall 2003Costas Busch - RPI38
  • Slide 39
  • Fall 2003Costas Busch - RPI39
  • Slide 40
  • Fall 2003Costas Busch - RPI40
  • Slide 41
  • Fall 2003Costas Busch - RPI41 In General For any transition: Add production: variableterminalvariable
  • Slide 42
  • Fall 2003Costas Busch - RPI42 For any final state: Add production:
  • Slide 43
  • Fall 2003Costas Busch - RPI43 Since is right-linear grammar is also a regular grammar with

Recommended

View more >