Programming Languages - Reviewer
Programming Languages - Reviewer
4 Sets
V – Variables
Σ – Terminals
P or R – Production or Rules
S – Start Variable/Symbol
A -> x
Comment:
A is a variable
X is any combo of terminals and variables.
Problem 1:
Want: 0011
Note:
S => AB
Note:
Problem 3:
S => ɛ
Note:
Questions:
Problem 4:
L = (0 U 1)*
Solution:
G = {(S), (), (S -> ɛ | S0 | S1)}
Answer: The created CFG can be empty, starts with 0 or 1, and ends with 0 or 1.
Problem 5:
Note:
Solution:
Want = 001
Problem 6:
Note:
If you see 1 at the beginning then the end must be 1, same with 0.
La = L 1 U L 2
Lb = L 1 • L2
Lc = L 1*
Note:
Answer:
La = S -> S1 | S2
Lb = S -> S1S2
Lc = S -> ɛ | S1S
Problem 8:
L = { aibjck : i != j }
G = {(S, Ai<j, Ai>j B, C, X), (a,b,c), (S -> Ai<jC | Ai>jC, Ai<j -> aAi<jb | bB, B -> bB | ɛ, C -> cC | ɛ, Ai>j ->
aAi>jb | aX, X -> aX | ɛ)}
B -> bB | ɛ
C -> cC | ɛ
X -> aX | ɛ
Problem 9:
L = { 0n1m2m3n : n, m > 0 }
S -> 0S3 | X
X -> 1x2 | ɛ
Problem 10:
L = { 0n1n2m3m : n, m >= 0 }
S -> X1X2
X1 -> 0X11 | ɛ
X2 -> 2X23 | ɛ
Problem 11:
L = { non-palindromes over { 0, 1} }
X -> 0X | 1X | ɛ