Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Theory of Computation  >  PPT: Context-Free Languages & Grammars

PPT: Context-Free Languages & Grammars | Theory of Computation - Computer Science Engineering (CSE) PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


1
Context-Free Languages &
Grammars
(CFLs & CFGs)
Page 2


1
Context-Free Languages &
Grammars
(CFLs & CFGs)
Not all languages are regular
n So what happens to the languages
which are not regular?
n Can we still come up with a language
recognizer?
n i.e., something that will accept (or reject)
strings that belong (or do not belong) to the
language?
2
Page 3


1
Context-Free Languages &
Grammars
(CFLs & CFGs)
Not all languages are regular
n So what happens to the languages
which are not regular?
n Can we still come up with a language
recognizer?
n i.e., something that will accept (or reject)
strings that belong (or do not belong) to the
language?
2 3
Context-Free Languages
n A language class larger than the class of regular
languages
n Supports natural, recursive notation called “context-
free grammar”
n Applications:
n Parse trees, compilers
n XML
Regular
(FA/RE)
Context-
free
(PDA/CFG)
Page 4


1
Context-Free Languages &
Grammars
(CFLs & CFGs)
Not all languages are regular
n So what happens to the languages
which are not regular?
n Can we still come up with a language
recognizer?
n i.e., something that will accept (or reject)
strings that belong (or do not belong) to the
language?
2 3
Context-Free Languages
n A language class larger than the class of regular
languages
n Supports natural, recursive notation called “context-
free grammar”
n Applications:
n Parse trees, compilers
n XML
Regular
(FA/RE)
Context-
free
(PDA/CFG)
4
An Example
n A palindrome is a word that reads identical from both
ends
n E.g., madam, redivider, malayalam, 010010010
n Let L = { w  | w is a binary palindrome}
n Is L regular?
n No.
n Proof:
n Let w=0
N
10
N (assuming N to be the p/l constant)
n By Pumping lemma, w can be rewritten as xyz, such that xy
k
z is also L
(for any k =0)
n But |xy| =N and y ? e
n ==> y=0
+
n ==> xy
k
z will NOT be in L for k=0
n ==> Contradiction
Page 5


1
Context-Free Languages &
Grammars
(CFLs & CFGs)
Not all languages are regular
n So what happens to the languages
which are not regular?
n Can we still come up with a language
recognizer?
n i.e., something that will accept (or reject)
strings that belong (or do not belong) to the
language?
2 3
Context-Free Languages
n A language class larger than the class of regular
languages
n Supports natural, recursive notation called “context-
free grammar”
n Applications:
n Parse trees, compilers
n XML
Regular
(FA/RE)
Context-
free
(PDA/CFG)
4
An Example
n A palindrome is a word that reads identical from both
ends
n E.g., madam, redivider, malayalam, 010010010
n Let L = { w  | w is a binary palindrome}
n Is L regular?
n No.
n Proof:
n Let w=0
N
10
N (assuming N to be the p/l constant)
n By Pumping lemma, w can be rewritten as xyz, such that xy
k
z is also L
(for any k =0)
n But |xy| =N and y ? e
n ==> y=0
+
n ==> xy
k
z will NOT be in L for k=0
n ==> Contradiction
5
But the language of
palindromes…
is a CFL, because it supports recursive
substitution (in the form of a CFG)
n This is because we can construct a
“grammar” like this:
1. A ==> e
2. A ==> 0
3. A ==> 1
4. A ==> 0A0
5. A ==> 1A1
Terminal
Productions
Variable or non-terminal
How does this grammar work?
Same as:
A => 0A0 | 1A1 |  0 | 1 | e
Read More
18 videos|69 docs|44 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on PPT: Context-Free Languages & Grammars - Theory of Computation - Computer Science Engineering (CSE)

1. What is a context-free language?
Ans. A context-free language is a type of formal language that can be generated by a context-free grammar. It is a set of strings composed of terminal symbols, non-terminal symbols, and production rules that define how the non-terminal symbols can be replaced by strings of terminal and non-terminal symbols.
2. What is a context-free grammar?
Ans. A context-free grammar is a formal way to describe the syntax of a context-free language. It consists of a set of production rules that define how symbols can be replaced in a given language. Each production rule has a left-hand side, which contains a single non-terminal symbol, and a right-hand side, which contains a sequence of symbols.
3. How are context-free languages different from regular languages?
Ans. Context-free languages are more expressive than regular languages. While regular languages can be described using regular expressions or finite automata, context-free languages require more powerful tools such as context-free grammars or pushdown automata. Context-free languages can handle nested structures, such as matching parentheses, which regular languages cannot.
4. What are some examples of context-free languages?
Ans. Some examples of context-free languages include: - The language of well-formed arithmetic expressions, where parentheses are properly balanced. - The language of nested HTML tags, where opening and closing tags are properly nested. - The language of balanced parentheses, where every opening parenthesis has a corresponding closing parenthesis.
5. How are context-free languages used in computer science and engineering?
Ans. Context-free languages and grammars are widely used in various areas of computer science and engineering. They are used in programming language design and parsing, where context-free grammars are used to define the syntax of programming languages. They are also used in compiler construction, where context-free grammars are used to analyze and transform source code. Additionally, context-free languages are used in natural language processing, where they help in understanding and generating human language.
18 videos|69 docs|44 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

PPT: Context-Free Languages & Grammars | Theory of Computation - Computer Science Engineering (CSE)

,

Viva Questions

,

Sample Paper

,

pdf

,

past year papers

,

shortcuts and tricks

,

practice quizzes

,

Exam

,

mock tests for examination

,

MCQs

,

Semester Notes

,

study material

,

Free

,

video lectures

,

ppt

,

PPT: Context-Free Languages & Grammars | Theory of Computation - Computer Science Engineering (CSE)

,

Important questions

,

Summary

,

Objective type Questions

,

PPT: Context-Free Languages & Grammars | Theory of Computation - Computer Science Engineering (CSE)

,

Extra Questions

,

Previous Year Questions with Solutions

;