-2

It is possible to write an algorithm that generates a CFG that parses a list of words, with maxim m rules, or if it is imposible to parse all words, to parse maximum words possible? Do you have any ideas about how should I start the algorithm? All input words will be in the [a-z] alphabet.

tairqammar
  • 151
  • 3
  • 10

1 Answers1

1

It is definitely possible to write such an algorithm. Without going through the details, you can enumerate all possible CFGs (unique up to renaming of the nonterminals) with m or fewer rules over the desired alphabet, and check each one to see whether it accepts your strings. If you do this in order of number of rules, you will stop on the first smallest CFG that works, if any. To see whether a CFG works, you can roll your own or derive a PDA from the CFG and then run the PDA on all inputs to see whether it accepts them. There are algorithms to generate PDA parsers from CFGs which you should be able to use.

This process is not particularly efficient but it is effective and suffices to show that it is possible.

Patrick87
  • 27,682
  • 3
  • 38
  • 73