Professional Documents
Culture Documents
Computation Theory CS 323: Context-Free Languages
Computation Theory CS 323: Context-Free Languages
CS 323
CONTEXT- FREE
LANGUAGES
Dr.Nesreen Alsharman
Context Free Grammar
Example
2
Context Free Grammar
Example
3
DESIGNING CONTEXT-FREE
GRAMMARS
4
AMBIGUITY
• If a grammar generates the same string in
several different ways, we say that the string is
derived ambiguously in that grammar.
• If a grammar generates some string
ambiguously, we say that the grammar is
ambiguous.
5
AMBIGUITY
• A derivation of a string w in a grammar G is a
leftmost derivation if
– at every step the leftmost remaining variable is
the one replaced.
6
AMBIGUITY
• Sometimes when we have an ambiguous
grammar we can find an unambiguous
grammar that generates the same language.
• Some context-free languages, however, can be
generated only by ambiguous grammars.
• Such languages are called inherently
ambiguous.
7
CHOMSKY NORMAL FORM
8
CHOMSKY NORMAL FORM
9
CHOMSKY NORMAL FORM
11
2.2 PUSHDOWN AUTOMATA
13
PUSHDOWN AUTOMATA
14
PUSHDOWN AUTOMATA
16
How it works
• A PDA that recognizes this language
17
PUSHDOWN AUTOMATA
19
EXAMPLES OF PUSHDOWN
AUTOMATA
20
EXAMPLES OF PUSHDOWN
AUTOMATA
21
EXAMPLES OF PUSHDOWN
AUTOMATA
22
EXAMPLES OF PUSHDOWN
AUTOMATA
23
EXAMPLES OF PUSHDOWN
AUTOMATA
24
guesses of NPDA
There are three "guesses" that the NPDA makes:
it guesses that the string is an even-length palindrome
when it guesses e e/e, where e is used in place of
lambda.
it guesses that the string is an odd-length palindrome
with a in between the two halves when it guesses a e/e,
where e is used in place of lambda
it guesses that the string is an odd-length palindrome
with b in between the two halves when it guesses b e/e,
where e is used in place of lambda