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

TCS Lect 21 Grammar Introduction

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

TCS Lect 21 Grammar Introduction

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

GRAMMAR

• It is the set of rules used to define the language

GRAMMAR • It tells whether a particular sentence is well formed or not

Typical Rule of English Grammar:


' A Sentence can consists of a noun phrase followed by
predicate'
<sentence> → <nounphrase> <predicate>
We can define noun and predicate as
<nounphrase> → <article> <noun>
<predicate> → <verb>

By using above rules, if articles = { a, the }

Possible Sentences: nouns = { boy, dog }

a boy runs verbs = { runs, walk }


the dog walks
GRAMMAR

• We start with top level concept and successfully

reduced it to the irreducible building blocks of the

language

• The Generalization of these ideas leads us to the formal

Grammar
Grammar G is defined as a quadruple:
GRAMMAR G = ( V, T, S, P )
Where
V – Finite Set of Objects (Variables)
T – Finite Set of Objects (Terminals)
S ∈ V Special Symbol (Start Symbol)

P – Finite Set of Productions

• Production Rules are core part of the Grammar


• They specify how the grammar transforms one string
into another
General Form: x→y
GRAMMAR Where x is an element of ( V U T )+
y is an element of ( V U T )*
PRODUCTION
RULES
Production rules are applied as:
Given string: w = u x v
Production: x → y
Then replace x with y to get new string
New string: z = u y v

The above process is written as w ⇒ z


w derives z OR
z is derived from w
GRAMMAR Successive strings can be obtained by applying production rules.
If w1 ⇒ w2 ⇒ w3 ⇒ … ⇒ wn
PRODUCTION
RULES Then w1 *⇒ wn [ w1 derives wn in unspecified number of steps ]

• By applying the production rules in different order, a given


grammar can normally generates many strings
• The set of all such terminal string is the language defined or
generated by the grammar
Definition:
GRAMMAR Let G = ( V, T, S, P ) be a grammar then the set
L ( G ) = { w ∈ T* | S *⇒ w }
PRODUCTION
It is the language generated by G
RULES

If w ∈ L ( G ) then the sequence


S ⇒ w1 ⇒ w2 ⇒ w3 ⇒ … ⇒ wn ⇒ w
• It is the derivation of sentence w
• The strings s, w1, w2, … , wn contains variable as well as terminals
are called SENTENTIAL FORM of derivation
Example 1:
GRAMMAR
G = ( { S } , { a, b }, S, P ) where
P is given by S → a S b
PRODUCTION
RULES S→ε
Then
S⇒aSb
⇒aaSbb
⇒aabb
Language generated by G can be represented as
L ( G ) = { an bn | n >= 0 }
GRAMMAR
Languag Languag
Grammar Machine Example
e Class e

Computa Regular FSM –


Type 3 Regular a*b*
ble Grammar NFA/DFA
Languag
e
Context Context
Sensitive Context
Language Type 2 Free PDA anbn
Free
Context Grammar
Free
Languag Context Linear
e Decidable
Type 1 Sensitive Bounded anbncn
Language
Grammar Automata
Regular
Languag
e Computab Unrestrict
Turing
Type 0 le ed n!
Machine
Language Grammar
GRAMMAR

Computa
ble
Type 3: Regular Languages
Languag
e • They can be described using Regular Expression
Context • Languages can be modelled by DFA / NFA
Sensitive
Language
• These automata doesn’t have any device to memorize
Context
Free
Languag
e

Regular
Languag
e
GRAMMAR

Type 2: Context Free Languages


• They can be represented with Context Free Grammar
Computa
ble • The Production rules are in the form
Languag
e A →∝
Context
Sensitive Where A is Single Non Terminal
Language
Context ∝ is combination of terminals and Non Terminals
Free
Languag • Push down Automata is used to represent these
e languages

Regular
Languag
e
GRAMMAR Type 1: Context Sensitive Languages
Context Sensitive Grammar is used to represent these
languages
Grammar has following rules:
Computa
ble • More than one symbol can be present on left hand side of
Languag production rules
e
Context • Number of symbols on the left hand side of the production
Sensitive
Language should not exceed number of symbols on right hand side of
Context the production
Free
Languag • The rule of the form A → ε unless A is start symbol
e
The machine used is Linear Bounded Automata
Regular Sentential form must always increased after applying
Languag
e production rule
GRAMMAR

Computa
ble Type 1: Unrestricted Languages
Languag
e • No restriction on the grammar rules of these type of
Context languages
Sensitive
Language
• Languages can be modelled using Turing Machine
Context
Free
Languag
e

Regular
Languag
e

You might also like