Compiler Design Gate Smashers
Imagine you have this simple code:
if (x > 0)
y = 10;
else
y = 20;
A standard compiler creates a branch (a gate):
A "Gate Smasher" compiler optimization transforms this into a single stream of instructions without jumps: compiler design gate smashers
The Optimized Assembly (Conceptual):
CMP x, 0 ; Compare x to 0
MOV eax, 10 ; Load 10 into register
MOV ebx, 20 ; Load 20 into register
CMOVG eax, ebx ; Conditionally move ebx to eax if Greater
By using CMOV, the compiler has "smashed" the branch. The CPU pipeline never stalls because there is no jump to predict. It simply calculates the data and selects the result on the fly. Imagine you have this simple code: if (x
Keywords: Tokens, Lexemes, Patterns, Regular Expressions.
Gate Smashers Focus: How does the compiler break int a = b + 5 into tokens?
GATE Question Pattern: Given a RE, find the number of tokens. Or, "Which error is detected by the Lexical Analyzer?" A standard compiler creates a branch (a gate):
GATE Example:
For E → E1 + E2, E.val = E1.val + E2.val (synthesized).
Type checking: