1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
IrinaVladis [17]
3 years ago
7

In most programming languages, the compiler carries a preprocessing step to determine if certain statements will compile. For in

stance 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.
Computers and Technology
1 answer:
MakcuM [25]3 years ago
6 0

Answer:

See explaination for program code

Explanation:

package com.company;

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.Paths;

import java.util.Stack;

/*

* A program which reads input from given text filename and prints

* whether it passed the pre-processing stage or not

* Sample input

* int A = (a + b);static void display(int x)

* {

* //A sample input file

* }

* */

public class MyPreprocessor {

/*

* Reads input from filename and returns a string

* containing whole text

* */

public String readInput(String filename) {

String content = "";

try {

content = new String(Files.readAllBytes(Paths.get(filename)));

} catch (IOException e) {

e.printStackTrace();

}

return content;

}

/**

* Filters input since we are only concerned with

* a subset of input = '{}[]()/*'

*/

public String filterText(String text) {

String output = "";

for(int i = 0;i<text.length();++i) {

switch (text.charAt(i)) {

case '[':

case ']':

case '{':

case '}':

case '(':

case ')':

case '*':

case '/':

output += text.charAt(i);

}

}

return output;

}

/*

* Uses stack to determine if input is valid or not

* */

public boolean parse(String input) {

Stack<Character> St = new Stack<Character>();

// '$' is special symbol to represent bottom of stack

St.push('$');

for(int i = 0;i<input.length();++i) {

Character symbol = input.charAt(i);

if(St.peek().equals(getOpenSymbol(symbol)))

St.pop();

else St.push(symbol);

}

return St.peek() == '$';

}

private static Character getOpenSymbol(Character symbol) {

switch (symbol) {

case '}': return '{';

case ']': return '[';

case ')': return '(';

case '*': return '*';

case '/': return '/';

default: return ' ';

}

}

public static void main(String[] args) {

MyPreprocessor preprocessor = new MyPreprocessor();

String inputText = preprocessor.readInput("src/input.txt");

String filteredInput = preprocessor.filterText(inputText);

if(preprocessor.parse(filteredInput))

System.out.println("preprocessing passed.");

else System.out.println("preprocessing failed!");

}

}

You might be interested in
* what is an electronic mail ?
Vikki [24]

Answer:

Electronic mail is a method of exchanging messages between people using electronic devices. Email entered limited use in the 1960s, but users could only send to users of the same computer, and some early email systems required the author and the recipient to both be online simultaneously, similar to instant messaging.

6 0
3 years ago
Interest assessments are always accurate. True False
Brums [2.3K]

Answer:

False

Explanation:

3 0
3 years ago
A large number of genetic codes are stored as binary values in a list. Which one of the following conditions must be true in ord
Bad White [126]

Answer:

D

Explanation:

3 0
2 years ago
Read 2 more answers
The data-linking feature that allows Internet users to skip directly from a highlighted word to a related file in another comput
tamaranim1 [39]

Answer:

Hypertext

Explanation:

According to my experience on information technology, I can say that based on the information provided within the question the term being mentioned is called Hypertext. Like described in the question this term refers to a software system which shows as a highlighted piece of text that allows a user to immediately be taken to another system with information associated with the highlighted text that was clicked.

If you have any more questions feel free to ask away at Brainly.

5 0
3 years ago
Read 2 more answers
​Which SQL keyword is used to search for records?
Over [174]
SQL (<span>Structured Query Language.) is the standard programming language for communicating and organizing databases (DB).
In order to search through the database the statement SELECT should be used.
SELECT select data from the database.
SELECT is followed by the statement FROM which defines from which database you search record. </span>
8 0
3 years ago
Other questions:
  • What’s the answer?............................
    13·1 answer
  • Write the pseudocode for linear search, which scans through the sequence, looking for ν. Using a loop invariant, prove that your
    14·1 answer
  • What is the voltage drop across R4 in the diagram shown above?
    13·1 answer
  • Arrange the steps below to outline what maia needs to do to accomplish this task.​
    9·1 answer
  • Air circulation is caused by ... A Earth's rotation around the sun B winds that move vertically C moving air between hot and col
    11·1 answer
  • Hey, how is everyone????????????????????????????????
    8·2 answers
  • Match the desired outcome to the appropriate action.
    6·1 answer
  • A business that helps people find jobs for a fee
    12·1 answer
  • To extract detailed and comprehensive responses from your client, use the _____ questioning technique.
    5·2 answers
  • List and describe each of the activities of technology
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!