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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 21:30, willwhitlock803
Write code using c . (take input from user) calculate the size of a given file in kbs. in this task you will complete the function with the following prototype: float get_file_size(char * filename); the function takes the file name (address to the start of a null terminated character array) as input. the function should then open the file and find the number of bytes it contains till eof. the number of bytes divided by 1024 will give the size in kbs. if the file cannot be opened the function should return -1.
Answers: 2
image
Computers and Technology, 21.06.2019 22:20, ptrlvn01
This problem has been solved! see the answeran evil king has a cellar containing n bottles of expensive wine, and his guards have just caught a spy trying to poison the king’s wine. fortunately, the guards caught the spy after he succeeded in poisoning only one bottle. unfortunately, they don’t know which one. to make matters worse, the poison the spy used was very deadly; just one drop diluted even a billion to one will still kill someone. even so, the poison works slowly; it takes a full month for the person to die. design a scheme that allows the evil king to determine exactly which one of his wine bottles was poisoned in just one month’s time while expending at most o(logn) of his taste testers. you are not allowed to use n testers, one for each bottle, and see which one tester dies after 30 days.(no pseudocode needed. just answer in words, how many testers you use, how you use them and why you correctly identify the poisoned bottle in 30 days)
Answers: 2
image
Computers and Technology, 22.06.2019 10:30, Twitches
This first part of the film shows the early history of motion pictures. how accurate do you think the portrayal of the early motion picture industry is? why? is historical accuracy important in films and theatre productions? explain. in the scene where don is going to the party (starting at time code 14: 51), we see a street scene as he first rides with cosmo and then with kathy. what aspects did the filmmaker include to make the scene look and feel like don, cosmo, and kathy are riding in a car on a street? think about elements such as scenery, sound, props, lighting, and so on. a "talkie" picture is shown starting around time code 21: 15. how does the audience in the film react to the "talkie"? what influence do audiences have on film and theatre performances? how do film and theatre actors influence audiences? in the musical scene with cosmo (starting at time code 27: 00), how does the actor use props? what is the result? do you think the use of props effectively fulfilled the artistic vision for this musical number? why or why not?
Answers: 1
image
Computers and Technology, 22.06.2019 17:30, glocurlsprinces
Rachel completed typing an official document with a word processing program. she wants to make sure that her document has no typographical errors. she also wants all headings to have the same font. which features in a word processing program should she use? rachel should use the feature in a word processing program to find typographical errors. she should apply to have uniform headings.
Answers: 1
You know the right answer?
The following defines a simple language, in which a program consists of assignments and each variabl...

Questions in other subjects:

Konu
Social Studies, 25.09.2019 06:30
Konu
Geography, 25.09.2019 06:30