Question: NOTE: DO NOT COPY AN ANSWER DIRECTLY FROM GOOGLE. THIS HAS HAPPENED TO ME FOUR TIMES SO FAR. I AM NOT LOOKING FOR A RANDOM
NOTE: DO NOT COPY AN ANSWER DIRECTLY FROM GOOGLE. THIS HAS HAPPENED TO ME FOUR TIMES SO FAR.
I AM NOT LOOKING FOR A RANDOM NUMBER GENERATOR. PLEASE READ THE ENTIRE QUESTION.
PLEASE - IF YOU ARE NOT GOING TO HELP, DO NOT POST SO THAT SOMEONE WHO IS WILLING TO CAN, I'VE ASKED THIS FOUR TIMES NOW.
The purpose of this exercise is to write a SYNTAX GENERATOR for a subset of the C++ programming language that will write random C++ programs to a file. By writing these random syntactically correct programs, you will further develop your understanding of the difference between syntax and semantics.
Consider the attached set of productions that define a subset of the C++ programming language:


Problem 1. Write a program in C, C++, C#, Java, or Python (your choice) that starts with the root non-terminal and generates a random syntactically correct C++ program using the productions defined above. You should follow the examples we saw in class where we expand non-terminals recursively until we obtain a sentence consisting of terminal tokens only. In the case where a production contains more than one expansion (i.e., right-hand-side expressions), your program should select one randomly (preferably with non-uniform weighting based on which expansions are more likely to occur in C++). Your program should write the random C++ code to an output file.
Here is the class that I am using:
class Production
{
private:
string lhs;
vector rhs_options; // list of options for expansion
vector trans_probs; // list of probabilities associated // with each choice
public:
Production();
Production(string);
void add_rhs(string, double); // adds new rhs to the production
string expand() const; // returns one of the rhs choices using
// a random number generator
};
In particular, I'm having trouble with the expand function and how to implement everything in my main function. The final product should create an output such as this (manually tabbed):
int main()
{
int F0Z = 0262;
if (22682 / 525)
double S1;
else
S = U;
while (8 - 594873)
{
while (97942 / 6871573097 * 7261055)
{
while (9307 * M / 4 / 2 + 4 - 7 / K)
{
double A;
}
}
}
return 0;
}
PLEASE NOTE (DO NOT SUBMIT UNTIL YOU'VE READ THIS): This assignment is NOT asking to output random numbers. Most of the answers on here for this question are just producing random numbers using srand - this is not what I'm asking for. I've already asked this several times and received such an answer. I've also received copy/pasted answers straight off google, so please don't bother. This program is supposed to create a syntactically correct C++ program. I don't need you to write the entire code, I just need some help getting in the right direction. I understand BNF grammar and parse trees, but have trouble translating that into code. Thank you
Edit: I received a comment saying "Need some Clarity of the question" but I'm not really sure how else I could be more clear? If you're going to ask to have more clarity, at least let me know what it is I could be more clear about.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
