title: Parse EOF token in CUP
body: <p>I'm having trouble making my CUP parser parse the EOF token. I read in the documentation that using the <code>%cup</code> flag in my Jflex code implies that there is something present like this:</p>
  
  <pre><code>%eofval{
    return new java_cup.runtime.Symbol(&lt;CUPSYM&gt;.EOF);
  %eofval}
  %eofclose
  </code></pre>
  
  <p>This is all good and well, but when I try the following first rule in my grammar (CUP file):</p>
  
  <pre><code>program                 ::=   program declaration EOF
                            | /* Empty */
                            ;
  </code></pre>
  
  <p>I get the error message that EOF is not declared by CUP. </p>
  
  <pre><code>Error : java_cup.runtime.Symbol "EOF" has not been declared
  </code></pre>
  
  <p>Allrighty, so I add the following to my CUP file:</p>
  
  <pre><code>terminal EOF;
  </code></pre>
  
  <p>No, because then CUP tells me:</p>
  
  <pre><code>Fatal : JavaCUP Internal Error Detected: Duplicate terminal (EOF) created
  enter code here
  </code></pre>
  
  <p>However, without defining the terminal EOF, and I have a look in the <code>sym.java</code> class that Cup generates I do find:</p>
  
  <pre><code>  public static final int EOF = 0;
  </code></pre>
  
  <p>So I'm pretty lost on how to fix this. The documentation for both is really vague on the issue.</p>
  
  <p>Edit:
  The main reason I want to parse the EOF token is because I want to print out my symbol table in the end and other stuff for debugging purposes.</p>