subject

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 1

Format 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 public class MyParser

{ {

dt fields; public static void main(String [ ] arg)

Name() {

{ display (10);

method(); }

} 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 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.

1. You will need a test class. You may want to name it MyPreprocessor.

2. 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.

3. Your output would echo the input, and say whether or not the input passed the preprocessing stage.

4. You are to use the concept of stack to determine if the constructs are syntactically correct.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 23:30
To check spelling errors in a document, the word application uses the to determine appropriate spelling. internet built-in dictionary user-defined words other text in the document
Answers: 1
question
Computers and Technology, 22.06.2019 23:50
You need to design a circuit that implements the functions in the following table: s0 s1 function0 0 a + 10 1 a – b1 0 a + b1 1 a – 1s0 and s1 are 1-bit control inputs to select the function of the circuit. inputs a and b are 4-bitnumbers in 2s complement form. the output is also a 4-bit number in 2s complement form.you are allowed to use only one ttl 7483 4-bit adder to implement all the functions. but anynumber of other components (except the adder) can be used.hint: design a combinational logic circuit to modify the input b and the “carry input” of theadder depending on the control inputs s0 and s1.important: lab grade will depend on the working of the circuit & will be checked of by your labinstructor.1. is the output valid for the following input combinations: a. s0 = 0, s1 = 0, a = 7, b = 3? b. s0 = 0, s1 = 1, a = 7, b = 3? c. s0 = 1, s1 = 0, a = -4, b = -5? d. s0 = 1, s1 = 1, a = -8, b = 6? 2. what is the range of inputs (for both a and b) that will produce the valid output for all the functions?
Answers: 3
question
Computers and Technology, 23.06.2019 09:00
Before you record your own voice, you should a. record other people's voices b. warm up and practice difficult names c. listen to your favorite songs d. read a transcript of a good radio news segment
Answers: 1
question
Computers and Technology, 23.06.2019 16:10
What is the ooh? a. omaha occupation handbook b. online occupational c. occupations online d. occupational outlook handbook select the best answer from the choices provided
Answers: 3
You know the right answer?
In most programming languages, the compiler carries a preprocessing step to determine if certain sta...
Questions
question
Social Studies, 26.03.2020 02:01
question
Mathematics, 26.03.2020 02:01
question
Biology, 26.03.2020 02:01
question
Mathematics, 26.03.2020 02:01
Questions on the website: 13722360