Mr. Sumeet kothari Vaishali Atoot (0832CS211198) Vasu Singh kushwaha (0832CS211196) Vimal Mishra (0832CS211197) Vishakha Mathurkar (0832CS211198) Backpatching Backpatching is the technique of updating previously generated code during the code generating phase. It involves filling the missing addresses or offsets of instructions or data that were initially left unspecified .this is the commonly used situation where the exact memory location or addresses are not known at the time of the code generation. During the initial code generation , the addresses for the jump instructions are not known, so we leave placeholders like if and else in the generated code. Later when we know the addresses of the “if” and “else” blocks, we can go back and update those placeholders with the correct addresses using the backpatching technique. This ensures that the executes the correct block based in the conditions Functions used for Backpatching •Makelist (i): Create a new list including only i, an index into the array of instructions and the makelist also returns a pointer to the newly generated list. •Merge(p1,p2): Concatenates the lists pointed to by p1, and p2 and returns a pointer to the concatenated list. •Backpatch (p, i): Inserts i as the target label for each of the instructions on the record pointed to by p. Need for Backpatching Backpatching is mainly used for two purposes: Boolean expression: Boolean expressions are statements whose results can be either true or false.Let’s look at some common language examples: My favorite color is blue. → true I am afraid of mathematics. → false Flow of control statements: The flow of control statements needs to be controlled during the execution of statements in a program. Labels and Gotos: The most elementary programming language construct for changing the flow of control in a program is a label and goto. When a compiler encounters a statement like goto L, it must check that there is exactly one statement with label L in the scope of this goto statement. Applications Of Backpatching Conditional statements: Backpatching is frequently used in the code generation of conditional statements, such as if-else and switch-case statements. Loop constructs: Backpatching plays a vital role in generating code for loop constructs, such as while and for loops. Jump instructions: Backpatching is employed when generating code for jump instructions, such as goto statements or function calls. Code optimization: Backpatching is sometimes used in code optimization techniques, such as constant folding or dead code elimination. Step-1 Generation of the production table Step-2 A < B OR C < D AND P < Q Step-3 THANK YOU!!!