

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Objectives
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