Write a program that employs a recursive function to check a series of strings to see if they are well-formed expressions.
The program must read an arbitrary series of zero or more strings from standard input. Input strings are to be separated by white space. For example, you can enter them one per line. There is to be no other input to the program. The sample input illustrates the kind of input I will use to test your program.
The program must write all output to standard output. First the program must write a heading/greeting message. Next, for each input string, the program must go to a new line of the output, echo (write) the input string to standard output, go to a new line again, and print a message telling whether the string is a well-formed expression. Finally, after processing all the input, the program prints an exit message and stops. There is no other output. If you are entering input at the keyboard, the program should stop reading input when you enter the end-of-file characater (cntrl-d).
This script shows the output produced in response to the sample input file.
Discussion of Processing
The following rule defines a well-formed expression:
<expr> = S|I(C)T(<expr>)
Your solution to this problem must be “recursive” – it must use a recursive function to test the strings. Design the function to input a string and output ‘true’ or ‘false’ – telling whether or not the string is an expression.
In class, we can discuss solutions to some problems that are similar to this one. That should give you some useful ideas for writing your program. In your solution code, you may want to use the substr method of the string object.
We’ll have a discussion of testing requirements in class. Never assume that sample inputs I give you with an assignment represent everything you need to test to make sure your program is correct.
What To Turn In
I am not requiring you to turn in a preliminary version. One can solve this problem with a very small program. My solution has just two functions, including main. Do not start coding until you think of a simple algorithm. If you are considering a solution that is complicated, then you are not using the right approach. If you don’t think of a simple solution after the first day of working on it, ask me for help (please!). You can ask me privately if you want, but I do like to get some questions in class, so I can help more than one person at a time.
You will send me one e-mail message. Please follow these rules:
1.Send me attachments of your program as a .Java file.
2.Always use the exact subject line I specify for each message. (I often get hundreds of e-mail messages in a week. The subject line allows me to find, filter and sort messages.) You will lose a significant number of points on the assignment if you use the wrong subject line.
3.Make sure you have the correct subject line and filename.
4.Always send yourself a copy of each e-mail message you send to me, and check to see if you receive the message intact. You are responsible for sending e-mail correctly.
Here is the list of things you have to turn in.