I have the following CFG,
$S \rightarrow CB$
$C \rightarrow aCa \text{ }|\text{ } bCb \text{ }|\text{ } \text{#}B$
$B \rightarrow AB \text{ }|\text{ } \varepsilon$
$A \rightarrow a\text{ }|\text{ }b$
This is the CFG for the following language:
$$L= \left\{w \text{#} x\mid w^R \text{ is a substring of }\ x \text{, where } x,w\in \{a, b\}^*\right \}$$
I have a problem with constructing PDA for this CFG.
My attempt
My idea was to store characters in stack until "#" character, then as soon as the sequence of reversed characters go, pop from the stack. If at the end of input stack is empty, then we are done.
The problem is that for the following string, for example:
abbaa#aabbbbbbb(aabba)bbbbbb
when we read characters after "#", PDA will pop 4 characters, the it will see that the sequence is not valid and proceed with input. How can I return these 4 characters back so that I can check sequence again because I need full stack to proceed with accepted reversed substring that I have showed in brackets?