Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Regular Languages

Type 3 Grammar (corresponds to a finite automata)


A regular grammar must be either a right-linear or a left-linear grammar
Right-linear grammar
All productions are of the following form:
A x B
A x
where A and B are a single non-terminal and x is a (possibly empty) string
of terminals
Left-linear grammar
All productions are of the following form:
A B x
A x
where A and B are a single non-terminal and x is a (possibly empty) string
of terminals
Restrictions: The left side of each rule is a single non-terminal symbol.
There is, at most, one non-terminal on the right hand side of its rules.
When a rule has a non-terminal on the right hand side, then that
non-terminal must be either all the way to the left of ALL such rules
or that non-terminal must be all the way to the right of ALL those rules.
Context-Free Languages
Type 2 Grammar (corresponds to a push-down automata)
Restrictions: Production rules have a single non-terminal on the left side but have
no restrictions on the right-hand side
Context-Sensitive Languages
Type 1 Grammar (corresponds to a linear-bounded automata)
Production rules can have strings of terminals and non-terminals on both the left
and right sides of its rules
All productions are of the following form:
x y
where x and y are non-empty strings of terminals and non-terminals such
that |x| <= |y| (i.e., the length of the string of symbols on the right hand
side is never less than the length of the left hand side in any rule)
Restriction: the production rules have to be non-contracting in the sense that each
successive sentential form in a derivation can never decrease in length
Recursively Enumerable Languages
Type 0 Grammar (corresponds to a Turing Machine)
No restrictions on the production rules

Example1: Let A and B be non-terminals and let x and y be terminal symbols. The
following grammar is not regular; it is context-free. Why?
A B y
B x A
A x
Example2: Let A and B be non-terminals and let x and y be terminal symbols. The
following grammar is regular; it is also context-free. Why?
A B x y
B A x y
A x
If A is the start symbol, then the language generated by this grammar is the same as the
language specified by the following regular expression:
x (x y x y)*
If B is the start symbol, then the language generated by this grammar is the same as the
language specified by the following regular expression:
x x y (x y x y)*

You might also like