Write a program to eliminate
-productions and unit
productions from a context-free grammar. (An
-production is a
production of the form
, and a unit production is
a production of the form
, where both A and B are
non-terminals). You can use any programming language available on CoC or
GIT machines. Please explain clearly how to compile and run the program.
The program has to read a CFG grammar, either from a file or from the standard input, then print the simplified CFG to the standard output. The format of the input/output grammars should be similar to the following example:
Input
TERMINALS: a b
VARIABLES: S A B
START: S
S -> ABS
S -> .
A -> a
A -> .
B -> b
B -> .
Output
TERMINALS: a b
VARIABLES: S1 S A B
START: S1
S1 -> .
S1 -> ABS
S1 -> AB
S1 -> AS
S1 -> BS
S1 -> a
S1 -> b
S -> ABS
S -> AB
S -> AS
S -> BS
S -> a
S -> b
A -> a
B -> b
Spaces that appear between symbols or whithin productions should be
ignored. The "." symbol is used to represent the empty string,
.
Note: The grade for the programming assignment will replace your lowest homework grade. You must turn it in by the last day of classes to receive credit.