Before(β)After(β) คือ CF ดังนั้น:
Before(L,β)={γ | ∃δ.γβδ∈L}
and
After(L,β)={γ | ∃δ.δβγ∈L}
are CF.
Proof? For Before(L,β) construct a non-deterministic finite-state transducer Tβ that scans a string, outputting every input symbol it sees and simultaneously searches non-deterministically for β. Whenever Tβ sees the first symbol of β it forks non-deterministically and ceases outputting symbols until either it finishes seeing β or it sees sees a symbol that deviates from β, stopping in either case. If Tβ sees β in full, it accepts upon stopping, which is the only way it accepts. If it sees a deviation from β, it rejects.
The lemma can be jiggered to handle cases where β could overlap with itself (like abab -- keep looking for β even while in the midst of scanning for a prior β) or appears multiple times (actually, the original non-determinisic forking already handles that).
It's fairly clear that Tβ(L)=Before(L,β), and since the CFLs are closed under finite-state transduction, Before(L,β) is therefore CF.
A similar argument goes for After(L,β), or it could be done with string reversals from Before(L,β) , CFLs also being closed under reversal:
After(L,β)=rev(Before(rev(L),rev(β)))
Actually, now that I see the reversal argument, it would be even easier to start with After(L,β), since the transducer for that is simpler to describe and verify -- it outputs the empty string while looking for a β. When it finds β it forks non-deterministically, one fork continuing to look for further copies of β, the other fork copying all subsequent characters verbatim from input to output, accepting all the while.
What remains is to make this work for sentential forms as well as CFLs. But that is pretty straightforward, since the language of sentential forms of a CFG is itself a CFL. You can show that by replacing every non-terminal X throughout G by say X′, declaring X to be a terminal, and adding all productions X′→X to the grammar.
I'll have to think about your question on unambiguity.