title: Problem yacc in golang: syntax error: unexpected $end
body: <p>A cordial greeting.</p>
  
  <p>I'm learning yacc in golang and i created this file:</p>
  
  <pre><code>%{
  
  package main
  
  import (
      "fmt"
  )
  
  %}
  
  %union{
      ex string
  }
  
  %token &lt;ex&gt; DB OTHER_DB
  
  %% 
  query:  other
          |
          db
          ;
  
  db:     DB
          {
              fmt.Printf("\tDB: %s\n", $1 )
          }
          ;
  
  other:  OTHER_DB
          {
              fmt.Printf("\tOTHER_DB: %s\n", $1 )
          }
          ;
  %% 
  
  type mlex struct {
      expr   string
      result int
  }
  
  func (f *mlex) Lex(lval *yySymType) int {
      yyErrorVerbose = true
      return 0
  }
  
  func (f *mlex) Error(s string) {
      fmt.Printf("syntax error: %s\n", s)
  }
  
  func Parse(expr string) int {
      m := &amp;mlex{expr, 0}
      yyParse(m)
      return m.result
  }
  </code></pre>
  
  <p>but when executing it I get this error:</p>
  
  <blockquote>
    <p>syntax error: syntax error: unexpected $end, expecting DB or OTHER_DB</p>
  </blockquote>
  
  <p>I have been testing this yacc file with this code:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  )
  
  func main() {
  
      res := Parse("db")
      fmt.Println(res)
  }
  </code></pre>
  
  <p><strong>What could it be ? Will I need anything else in the yacc file?</strong></p>
  
  <p>I am trying to make a very simple, fully functional example to understand it well.</p>
  
  <p>Thanks for your time. </p>