





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
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 specifc 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 ⇒ 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 ⇒ E Op E ⇒ E Op int ⇒ int Op int ⇒ int / int
● In today’s slides, capital letters in Bold Red Uppercase will represent nonterminals. ● e.g. A , B , C , D ● Lowercase letters in blue monospace will represent terminals. ● e.g. t , u , v , w ● Lowercase Greek letters in gray italics will represent arbitrary strings of terminals and nonterminals. ● (^) e.g. α , γ , ω ● You don't need to use these conventions on your own; just make sure whatever you do is readable. ☺
E → int | E Op E | (E) Op → + | - | * | /
● If G is a CFG with alphabet Σ and start symbol S , then the language of G is the set ℒ ( G ) = { ω ∈ Σ* | S ⇒
ω } ● That is, ℒ( G ) is the set of strings of terminals derivable from the start symbol.
Answer at PollEv.com/cs103 or text CS103 to 22333 once to join, then a number. Answer at PollEv.com/cs103 or text CS103 to 22333 once to join, then a number.
How many of the following strings are in ℒ( G )?
How many of the following strings are in ℒ( G )?
If G is a CFG with alphabet Σ and start symbol S , then the language of G is the set ℒ( G ) = { ω ∈ Σ* | S ⇒* ω } If G is a CFG with alphabet Σ and start symbol S , then the language of G is the set ℒ( G ) = { ω ∈ Σ* | S ⇒* ω }
● CFGs consist purely of production rules of the form A → ω. They do not have the regular expression operators * or ∪. ● However, we can convert regular expressions to CFGs as follows: S → ab*
● CFGs consist purely of production rules of the form A → ω. They do not have the regular expression operators * or ∪. ● However, we can convert regular expressions to CFGs as follows: S → Ab A → Aa | ε
● CFGs consist purely of production rules of the form A → ω. They do not have the regular expression operators * or ∪. ● However, we can convert regular expressions to CFGs as follows: S → aX X → b | C C → Cc | ε
● Theorem: Every regular language is context-free. ● Proof Idea: Use the construction from the previous slides to convert a regular expression for L into a CFG for L. ■ ● Problem Set 8 Exercise: Instead, show how to convert a DFA/NFA into a CFG.
Regular Languages CFLs All Languages
● Why do CFGs have more power than regular expressions? ● Intuition: Derivations of strings have unbounded “memory.” S → aSb | ε