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 18:10
How can i delete permalinks from a word press site?
Answers: 1
question
Computers and Technology, 23.06.2019 21:30
Examine the list below. which factors positively affect lifetime income? check all that apply.
Answers: 1
question
Computers and Technology, 24.06.2019 13:30
Type the correct answer in the box. spell all words correctly. what is the default margin width on all four sides of a document? by default, the document has a margin on all four sides.
Answers: 1
question
Computers and Technology, 24.06.2019 16:30
Which program can damage your computer?
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, 11.10.2019 22:30
question
Social Studies, 11.10.2019 22:30
Questions on the website: 13722367