Context-free grammars (CFGs)
10/9/19 (Using slides adapted from the book)
Context-free grammars (CFGs) 10/9/19 (Using slides adapted from the - - PowerPoint PPT Presentation
Context-free grammars (CFGs) 10/9/19 (Using slides adapted from the book) Administrivia HW 4 (proving languages are non-regular) due Friday at 4:30 Midterm out Friday night No class on Monday Multi-day take home Open book,
10/9/19 (Using slides adapted from the book)
1.Proof is by contradiction using the pumping lemma for regular
holds for L. Let k be as given by the pumping lemma. 2.Choose x, y, and z as follows: x = ak y = bk z = ε Now xyz = akbk ∈ L and |y| ≥ k as required. 3 Let u, v, and w be as given by the pumping lemma, so that uvw = y, |v| > 0, and for all i ≥ 0, xuviwz ∈ L. 4 Choose i = 2. Since v contains at least one b and nothing but bs, uv2w has more bs than uvw. So xuv2wz has more bs than as, and so xuv2wz ∉ L. 5 By contradiction, L = {anbn} is not regular.
have grammars
rather restricted form…
production has a single nonterminal symbol on the left-hand side
y, regardless of the context of symbols around R in the string
says that R can be replaced with y only in a specific context
potentially infinite collection of runtime behaviors
executes
potentially infinite language
derivations of terminal strings
muscles
L = {x ∈ {0,1}* | the number of 0s in x is divisible by 3} S → 1S | 0T | ε T → 1T | 0U U → 1U | 0S
manually:
L = {x ∈ {0,1}* | the number of 0s in x is divisible by 3} S → 1S | 0T | ε T → 1T | 0U U → 1U | 0S S → T0T0T0S | T T → 1T | ε
side
S → aSb | ε S → aSa | bSb | ε S → aSa | R R → bR | b
S → aSbbb | ε S → XSY | ε X → a | b Y → c | d
(either c or d)
from the second
S1 → aS1b | ε S2 → cS2d | ε S → S1S2 S1 → aS1b | ε S2 → cS2d | ε
for L1 and L2
nonterminal is used in both
two sub-grammars, plus a new start symbol S with the production S → S1S2
languages L = L1 ∪ L2
for L1 and L2
nonterminal is used in both
two sub-grammars, plus a new start symbol S with the production S → S1 | S2
L = {z ∈ {a,b}* | z = xxR for some x, or |z| is odd}
S1 → aS1a | bS1b | ε S2 → XXS2 | X X → a | b S → S1 | S2 S1 → aS1a | bS1b | ε S2 → XXS2 | X X → a | b
concatenation:
L = {anbm | n ≠ m}
S → S1S2 | S3S1 S1 → aS1b | ε S2 → bS2 | b S3 → aS3 | a
languages (Algol), 1959-1963
instead of E
was developed independently
<exp> ::= <exp> - <exp> | <exp> * <exp> | <exp> = <exp> | <exp> < <exp> | (<exp>) | a | b | c
c = c * a; a = a + a; }
include hundreds of productions
<stmt> ::= <exp-stmt> | <while-stmt> | <compound-stmt> |... <exp-stmt> ::= <exp> ; <while-stmt> ::= while ( <exp> ) <stmt> <compound-stmt> ::= { <stmt-list> } <stmt-list> ::= <stmt> <stmt-list> | <empty>
syntactic way
x says that the symbols in x may be added as children of the nonterminal symbol R
<exp> ⇒ <exp> * <exp> ⇒ <exp> - <exp> * <exp> ⇒ a- <exp> * <exp> ⇒ a-b* <exp> ⇒ a-b*c <exp> ::= <exp> - <exp> | <exp> * <exp> | <exp> = <exp> | <exp> < <exp> | (<exp>) | a | b | c