Replacing Arithmetic operations in C program with ternary operations and return the modified program

64 Views Asked by At

This is my first post on a community forum like stackoverflow so please forgive any mistakes.

I am working in the field of program repair and unable to pass this roadblock. For every arithmetic operation in a program, the goal is to introduce another arithmetic operation (inverse of current operator) between the same operands, such that decision to choose between the original operation and new operation can be chosen conditionally during run time.

For Example : Consider the snippet

d = a + b;

Here, the statement should be replaced with

d = b1 ? a + b : a - b;

b1 is a boolean variable introduced to make the decision. This has to be done for every arithmetic operation in a given c program.

Consider the following c Program

int function(int a, int b, int c) {
  int d = a + b * c;
  return d;
}

The output should be

int function(int a, int b, int c, int b1, int b2) {
  int d = (b2 ? a + (b1 ? b * c : b / c) : a - (b1 ? b * c : b / c)) ;
  return d;
}

Here again, b1 and b2 are boolean variables introduced to make the decision.

I am still not sure what's the best way to do this. I tried designing a parser but being new to the field, was unable to do so as unlike parsing, new statements have to be added here.

I am stuck on this for days and any help would be appreciated.

0

There are 0 best solutions below