The bulk of this lecture is still in power-point form
In many of the syntax definitions we use to define flow-of-control you will see the term statement
It is important to understand that whenever you see it it can mean
{ }
)These can be slightly tricky to define. Here's a partial grammar for various kinds of statements
We've seen the declaration-statement in the section on variables.
Type Identifier ;
|
Type Identifier = Value ;
expressionopt ;|
return expressionopt ;|
other executable statement
declaration-statement |
executable-statement
single-statement |
statement-sequence
single-statement
5. statement-block:
{statement sequenceopt}
6. statement:
executable-statement |
statement-block
Example:
{ // open block
double pi=3.14159; //dec
cout << pi; // exec
} // close block
Interpretation: The second line is a declaration-statement. The 3rd line is an executable statement. 2 and 3 together constitute a statement-sequence and lines 1-4 are a statement-block. Thus line 3 is a statement as is lines 1-4 taken together.
Let's just take a little more extensive example:
double pi = 3.14159; double r = 2.4; double y; y = 4*pi*r*r/3; cout<<"The area is " << y << endl;
Now we try to categorize it according to the grammar
;
and
so is an executable
statement of the first type.cout<<"The
area is " << y << endl
is technically an expression!Now it gets interesting
Here are a bunch of examples. Try to decide, based on the grammar above, exactly what each of them corresponds to (it may be more than one).
{};
{ y=3.5; }
x