SlideShare a Scribd company logo
Recap
Applications of minimum edit distance, calculating minimum edit
distance.
•1
Today’s Agenda
 Context Free Grammar,
 Terminals,
 non-terminals,
 productions,
 CFG,
 context Free language,
 examples.
•2
Context Free Grammar (CFG)
The earliest computers accepted no
instructions other then their own
assembly language. Every procedure,
no matter how complicated , had to
be encoded in the set of instructions,
LOAD, STORE, ADD the contents of two
registers and so on. The major problem
was to display mathematical formulas
as follows
•3
2
)1011()107()08( 222
−+−+−
=S
or
CFG continued …
So, it was necessary to develop a way
of writing such expressions in one line of
standard typewriter symbols, so that in
this way a high level language could
be invented. Before the invention of
computers, no one would ever have
dreamed of writing such complicated
formula in parentheses e.g. the right
side of formula can be written as
((1/2)+9)/(4+(8/21)+(5/(3+(1/2))))
•4
2
1
3
5
21
8
4
9
2
1
+
++
+
=A
CFG continued …
The high level language is converted into
assembly language codes by a program
called compiler.
The compiler that takes the user’s
programs as its inputs and prints out an
equivalent program written in assembly
language.
Like spoken languages, high level
languages for computer have also, certain
grammar. But in case of computers, the
grammatical rules, don’t involve the
meaning of the words.
•5
CFG continued …
It can be noted that the grammatical rules
which involve the meaning of words are
called Semantics, while those don’t
involve the meaning of the words are
called Syntactics.
e.g. in English language, it can not be
written “ Buildings sing ”, while in computer
language one number is as good as
another.
e.g. X = B + 10, X = B + 999
Following is a remark
•6
Remark
In general, the rules of computer language grammar,
are all syntactic and not semantic. A law of grammar
is in reality a suggestion for possible substitutions.
•7
CFG terminologies
Terminals: The symbols that can’t be replaced by
anything are called terminals.
Non-Terminals: The symbols that must be replaced by
other things are called non-terminals.
Productions: The grammatical rules are often called
productions.
•8
CFG
CFG is a collection of the followings
1. An alphabet ∑ of letters called terminals
from which the strings are formed, that will
be the words of the language.
2. A set of symbols called non-terminals, one of
which is S, stands for “start here”.
3. A finite set of productions of the form
A Non-terminal  finite string of terminals
and /or non-terminals.
Following is a note in this regard
•9
Note
The terminals are designated by small letters, while the
non-terminals are designated by capital letters.
There is at least one production that has the non-
terminal S as its left side.
•10
Context Free Language (CFL)
The language generated by CFG is called Context Free
Language (CFL).
Example:
∑= {a}
productions:
1. S aS
2. S^
Applying production (1) six times and then
production (2) once, the word aaaaaa is
generated as
•11
•12
S aS
aaS
aaaS
aaaaS
aaaaaS
aaaaaaS
aaaaaa^
= aaaaaa
⇒
⇒
⇒
⇒
⇒
⇒
⇒
Example continued …
It can be observed that prod (2)
generates ^, a can be generated
applying prod. (1) once and
then prod. (2), aa can be
generated applying prod. (1)
twice and then prod. (2) and so
on. This shows that the grammar
defines the language expressed
by a*
.
•13
Example
∑ = {a}
productions:
1. SSS
2. Sa
3. S^
This grammar also defines the language
expressed by a*
.
Note: It is to be noted that  is considered to be
non-terminal. It has a special status. If for a
certain non-terminal N, there may be a
production N. This simply means that N can be
deleted when it comes in the working string.
•14
Example
∑ = {a,b}
productions:
1. SX
2. SY
3. X^
4. YaY
5. YbY
6. Ya
7. Yb
•15
Example continued …
All words of this language are of
either X-type or of Y-type. i.e. while
generating a word the first
production used is SX or SY.
The words of X-type give only ,
while the words of Y-type are
words of finite strings of a’s or b’s or
both i.e. (a+b)+
. Thus the language
defined is expressed by (a+b)*
.
•16
Example
∑ = {a,b}
productions:
1. SaS
2. SbS
3. Sa
4. Sb
5. S^
This grammar also defines the language
expressed by (a+b)*
.
•17
Example
∑ = {a,b}
productions:
1. SXaaX
2. XaX
3. XbX
4. X^
This grammar defines the language
expressed by (a+b)*
aa(a+b)*
.
•18
Summing Up
Context Free Grammar, Terminals, non-terminals,
productions, CFG, context Free language, examples.
•19

More Related Content

PDF
Flat unit 3
PDF
CodeJugalbandi-Expression-Problem-HealthyCode-Magazine#Jan-2015-Issue
PPTX
Types of Language in Theory of Computation
PPTX
Deterministic context free grammars &non-deterministic
PPTX
Speech Recognition: Advanced Topics
PPT
SDL Trados: Two TMs for the Price of One
PDF
Introduction to the theory of computation
PPTX
2.1 & 2.2 grammar introduction – types of grammar
Flat unit 3
CodeJugalbandi-Expression-Problem-HealthyCode-Magazine#Jan-2015-Issue
Types of Language in Theory of Computation
Deterministic context free grammars &non-deterministic
Speech Recognition: Advanced Topics
SDL Trados: Two TMs for the Price of One
Introduction to the theory of computation
2.1 & 2.2 grammar introduction – types of grammar

What's hot (19)

PPT
PDF
Ch3 4 regular expression and grammar
PDF
Unit iii
PDF
Prefix and suffix of open gl
PDF
regular expressions (Regex)
PDF
Lecture: Regular Expressions and Regular Languages
PDF
Lecture 3 RE NFA DFA
PPTX
Unit v
PPT
Lecture 1,2
PPT
Data compression tech cs
PDF
Formal language & automata theory
PPTX
Materi 4 Regular Expression
PPTX
Regular expression (compiler)
PPT
POST’s CORRESPONDENCE PROBLEM
DOC
Chapter 2 2 1 1
PDF
Theory of Computation Lecture Notes
PDF
Koreanizer : Statistical Machine Translation based Ro-Ko Transliterator
PPT
Theory of Automata
Ch3 4 regular expression and grammar
Unit iii
Prefix and suffix of open gl
regular expressions (Regex)
Lecture: Regular Expressions and Regular Languages
Lecture 3 RE NFA DFA
Unit v
Lecture 1,2
Data compression tech cs
Formal language & automata theory
Materi 4 Regular Expression
Regular expression (compiler)
POST’s CORRESPONDENCE PROBLEM
Chapter 2 2 1 1
Theory of Computation Lecture Notes
Koreanizer : Statistical Machine Translation based Ro-Ko Transliterator
Theory of Automata
Ad

Similar to Cfg part i (20)

PPTX
Conteext-free Grammer
PPTX
TOA_WEEK 14.pptx
PPT
Cfg part ii
PDF
Syntax Analyzer.pdf
PPTX
Context free grammar
PPTX
ContextFreeGrammars (1).pptx
PPTX
ContextFreeGrammars.pptx
PPT
Theory of computing
DOCX
Context Free Grammer .docx
PPTX
AUTOMATA AUTOMATA AUTOMATA Automata6Chapter5.pptx
PPTX
Automata theory - CFG and normal forms
PPTX
CFG to CNF
PPTX
CS911-Lecture-21_43709.pptx
PPT
Context Free Languages by S.Mandal-1.ppt
PDF
contextfreegrammars-120925004035-phpapp02.pdf
PPT
Context free grammer.ppt
PPT
context-freelanguages and properties lecture note.ppt
PPT
2. context free langauages
PPTX
Automata and Language Theory-Context Free Grammars
PDF
Regular Language and Regular Grammar Lecture
Conteext-free Grammer
TOA_WEEK 14.pptx
Cfg part ii
Syntax Analyzer.pdf
Context free grammar
ContextFreeGrammars (1).pptx
ContextFreeGrammars.pptx
Theory of computing
Context Free Grammer .docx
AUTOMATA AUTOMATA AUTOMATA Automata6Chapter5.pptx
Automata theory - CFG and normal forms
CFG to CNF
CS911-Lecture-21_43709.pptx
Context Free Languages by S.Mandal-1.ppt
contextfreegrammars-120925004035-phpapp02.pdf
Context free grammer.ppt
context-freelanguages and properties lecture note.ppt
2. context free langauages
Automata and Language Theory-Context Free Grammars
Regular Language and Regular Grammar Lecture
Ad

Recently uploaded (20)

PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
IGGE1 Understanding the Self1234567891011
PDF
My India Quiz Book_20210205121199924.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
1_English_Language_Set_2.pdf probationary
PPTX
Computer Architecture Input Output Memory.pptx
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
20th Century Theater, Methods, History.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PPTX
Introduction to Building Materials
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
Hazard Identification & Risk Assessment .pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
IGGE1 Understanding the Self1234567891011
My India Quiz Book_20210205121199924.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Introduction to pro and eukaryotes and differences.pptx
1_English_Language_Set_2.pdf probationary
Computer Architecture Input Output Memory.pptx
History, Philosophy and sociology of education (1).pptx
20th Century Theater, Methods, History.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
AI-driven educational solutions for real-life interventions in the Philippine...
Chinmaya Tiranga quiz Grand Finale.pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
B.Sc. DS Unit 2 Software Engineering.pptx
Introduction to Building Materials
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Hazard Identification & Risk Assessment .pdf
Weekly quiz Compilation Jan -July 25.pdf

Cfg part i

  • 1. Recap Applications of minimum edit distance, calculating minimum edit distance. •1
  • 2. Today’s Agenda  Context Free Grammar,  Terminals,  non-terminals,  productions,  CFG,  context Free language,  examples. •2
  • 3. Context Free Grammar (CFG) The earliest computers accepted no instructions other then their own assembly language. Every procedure, no matter how complicated , had to be encoded in the set of instructions, LOAD, STORE, ADD the contents of two registers and so on. The major problem was to display mathematical formulas as follows •3 2 )1011()107()08( 222 −+−+− =S or
  • 4. CFG continued … So, it was necessary to develop a way of writing such expressions in one line of standard typewriter symbols, so that in this way a high level language could be invented. Before the invention of computers, no one would ever have dreamed of writing such complicated formula in parentheses e.g. the right side of formula can be written as ((1/2)+9)/(4+(8/21)+(5/(3+(1/2)))) •4 2 1 3 5 21 8 4 9 2 1 + ++ + =A
  • 5. CFG continued … The high level language is converted into assembly language codes by a program called compiler. The compiler that takes the user’s programs as its inputs and prints out an equivalent program written in assembly language. Like spoken languages, high level languages for computer have also, certain grammar. But in case of computers, the grammatical rules, don’t involve the meaning of the words. •5
  • 6. CFG continued … It can be noted that the grammatical rules which involve the meaning of words are called Semantics, while those don’t involve the meaning of the words are called Syntactics. e.g. in English language, it can not be written “ Buildings sing ”, while in computer language one number is as good as another. e.g. X = B + 10, X = B + 999 Following is a remark •6
  • 7. Remark In general, the rules of computer language grammar, are all syntactic and not semantic. A law of grammar is in reality a suggestion for possible substitutions. •7
  • 8. CFG terminologies Terminals: The symbols that can’t be replaced by anything are called terminals. Non-Terminals: The symbols that must be replaced by other things are called non-terminals. Productions: The grammatical rules are often called productions. •8
  • 9. CFG CFG is a collection of the followings 1. An alphabet ∑ of letters called terminals from which the strings are formed, that will be the words of the language. 2. A set of symbols called non-terminals, one of which is S, stands for “start here”. 3. A finite set of productions of the form A Non-terminal  finite string of terminals and /or non-terminals. Following is a note in this regard •9
  • 10. Note The terminals are designated by small letters, while the non-terminals are designated by capital letters. There is at least one production that has the non- terminal S as its left side. •10
  • 11. Context Free Language (CFL) The language generated by CFG is called Context Free Language (CFL). Example: ∑= {a} productions: 1. S aS 2. S^ Applying production (1) six times and then production (2) once, the word aaaaaa is generated as •11
  • 13. Example continued … It can be observed that prod (2) generates ^, a can be generated applying prod. (1) once and then prod. (2), aa can be generated applying prod. (1) twice and then prod. (2) and so on. This shows that the grammar defines the language expressed by a* . •13
  • 14. Example ∑ = {a} productions: 1. SSS 2. Sa 3. S^ This grammar also defines the language expressed by a* . Note: It is to be noted that  is considered to be non-terminal. It has a special status. If for a certain non-terminal N, there may be a production N. This simply means that N can be deleted when it comes in the working string. •14
  • 15. Example ∑ = {a,b} productions: 1. SX 2. SY 3. X^ 4. YaY 5. YbY 6. Ya 7. Yb •15
  • 16. Example continued … All words of this language are of either X-type or of Y-type. i.e. while generating a word the first production used is SX or SY. The words of X-type give only , while the words of Y-type are words of finite strings of a’s or b’s or both i.e. (a+b)+ . Thus the language defined is expressed by (a+b)* . •16
  • 17. Example ∑ = {a,b} productions: 1. SaS 2. SbS 3. Sa 4. Sb 5. S^ This grammar also defines the language expressed by (a+b)* . •17
  • 18. Example ∑ = {a,b} productions: 1. SXaaX 2. XaX 3. XbX 4. X^ This grammar defines the language expressed by (a+b)* aa(a+b)* . •18
  • 19. Summing Up Context Free Grammar, Terminals, non-terminals, productions, CFG, context Free language, examples. •19