0% found this document useful (0 votes)
58 views11 pages

Regular Grammar: Bachelor of Technology Computer Science and Engineering

This document discusses regular grammars and provides examples. It defines regular grammars as grammars where production rules are of the form: A → a, A → aB, or A → ε, where A and B are nonterminals and a is a terminal. Regular grammars generate regular languages. Examples of regular grammars are provided to generate languages of strings with even length and strings ending in "aaaa".

Uploaded by

Tuhin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views11 pages

Regular Grammar: Bachelor of Technology Computer Science and Engineering

This document discusses regular grammars and provides examples. It defines regular grammars as grammars where production rules are of the form: A → a, A → aB, or A → ε, where A and B are nonterminals and a is a terminal. Regular grammars generate regular languages. Examples of regular grammars are provided to generate languages of strings with even length and strings ending in "aaaa".

Uploaded by

Tuhin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

REGULAR GRAMMAR

Bachelor of Technology
Computer Science and Engineering

Submitted By

TUHIN DAS (13000118002)


SEC- A, 2nd YEAR

MAY 2019

Techno India
EM-4/1, Sector-V, Salt Lake
Kolkata- 700091
West Bengal
India
TABLE OF CONTENTS

1. Introduction
2. Body
i. Regular Grammars

ii. Regular Grammar Example

iii. Regular Languages and Regular Grammars

iv. Example 1 - Even Length Strings

v. Strings that End with aaaa

vi. Example 2 – One Character Missing

3. References
1. Introduction:

Strictly regular grammars


A right regular grammar (also called right linear grammar) is a formal grammar (N, Σ, P, S)
such that all the production rules in P are of one of the following forms:

1. A → a, where A is a non-terminal in N and a is a terminal in Σ


2. A → aB, where A and B are non-terminals in N and a is in Σ
3. A → ε, where A is in N and ε denotes the empty string, i.e. the string of length 0.
In a left regular grammar (also called left linear grammar), all rules obey the forms

1. A → a, where A is a non-terminal in N and a is a terminal in Σ


2. A → Ba, where A and B are in N and a is in Σ
3. A → ε, where A is in N and ε is the empty string.
A regular grammar is a left or right regular grammar.
Some textbooks and articles disallow empty production rules, and assume that the empty string is
not present in languages.
Extended regular grammars
An extended right regular grammar is one in which all rules obey one of

1. A → w, where A is a non-terminal in N and w is in a (possibly empty) string of terminals


Σ*
2. A → wB, where A and B are in N and w is in Σ*.
Some authors call this type of grammar a right regular grammar (or right linear grammar) and
the type above a strictly right regular grammar (or strictly right linear grammar).
An extended left regular grammar is one in which all rules obey one of

1. A → w, where A is a non-terminal in N and w is in Σ*


2. A → Bw, where A and B are in N and w is in Σ*.

Examples
An example of a right regular grammar G with N = {S, A}, Σ = {a, b, c}, P consists of the
following rules
S → aS
S → bA
A→ε
A → cA
and S is the start symbol. This grammar describes the same language as the regular
expression a*bc*, viz. the set of all strings consisting of arbitrarily many "a"s, followed by a
single "b", followed by arbitrarily many "c"s.A somewhat longer but more explicit extended
right regular grammar G for the same regular expression is given by N = {S, A, B, C}, Σ = {a, b,
c}, where P consists of the following rules:
S→A
A → aA
A→B
B → bC
C→ε
C → cC
…where each uppercase letter corresponds to phrases starting at the next position in the regular
expression.As an example from the area of programming languages, the set of all strings
denoting a floating point number can be described by an extended right regular
grammar G with N = {S, A,B,C,D,E,F}, Σ = {0,1,2,3,4,5,6,7,8,9,+,-,.,e}, where S is the start
symbol, and P consists of the

following rules:
S → +A A → 0A B → 0C C → 0C D → +E E → 0F F → 0F

S → -A A → 1A B → 1C C → 1C D → -E E → 1F F → 1F

S→A A → 2A B → 2C C → 2C D→E E → 2F F → 2F

A → 3A B → 3C C → 3C E → 3F F → 3F

A → 4A B → 4C C → 4C E → 4F F → 4F

A → 5A B → 5C C → 5C E → 5F F → 5F

A → 6A B → 6C C → 6C E → 6F F → 6F

A → 7A B → 7C C → 7C E → 7F F → 7F

A → 8A B → 8C C → 8C E → 8F F → 8F

A → 9A B → 9C C → 9C E → 9F F → 9F

A → .B C → eD F→ε

A→B C→ε
I. Regular Grammars
A regular grammar G is a quadruple (V, , R, S), where:

● V is the rule alphabet, which contains non terminals and terminals,

●  (the set of terminals) is a subset of V,

● R (the set of rules) is a finite set of rules of the form:

X  Y,

● S (the start symbol) is a nonterminal.

In a regular grammar, all rules in R must:

● have a left-hand side that is a single nonterminal

● have a right-hand side that is:

● , or

● a single terminal, or

● a single terminal followed by a single nonterminal.

Legal: S  a, S  , and T  aS

Not legal: S  aSa and aSa  T


II. Regular Grammar Example

L = {w  {a, b}* : |w| is even} ((aa)  (ab)  (ba)  (bb))*

L = {w  {a, b}* : |w| is even} ((aa)  (ab)  (ba)  (bb))*

S

S  aT

S  bT

Ta

Tb

T  aS

T  bS
III. Regular Languages and Regular Grammars

 Theorem: The class of languages that can be defined with regular grammars is exactly
the regular languages.
 Proof: By two constructions.

Regular grammar  FSM:


grammar (G = (V, , R, S)) =
1. Create in M a separate state for each nonterminal in V.
2. Start state is the state corresponding to S .
3. If there are any rules in R of the form X  w, for some
w  , create a new state labeled #.
4. For each rule of the form X  w Y, add a transition from
X to Y labeled w.
5. For each rule of the form X  w, add a transition from X
to # labeled w.
6. For each rule of the form X  , mark state X as
accepting.
7. Mark state # as accepting.
FSM  Regular grammar: Similarly.
IV. Example 1 - Even Length Strings

S Ta
S  aT Tb
S  bT T  aS
T  bS

V. Strings that End with aaaa

L = {w  {a, b}* : w ends with the pattern aaaa}.


S  aS
S  bS
S  aB
B  aC
C  aD
Da
L = {w  {a, b}* : w ends with the pattern aaaa}.
S  aS
S  bS
S  aB
B  aC
C  aD
Da
VI. Example 2 – One Character Missing

S A  bA C  aC
S  aB A  cA C  bC
S  aC A C
S  bA B  aB
S  bC B  cB
S  cA B
S  cB
2. References:

 https://en.wikipedia.org/wiki/Regular_grammar
 https://www.tutorialspoint.com/automata_theory/introduction_to_grammars.htm
 https://www.tutorialspoint.com/automata_theory/regular_expressions.htm
 https://www.geeksforgeeks.org/regular-expressions-regular-grammar-and-regular-languages/
 https://www.cs.montana.edu/ross/theory/contents/chapter02/green/section05/page04.xhtml
 http://www.montefiore.ulg.ac.be/~pw/cours/psfiles/calc-chap3.pdf
 https://ocw.mit.edu/ans7870/6/6.005/s16/classes/17-regex-grammars/
 https://www.sanfoundry.com/automata-theory-regular-grammars/

You might also like