title: How do I parenthesize an expression?
body: <p>I have an idea for a simple program to make that will help me with operator precedence in languages like C. The most difficult part of this is parenthesizing the expression. For example, I want this:</p>
  
  <pre><code>*a.x++ = *b.x++
  </code></pre>
  
  <p>Converted to this:</p>
  
  <pre><code>((*(((a).(x))++)) = (*(((b).(x))++)))
  </code></pre>
  
  <p>Which I did manually in these steps:</p>
  
  <pre><code>           *a.x++ = *b.x++
         *(a).(x)++ = *(b).(x)++
       *((a).(x))++ = *((b).(x))++
     *(((a).(x))++) = *(((b).(x))++)
   (*(((a).(x))++)) = (*(((b).(x))++))
  ((*(((a).(x))++)) = (*(((b).(x))++)))
  </code></pre>
  
  <p>What is the best way to accomplish this? Is there already a solution out there that I could use? I'd prefer to do this in either PHP, C, C++, Python, or Ruby.</p>
  
  <p>(This isn't the whole idea of my program, it is only the first step.)</p>