Write a class called RandomArithmeticExpression that forms a randomly generated expression that follows the rules listed in the grammar shown below. Your code will be tested by RandomArithmeticGenerator, which is available on Site to get you started.
Grammar:
The initial expression is S. The non-terminal expressions are S and E. The values x, y, and z are terminals, that is, they cannot be replaced by any other symbol. An expression appearing on the left of a --> may be replaced by any expression of the right of that arrow as shown below.
S --> E
E --> E + E
E --> E – E
E --> E * E
E --> E / E
E --> ( E )
E --> x | y | z
For example, a derivation might be:
S --> E --> E + E --> E + ( E ) --> E * E + ( E ) --> x * E +( E ) --> x * E – E +( E ) --> x * E – E +( z ) --> x * E – z +( z ) --> x * y – z +( z )
Here are four randomly generated expressions:
( x + ( x + z / y + z / x * z / y * z / y ) - y - y / x ) x * ( ( y * ( x * y * y * y ) * y / z * z + x ) / x ) ( z ) y / y * y - x * z / ( x ) + x - z - z
Here is the test driver code: See image.