0% found this document useful (0 votes)
157 views13 pages

Grammer

The document discusses formal language theory and the Chomsky hierarchy of languages. It defines grammars and their components. There are four types of languages in the Chomsky hierarchy from least to most expressive: regular languages (Type-3), context-free languages (Type-2), context-sensitive languages (Type-1), and unrestricted languages (Type-0). Regular languages can be recognized by finite state automata, while the other types require more complex machines like pushdown automata and Turing machines. Context-free languages include all programming languages.

Uploaded by

Anik
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views13 pages

Grammer

The document discusses formal language theory and the Chomsky hierarchy of languages. It defines grammars and their components. There are four types of languages in the Chomsky hierarchy from least to most expressive: regular languages (Type-3), context-free languages (Type-2), context-sensitive languages (Type-1), and unrestricted languages (Type-0). Regular languages can be recognized by finite state automata, while the other types require more complex machines like pushdown automata and Turing machines. Context-free languages include all programming languages.

Uploaded by

Anik
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Formal Languages

How Many Languages Are There?


How many languages over a particular alphabet
are there?
Uncountably infinitely many!
Then, any finite method of describing languages
can not include all of them.
Formal language theory gives us techniques for
defining some languages over an alphabet.
How Many Languages Are There?
How many languages over a particular alphabet
are there?
Uncountably infinitely many!
Then, any finite method of describing languages
can not include all of them.
Formal language theory gives us techniques for
defining some languages over an alphabet.
Definition of a Grammar
A grammar G is a 4 tuple G = (N,, P, S), where
N is an alphabet of nonterminal symbols
 is an alphabet of terminal symbols
N and  are disjoint
S is an element of NS is the start symbol or initial symbol of
the grammar
P is a set of productions of the form { u  v | u  V*NV*
and v  V* }
leftpart rightpart

Where VG = N   (vocabulary of G)
Example
G=(N,∑, P, S) is a grammar
Where
N={<sentence>,<noun>,<verb>,<adverb>}
∑={Sam, John , ate ,sang , well}
S=<sentence>
P has the following productions:
<sentence> --> <noun> <verb>
<sentence> --> <noun> <verb> <adverb>
<noun> --> Sam
<noun> --> John
<verb> --> ate
<verb> --> sang
<adverb> --> well
Find the Language of the Grammar:
• Now language is:
L(G)={anbn+1 : n>=0 } generate grammar

So G=({S,A}, {a,b},S,P)
where
P: S  Ab
A  aAb
Aλ
# Find a grammar for ∑={a,b} that generate
the sets of all strings with exactly one ‘a’

So G=({S,A}, {a,b},S,P)
where
P: S  AaA
A  λ|bA
# Find a grammar for ∑={a,b} that generate
the sets of all strings with atleast one ‘a’

So G=({S,A}, {a,b},S,P)
where
P: S  AaA
A  λ|bA|aA
The Chomsky Classification of
Languages
The Chomsky Hierarchy of Languages
Technical Note:
Type-0 Languages
Type-1 languages explicitly
(Recursively Enum.)
exclude the null string.
All other language Recursive
families permit the null Languages
string as a member.
(The Venn diagram is
in slight error because
of this technicality.) Type-1
(Context-sensitive)
Languages
Type-2
(Context-free)
Languages
Linear
(Context-free)
Type-3 Languages
(Regular)
Languages
Languages and corresponding
Automata
Type 0 TM
Context- Senstive or
LBA
type 1
Context- free or PDA
type 2

Regular FA
Regular or
Type 3
Type 0: Unrestricted Grammars are all formal grammars . They are exactly all those
that can be accepted by some Turing machine.

 Type 1: Context Sensitive Grammars. These have rules of the form


aAb → agb
  where to make the substitution, the preexistence of prefix 'a' and postfix 'b'
is required; that is the context to which the rule is sensitive.

 Type 2: Context Free Grammars. These have production rules all of which do not
have any of the contextual restrictions of type 1 grammars.
This is a very rich category of languages. This category includes all programming languages, and
the sample language described above.

 Type 3: Regular Grammars are formal grammar (N, T, P, S)


where all the production rules in P are of one of the forms:
A→a
A → aB or A → Ba
A→e
Regular languages are recognizable by finite state automata.

You might also like