In this project, read a CFG from a txt file, simplify it by removing ε-rules and useless rules, and print out the simplified equivalent CFG. No need to care or remove unit-rules. For example, given the following CFG in a txt file (0 denotes empty string and "-" denotes arrow head "→"): S-aA|aBB A-aaA|0 B-bB|bbC C-B After processing, your program should print out the following simplified equivalent CFG: S-aA|a A-aaA|aa The following are a few more examples you can use to test your program (I highly recommend that you come up with more examples to make sure the correctness of your program): (1) S-AaBaCbD A-0|a B-0|b C-0|c D-0|d For the above CFG, the print out should be S-aab|Aaab|aBab|AaBab|aaCb|AaaCb|aBaCb|AaBaCb|aabD|AaabD|aBabD|AaBabD|aaCbD|AaaCbD|aBaCbD|AaBaCbD A-a B-b C-c D-d (2) S-AaB|aaB A-0 B-baA|0 For the above CFG, the print out should be S-aB|aaB|a|aa B-ba (3) S-ASA|aB A-B|S B-b|0 For the above part of the transition table of a NFA, the print out should be S-ASA|aB|a|SA|AS A-B|S B-b Note that your program must be able to work for any CFG, not only just for the above given examples.
(2) S-AaB|aaB A-0 B-baA|0 For the above CFG, the print out should be S-aB|aaB|a|aa B-ba (3) S-ASA|aB A-B|S B-b|0 For the above part of the transition table of a NFA, the print out should be S-ASA|aB|a|SA|AS A-B|S B-b Note that your program must be able to work for any CFG, not only just for the above given examples.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)