Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.


What I have tried:

(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.
Posted
Updated 19-Apr-22 23:34pm

1 solution

The solution is that you design and implement a program to do it, as directed by your teacher. If you need help to understand that process then see How to Write Code to Solve a Problem, A Beginner's Guide[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900