title: How to implement a BNF grammar tree for parsing input in GO?
body: <p>The grammar for the type language is as follows:</p>
  
  <pre><code>TYPE ::= TYPEVAR | PRIMITIVE_TYPE | FUNCTYPE | LISTTYPE;
  PRIMITIVE_TYPE ::= ‘int’ | ‘float’ | ‘long’ | ‘string’;
  TYPEVAR ::= ‘`’ VARNAME; // Note, the character is a backwards apostrophe!
  VARNAME ::= [a-zA-Z][a-zA-Z0-9]*; // Initial letter, then can have numbers
  FUNCTYPE ::= ‘(‘ ARGLIST ‘)’ -&gt; TYPE | ‘(‘ ‘)’ -&gt; TYPE;
  ARGLIST ::= TYPE ‘,’ ARGLIST | TYPE;
  LISTTYPE ::= ‘[‘ TYPE ‘]’;
  </code></pre>
  
  <p>My input like this:  TYPE </p>
  
  <p>for example, if I input (int,int)->float, this is valid. If I input ( [int] , int), it's a wrong type and invalid.</p>
  
  <p>I need to parse input from keyboard and decide if it's valid under this grammar(for later type inference). However, I don't know how to build this grammar with go and how to parse input by each byte. Is there any hint or similar implementation? That's will be really helpful.</p>