Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Dear Sir or Madam, Hope your day is going well. I need help with the following programming assignment. I need it to be written in

Dear Sir or Madam,
Hope your day is going well. I need help with the following programming assignment. I need it to be written in Java. If you could also include comments, that would be highly appreaciated. Please followi the instructions.
-------------------------------------
The following below defines a simple language, in which a program consists of assignments and each variable is assumed to be of the integer type. For the sake of simplicity, only operators that give integer values are included. Write an interpreter for the language in a language of your choice. Your interpreter should be able to do the following for a given program:
(1) detect syntax errors
(2) report uninitialized variables
(3) perform the assignments if there is no error and print out the values of all the variables after all the assignments are done.
Program:
Assignment*
Assignment:
Identifier = Exp;
Exp:
Exp + Term | Exp - Term | Term
Term:
Term * Fact | Fact
Fact:
( Exp )|- Fact |+ Fact | Literal | Identifier
Identifier:
Letter [Letter | Digit]*
Letter:
a|...|z|A|...|Z|_
Literal:
0| NonZeroDigit Digit*
N onZeroDigit:
1|...|9
Digit:
0|1|...|9
Here's the sample of inputs and outputs:
Input 1
x =001;
Output 1
error
Input 2
x_2=0;
Output 2
x_2=0
Input 3
x =0
y = x;
z =---(x+y);
Output 3
error
Input 4
x =1;
y =2;
z =---(x+y)*(x+-y);
Output 4
x =1
y =2
z =3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

Describe the five steps in the creative process.

Answered: 1 week ago

Question

Discuss how S. Truett Cathys values shaped Chick-fil-As operation.

Answered: 1 week ago