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, 22.06.2019 04:30
Which of the statements below is true? the formatting, standard, and drawing commands are unavailable. the formatting, standard, and drawing commands have been used. the formatting, standard, and drawing toolbars are displayed. the formatting, standard, and drawing toolbars are hidden.
Answers: 1
question
Computers and Technology, 23.06.2019 04:31
Which of the following is not a way in which trees benefit the environment? a. they remove a significant amount of carbon dioxide from the atmosphere. b. they remove a significant amount of oxygen from the atmosphere. c. their roots hold soil in place, reducing rates of erosion. d. they remove ozone and particulates from the atmosphere. select the best answer from the choices provided a b c d
Answers: 1
question
Computers and Technology, 23.06.2019 16:00
An english teacher would like to divide 8 boys and 10 girls into groups, each with the same combination of boys and girls and nobody left out. what is the greatest number of groups that can be formed?
Answers: 2
question
Computers and Technology, 24.06.2019 01:00
How can the temperature of a room be raised by 5degreesf?
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, 22.01.2021 14:00
question
Mathematics, 22.01.2021 14:00
question
Physics, 22.01.2021 14:00
question
Mathematics, 22.01.2021 14:00
question
Mathematics, 22.01.2021 14:00
Questions on the website: 13722363