1) before doing left shift i have to typecast variable to unsigned 2) after this i have to put proper paranthesis. 3) find out the type of variable on the left side of = and typecast the whole operation to the that type

please don't cross post the same question. Delete or close this thread as the other one already has a reply and better defines what you are trying to do. -------------------------------------------------

The code seems to work correctly, but is not a generic solution. At the moment, this code try to find a declaration (e.g. "int a;" or "int b=0;") reading the lines before the "var1 <<= var2" line. To do that, it uses the following regex:

Code

m/(char|int|long|float|double)\s+$var[^\(]/

this regex can find only the types specified and is not capable to understand if the declaration is contained in a struct or in a string.

In any case, I hope you can solve your problem with the help of this code.