title: YACC|BISON :How do I manipulate parse tree?
body: <p>The goal of my application is to validate an sql code and generate,in the mean time, from that code a formatted one with some modification.<br/>For example this where clause :<br/></p>
  
  <blockquote>
    <p>where <br/> e.student_name= c.contact_name and  (   c.address =  "   nefta"
    or c.address="  tozeur ") and<br/> e.age &lt;18 <br/></p>
  </blockquote>
  
  <p>we will have as formatted output something like that :<br/></p>
  
  <blockquote>
    <p>where  e.student_name= c.contact_name <br/>and  (c.address=trim("nefta")
    <br/>or c.address=trim("tozeur") ) <br/>and e.age &lt;18 <br/></p>
  </blockquote>
  
  <p>I hope I've explained my aim well</p>
  
  <hr>
  
  <p>The problem is grammars may contain recursive rules which make the rewrite task unreliable ; for instance in my sql grammar i have this :</p>
  
  <pre>search_condition         : search_condition OR search_condition{clbck_or}
                           | search_condition AND search_condition{clbck_and}
                           | NOT search_condition {clbck_not}
                           | '(' search_condition ')'{clbck__}
                           | predicate {clbck_pre}
                           ;
  </pre>
  
  <p>Knowing that I specified a precedence priority to solve shift reduce problems <br/></p>
  
  <blockquote>
    <p>%left OR<br>
    %left AND<br>
    %left NOT</p>
  </blockquote>
  
  <p>So back on the last example ; my clause where will be consumed this way:</p>
  
  <blockquote>
    <p>c.address="nefta"or c.address="tozeur" -> search_condition<br/> 
    (c.address="nefta"or c.address="tozeur")->search_condition<br/>
     e.student_name= c.contact_name and (c.address="nefta"or c.address="tozeur")-> search_condition<br/>
     ... and e.age&lt;18-> search_condition<br/></p>
  </blockquote>
  
  <p>You can by the way understand that it's tough to rebuild the input stream referring to callbacks triggered by each reduction cause the order is not the same.</p>
  
  <p>Any help for this problem ? </p>