(a) Develop stack machine code equivalents of the following simple programs:
(1) void main () { for (int i = 0; i <= 10; i++) printf("%d\n", i) } (2) void main () { int i, list[11]; i = 0; while (i <= 10) { list[i] = 2 * i; i++; } } (3) PROGRAM Silly; VAR List[10], I, J; BEGIN Read(I, J, List[I+J]); List[List[J]] := List[J + 2 * I] END.
(b) Consider the following general form of T diagram. Although it uses the letters A through I in the various arms of the T's, one could draw the diagram with fewer letters. How and why?
.--------------------------. .--------------------------. | | | | | A ----------> B | | C -----------> D | | | | | `-------. .--------------------------. .-------' | | | | | E | F --------> G | H | | | | | `------------------. .------------------' | | | I | | | `----------'
(c) A pretty printer is a program that will take the source code of a program written in some language and essentially simply reproduce it, but making it look "pretty", for example adjusting all the indentation to be consistent, placing each statement on a new line, adding blank lines between functions and so on.
Suppose you have available a C++ compiler CC.EXE for the PC, and that you have just been introduced to the language Parva. Use T diagrams to show in broad detail how you would (a) develop a pretty printer PRETTY.EXE for Parva that would run on a Windows 2000 system in the Hamilton Compass Laboratories, and (b) use this pretty printer on that system to beautify a messy program MESSY.PAV written in Parva.
(d) In the practical sessions you should have used the Extacy Modula-2 to C translator. This was developed in Russia by a team who used the JPI Modula-2 compiler available for the PC. But the demonstration system we downloaded from the Internet came with the file XC.EXE, and a few other modules written in Modula- 2 (but not the source of the XC.EXE executable itself). Draw T-diagrams showing the process the Russians must have used to produce this system, and go on to draw T-diagrams showing how you managed to take the program SIEVE.MOD and run it on the PC using the MicroSoft C++ system as your compiler of choice.