title: Handling prolog context free grammar
body: <p>Given a CFG</p>
  
  <pre><code>S --&gt; a S b | c | d
  </code></pre>
  
  <p>I wanna write a predicate like, <strong>grammar('S', sentence)</strong> which generates all possible </p>
  
  <pre><code>sentences like
  sentence=acb,
  sentence=acd,
  sentence=c,
  sentence=ab......................
  </code></pre>
  
  <p>Using <em>left most derivation</em>, if the encountered symbol is <em>terminal</em> it should print out that terminal, and if the encountered symbol is <em>non terminal</em> <strong>'S'</strong>, it should backtrack and substitute and one of the grammar <strong>a S b or c or d</strong> and repeat the process.</p>
  
  <p>I dont want any code...just help me with some tips how to start with</p>