CSE 105
THEORY OF COMPUTATION
Fall 2016 http://cseweb.ucsd.edu/classes/fa16/cse105-abc/
CSE 105 THEORY OF COMPUTATION Fall 2016 - - PowerPoint PPT Presentation
CSE 105 THEORY OF COMPUTATION Fall 2016 http://cseweb.ucsd.edu/classes/fa16/cse105-abc/ Today's learning goals Sipser Ch 1.4, 2.1 Non-regular languages Define context-free grammars Test if a specific string can be generated by a
Fall 2016 http://cseweb.ucsd.edu/classes/fa16/cse105-abc/
Sipser Ch 1.4, 2.1
context-free grammar
Sipser Def 2.2, page 102
(V, Σ, R, S) Variables: finite set of (usually upper case) variables V Terminals: finite set of alphabet symbols Σ Rules / Productions: finite set of allowed moves R Start variable: S
Notation: S ⇒* w Terminology: sequence of rule applications is derivation Notation: S ⇒* w Terminology: sequence of rule applications is derivation
Sipser p. 104
The language of a CFG (V, Σ, R, S) is { w in Σ* | Starting with the Start variable and applying zero or more rules, can get to w}
1) S → 0S1 2) S → ε
– S → 0S1 → 00S11 → 000S111 → 000111
Consider the CFG ({S}, {0}, R, S) where R is the following set of rules S →0S S →0 Is this a well-formed defjnition?
Sipser p. 104
The language of a CFG (V, Σ, R, S) is { w in Σ* | Starting with the Start variable and applying zero or more rules, can get to w} What is the language of the CFG ({S}, {0}, R, S) with R = {S→0S, S→0} ?
Sipser p. 104
What is the language of the CFG ({S}, {0,1}, R, S) with R = the set of rules S →0S S→1S S→ε
S → 0S | 1S | ε S → 0S | 1S | ε
Sipser p. 104
What is the language of the CFG ({S}, {0,1}, R, S) with R = the set of rules S → 0S | T T → 1T | ε
Sipser p. 104
What is the language of the CFG ({S}, {0,1}, R, S) with R = the set of rules S → 0S | T T → 1T | S
computational model?
closed under union, concatenation, star, intersection, complement?
a CFG?
S → S+S | S*S | S^N | N N → D | DN D → 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
–
S → DN → 1N → 1DN→ 12N→ 12D → 123
–
S → S+S → 1+S → 1+S*S →* 1+2*S →* 1+2*3
S S + S 1 S * S 2 3
S S + S 1 S * S 2 3
S S + 3 1 + 2 S 1 + S 2 + 3
S S + 3 1 + 2 S 1 + S 2 + 3 (1+2)+3 1+(2+3)
S S * 3 1 + 2 S 1 + S 2 * 3 (1+2)*3 = 9 1+(2*3) = 7
unique parse tree (or, equivalently, a unique leftmost derivation)
such that w has two difgerent parse trees (or, equivalently, two difgerent leftmost derivations)
S → S+S | S*S | 0 | 1 A) Yes B) No C) It depends on the input string D) There is no answer because the question is ambiguous E) I don’t know
language of arithmetic expressions?