[dir] Zum Verzeichnisinhalt     [exercise] Zum Aufgabenblatt     [download] (SHIFT + Linke Maustaste)
@=~
~p maximum_input_line_length = infinity

~A~<Switch Case Labels~>

Switch statements sometimes span over a wide range of case label
values, and only a few case labels are stated for the non-default cases.
A poor C compiler might then produce a large jump table with only a few
non-default entries. Hence the style guide requires not to waste
storage by sparse switch cases. 

You decide to suggest to your manager
that this requirement should be removed, because today's C compiler
automatically translate sparse switch cases into cascades of conditional
jumps. 

In order to strengthen your argument by figures, your analysis
tool will compute the number of the case labels in a switch statement
and the range of their values.

For a program like

~O~<switch.in~>~{~-
{ int i, z;
  i = read();
  switch (i)
  {
   case 0:   z = 1;
             break;
   case 99:
   case 100: z = 2;
             break;
   default:  z = 0;
  }
  print (z);
}
~}

the tool will produce the output:

~O~<switch.out~>~{~-
switch in line 3 has 3 case labels in the range 0 to 100
~}

The following questions may help to focus your attention on the
significant aspects of this problem:

1. How do you access the case label values from the switch statement
context?

2. Which functions do you need to combine the values?

3. How do you handle nested switch statements?


~B~<Solution~>

Fill in the description of your solution here.

~$~<Switch case label computation~>~{

/* Fill in your Lido specification here. */

~}


~$~<Cpp macro definitions~>~{

/* Fill in your cpp macros here. */

~}

~B~<Further Questions~>

1. Does your solution work for nested switch statements?
Explain why.

2. Explain why the ~{f0~} functions are needed
(look at the grammar).

3. Can you make any assumption about the order in which
the functions are called?

4. Reconsider your solution when you have learned about
SYMBOL computations. How can you use them to simplify
your solution?

~B~<Output files~>

~O~<switch.lido~>~{
~<Switch case label computation~>
~}

~O~<switch.head~>~{
~<Cpp macro definitions~>
~}