Question: Help with this java code please? In most programming languages, the compiler carries a preprocessing step to determine of certain statements will compile. For instance

Help with this java code please?

In most programming languages, the compiler carries a preprocessing step to determine of 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 will detected if certain Java constructs are syntactically correct. Table 1 shows the types of Java statement formats under consideration:

Construct

Example

Statement

data_type = expression

int x = 3 + (10 4) * ( 10 + 4)

Method

rt name()

{

}

public void display(int n)

{

int arr[ ] = new int[n];

System.out.println( x[2]);

}

class

class Name

{

dt fields;

Name( )

{

method ();

}

rt method()

{

}

}

public class MyParser

{

public static void main(String [ ] arg )

{

display (10);

}

static void display(int x)

{

/*

My pre-processor

*/

}

}

Table 2 shows the delimiters under consideration.

Table 2

Delimiters

Symbol

Left parenthesis

(

Right parenthesis

)

Left curly braces

{

Right curly braces

}

Left square brackets

[

Right square brackets

]

Forward slash

/

Star (multiplication symbol)

*

Note:

In your implementation, design a class called Preprocessor that accepts a string that represents the statement to be analyzed. The class will contain, among other possible methods, a method that determines whether or not the given statement is 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 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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!