4. Expressions and Statements

Syntax Summary
All C++/Java arithmetic, logical, and assignment operators are supported.

All C++/Java flow control statements are supported (if-else, do-while, while, for, case).

Flavor supports all of the C++ and Java arithmetic, logical, and assignment operators. However, parsable variables cannot be used as lvalues. (Note: This ensures that they always represent the bitstream’s contents, and allow consistent operation for the translator-generated put() and get() methods).

Flavor also supports all the familiar flow control statements: if-else, do-while, while, and switch. In contrast with C++ and Java, variable declarations are not allowed within the arguments of these statements (i.e., 'for (int i=0; ; );' is not allowed. This is because in C++ the scope of this variable will be the enclosing one, while in Java it will be the enclosed one.

The following is an example of the use of these flow control statements.

    int(2) a;
    if (a==1) {
        int(3) b;
    }
    else {
        int(4) b;
    }

The variable b is declared with a parse size of 3 if a is equal to 1, and with a parse size of 4 otherwise. Observe that this construct would not be meaningful in C++ or Java as the two declarations would be considered as being in separate scopes. This is the reason why parsable variables need to obey slightly different scoping rules than regular variables (see Scoping Rules).