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 an example of each statement.
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.
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 an example of each statement.
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 presumably 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 the stack to determine if the constructs are syntactically correct.
Comments
Post a Comment