Functions, Operators, Switch Cases and Truth Tables : Switch Cases : Ada Language : Translator

Translator

The Translator translates case-ada/when_ada structures to if/then/else structures for simulation and code generation needs:

A case_ada statement selects for execution one of a number of alternative sequences_of_statements; the chosen alternative is defined by the value of an expression and simply evaluated to an if/then/else statement. For example:

if (expression == key_value1) then actions;
else if(expression == key_value2) then actions;
. . .

 
A choice list is translated as sequence of or statements in an if/then/else expression. For example, when_ada 1| 2| 3 => <actions> translates to:

if (expression == 1 || expression == 2 || expression == 3)
then <actions>

 

The following table shows the translation of a case_ada statement.

 
case_ada X is
when_ada 1 | 2 => Y++;Y=Y+2;
when_ada 3 => FOO1(Y);
when_ada 4 => FOO2(Y);
when_ada others => DEF_ACTION(X);
end case_ada
if ( (X==1) || (X==2) )
{
Y = (Y + 1);
Y = (Y + 2);
}
else
{
if ( X==3 )
{
FOO1();
}
else
{
if ( X==4 )
{
FOO2();
}
else
{
DEF_ACTION();
}
}
}