The following 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 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; and (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]*

NonZeroDigit: 1|...|9

Digit: 0|1|...|9

Sample 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+y);
Output 3
error

Input 4
x = 1;
y = 2;
z = ---(x+y)*(x+-y);
Output 4
x = 1
y = 2
z = 3

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.