Docsity

Compiler Design - Programming Assignment 1 | CIS 4930, Assignments of Computer Science

Toggle sidebar
bg1
Compiler Design (CIS 4930/6930) [Fall 2007]
Programming Assignment I
Objectives
1. To understand the definitions of DJ and DISM, which will serve as source and target
languages for a compiler built in future assignments.
2. To implement small DJ and DISM programs.
3. To become familiar with and be able to use a DISM simulator.
Due Date: Sunday, September 9, 2007 (at 11:59pm).
Machine Details
Complete this assignment by yourself on the following CSEE network computers:
c4labpc11, c4labpc12, ..., c4labpc29. These machines are physically located in the
Center 4 lab (Room 220). Do not use any server machines like grad, babbage, sunblast,
etc. You can connect to the C4 machines from home using SSH. (Example: Host name:
c4labpc11.csee.usf.edu Login ID and Password: <your login id and password>) You are
responsible for ensuring that your DISM program executes properly on these machines.
Assignment Description
For this assignment, you will acquaint yourself with the DJ and DISM languages by
implementing one small program in each language. You will write a number-list-
reversing program in DJ and a factorial program in DISM.
The Number-list-reversing Program in DJ
In this part of the assignment you will write a small DJ program in a file called
reverse.dj. Your program needs to read natural numbers as they are entered by the user,
until the user enters a zero. At that point, your program must print the list of numbers the
user has entered (including the zero), but they must be printed in reverse order from the
order in which the user entered them.
Hints
A good way to implement this functionality involves linked lists. You could define a
class LinkedList with only three methods: setData (to set the data value in a new linked-
list node to some desired value), prepend (to prepend a new node with a specified value
onto the head of the linked list), and printList (to print the linked list from head to tail).
The main block in your DJ program could read user input and prepend all the numbers
read into the linked list. After the user enters a zero, the main block would call printList.
Please review the code in file good10.dj at
http://www.cse.usf.edu/~ligatti/compilers-07/as1/dj/. That DJ program implements
functionality very similar to what you are asked to implement in this assignment (except
good10.dj uses a binary search tree, rather than a linked list, so the numbers get output in
1
pf2

Partial preview of the text

Download Compiler Design - Programming Assignment 1 | CIS 4930 and more Assignments Computer Science in PDF only on Docsity!

Compiler Design (CIS 4930/6930) [Fall 2007]

Programming Assignment I

Objectives

  1. To understand the definitions of DJ and DISM, which will serve as source and target languages for a compiler built in future assignments.
  2. To implement small DJ and DISM programs.
  3. To become familiar with and be able to use a DISM simulator. Due Date: Sunday, September 9, 2007 (at 11:59pm). Machine Details Complete this assignment by yourself on the following CSEE network computers: c4labpc11, c4labpc12, ..., c4labpc29. These machines are physically located in the Center 4 lab (Room 220). Do not use any server machines like grad, babbage, sunblast, etc. You can connect to the C4 machines from home using SSH. (Example: Host name: c4labpc11.csee.usf.edu Login ID and Password: ) You are responsible for ensuring that your DISM program executes properly on these machines. Assignment Description For this assignment, you will acquaint yourself with the DJ and DISM languages by implementing one small program in each language. You will write a number-list- reversing program in DJ and a factorial program in DISM. The Number-list-reversing Program in DJ In this part of the assignment you will write a small DJ program in a file called reverse.dj. Your program needs to read natural numbers as they are entered by the user, until the user enters a zero. At that point, your program must print the list of numbers the user has entered (including the zero), but they must be printed in reverse order from the order in which the user entered them. Hints A good way to implement this functionality involves linked lists. You could define a class LinkedList with only three methods: setData (to set the data value in a new linked- list node to some desired value), prepend (to prepend a new node with a specified value onto the head of the linked list), and printList (to print the linked list from head to tail). The main block in your DJ program could read user input and prepend all the numbers read into the linked list. After the user enters a zero, the main block would call printList. Please review the code in file good10.dj at http://www.cse.usf.edu/~ligatti/compilers-07/as1/dj/. That DJ program implements functionality very similar to what you are asked to implement in this assignment (except good10.dj uses a binary search tree, rather than a linked list, so the numbers get output in 1

ascending, rather than reverse, order). My solution reverse.dj file is 56 lines long, though only 32 of those lines actually contain DJ code (the others are whitespace/comments). Testing Your DJ Program Because you are writing a program in a new language for which no compiler yet exists, you cannot test your program by executing it! This situation is unpleasant but realistic. You will have to ensure by hand that your DJ program is valid and would behave correctly if executed. Although you cannot directly test your DJ program, I recommend testing it indirectly by modifying it (by hand) into an equivalent, valid Java program. You can then compile and execute that Java program. If you want to test your reverse.dj in this way, you may find David Eck’s TextIO.java file helpful—his TextIO class has a Java method getInt that is roughly equivalent to DJ’s readNat expression. The TextIO class is described at: http://www.faqs.org/docs/javap/c2/s4.html The Factorial Program in DISM In this part of the assignment you will write a small DISM program in a file called factorial.dism. Your DISM program simply needs to input a natural number n and then output the natural number equal to n! (i.e., n factorial). Hint The factorial.dism program can be implemented in 10 lines of code. Testing Your DISM Program Please use the DISM simulator, sim-dism, to test your DISM program. Here is an execution trace of running sim-dism on a correct factorial.dism program:

./sim-dism factorial.dism Enter a natural number: 5 120 Simulation complete. Halt instruction reached at PC=9.

Submission Notes  Type the following pledge as an initial comment in both your DJ and DISM files: “I pledge my honor that I have not cheated on this assignment.” Type your name after the pledge. Not including this pledge in both files will lower your grade 50%.  Upload and submit your reverse.dj and factorial.dism files into the digital dropbox in Blackboard.  For every day that your assignment is late, your grade reduces 10%.  Your programs must be commented appropriately. 2