Computer Languages History
(Click or use local copy.)
 CS 3723/3721
 Programming Languages
 Fall 2004

 Recitation 6
 Tiny Compiler 2: Translate Assignments
    Week 6: Sep 27-Oct 1
 Due (on time): 2004-10-04  23:59:59
 Due (late):        2004-10-08  23:59:59

Recitation 6 must be submitted following directions at: submissions with deadlines
  • 2004-10-04  23:59:59 (that's Monday, 4 October 2004, 11:59:59 pm) for full credit.
  • 2004-10-08  23:59:59 (that's Friday, 8 October 2004, 11:59:59 pm) for 75% credit.


Overview: For a description and examles of semantic action or syntax-directed translation, refer to syntax directed translation.


Initial Recitation work: For this recitation and the next one, you are to translate the language described in the previous recitation into MIPS assembly code.

For this recitation you should ignore all statements except assignments and output statements, which are of the form:

The recitation is also ignoring the ^ operator. These are what you should translate.


Form of assembler output: There are many forms the output could take. I am suggesting one form here:
How to do the actual translation: This first part of the recitation is only using part of the grammar (just for assignments and output):

Simplified Tiny® Grammar
M  --->  { S } '#'
S  --->  A  |  P  |  C
A  --->  lower-case '=' E ';'
P  --->  '<'  E  ';'
C  --->  '<'  upper-case ';'
E  --->  T {('+' | '-') T}
T  --->  U {('*' | '/' | '%') U}
U  --->  F
F  --->  '(' E ')'  |  lower-case  |  digit

As a hint for completing the recitation, you can work with the evaluator code above, since the code you need is actually quite similar. Each of the various functions of the parser must return an integer giving the location in memory where the given operand or expression is to be found: memory locations 0 to 9 for constants 0 to 9, locations 10 to 35 for variables a to z, and locations 36 to 85 for 50 temporaries.


Sample Inputs:
What you should submit: Refer to the submissions directions and to deadlines at the top of this page. The text file that you submit should first have Your Name, the Course Number, and the Recitation Number. The rest of the file should have the following in it, in the order below, and clearly labeled, including at the beginning the appropriate item letters: a, b, c, etc.

 Contents of submission for Recitation 6:

Last Name, First Name; Course Number; Recitation Number (6).

a. Java or C++ code for your translator, perhaps in multiple files.

b. Results of a run of your program using Sample Input 1 above, giving the complete resulting MIPS code.

c. Results of executing the MIPS code in b using the SPIM simulator.

d. Results of a run of your program using Sample Input 2 above, giving the complete resulting MIPS code.

e. Results of executing the MIPS code in d using the SPIM simulator.

f. Results of a run of your program using Sample Input 3 above, giving the complete resulting MIPS code.

g. Results of executing the MIPS code in f using the SPIM simulator.


Key ideas: It is relatively easy to add code to the recursive-descent parser that will carry out tasks, such as translating input assignment statements into MIPS assembler code. This process is known as syntax-directed traslation. It is an extremely powerful technique for writing compilers and for other similar tasks.


Revision date: 2004-06-29. (Use ISO 8601, an International Standard.)