Presentation is loading. Please wait.

Presentation is loading. Please wait.

Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.

Similar presentations


Presentation on theme: "Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language."— Presentation transcript:

1 Regular Grammars Reading: 3.3

2 What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language has a Regular Expression  Now, what about grammars?

3 Right Linear Grammars  Right-linear: at most one variable on the right side of the production, must be the right-most symbol. A -> xB A -> x x is any string of terminals.

4 Left Linear Grammars  Left-linear: at most one variable on the right side of the production, must be the left-most symbol. A -> Bx A -> x x is any string of terminals.

5 Regular Grammars  A grammar is regular if it is either left- or right-linear.  A linear grammar may have a mix of left and right productions. Its only restriction is that there is at most one symbol on the right.  All regular grammars are linear, but not all linear grammars are regular!

6 Prove: All right-linear grammars describe regular languages  Idea: Find a way to convert any right-linear grammar into a FSA.  Terminals before a non-terminal represent arcs  Non-terminals represent non-final states.  Terminals without non-terminals following represent final states.

7 Reg Grammar to NFA S -> aD D -> abS D -> b Step 1: Start variable is the initial node. S

8 Reg Grammar to NFA S -> aD D -> abS D -> b Step 2: Each rule ending in a non- terminal is a chain of arcs followed by a non-final node. S D a

9 Reg Grammar to NFA S -> aD D -> abS D -> b Step 2: Each rule ending in a non- terminal is a chain of arcs followed by a non-final node. S D a ab

10 Reg Grammar to NFA S -> aD D -> abS D -> b Step 3: Each rule ending in a terminal leads to a final state. S D a ab b

11 Example: Convert to a FSA  S -> aB S -> bS S -> λ B -> aS B -> bB

12 Does every regular language have a regular grammar that describes it?  Yes! Reverse the algorithm for constructing the FSA from the grammar  Every rule in δ is a line in the grammar.

13 Write a regular grammar

14 Regular Language Wrap-up Regular expressions DFA or NFA Regular grammar

15 Examples:  Find the grammar for the expression: aab*a  Find the regular expression for: S -> abS | bA A -> aA | b


Download ppt "Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language."

Similar presentations


Ads by Google