title: Creating custom PHP Syntax Parser
body: <p>I am thinking about how one would go about creating a PHP equivalent for a couple of libraries I found for CSS and JS. </p>
  
  <p>One is <code>Less CSS</code> which is a <code>dynamic stylesheet language</code>. The basic idea behind <code>Less CSS</code> is that it allows you to create more dynamic CSS rules containing entities that "regular" CSS does not support such as <code>mixins</code>, <code>functions</code> etc and then the final <code>Less CSS</code> <strong>compiles</strong> those syntax into regular CSS.</p>
  
  <p>Another interesting JS library which behaves in a (kind of) similar pattern is <code>CoffeeScript</code> where you can write "tidier &amp; simpler" code which then gets <strong>compiled</strong> into regular Javascript.</p>
  
  <p>How would one go about creating a simple similar interface for PHP? Just as a proof of concept; I am only trying to learn stuff. Lets just take a simple use case of extending classes.</p>
  
  <pre><code>class a
  {
      function a_test()
      {
          echo "This is test in a ";
      }
  }
  
  class b extends a
  {
      function b_test()
      {
          parent::a_test();
          echo "This is test in b";
      }
  }
  
  $b = new b();
  $b-&gt;b_test();
  </code></pre>
  
  <p>Suppose I want to let the user write class <code>b</code> as (just for the example):</p>
  
  <pre><code>class b[a] //would mean b extends a
  {
      function b_test()
      {
          [a_test] //would mean parent::a_test()
          echo "This is test in b";
      }
  }
  </code></pre>
  
  <p>And let them later have that code "resolve" to regular PHP (Usually by running a separate command/process I would believe). My question is how would I go about creating something like this. Can it be done in PHP, would I require to use something like C/C++. How should I approach this problem if I were to go at it? Are there any resources online? Any pointers are deeply appreciated!</p>