USE SCALA ONLY:
Here is an example of “Our Language”
1. integer a
2. integer b
3. string name
4. a = 14
5. b = 27
6. c = a + b
7. name = “example program”
8. display name
9. display c
10. read a
11. b = a * a
12. display a
13. end
Your interpreter will:
(a) Create an empty Map[String, String]
(b) Read the program
(c) Print each line as it is read
(d) Store each line into a text file
(e) Whenever a variable is declared (lines 1, 2 and 3, above), the variable name will be used to create a key -> value pair (variable name as the key and variable value as the value of the pair, converted to a string if necessary, and added to the Map)
(f) If an error is detected while reading the program text (lines 6 and 9, above, where c is an undeclared variable), a message will be printed along with the line of code
(g) When the “end” is reached, if any error has been detected during the reading, a message will be printed, saying that the program cannot be executed.
(h) If no error has been detected, your interpreter will begin to execute the program by reading it, line by line from the text file where you stored it and performing each line.
(i) Lines 1, 2 and 3 will cause entries to be created and added to the Map Lines 4 and 5 will cause the values 14 and 27 to be stored in the Map as the value part of the key -> value pair that has the variable name as the key Line 6 (if the name c had not been an undeclared variable) would cause the interpreter to look up the names a and b in the map and use their current values to be added and the result stored as the value for the pair whose key is c
The lines with "Display" (lines 8, 9 and 12) will cause the displayed value to be printed to the user.
The lines with "Read”(line 10) will prompt the user to input a value which will then be stored in the Map
The result will be that your interpreter will have read your “program”, tested and saved it in a text file and recovered it from the text file, a line at a time and each line will be executed by the interpreter.
Please read the example and post an answer for this question. Again please write the code using scala only. Thanks


//save
the following in filename.scala
import scala.io.Source
object HelloWorld {
def main(args: Array[String]) {
var error_count=0
var line_number=0
var int_variables_and_values:Map[String,Int] = Map()
var string_variables_and_values:Map[String,String] = Map()
val filename = "C:\\Users\\MANIKANTA\\IdeaProjects\\Chegg_scala\\src\\instructions.txt"
for (line <- Source.fromFile(filename).getLines) {
line_number+=1
//comment the following line for clean expected outut
println("Processing line "+line_number+" "+line)
if(line!="end"){
val string_array=line.split(' ')
//declaring a int variable
if(string_array(0)=="integer")
int_variables_and_values+=(string_array(1)->0)
//declaring a string variable
else if(string_array(0)=="string")
string_variables_and_values+=(string_array(1)->"")
//to handle reading from console
else if(string_array(0)=="read"){
if(int_variables_and_values.contains(string_array(1))){
print("Enter value for int "+ string_array(1)+": ")
var input_int=scala.io.StdIn.readInt()
int_variables_and_values+=(string_array(1)->input_int)
}
else if(string_variables_and_values.contains(string_array(1))){
print("Enter value for string "+ string_array(1)+": ")
var input_string=scala.io.StdIn.readLine()
string_variables_and_values+=(string_array(1)->input_string)
}
else{
error_count+=1
println("ERROR :can not read for a un declared variable!")
}
}
//to handle display
else if(string_array(0)=="display"){
if(int_variables_and_values.contains(string_array(1)))
println(int_variables_and_values.get(string_array(1)).getOrElse(0))
else if(string_variables_and_values.contains(string_array(1)))
println(string_variables_and_values.get(string_array(1)).getOrElse(0))
else {
error_count+=1
println("ERROR :can not diplay an un declared variable!")
}
}
//to hanfle assgining
else if(string_array(0).contains('=')){
val assigining = line.split('=')
//check int variables map for key exists or not
if(int_variables_and_values.contains(assigining(0))){
int_variables_and_values+=(assigining(0)->assigining(1).toInt)
}
//check string variables map for key exists or not
else if(string_variables_and_values.contains(assigining(0))){
string_variables_and_values+=(assigining(0)->assigining(1))
}
else{
error_count+=1
println("ERROR: undeclared variable "+assigining(0)+" encountered")
}
}
}
else if(line=="end" && error_count!=0) {
println("As errors are present, program cannot be executed!")
println(int_variables_and_values)
println(string_variables_and_values)
}
else {
println("Program Successfully executed")
println(int_variables_and_values)
println(string_variables_and_values)
}
}
}
}

USE SCALA ONLY: Here is an example of “Our Language” 1. integer a 2. integer b...
C Language Programming. Using the program below - When executing on the command line only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the...
Java Programming Reading from a Text File
Write a Java program that will use an object of the Scanner class to read employee payroll data from a text file The Text file payroll.dat has the following: 100 Washington Marx Jung Darwin George 40 200 300 400 Kar Car Charles 50 22.532 15 30 The order of the data and its types stored in the file are as follows: Data EmployeelD Last name FirstName HoursWorked double HourlyRate Data Tvpe String String...
This assignment involves 2 Java programs 1) Write a Java program to read a CSV (Comma separated values) text file. The text file will contain comma separated values in each line. Each line contains data in this format: String(20), String(5),String(10), double. There will be multiple lines with each line containing the same number of values. Ask the user to enter the path for the CSV file for reading the file. After reading the data from the file output the data...
There is a file called mat2.txt in our files area under the Assignments folder. Download it and save it in the same folder where this Matlab file (HW08_02.m) is saved. It may be worth opening that text file to see how it is set out. Note well, however, that the file might have a different number of lines and different number of numbers on each line. Write a Matlab program that does the following: Prompt the user for an input...
Write a Java program to read customer details from an input text file corresponding to problem under PA07/Q1, Movie Ticketing System The input text file i.e. customers.txt has customer details in the following format: A sample data line is provided below. “John Doe”, 1234, “Movie 1”, 12.99, 1.99, 2.15, 13.99 Customer Name Member ID Movie Name Ticket Cost Total Discount Sales Tax Net Movie Ticket Cost Note: if a customer is non-member, then the corresponding memberID field is empty in...
The purpose of this program is to read a file, called WaterData.csv. It will output date and gallons. So it would look something like "2/04/15 40 Gallons". The pseudo code is as follows. prompt the user for a file name open the file if that file cannot be opened display an error message and quit endif create a String variable 'currentDate' and initialize it to the empty string. create a variable gallonsUsed and initialize it to 0 while the file...
Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1. The input and variable value file are both text files that will be specified in...
Python 3.7 Coding assignment This Program should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file....
In this lab, you will write a program that reads a series name/value pairs, and stores them in a pair of vectors. After the name/value pairs are read, it will then read names (until the input is exhausted) and print out the corresponding value for that name. If the name is not found in the list, "name not found" should be printed. The names should be read as strings and stored as a vector<string>; the values should be read as...
In java netbean8.1 or 8.2 please. The class name is Stock. It has 5 private attributes (name, symbol, numberOfShares, currentPrice and boughtPrice)and one static private attribute (numberOfStocks). All attributes must be initialized (name and symbol to “No name/ symbol yet” and numberOfShares, currentPrice and boughtPrice to 0. Create two constructors, one with no arguments and the other with all the attributes. (However, remember to increase the numberOfStocks in both constructors. Write the necessary mutators and accessors (getters and setters) for...