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
A student is recording a song on her computer. When the recording is finished, she saves a copy on her computer. The student not
denis23 [38]

Answer:

A. The song was saved using fewer bits per second than the original song.

Explanation:

A song can be recorded on the computer or any device ranging from bit rates 96 kbps to 320 kbps.  

The lesser the bitrates the lesser the quality of the audio and when we increase the bit rates, the quality of the audio recorded gradually increases.

Bitrates of 128 kbps give us a radio like quality whereas when we use bitrates of 320 kbps we get very good or CD-like quality.

According to the scenario, the most appropriate answer is option A.

3 0
3 years ago
_____ allow you to resize a graphic using the mouse.
timofeeve [1]
Microsoft.././/.//././././././.
5 0
3 years ago
Read 2 more answers
How has technology impacted society and education throughout history? What innovation has had the most profound impact on educat
Ganezh [65]
Technology has impacted society and education throughout history by helping save more lives and distroying​ them. I think the innovation that has had the most profound on education is being able to connect with teachers to better help us understand even we are not in school like what I am doing right now.
8 0
3 years ago
Read 2 more answers
when searching for a peer-reviewed journal article, you see the phrase "full text available" in the item record. what does this
Stells [14]

Answer: pay a fee for the whole paper

Explanation:

"Full text available" sometimes alludes to the fact that they have the paper available, but for a price. You must click on this button to view the entire paper instead of just a summary or abstract.

4 0
3 years ago
When a computer is the.................of an attack, it is used as an active tool to conduct the attack
BARSIC [14]

Answer:

Attack is an intentional or unintentional act that causes damage or compromises information of systems supporting it.When a computer is the subject of an attack, it is used as an active tool to conduct the attack.

On the other hand, when a computer is the entity being attacked, it is the object of an attack.

3 0
2 years ago
Other questions:
  • // This pseudocode is intended to display // employee net pay values. All employees have a standard // $45 deduction from their
    12·1 answer
  • You are a network administrator for a large bagel manufacturer that has 32 bakeries located throughout the United States, United
    6·1 answer
  • What sends massive amounts of email to a specific person or system that can cause that user's server to stop functioning? mail b
    6·1 answer
  • On the seventh day of the iteration, the team realizes that they will not complete 5 of the 13 stories. the product owner says s
    12·1 answer
  • "A user reports that the corporate web server cannot be accessed. A technician verifies that the web server can be accessed by i
    8·1 answer
  • A company develops a gaming application that it intends to sell. One of the scenarios that the sales team is concerned about is
    15·1 answer
  • is there anybody out there who is a social butterfly like me? If so then you can tlk to me on this. and to anybody out there tha
    12·1 answer
  • What is drop shipping and how it works on amazon?
    12·1 answer
  • What is the purpose of a forecast worksheet?
    15·1 answer
  • A document commonly used in real estate transactions, detailing the fees, commissions, insurance, etc. that must be transacted f
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!