0
0
Compiler Designknowledge~10 mins

Dead code elimination in Compiler Design - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to identify dead code by checking if a statement's result is {{BLANK_1}}.

Compiler Design
if statement.result == [1]:
    print("Dead code detected")
Drag options to blanks, or click blank then click option'
Anull
Bused
Cactive
Dunused
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'used' with 'unused' when checking code usage.
2fill in blank
medium

Complete the code to remove dead code by deleting statements that have no side effect.

Compiler Design
for stmt in program.statements:
    if not stmt.has_side_effect and stmt.result == None:
        program.statements.remove([1])
Drag options to blanks, or click blank then click option'
Aprogram
Bresult
Cstmt
Dside_effect
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to remove the whole program or unrelated attributes.
3fill in blank
hard

Fix the error in the code that checks if a variable is dead by comparing its use count.

Compiler Design
if variable.[1] == 0:
    mark_as_dead(variable)
Drag options to blanks, or click blank then click option'
Ause_count
Bdefinition
Cvalue
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Checking variable name or value instead of usage count.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps variables to their usage count only if the count is zero.

Compiler Design
dead_vars = {var: var.[1] for var in variables if var.[2] == 0}
Drag options to blanks, or click blank then click option'
Ause_count
Bvalue
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names or values instead of usage count.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps variable names in uppercase to their usage count, but only if the usage count is zero.

Compiler Design
dead_vars = { [1]: [2] for var in variables if var.[3] == 0}
Drag options to blanks, or click blank then click option'
Avar.name.upper()
Bvar.use_count
Cuse_count
Dvar.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without uppercase or wrong property names.