title: Grammar production class implementation in C#
body: <p>Grammar by definition contains productions, example of very simple grammar:</p>
  
  <pre><code>E -&gt; E + E
  E -&gt; n
  </code></pre>
  
  <p>I want to implement Grammar class in c#, but I'm not sure how to store productions, for example how to make difference between terminal and non-terminal symbol.
  i was thinking about:</p>
  
  <pre><code>struct Production
  {
     String Left;       // for example E
     String Right;      // for example +
  }
  </code></pre>
  
  <p>Left will always be non-terminal symbol (it's about context-free grammars)
  But right side of production can contain terminal &amp; non-terminal symbols</p>
  
  <p>So now I'm thinkig about 2 ways of implementation:</p>
  
  <ol>
  <li><p>Non-terminal symbols will be written using brackets, for example:</p>
  
  <p>E+E will be represented as string "[E]+[E]"</p></li>
  <li><p>Create additional data structure NonTerminal</p>
  
  <p>struct NonTerminal
  {
    String Symbol;
  }</p></li>
  </ol>
  
  <p>and E+E will be represented as array/list:</p>
  
  <pre><code>[new NonTerminal("E"), "+", new NonTerminal("E")]
  </code></pre>
  
  <p>but think that there are better ideas, it would be helpfull to hear some response</p>