It is probably best to have this conversation public, because if you solve the problem, then whoever reads this forum may benefit from that too - that's a purpose of the forum.
Besides, it would be much better if you could show what you already tried. Once you can show a practical problem, it's easier to tell you how to fix it. I still don't understand what exactly you are trying to do. Every non-trivial program reads input and writes output by some "rules", but this doesn't answer my question about what you want the program to do. The task implies you might have a grammar defined and you want to implement it in code, or, you may write a program, that given any grammar that fits the definition will generate the parser. Or you can process the product of the grammar, assuming it was written by some set of rules, which adhere to the definition of the grammar (this grammar is by definition reversible) and try to restore the set of rules used to generate the grammar. One more possibility is that you want to generate all grammar products for any given grammar if it is a simple precedence grammar (sounds a bit wasteful, but who knows...)