Removed reduntant part of code in compilef.

To follow the DRY rule I've separated the duplicated part of the code into another function. To gain the effect of creating an output string from left to right (or right to left) the input string or the output string should be reversed.