title: Pre-Processing using m4
body: <p>I am writing a pre-processor for Free-Pascal (Course Work) using <a href="https://www.gnu.org/software/m4/" rel="nofollow noreferrer">m4</a>. I was reading the thread at stackoverflow <a href="https://stackoverflow.com/questions/396644/replacements-for-the-c-preprocessor">here</a> and from there reached a <a href="https://kvanberendonck.wordpress.com/tag/m4/" rel="nofollow noreferrer">blog</a> which essentially shows the basic usage of <code>m4</code> for pre-processing for <code>C</code>. The blogger uses a testing <code>C</code> file <code>test.c.m4</code> like this:</p>
  
  <pre><code>#include 
  
  define(`DEF', `3')
  
  int main(int argc, char *argv[]) {
          printf("%d\n", DEF);
          return 0;
  }
  </code></pre>
  
  <p>and generates processed <code>C</code> file like this using <code>m4</code>, which is fine.</p>
  
  <pre><code>$ m4 test.c.m4 &gt; test.c
  $ cat test.c
  #include &lt;stdio.h&gt;
  
  
  
  int main(int argc, char *argv[]) {
      printf("%dn", 3);
      return 0;
  }
  </code></pre>
  
  <p>My doubts are:<br>
  1. The programmer will write the code where the line</p>
  
  <pre><code>    define(`DEF', `3')
  </code></pre>
  
  <p>would be </p>
  
  <pre><code>    #define DEF 3
  </code></pre>
  
  <p>then who converts this line to the above line? We can use tool like <code>sed</code> or <code>awk</code> to do the same but then what is the use of <code>m4</code>. The thing that <code>m4</code> does can be implemented using <code>sed</code> also.<br>
  It would be very helpful if someone can tell me how to convert the programmer's code into a file that can be used by <code>m4</code>.<br><br>
  2. I had another issue using <code>m4</code>. The comment in languages like <code>C</code> are removed before pre-processing so can this be done using <code>m4</code>? For this I was looking for commands in <code>m4</code> by which I can replace the comments using regex and I found <code>regexp()</code>, but it requires the string to be replaced as argument which is not available in this case. So how to achieve this?
  <br><br>
  Sorry if this is a naive question. I read the documentation of <code>m4</code> but could not find a solution.</p>