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 the full path and filename for the file on a Debian Linux distribution that displays the time zone settings?
lesya [120]

Answer:

/etc/timezone

Explanation:

Debian based Linux distribution is a free distribution software and an operating system. It is composed of a open source and free source software. It is one of the most popular distributions.

A computer file name is a unique system of identifying the computer stored file in the file system. The names of the different file system have different formats or extensions in the file name and imposed different file restrictions.

In the context, the full path and the file name of a file that displays a time zone settings on a Debian Linux distribution is " ../etc/timezone".

3 0
2 years ago
In computer security what do the rows and columns correspond to in an 'Access Control Matrix'. What does each cell in the matrix
Tcecarenko [31]

Answer:

Explanation:

An Access Control Matrix ACM can be defined as a table that maps the permissions of a set of subjects to act upon a set of objects within a system. The matrix is a two-dimensional table with subjects down the columns and objects across the rows. The permissions of the subject to act upon a particular object are found in the cell that maps the subject to that object.

Summary

The rows correspond to the subject

The columns correspond to the object

What does each cell in the matrix contain? Answer: Each cell is the set of access rights for that subject to that object.

4 0
3 years ago
30points for help
stealth61 [152]

Answer:

blank 4

Explanation:

I just did this assignment got 100

4 0
3 years ago
We need goku and naruto fight story someone
lana [24]

Answer:

goku comes in and turns super sayain  naruto come in with kurama and naruto get goku with a rasagen and geku is still fist fightin while naruto is using his kurama and turns into kurama and knocks out goku now naruto thinks he won and goku IS HITIN HIM WITH A KAMEKAMEHA GOKU IS SIROUS NOW

Explanation:

8 0
3 years ago
Read 2 more answers
Hordes of surreptitiously infiltrated computers, linked and controlled remotely, also known as zombie networks are known as:
icang [17]
~Hello there! ^_^

Your answer: Hordes of surreptitiously infiltrated computers, linked and controlled remotely, also known as zombie networks are known as..?

Your answer: Hordes of surreptitiously infiltrated computers, linked and controlled remotely, also known as zombie networks are known as botnets.

Hope this helps~





3 0
3 years ago
Other questions:
  • HELLLLLP ill make you brainiest and ill give u a lot of points if you HELP ME Directions Part One.
    12·2 answers
  • Write a function DrivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar
    12·1 answer
  • #The Fibonacci sequence is a number sequence where each #number is the sum of the previous two numbers. The first #two numbers a
    7·1 answer
  • The read/write heads of a hard disk gently rest on the hard disk platters in order to read and write the data.
    13·1 answer
  • What are personal skills? A manner of individual style How a person manages and expresses oneself One's ability to excel at spor
    13·2 answers
  • In which type of attack do you get malicious code in links from seemingly reliable websites?
    14·1 answer
  • Which of the following is true? Group of answer choices worst case time of Heapsort is better than worst cast time of Quicksort
    10·1 answer
  • For BitTorrent, which of the following is true:
    6·1 answer
  • What is the correct order of precedence of the mathematical operators?
    12·1 answer
  • The cause of french revolution and anayze the reason for significane out come
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!