Back Patching CC Presentation
Back Patching CC Presentation
Back patching is the activity of filling up the unspecified information of labels by using the appropriate
semantic expression in during the code generation process. It is done by Boolean expression.
It is putting the address instead of labels when the proper label is
determined.
For Example.
1. if a < b goto _
2. goto _
3. if c < d goto _
4. goto _
5. if e < f goto _
6. goto _
Back Patching Operations
1) make list (i) – creates a new list containing only i, an index into the array of quadruples and
returns a pointer to the list it has made.
2) Merge (i, j) – concatenates the lists pointed to by i and j, and returns a pointer to the
concatenated list.
3) Back patch (p, i) – inserts i as the target label for each of the statements on the list pointed
to by p.
One-Pass Code Generation Using
Backpatching
Backpatching can be used to generate code for boolean expressions and flow-of-control
statements in one pass. The translations we generate will be of the same form as those , except
for how we manage labels.
we generate instructions into an instruction array, and labels will be indices into this array. To
manipulate lists of jumps,
Truelist, Falselist
Boolean expressions are usually translated using the jump method since this is convenient
for optimization.
However, more than a single pass may be needed in order to generate code for boolean
expressions and flow of control during bottom-up parsing!
Indeed, when translating forward jumps, at the time we generate the code we do not know
the (numerical) address of the label we want to branch to
Semantic Rules for Incorporating Backpatching
104: if x != y goto
105: goto-
Flow-of-Control Statements
Translation of statements
Translation of statements
Goto-statements can be implemented by maintaining a list of unfilled jumps for each label
and then backpatching the target when it is known.
Java does away with goto-statements. However, Java does permit disciplined jumps called
break-statements, which send control out of an enclosing construct, and continue-
statements, which trigger the next iteration of an en-closing loop.
Code
The following excerpt from a lexical analyzer illustrates simple break- and continue-statements:
1) for ( ; ; readch() ) {
2) if( peek == ' ' || peek == '\t' ) continue;
3) else if( peek == '\n' ) line = line + 1;
4) else break;
5) }
Control jumps from the break-statement on line 4 to the next statement after
the enclosing for-loop. Control jumps from the continue-statement on line 2 to
code to evaluate readch() and then to the if-statement on line 2.