|
|
|
|
|
|
|
|
|
|
|
Statements
|
|
|
A statement, by definition, includes a terminating semi-colon. |
|
|
|
|
|
Example : |
|
|
|
|
|
|
|
|
|
|
|
The following is not legal and generates a parse error. |
|
|
|
|
|
if(1) ; else ; |
|
|
|
|
|
Example : Statement
|
|
|
|
|
|
1 program statement {
2 // Valid statements
3 integer a;
4 a = 10;
5 // Invalid statements
6 if (10); else; // This will give compile error
7 }
You could download file statement.vr here
|
|
|
|
|
|
Statement Blocks
|
|
|
A statement block, by definition, is created by using braces to group a sequence of variable declarations and statements. The declared variables are visible to the statements declared within the braces. |
|
|
|
|
|
{ |
|
|
statment1; |
|
|
statement2; |
|
|
} |
|
|
|
|
|
Empty block is {} without any statments in it. |
|
|
|
|
|
|
|
|
|
|
|
Example : Statement Block
|
|
|
|
|
|
1 program statement_block {
2 {
3 integer i = 10;
4 printf ("Value of i : %d\n",i);
5 }
6 // Empty statement block
7 {
8
9 }
10 // One more statment block
11 {
12 integer j = 15;
13 printf ("Value of j : %d\n",j);
14 }
15 }
You could download file statement_block.vr here
|
|
|
|
|
|
Assignment
|
|
|
Assignment is the primitive operation to initialize or change the value of a variable. Assignments are allowed in the scope of a program, task, function or statement block. |
|
|
|
|
|
Syntax variable_name = expression; |
|
|
|
|
|
Is the name of the variable to which the value is assigned. expression The value of the expression evaluated at the execution of the assignment is assigned to the variable. |
|
|
|
|
|
Variable declarations must be placed before any executable statements in a program, task, function, or statement block. Optionally, a variable declaration may contain an assignment to initialize the variable. Initializations are equivalent to inserting assignments to variables before the first executable statement. |
|
|
|
|
|
Compound Assignment
|
|
|
Vera supports compound assignments that are equivalent to valid assignments in a compacted form. |
|
|
|
|
|
Syntax var1 operator= var2 ; operator |
|
|
|
|
|
Supported operators are: +, - , *, /, %, & (bit-wise and), | (bit-wise or), ^ (bit-wise exclusive or), << and >>, also &~ |~ ^~, for which the compound operators are named ~&= ~|= ~^=. |
|
|
|
|
|
The compound assignment performs the same operation as: |
|
|
|
|
|
var1 = var1 operator var2; |
|
|
|
|
|
Vera does not support assignment recursion as in C and C++ language. |
|
|
|
|
|
Example : Compound Assignment
|
|
|
|
|
|
1 program compound_assignment {
2 integer i = 55; // Variable init
3 integer j = 20; // one more variable
4 integer m,n;
5 i = j + 1; // Compound assignment
6 i ++ ;//
7 // Below code is invalid assignment
8 m = n = i;
9 }
You could download file compound_assignment.vr here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|