subject

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 for the language in c++ or java. 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]*

letter:
a||z|a||z|_

literal:
0 | nonzerodigit 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;
z = +y);

output 3
error

input 4
x = 1;
y = 2;
z = +y)*(x+-y);

output 4
x = 1
y = 2
z = 3

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 20:00
What software programs are used to to create professional publication? a.) graphics programs b.) word processors c.) page layout programs d.) spreadsheet programs
Answers: 2
question
Computers and Technology, 23.06.2019 23:00
How do you know if the website is secure if you make a purchase
Answers: 2
question
Computers and Technology, 24.06.2019 14:00
Text or graphics that print at the bottom of every page are called footings footers headers headings
Answers: 1
question
Computers and Technology, 24.06.2019 15:00
When a presentation is being planned, it is important to ensure that it covers all available information. appeals to the audience. uses multimedia tools. entertains the audience.
Answers: 1
You know the right answer?
The following defines a simple language, in which a program consists of assignments and each variabl...
Questions
question
Mathematics, 09.04.2021 14:00
question
Social Studies, 09.04.2021 14:00
question
Mathematics, 09.04.2021 14:00
question
Physics, 09.04.2021 14:00
question
Physics, 09.04.2021 14:00
question
Mathematics, 09.04.2021 14:00
question
Mathematics, 09.04.2021 14:00