quarta-feira, 18 de dezembro de 2013

18.05.04.07 Instrução if

 

Exemplo

 

 

if sumValue < minimum then

  factor := sumValue;

  sumValue := minimum;

elsif sumValue > maximum then

  factor := -sumValue;

  sumValue := maximum;

else

  factor := 0;

end if;

 

 

 

Semântica:

 

A expressão entre "if" e "then" é processada.

Quando tal expressão resulta em TRUE as instruções seguintes a "then" são executadas e a instrução "if" é finalizada.

Se a expressão de "if" e todas expressões "elsif" resultarem em FALSE as instruções do bloco "else" serão executadas e a instrução "if" é finalizada.

Se a expressão de "if" e todas expressões "elsif" resultarem em FALSE e não existir um "else" a instrução "if" é finalizada.

 

Sintaxe:

 

 

if_statement ::=

'if' expression 'then'

  statement

{ 'elsif' expression 'then'

  statement }

[ 'else'

  statement ]

'end' 'if' .

 

 

 

A expressão deve ser do tipo "boolean".

 

Declaration:

 

 

$ syntax expr: .if.().then.().end.if is           -> 25;

$ syntax expr: .if.().then.().().end.if is        -> 25;

 

$ syntax expr: .elsif.().then.() is               <- 60;

$ syntax expr: .elsif.().then.().() is            <- 60;

$ syntax expr: .else.() is                        <- 60;

 

const type: ELSIF_RESULT is newtype;

const proc: (ref ELSIF_RESULT param) ::= enumlit is  action "ENU_GENLIT";

const ELSIF_RESULT: ELSIF_EMPTY is enumlit;

const type: ELSIF_PROC is                        (func ELSIF_RESULT);

const proc: (ref ELSIF_PROC param) ::= (ref ELSIF_RESULT param) is action "ENU_CREATE";

 

const proc:       if (in boolean param) then

                    (in proc param)

                  end if is                        action "PRC_IF";

 

const proc:       if (in boolean param) then

                    (in proc param)

                  (in ELSIF_PROC param)

                  end if is                        action "PRC_IF_ELSIF";

 

const ELSIF_PROC: elsif (in boolean param) then

                    (in proc param) is             action "PRC_IF";

 

const ELSIF_PROC: elsif (in boolean param) then

                    (in proc param)

                  (in ELSIF_PROC param) is         action "PRC_IF_ELSIF";

 

const ELSIF_PROC: else

                    (in void param) is             ELSIF_EMPTY;

 

 

const proc: if TRUE  then (in void param) end if is                           noop;

const proc: if TRUE  then (in void param) (in ELSIF_PROC param) end if is     noop;

const proc: if FALSE then (in proc param) end if is                           noop;

const proc: if FALSE then (in proc param) (in ELSIF_RESULT param) end if is   noop;

const ELSIF_PROC: elsif TRUE  then (in void param) is                         ELSIF_EMPTY;

const ELSIF_PROC: elsif TRUE then (in void param) (in ELSIF_PROC param)   is  ELSIF_EMPTY;

const ELSIF_PROC: elsif FALSE then (in proc param) is                         ELSIF_EMPTY;

const ELSIF_PROC: elsif FALSE then (in proc param) (in ELSIF_RESULT param) is ELSIF_EMPTY;

 

 

 

 

 

 

 

 

 

Nenhum comentário:

Postar um comentário