jflexcup

Jflex and CUP not working on vscode and mac


I downloaded jflex by doing brew install jflex everything worked the way it should.

But now when I'm trying to make it work with java_cup.runtime.*. And I keep getting the errors below

Lexer.java:681: error: cannot find symbol
          { return new java_cup.runtime.Symbol(sym.EOF); }
                                               ^
  symbol:   variable sym
  location: class Lexer

My proffesor said,

"The Symbol class is part of the parser (JavaCUP)’s runtime jar file. You may use it in the lexer simply by setting the classpath to include the jar file from JavaCUP and importing it"

So I made bash file below and did what he said and it is not working.

#!/bin/bash
jflex MiniJava.jflex
javac -cp "/Users/carlosfield/Desktop/School/csc453/java-cup-bin-11b-20160615/java-cup-11b.jar" Lexer.java
java -cp "/Users/carlosfield/Desktop/School/csc453/java-cup-bin-11b-20160615/java-cup-11b-runtime.jar"  Lexer Factorial.java
rm Lexer*

This is my jflex file

import java.util.*;
import java_cup.runtime.*;
%% 
%class Lexer
%cup
%line
%column
%{
private Symbol symbol(int type) {
    return new Symbol(type, yyline, yycolumn);
}
private Symbol symbol(int type, Object value) { 
    return new Symbol(type, yyline, yycolumn, value); 
} 
%} 
WhiteSpace = [ \t\r\n]
Identifier = [a-zA-Z_][a-zA-Z0-9_]*
Integer = 0 | [1-9][0-9]* 
%% 
“+” {  }

Solution

  • The fix for this issue is that if you use %cup in your jflex file you must then make your own sym class which contains public static final int EOF=0.