Hints To Help You Write The Program

  1. I advise you to use the C++ string data type. (You need to include <string>)

  2. A good way to program the main loop is to declare a string variable (say you call it testStr) and then make cin>>testStr the loop condition. That will take care of doing the input and the testing for end of input. (Remember you "simulate end of file" by doing a ctrl-D from the keyboard.)

  3. The main loop should repeatedly read a string and call a (recursive) function to test the string. I would write a Boolean function (isExpr would be a good name) that returns true if the input is an expression, otherwise false.

  4. Basically isExpr should be written to implement the grammar rules I gave you - If the string is "Good" it's an expression, otherwise if it starts with "Good" and the rest of it is an expression (as indicated by a recursive call to isExpr) then it's an expression, otherwise if it's a name it's an expression, and if none of the above is true the string is not an expression.

  5. You can implement that logic with some if-else language. You can use the substr method of the string class to isolate substrings like the first four characters of the input string and the part of the string that comes after the first four characters. Substr is explained in Appendix A (A33-A34).

  6. IsExpr may have to treat strings that have less than four characters as special cases.

  7. I'd write a separate Boolean function (say you call it isName) to test a string to see if it is a name. The problem of writing isName is similar to the problem of writing isExpr - adapt.