Question & Answer: Problem Description: The goal of this exercise is to reproduce in a limited way, an interpreter for a…..

Problem Description: The goal of this exercise is to reproduce in a limited way, an interpreter for a computer language. The language will be defined as the following:

Declaration statements (integer or string only, single-letter names)

Character-string literals (Ex: “Jim Scandale”)

Simple numeric assignments (Ex: a = b + c,    =,    ̶ , *,   /,   %)

Simple character-string assignments (Ex: n = “CSE116” )

Read (input one integer value)

Display (output integer value or output character-string value)

End-statement (‘end’ signals the end of the program)

The program will be typed by the user, a single statement on each line. The interpreter will read the program in this language and store it onto a text file. Variables will be checked against their declaration statements and each use of an undeclared variable will be flagged as an error. When the ‘end’ statement is reached and stored, the interpreter will check to see if there were any errors flagged. If none, it will begin executing the statements a line at a time. If there were errors, the interpreter will display a summary error message (ex: “too many errors – execution deleted”) and go back to reading user input.

The execution phase will

Display each statement exactly as supplied by the user.

Create an internal variable for each declaration statement

Manipulate values as dictated by the program

Perform read and display statements

When execution reaches the ‘end’ statement, stop!

Please give the complete answer. Thanks!

Expert Answer

 

//Interpret.java

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Interpret{

public static void main(String[] args){

Scanner scn = new Scanner(System.in);

BufferedWriter bwr =null;
FileWriter fwr =null;

try{
File file = new File(“C:\air\input.txt”);

if(!file.exists()){
file.createNewFile();
}

fwr = new FileWriter (file);
bwr = new BufferedWriter(fwr);

System.out.println(“Enter any single Letter:n”);
String str=scn.nextLine();
bwr.write(str);
bwr.newLine();

System.out.println(“Enter any String Literals:n”);
String str1=scn.nextLine();
bwr.write(str1);
bwr.newLine();

System.out.println(“Enter any two Numbers:n”);
int num1=scn.nextInt();

System.out.println(“Enter any 2nd Number:n”);
int num2=scn.nextInt();

int operation=num1*num2;
bwr.write(operation);
bwr.newLine();

System.out.println(“Read any integer value:n”);
int integer=scn.nextInt();

System.out.println(“the value is :” +integer);
bwr.write(integer);
bwr.newLine();
bwr.write(“end”);
}
catch (IOException e){
e.printStackTrace();
}
}
}

Still stressed from student homework?
Get quality assistance from academic writers!