A Uniform Framework for Problems on Context-Free Grammars