Saturday, November 01, 2003

Ok, now on to solving A in the book under number 7. What is the difference between it and what we just did? Instead of doing just one statement, we are doing a series of statements. Before we just delt with

while (a <= 9) S1

Now we are dealing with a whole block of statements...

{ if (C1)
S1;
S2;
}


I am going to use [ ] to mark out seperate statements and put it on one line here.

{ [if (C1) S1][S2]}

another words we have two statements we are dealing with here not just one. So what do we do. Well the example as it is in the book at this point in time is no good, as we are at a step before that step. To me, what I see in the grammar rules that fits this is statement list. But in checking what out instructor posted in the doc share I see that I am wrong. He says that it is a compound-statement. I see that he went back one step further than I did. That being the case.... <compund-statement> breaks down to { <declaration-list> <statement-list>}

OK I hear it now, we do not have a decloration list... well one of the items under the declaration list is that fully looking E, that means that it can be empty string. so for review, here is our chart so far.


<compound-statement>
|
________________________________________
| | | |
{ <declration-lists> <statemen-tlist }
|
E


Any questions.... nope, gee I must be good. ok from our original we have the { and the } taken care of, now to work on the statment-list. statement-list breaks down to the E OR <statement> OR <statement-list><statement>. Since we have more than one statement to deal with we have to go with <statement-list><statement>


<compound-statement>
|
________________________________________
| | | |
{ <declration-lists> <statemen-tlist> }
| |
E |
____________________
| |
<statement-list><statement>


We know that the <statement> breaks down to S2 but it takes a convulted way of getting there cause we have to worry about the ;.
<statement> breaks down to <expression> and ; and we now can make the <expression> S2

<compound-statement>
|
________________________________________
| | | |
{ <declration-lists> <statemen-tlist> }
| |
E |
____________________
| |
<statement-list><statement>
|
__________
| |
<expression> ;
|
S2

So now we have {. } and S2 taken care of. All we have left is if (C1) S1; to fit it into <statement-list> Again we cheat a bit here and work backwards... we need a if statement. What can we use from grammar rules to get it? Only one thing will let us to it, a <selection-statement>. So we look back and how to we get from <statement> to <selection-statement>, well <statement> can become a <selection-statement> along with several others. But right now we are sitting at <statement list> Look carefully what is under <statement list>, yup <statement>. Or in other words:


<compound-statement>
|
________________________________________
| | | |
{ <declration-lists> <statemen-tlist> }
| |
E |
____________________
| |
<statement-list><statement>
| |
| __________
| | |
| <expression> ;
| |
| S2
<statement>
|
<selection-statement>

<selection-statement> breaks down to the one we are looking fo: if (<expression> ) <statement>. <expression>, in this case breaks down easy also (it does not in later assignments). It is C1 So:

<compound-statement>
|
________________________________________
| | | |
{ <declration-lists> <statemen-tlist> }
| |
E |
____________________
| |
<statement-list><statement>
| |
| __________
| | |
| <expression> ;
| |
| S2
<statement>
|
<selection-statement>
_________________________
| | |
if (<expression>) <statement>
| |
(C1)


Now the other half. statement must break down into an expression and a ; . It must be come a <expression-statement>. That will break down to an <expression> and a ;.

<compound-statement>
|
________________________________________
| | | |
{ <declration-lists> <statemen-tlist> }
| |
E |
____________________
| |
<statement-list><statement>
| |
| __________
| | |
| <expression> ;
| |
| S2
<statement>
|
<selection-statement>
_________________________
| | |
if (<expression>) <statement>
| |
(C1) <expression-statement>
__________
| |
<expression> ;


Now replace the <expression> with S1 and our job is done:


<compound-statement>
|
________________________________________
| | | |
{ <declration-lists> <statemen-tlist> }
| |
E |
____________________
| |
<statement-list><statement>
| |
| __________
| | |
| <expression> ;
| |
| S2
<statement>
|
<selection-statement>
_________________________
| | |
if (<expression>) <statement>
| |
(C1) <expression-statement>
__________
| |
<expression> ;
|
S1


If this does not line up I am not sure what to tell you, I used standard fonts on my browser to put it together.
I hope this helps at least one classmate, if it does the time putting it together was worth it.

No comments:

Post a Comment