In compiler design, flow-of-control statements like if, if-else, and while require translation of Boolean expressions and jump instructions in intermediate code (such as three-address code). This is achieved using a syntax-directed definition (SDD).
Grammar for Flow-of-Control Statements:
S → assign
S → if ( B ) S1
S → if ( B ) S1 else S2
S → while ( B ) S1
S → S1 S2
Sis a statement.Bis a Boolean expression.assignstands for assignment statements likea = b + c;

| Attribute | Type | Description |
|---|---|---|
S.code | Synthesized | Generated three-address code for statement S |
B.code | Synthesized | Three-address code for Boolean expression B |
B.true | Inherited | Label to jump to if B is true |
B.false | Inherited | Label to jump to if B is false |
S.next | Inherited | Label after execution of statement S (used for managing jumps) |

Note:
- All labels ensure proper branching.
- The
gotostatements help in skipping or repeating blocks. - This approach assumes Boolean expressions are already translated with conditional jumps.
