title: How can I parse C switch-case and for Statement in AWK?
body: <p>How to parse switch-case statement like below with awk? I want to create simple C syntax checker with awk. This checker must read the code and return whether there is syntax error or not. If there is, awk should print what error on it.</p>
  <pre><code>switch(number)
  {
      case 1  : number = 'a'; break;
      case 2  : number = 'b'; break;
      default : number = 'x'; 
  }
  </code></pre>
  <p>And for <strong>for()</strong> statement, like this:</p>
  <pre><code>for(i=0;i&lt;10;i++) 
      {
          number = 'A';
      }
  </code></pre>
  <p>My current code for <strong>switch-case</strong> statement was:</p>
  <pre><code>#parser_switchcase.awk
  {
  for(i=1; i&lt;=NF; i++)
  {
    if($i~/switch\([[:alnum:]]+\)/)
      print(&quot;switch(VALID_VARIABLE)&quot;)
  }
  
  }
  </code></pre>
  <p>result for my first C <strong>switch-case</strong> code above:</p>
  <pre><code>master@master:~/Dokumen/Root$ awk -f parser_switchcase.awk soalswitch 
  switch(VALID_VARIABLE)
  </code></pre>
  <p>but really it needs many improvements. It is not complete.</p>
  <p>I need awk suggestion just for reading and checking exactly code examples I have typed above. Exactly, so I just need awk parsing code for those, not the outside possibility such as additional function, additional code, only what mentioned on the codes above.</p>