title: writing a parser in prolog
body: <p>Here is the grammar:</p>
  
  <pre><code>&lt;S&gt;-&gt;&lt;X&gt;&lt;Y&gt;&lt;Z&gt;
  &lt;X&gt;-&gt;a&lt;X&gt;|a
  &lt;Y&gt;-&gt;b&lt;Y&gt;|b
  &lt;Z&gt;-&gt;c&lt;Z&gt;|c
  </code></pre>
  
  <p>I need to write a parser in this grammar.</p>
  
  <p>and when test S([a,a,b,c,c,c],[]).
  it should return true.
  in my code I defined match rule to check list elements.</p>
  
  <pre><code>
  match(H,[H|T],T).
  na(X0,X1):-match(a,X0,X2). 
  nb(X0,X1):-match(b,X0,X2). 
  nc(X0,X1):-match(c,X0,X2).
  ns(X0,X1):-na(X0,X2),nb(X2,X3),nc(X3,X1).
  </code></pre>
  
  <p>what is wrong in this code? it give true but when you trace. it does not working.</p>
  
  <p></p>