I would like to construct a LL(1) context-free grammar for a formal language $A$ = "strings where the amount of character b
is exactly triple compared to the amount of character a
" for $\Sigma = \{a,b\}$.
I've tried to figure it out so that if we consider a string $w$ to have one a
, then the acceptable presentations for $w$ considering language $A$ would be abbb
, babb
, bbab
and bbba
.
But how do I build the CFG rules for that? I have tried something like $$S \rightarrow A$$ $$A \rightarrow \epsilon | aAbbb |baAbb | bbaAb | bbbaA$$ but I think it's not very good because at least I cannot build an LL(1)-parser out of it (which would be good) because of ambiguity. And it doesn't quite work out for a string like bbbbbbaa $\in A$.
Is it possible to build a CFG for this language that can be parsed using a LL(1) parser? If not, why not?