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 anatomy of software house?
alexira [117]

Answer:

2. All reports of software house.

Explanation:

A software house is a business providing software products mainly. These firms may be specialized in products for company or consumer software or software-as -a-service (SaaS). The popular definition is that the firm is invested primarily in software product development and distribution.

In anatomy of software house they include-

  • Software development
  • Finance report
  • Client report
  • Sales and marketing report

It consist all reports like finance,client,sales or development of software house.

4 0
3 years ago
What is the differnces between dark and middle ages of computer?​
noname [10]
The "middle ages" are anything between the collapse of Rome (400 AD) to its re-emergence in Rennaissance Italy (1400). Rennaissance means "rebirth". The "dark ages" are the period in the middle ages which were relatively undocumented. This would definitely include 400 AD to 700 AD, and some extend it to 900 AD.
3 0
3 years ago
Anyone have any website ideas I could use for my computing website project? Thank you.
nlexa [21]
Yes like keynote yup keynote I use a lot of PowerPoints on keynote Yk
8 0
2 years ago
Read 2 more answers
In 1-2 pages, identify a social networking technology and identify at least 10 security and/or privacy risks the technology has
algol13

Answer:

One of the biggest social media giants has faced many such security and privacy risks in the past 3 years. 10 are listed below:

1. No one can forget the New Zealand attack on the mosque, and it was telecast live via it. And that is certainly a security risk. And if someone is able to stream live, the AI is in question definitely as this cannot be telecast.

2. Can you forget the various US shooting cases in the past 5 years? And many out of them where telecast lives on it. Again the AI, and the authentication is in question.

3. Many evils have many times advertised itself through it, and that is a security risk. This put up the question on the Data Scientists of the company.

4. It's a huge data on it, and many users have been able to misuse it, and that is a security risk. This put up the question mark on the application of the Big Data.

5. Once, the UK parliament questioned it to sell the secret data, and that was a privacy risk.

6. An Engineer was caught negotiating to sell secret users data to a third party, and that is a privacy risk as well as a question on management technology, as its possible now to check these kind of frauds.

7. Its accounts have been hacked many times, as well as millions of user-profiles, were stolen. This is a security and privacy risk.

8. Its data is still not safe as evils have proved they can break the authentication. However, it has reacted well, and they look like being a safe destination now.

9. Once, someone from Russia was caught collecting a lot of data from it. That was a security and privacy risk. And surely if someone is uploading a lot of complicated and confidential data, must be checked through proper AI implementation.

10. In India too there have been claims that a lot of personal information during elections 2014 was sold. That was a security and data risk. And the data scientists were proved vulnerable again. Its quite sure hence, a lot of work has to be done in Data Science and Artificial intelligence still.

However, its owner is one of the finest souls on earth. He donated all his money when he was blessed with a child. Some out of his team cheated, and else some technology failure or the huge amount of data was the reason for the fault. However, other companies are also facing such problems. And hence, he cannot be blamed for this. And the company now definitely has recovered from the nightmare that they faced in the past 3 years.

Explanation:

The answer is self explanatory.

8 0
3 years ago
Vendors who use open source as part of their product offerings can expect to bring new products to the market faster because: Gr
tamaranim1 [39]

Answer:

A.  they can skip whole segments of the software development process.

Explanation:

A software development process refers to the process of dividing software development work into various phases for product management, project management and to improve the design.

Vendors who use open source as part of their product offerings can expect to bring new products to the market faster because they can skip whole segments of the software development process.

They don't have to go through different phases of software development.

6 0
3 years ago
Other questions:
  • Is bit stuffing necessary in the control or address field in theHDLC protocol? why?
    13·1 answer
  • Sarah is working on a project in which she needs to record all the extracurricular activities in her college. Her college teache
    5·1 answer
  • What is a googleplex?
    7·1 answer
  • "The ____________________ function is a logical function that returns a TRUE value if any of the logical conditions are true and
    14·1 answer
  • What is a central location that houses Joint Information System (JIS) operations and where public information staff perform publ
    6·1 answer
  • Write a C program that includes a function of type double called divemaster accepts two double arguments (you must write the div
    15·1 answer
  • Write an if/else statement that compares the double variable pH with 7.0 and makes the following assignments to the bool variabl
    6·1 answer
  • Write an algorithm that accepts two numbers,
    7·1 answer
  • Int a = 1; int b = 0; int c = -1; if ((b + 1) == a) { b++; c += b; } if (c == a) { a--; b = 4; }
    7·1 answer
  • WIRELESS DATA TRANSMISSION METHODS​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!