Linear grammars
Download
1 / 43

Linear Grammars - PowerPoint PPT Presentation


  • 91 Views
  • Uploaded on

Linear Grammars. Grammars with at most one variable at the right side of a production Examples:. A Non-Linear Grammar. Grammar :. Number of in string. Another Linear Grammar. Grammar :. Right-Linear Grammars. All productions have form: Example:. or. string of

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Linear Grammars' - yale


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Linear grammars
Linear Grammars

Grammars with

at most one variable at the right side

of a production

Examples:

Prof. Busch - LSU


A non linear grammar
A Non-Linear Grammar

Grammar :

Number of in string

Prof. Busch - LSU


Another linear grammar
Another Linear Grammar

Grammar :

Prof. Busch - LSU


Right linear grammars
Right-Linear Grammars

All productions have form:

Example:

or

string of

terminals

Prof. Busch - LSU


Left linear grammars
Left-Linear Grammars

All productions have form:

Example:

or

string of

terminals

Prof. Busch - LSU


Regular grammars

Regular Grammars

Prof. Busch - LSU


Regular grammars1
Regular Grammars

A regular grammaris any

right-linear or left-linear grammar

Examples:

Prof. Busch - LSU


Observation
Observation

Regular grammars generate regular languages

Examples:

Prof. Busch - LSU


Regular grammars generate regular languages

Regular Grammars GenerateRegular Languages

Prof. Busch - LSU


Theorem
Theorem

Languages

Generated by

Regular Grammars

Regular

Languages

Prof. Busch - LSU


Theorem - Part 1

Languages

Generated by

Regular Grammars

Regular

Languages

Any regular grammar generates

a regular language

Prof. Busch - LSU


Theorem - Part 2

Languages

Generated by

Regular Grammars

Regular

Languages

Any regular language is generated

by a regular grammar

Prof. Busch - LSU


Proof part 1
Proof – Part 1

Languages

Generated by

Regular Grammars

Regular

Languages

The language generated by

any regular grammar is regular

Prof. Busch - LSU


The case of right linear grammars
The case of Right-Linear Grammars

Let be a right-linear grammar

We will prove: is regular

Proof idea: We will construct NFA

with

Prof. Busch - LSU


Grammar is right-linear

Example:

Prof. Busch - LSU


Construct NFA such that

every state is a grammar variable:

special

final state

Prof. Busch - LSU








NFA

Grammar

Prof. Busch - LSU


In general
In General

A right-linear grammar

has variables:

and productions:

or

Prof. Busch - LSU


We construct the NFA such that:

each variable corresponds to a node:

special

final state

Prof. Busch - LSU


For each production:

we add transitions and intermediate nodes

………

Prof. Busch - LSU


For each production:

we add transitions and intermediate nodes

………

Prof. Busch - LSU


Resulting NFA looks like this:

It holds that:

Prof. Busch - LSU


The case of left linear grammars
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

Prof. Busch - LSU


Since is left-linear grammar

the productions look like:

Prof. Busch - LSU


Construct right-linear grammar

Left

linear

Right

linear

Prof. Busch - LSU


Construct right-linear grammar

Left

linear

Right

linear

Prof. Busch - LSU


It is easy to see that:

Since is right-linear, we have:

Regular

Language

Regular

Language

Regular

Language

Prof. Busch - LSU


Proof part 2
Proof - Part 2

Languages

Generated by

Regular Grammars

Regular

Languages

Any regular language is generated

by some regular grammar

Prof. Busch - LSU


Any regular language is generated

by some regular grammar

Proof idea:

Let be the NFA with .

Construct from a regular grammar

such that

Prof. Busch - LSU


Since is regular

there is an NFA such that

Example:

Prof. Busch - LSU






In general1
In General

For any transition:

Add production:

variable

terminal

variable

Prof. Busch - LSU


For any final state:

Add production:

Prof. Busch - LSU


Since is right-linear grammar

is also a regular grammar

with

Prof. Busch - LSU


ad