Zum Verzeichnisinhalt
Zum Aufgabenblatt
(SHIFT + Linke Maustaste)
@=~
~p maximum_input_line_length = infinity
~A~<Loop Enumeration~>
The program analyzer shall derive information about for loops
in the program: The loops are counted from left to right
throughout the program. For each loop its number, its nesting
depth, and its line number is to be printed.
For example the following program
~O~<loops.in~>~{~-
{
int i, k, j, s;
s = 0;
for (i=1; i<10; i=i+1)
for (j=i; j<10; j=j+1)
s = s + j;
for (k=0; k<5; k=k+2)
s = s - k;
print (s);
}
~}
shall produce output like
~O~<loops.out~>~{~-
for loop number 1 in line 4 has depth 1
for loop number 2 in line 5 has depth 2
for loop number 3 in line 7 has depth 1
~}
The following questions may help to focus your attention on the
significant aspects of this problem:
What is the computational pattern for left-to-right enumeration?
In which context and with which value do you start the enumeration?
What is the computational pattern for nesting depth?
How is the recursive nesting being founded?
~B~<Solution~>
Decompose your solution into 3 parts:
Loop enumeration, loop nesting depth, and printing the information.
Fill in the description of your loop enumeration solution here.
~$~<Loop enumeration~>~{
/* Fill in your Lido specification here. */
~}
Fill in the description of your loop nesting depth solution here.
~$~<Loop nesting depth~>~{
/* Fill in your Lido specification here. */
~}
Fill in the description of your printing solution here.
~$~<Loop information~>~{
/* Fill in your Lido specification here. */
~}
~B~<Further Questions~>
Reconsider your solution when you have learned about
SYMBOL computations. Which of the computations can be
turned into SYMBOL computations? Explain why.
~B~<Output files~>
~O~<loops.lido~>~{
~<Loop enumeration~>
~<Loop nesting depth~>
~<Loop information~>
~}