Home   :   Matrix Language   :   Primitive Action Statements   :   Case Selection Statements

Case Selection Statements

 

Statements

 

    CaseSelection

    WhenCase

    WhenCaseSelection

    NullCaseSelection

 

 

Overview

 

These statements generalise the classic "if" and "case" statements found in typical 3GLs.

 

 

CaseSelection Statement

 

    CaseSelection

        WhenCase

            ConditionAnd

                ...

            WhenCaseSelection

                ...

        WhenCase

            ConditionAnd

                ...

            WhenCaseSelection

                ...

        NullCaseSelection

            ...

 

The CaseSelection statement introduces further selection statements.

 

 

WhenCase Statement

 

    CaseSelection

        WhenCase

            ConditionAnd

                ...

            WhenCaseSelection

                ...

        WhenCase

            ConditionAnd

                ...

            WhenCaseSelection

                ...

 

This statement introduces a pair of statements that test for a condition and performs processing in the associated WhenCaseSelection subregion if true.

 

If there is more than one WhenCase statement, these are processed in order until a true condition is evaluated.  The action statements in the WhenCaseSelection statements are then processed and the CaseSelection statement is exited.

 

 

WhenCaseSelection Statement

 

    CaseSelection

        WhenCase

            ConditionAnd

                ...

            WhenCaseSelection

                ...

 

The WhenCaseSelection statement subregion is executed if the associated WhenCase condition is evaluated to be true.

 

 

NullCase Statement

 

    CaseSelection

        WhenCase

            ConditionAnd

                ...

            WhenCaseSelection

                ...

        NullCaseSelection

            ...

 

The NullCaseSelection statement subregion is executed if all of the preceding WhenCase condition statements are found to be false.

 

This statement cannot be used on its own and must appear after at least one WhenCase statement.

 

 

Discussion

 

The CaseSelection statement is similar to "if", "switch" and "case" statements found in programming languages and translates to these structures.

 

Programming statement: "if"

 

    CaseSelection

        WhenCase

            ConditionAnd

                TestAnd

                    Account.Balance >= <<FixedZero>>

            WhenCaseSelection

                Template

                    OK

 

    Generated code:

 

    if (account->balance >= 0.0) {

        printf("OK");

    }

 

Programming statement: "if then else"

 

    CaseSelection

        WhenCase

            ConditionAnd

                TestAnd

                    Account.Balance >= <<FixedZero>>

            WhenCaseSelection

                Template

                    OK

        NullCaseSelection

            Template

                Overdrawn

 

    Generated code:

 

    if (account->balance >= 0.0) {

        printf("OK");

    } else {

        printf("Overdrawn");

    }

 

Programming statement: "switch" or "case"

 

    CaseSelection

        WhenCase

            ConditionAnd

                TestAnd

                    Account.Balance >= <<FixedZero>>

            WhenCaseSelection

                Template

                    OK

        WhenCase

            ConditionAnd

                TestAnd

                    Account.Balance >= Bank_Policy.Special_limit

            WhenCaseSelection

                Template

                    Special Measures

        NullCaseSelection

            Template

                Overdrawn

 

    Generated code:

 

    if (account->balance >= 0.0) {

        printf("OK");

    } else if (account->balance >= bank_policy->special_limit) {

        printf("Special Measures");

    } else {

        printf("Overdrawn");

    }

 

Note that the CaseSelection statement is not generated as a C switch statement.  This is because switch statements are implemented as jump tables that use a single variable value to decide which case out of many to execute.

Copyright © 2017 Dark Matter Systems Ltd. All Rights Reserved.