0
0
Compiler Designknowledge~10 mins

Common subexpression 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 a common subexpression in the given expressions.

Compiler Design
if (a + b) == [1]:
Drag options to blanks, or click blank then click option'
Aa * b
Ba - b
Cb + c
Da + b
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a different expression that is not repeated.
Confusing addition with subtraction or multiplication.
2fill in blank
medium

Complete the code to replace a repeated expression with a temporary variable.

Compiler Design
temp = [1]
result = temp * 2
Drag options to blanks, or click blank then click option'
Ac * d
Ba - b
Ca + b
Db + c
Attempts:
3 left
💡 Hint
Common Mistakes
Using an expression that is not repeated.
Not assigning the expression to a temporary variable.
3fill in blank
hard

Fix the error in the code to correctly eliminate the common subexpression.

Compiler Design
result = (x + y) * 2
value = (x + [1]) - 3
Drag options to blanks, or click blank then click option'
Ay
Bz
Cx
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable that breaks the common subexpression.
Replacing with a constant instead of the variable.
4fill in blank
hard

Fill both blanks to create code that eliminates the common subexpression 'a * b'.

Compiler Design
[1] = a * b;
result1 = [2] + c;
result2 = [2] * d;
Drag options to blanks, or click blank then click option'
Atemp
Ba * b
Ca + b
Db * a
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the temporary variable.
Putting the expression in the reuse spots instead of the temp name.
5fill in blank
hard

Fill all three blanks to eliminate common subexpressions in a chained computation.

Compiler Design
[1] = x + y;
[2] = [1] * z;
final = [3] + w;
Drag options to blanks, or click blank then click option'
At1
Bt2
Dx + y
Attempts:
3 left
💡 Hint
Common Mistakes
Reusing the wrong temporary.
Not chaining the dependencies correctly.
Using the original expressions instead of temps.