





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Context-free grammars (CFGs) and their relation to regular languages. It describes how CFGs are used to describe languages and how they can be used to describe arithmetic expressions. The document also explains CFG notation, derivations, and the language of a grammar. It then goes on to explain how regular expressions can be converted to CFGs and how every regular language is context-free. The document ends with a problem set and tips for designing CFGs.
Typology: Lecture notes
1 / 45
This page cannot be seen from the preview
Don't miss anything!






































โ (^) We've seen two models for the regular languages: โ (^) Finite automata accept precisely the strings in the language. โ (^) Regular expressions describe precisely the strings in the language. โ Finite automata recognize strings in the language. โ (^) Perform a computation to determine whether a specific string is in the language. โ (^) Regular expressions match strings in the language. โ (^) Describe the general shape of all strings in the language.
โ (^) Suppose we want to describe all legal arithmetic expressions using addition, subtraction, multiplication, and division. โ (^) Here is one possible CFG: E โ int E โ E Op E E โ (E) Op โ + Op โ - Op โ *** Op** โ /
โ E Op E โ E Op (E) โ E Op (E Op E) โ E * (E Op E) โ int * (E Op E) โ int * (int Op E) โ int * (int Op int) โ int * (int + int)
โ (^) Suppose we want to describe all legal arithmetic expressions using addition, subtraction, multiplication, and division. โ (^) Here is one possible CFG: E โ int E โ E Op E E โ (E) Op โ + Op โ - Op โ *** Op** โ /
โ E Op E โ E Op int โ int Op int โ int / int
โ
โ i.e. A , B , C , D โ
โ (^) i.e. t , u , v , w โ
โ i.e. ฮฑ , ฮณ , ฯ
E โ int E โ E Op E E โ (E) Op โ + Op โ - Op โ *** Op** โ /
โ E โ E Op E โ E Op (E) โ E Op (E Op E) โ E * (E Op E) โ int * (E Op E) โ int * (int Op E) โ int * (int Op int) โ int * (int + int) โ A sequence of steps where nonterminals are replaced by the right-hand side of a production is called a derivation. โ If string ฮฑ derives string ฯ , we write ฮฑ โ
ฯ. โ In the example on the left, we see E โ
int * (int + int). E โ E Op E | int | ( E ) Op โ + | ***** | - | /
โ
โ
โ
โ
โ
S โ ab*
โ
โ
S โ Ab A โ Aa | ฮต
โ
โ
S โ aX X โ b | C C โ Cc | ฮต
โ
โ
โ
Regular Languages CFLs All Languages
โ
โ
a a a a b b b b