5.1.18 Show that the language L = { w1cw2 : w1,w2 {a,b}+, w1 ≠ w2

Download Report

Transcript 5.1.18 Show that the language L = { w1cw2 : w1,w2 {a,b}+, w1 ≠ w2

5.1.18 Show that the language L = { w1cw2 : w1,w2  {a,b}+,
w1 ≠ w2R} , with Σ = { a,b,c }, is context-free.
w1 ≠ w2R :
1. |w1| ≠ |w2|
2. |w1| = |w2| , 但 w1 和 w2R 至少有一字元不同
1 的情形:
G=({S},{a,b,c},S,P)
S → aS1a | bS1b | aS1b | bS1a
S1 → aS1a | bS1b | aS1b | bS1a | S2a | aS3 | S2b | bS3
S2 → S2a | S2b | c
S3 → aS3 | bS3 | c
2 的情形:
G=({S},{a,b,c},S,P)
S → aSa | bSb | aS1b | bS1a
S1 → aS1a | bS1b | aS1b | bS1a | c
=> L 的 context-free grammar 為
G=({S},{a,b,c},S,P)
S → aS1a | bS1b | aS2b | bS2a
S1 → aS1a | bS1b | aS2b | bS2a | S3a | aS4 | S3b | bS4
S2 → aS2a | bS2b | aS2b | bS2a | S3 | S4
S3 → S3a | S3b | c
S4 → aS4 | bS4 | c
L 是 context-free
Spring 的想法
G=({S},{a,b,c},S,P)
S → aSa | bSb | aS1b | bS1a | aS1c | bS1c | cS1b | cS1a | C
S1 → aS1 | bS1 | cS2 | λ
C→a|b|c
L 是 context-free