title: Linking CUP and jflex
body: <p>I am trying to link my parser.java and yylex.java using help from <br><a href="http://www2.cs.tum.edu/projects/cup/examples.php" rel="nofollow">http://www2.cs.tum.edu/projects/cup/examples.php</a> <br>
  <a href="http://www.cs.princeton.edu/~appel/modern/java/CUP/manual.html" rel="nofollow">http://www.cs.princeton.edu/~appel/modern/java/CUP/manual.html</a> <br>
  <a href="http://jflex.de/manual.html" rel="nofollow">http://jflex.de/manual.html</a></p>
  
  <p>But I am getting these errors.</p>
  
  <blockquote>
    <p>error: Yylex is not abstract and does not override abstract method
    next_token() in Scanner</p>
    
    <p>error: next_token() in Yylex cannot implement next_token() in Scanner</p>
  </blockquote>
  
  <p>How to resolve them ?</p>
  
  <p>My mini.flex file is:</p>
  
  <pre><code>import java.io.*; 
  
  %%
  
  %public
  %cup 
  %line
  %column
  %type int
  
  identifier = {letter} ( {letter} | {decimal_digit} )*
  letter        = [a-z] | "_"
  decimal_digit = [0-9]
  
  LineTerminator = \r|\n|\r\n
  WhiteSpace     = {LineTerminator} | [ \t\f]
  Comment = {GeneralComment} | {LineComment}
  GeneralComment   = "/*"([^*]|\*+[^*/])*\*+"/"
  LineComment     = "//" {LineTerminator}?
  
  %%
  
  &lt;YYINITIAL&gt; { 
  "break" { return sym.breakd; }
  "default" { return sym.defaultd; }
  }
  
  &lt;YYINITIAL&gt; {
    {identifier} { return sym.identifier; }
  }
  
  &lt;YYINITIAL&gt; { 
  "+" {return sym.plus_op;}
  "&amp;" {return sym.amp_op;}
  }
  
  &lt;YYINITIAL&gt; { 
    {Comment}                      { /* ignore */ }
    \n                             { }
    {WhiteSpace}                   { /* ignore */ }
    [^]                            { /*Illegeal Character*/ }
  }
  </code></pre>
  
  <p>My mini.cup file is:</p>
  
  <pre><code>// import java-cup-11b-runtime.*;
  
  import java_cup.runtime.*;
  
  parser code {: public Parser (java.io.Reader input) { super(new Yylex(input)); } :};
  
  /* Preliminaries to set up and use the scanner.  */
  
  /*init with {: scanner.init();              :};
  scan with {: return scanner.next_token(); :};*/
  
  terminal identifier;
  terminal breakd, defaultd, plus_op, amp_op;
  
  non terminal SourceFile, UnaryExpr, Expression, Statement, SimpleStmt, EmptyStmt, ExpressionStmt, unary_op;
  
      precedence left plus_op;
  
  Expression ::= UnaryExpr | Expression plus_op UnaryExpr;
  UnaryExpr  ::=  unary_op identifier;
  unary_op   ::= plus_op | amp_op;
  
  Statement ::= SimpleStmt;
  SimpleStmt ::= EmptyStmt | ExpressionStmt;
  EmptyStmt ::= ; // should be Empty
  ExpressionStmt ::= Expression;
  
  SourceFile ::= Statement;
  </code></pre>
  
  <p>I compile using:</p>
  
  <pre><code>java -jar java-cup-11b.jar -interface -parser Parser mini.cup
  jflex mini.flex
  javac -cp java-cup-11b-runtime.jar:. -Xlint *.java
  </code></pre>
  
  <p>The errors thrown are:</p>
  
  <blockquote>
    <p>Parser.java:19: warning: [deprecation] lr_parser() in lr_parser has
    been deprecated public Parser() {super();} <br>
                       ^ Parser.java:22: warning: [deprecation] lr_parser(Scanner) in lr_parser has been deprecated public
    Parser(java_cup.runtime.Scanner s) {super(s);} <br>
                                                 ^ Parser.java:96: warning: [deprecation] lr_parser(Scanner) in lr_parser has been
    deprecated public Parser (java.io.Reader input) { super(new
    Yylex(input)); }  <br>
                                            ^ Parser.java:137: warning: [cast] redundant cast to Object Object start_val =
    (Object)((java_cup.runtime.Symbol)
    CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; <br>
                             ^ <strong>Yylex.java:12: error: Yylex is not abstract and does not override abstract method next_token() in Scanner</strong> <br> public
    class Yylex implements java_cup.runtime.Scanner {
           ^ <br>
    Yylex.java:474: <strong>error: next_token() in Yylex cannot implement next_token() in Scanner</strong> <br>   public int next_token() throws
    java.io.IOException { <br>
                 ^ return type int is not compatible with Symbol <br> Yylex.java:631: error: incompatible types <br>  { return new
    java_cup.runtime.Symbol(sym.EOF); } <br>
                           ^ required: int <br> found:    Symbol <br> 3 errors <br> 4 warnings <br></p>
  </blockquote>