use PYTHON
Write a program that will take an input file called input.txt
which will contain a Java program and parse it and output an
annotated version.
Your program will track the nesting depth of the braces of the
input file and will output an annotated version of the file.
Your final program will
1. List the nesting depth of curly braces
2. Ignore braces inside quotes or comments
Use Python
Assume that all quoted strings begin and end on the same
line.
Sample INPUT:
-------------------
import blah;
class Foo
{
void Foo()
{
System.out.println("braces are
fun! {{{{{"); // ignored
if (condition)
{
// also
ignored: {
int a =
1;
// as is
this: }
}
}
}
//end of program
Sample annotated OUTPUT:
-------------
0 import blah;
0 class Foo
1 {
1 void Foo()
2 {
2 System.out.println("braces
are fun! {{{{{"); // ignored
2 if (condition)
3 {
3 //
also ignored: {
3 int
a = 1;
3 //
as is this: }
3 }
2 }
1 }
0 // end of program
Extra credit
Handle block comments that cross multiple lines of the input
file.
/* comment with
ignored brace { */
Code
# Open the file with read only permit
f = open('input.txt')
# use readline() to read the first line
line = f.readline()
# use the read line to read further.
# If the file is not empty keep reading one line
# at a time, till the file is empty
count=0
while line:
mainLine=line.rstrip()
line=line.strip()
if(line=="{"):
count+=1
print(str(count)+mainLine)
if(line=="}"):
count-=1
line = f.readline()
f.close()
output
code snaps
If you have any
query regarding the code please ask me in the comment i am here for
help you. Please do not direct thumbs down just ask if you have any
query. And if you like my work then please appreciates with up
vote. Thank You.
Use PYTHON Write a program that will take an input file called input.txt which will contain a Jav...
Write a program that will check a Java file for syntax errors. The program will ask for an input-file name and output-file name and will then copy all the code from the Java input file to the Java output file, but with the following changes: 1. Any syntax error found in the Java input file will be corrected: a. Missing semicolon b. Missing compound statements (curly braces) c. All comments have to start with // and end with a period....
Write a PYTHON program that reads a file (prompt user for the input file name) containing two columns of floating-point numbers (Use split). Print the average of each column. Use the following data forthe input file: 1 0.5 2 0.5 3 0.5 4 0.5 The output should be: The averages are 2.50 and 0.5. a) Your code with comments b) A screenshot of the execution Version 3.7.2
I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...
Write a Python program that converts an input file in FASTA format, called "fasta.txt", to an output file in PHYLIP format called "phylip.txt". For example, if the input file contains: >human ACCGTTATAC CGATCTCGCA >chimp ACGGTTATAC CGTACGATCG >monkey ACCTCTATAC CGATCGATCC >gorilla ATCTATATAC CGATCGATCG Then the output file should be human ACCGTTATACCGATCTCGCA chimp ACGGTTATACCGTACGATCG monkey ACCTCTATACCGATCGATCC gorilla ATCTATATACCGATCGATCG FASTA format has a description (indicated with a '>') followed by 1 or more lines of a DNA sequence. PHYLIP format has a description...
Problem: Use the code I have provided to start writing a program that accepts a large file as input (given to you) and takes all of these numbers and enters them into an array. Once all of the numbers are in your array your job is to sort them. You must use either the insertion or selection sort to accomplish this. Input: Each line of input will be one item to be added to your array. Output: Your output will...
Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...
Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains a Java program. Your program should read the file (e.g., InputFile.java) and output its contents properly indented to ProgramName_Formatted.java (e.g., InputFile_Formatted.java). (Note: It will be up to the user to change the name appropriately for compilation later.) When you see a left-brace character ({) in the file, increase your indentation level by NUM_SPACES spaces. When you see a right-brace character (}), decrease your indentation...
Filename(s): ReformatCode. java Public class: ReformatCode Package-visible class(es): none Write a program that reformats Java source code from the next-line brace style to the end-of-line brace style. The program is invoked from the command line with the input Java source code file as args [0] and the name of the file to save the formatted code in as args [1]. The original file is left untouched. The program makes no other changes the source code, including whitespace. For example, the...
Write the proposed program in Java, JavaScript, and Python. Run them and compare the results. Submit source code for 3 programs. Let the function fun be defined as int fun(int* k) { *k += 4; return 3 * (*k) - 1; } Suppose fun is used in a program as follows: void main() { int i = 10, j = 10, sum1, sum2; sum1 = (i / 2) + fun(&i); sum2 = fun(&j) + (j / 2); }
Let's update our program, SalaryCalcLoop.java, from last week, to now take input about each employee from a file and write their information and salary/pay information to a file. Rashid night 60 20 Chin day 30 15 Tran day 45 10 Deeshan night 55 11.5 Serena day 24 10 Deepak day 66 12 Tyrone night 11 18 Andre night 80 15 import java.util.Scanner; import java.io.*; import java.io.FileWriter; import java.util.NoSuchElementException; public class SalaryCalcLoop{ double pay=0, OTpay=0; void gpay(double hours, double wage){ if...