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

Classification of Grammars

Classification of grammar SS and OS

Uploaded by

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

Classification of Grammars

Classification of grammar SS and OS

Uploaded by

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

CLASSIFICATION OF

GRAMMAR

presented by
Nivea
CHOMSKY CLASSIFICATION
OF GRAMMARS
The Chomsky hierarchy is a system for classifying formal
grammars and languages in computer science and
linguistics.According to Noam Chomosky, there are four types
of grammars
TYPE 0: UNRESTRICTED GRAMMAR

The productions have no restrictions.


They generate the languages that are recognized by a Turing machine.
The productions can be in the form of
α→β
where α is a string of terminals and nonterminals with at least one non-terminal
and α cannot be null.
β is a string of terminals and non-terminals.

Example
S → ACaB
Bc → acB
CB → DB
These grammars, known as phrase structure grammars, contain productions of
the form:

where both α and β can be strings of terminals (Ts) and non-terminals (NTs).
Such productions permit arbitrary substitution of strings during derivation or
reduction, hence they are not relevant to the specification of programming
languages.
TYPE 1: CONTEXT-SENSITIVE GRAMMAR
The productions must be in the form

αAβ→αγβ

where A ∈ N (Non-terminal)
and α, β, γ ∈ (T ∪ N)* (Strings of terminals and non-terminals)
count symbol in LHS must be less than or equal to RHS.
Example
AB → AbBc
A → bcA
B→b
These grammars are known as context-sensitive grammars because their productions specify
that derivation or reduction of strings can take place only in specific contexts. A Type-1
production has the form:

Thus, a string in a sentential form can be replaced by 'A' (or vice versa) only when it is
enclosed by the strings and these grammars are also not particularly relevant for
programming language (PL) specification since recognition of PL constructs is not context-
sensitive.
TYPE 2: CONTEXT-FREE GRAMMAR
Grammar Production for Type 2 is given by

A —> α

Where A is a single non-terminal.


String of terminals and non-terminals
Example
S→Xa
X→a
X → aX
X → abc
These grammars impose no context requirements on derivations or reductions. A
typical Type-2 production is of the form:

which can be applied independently of its context. These grammars are therefore
known as context-free grammars (CFGs). CFGs are ideally suited for programming
language specification. Two best-known uses of Type-2 grammars in PL
specification are the ALGOL-60 specification (Naur, 1963) and Pascal specification
(Jensen, Wirth, 1975).
TYPE 3: REGULAR GRAMMAR
Type-3 grammars must have a single non-terminal on the left-hand side and
a right-hand side consisting of a single terminal or single terminal followed
by a single non-terminal
The productions must be in the form X → a or X → aY
where X, Y ∈ N (Non terminal)
and a ∈ T (Terminal)
Example
X→ε
X → a | aY
Y→b
Type-3 grammars are characterized by productions of the form:

Note that these productions also satisfy the requirements of Type-2 grammars. The
specific form of the right-hand side alternatives—namely a single terminal (T) or a string
containing a single terminal and a single non-terminal (NT)—gives some practical
advantages in scanning. However, the nature of the productions restricts the expressive
power of these grammars.
OPERATOR GRAMMAR
An operator grammar is a grammar where none of the productions
contain two or more consecutive non-terminals in any right-hand side
alternative

A grammar that is used to define mathematical operators is called an


operator grammar or operator precedence grammar.
Such grammars have the restriction that no production has either an
empty right-hand side (null productions) or two adjacent non-terminals
in its right-hand side.

Example
E->E+E/E*E/id
THANK YOU!!

You might also like