In most programming languages, the compiler carries a preprocessing step to determine if certain statements will compile. For instance it may check to see if parentheses match.
Write a Java program that simulates the actions of a preprocessor, to detect if certain Java constructs are syntactically correct. Table 1 shows the types of Java statement formats under consideration, and also example of each statement.
Table 2 shows the delimiters under consideration. see image.
Note: In your implementation, design a class called Preprocessor that accepts a file that represents the program to be analyzed. The class will contain, among other possible methods, a method that determines whether or not the statement in the file are valid, with respect to the delimiters of Table
2. Do not be concerned with other symbols.
You will need a test class. You may want to name it MyPreprocessor.
You may have to enter all statements on a single line, unless you will be reading the input from a file, in which case the file would be read using presumable the class BufferedReader or LineNumberReader.
Your output would echo the input, and say whether or not the input passed the preprocessing stage.
You are to use the concept of stack to determine if the constructs are syntactically correct.
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.