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

Grammar

The document discusses alphabets, strings, languages, and Chomsky hierarchy of grammars. It defines that an alphabet is a character set, a string is a set of characters from an alphabet, and a language is the set of all possible strings from an alphabet. It also defines grammar as a 4-tuple consisting of variables, terminals, rules, and a start variable. Finally, it explains Chomsky hierarchy which classifies grammars from type-0 to type-3 based on restrictions on production rules.

Uploaded by

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

Grammar

The document discusses alphabets, strings, languages, and Chomsky hierarchy of grammars. It defines that an alphabet is a character set, a string is a set of characters from an alphabet, and a language is the set of all possible strings from an alphabet. It also defines grammar as a 4-tuple consisting of variables, terminals, rules, and a start variable. Finally, it explains Chomsky hierarchy which classifies grammars from type-0 to type-3 based on restrictions on production rules.

Uploaded by

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

Alphabet, String & Language

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Alphabet, String & Language
 Alphabet ( ∑ )
• Character set 0&1

 String
• Set of characters defined over alphabet 10010

 Language ( L ) { 0 , 1 , 01 , 10 , 00 , 11 ,
• Set of all possible strings over alphabet 001 , 010 , 011, 101 ,
110 , 111 }

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Grammar

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Grammar
 Grammar (G) is a 4-tuple ( V , ∑ , R , S )

V : finite set of nonterminals / variables


∑ : finite set of terminals
R : rules / productions
S : start nonterminal / variable

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Grammar
 Symbols used as Terminal

• Lower-case letter ( a-z )


• Operator symbols ( + - / * etc. )
• Punctuation symbols ( , ; : () {} [] etc. )
• Digits ( 0-9 )
• Boldface string ( if , while etc. Used represent single terminal)

 Symbols used as Nonterminal

• Upper-case letters ( A-Z )


• S used as start symbol
• Lower-case italic names ( expression , statement etc.)

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Grammar
 Rules/Productions

• It will be of form V  w

 Start variable

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Chomsky Hierarchy

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Classification of grammar
 Grammars can classified on the basis of the nature of productions
used in them

 Chomsky have given grammar classification (Chomsky hierarchy)


• Type-0 : Phase Structured Grammar/Recursively enumerable grammar
• Type-1 : Context Sensitive Grammar
• Type-2 : Context Free Grammar
• Type-3 : Regular Grammar

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Classification of grammar : Chomsky
hierarchy

Type – 0
Recursively enumerable grammar

Type – 1
Context sensitive grammar

Type – 2
Context free grammar

Type – 3
Regular grammar

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Type-3 : Regular Grammar/Linear Grammar
 Contain productions of the form

A  tB | t or
A  Bt | t

 Specific form of RHS

• Single terminal
or
• String of single terminal and single nonterminal

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Type-2 : Context free Grammar (CFG)
 Contain productions of the form

AΠ

where
A : single nonterminal
Π : string of terminals and/or nonterminals

 String “Π” can be replaced by “A” (or vice versa) independent of its
context

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Type-1 : Context Sensitive Grammar
 Contain productions of the form

αAβαΠβ

 String “Π” can be replaced by “A” (or vice versa) only when it is
enclosed by the strings “α” and “β”

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT


Type-0 : Phase Structured Grammar
 Contain productions of the form

αβ

where
α and β both an be string of terminals and nonterminals

Trusha R. Patel, CE Dept., CSPIT, CHARUSAT

You might also like