Does there exist an algorithm to generate the production rules of CFG, given a sample production? Lets say, we provide the algorithm a set of tokens.

e.g.

x + y - z
x - x - x


It will then try to generate a CFG which fits all the provided examples

S -&gt; S O T | T
T -&gt; x | y | z
O -&gt; + | -


It feels like a data compression problem but I could be wrong.

Does anybody know any existing literature or a starting point to solve this problem?

Does this problem have a name? What should I Google?
Any interesting grammar will generate an infinite language. There is always the trivial grammar with a start symbol that generates each example string on it's own. Checking if two grammars generate the same language, and thus in any sense finding "the smallest" (or whatever other measure you care about) grammar for a language is unsolvable. Inferring the grammar (in any meaningful sense) is probably impossible.