0

I've just started to learn JFlex. I am studying one of the official Jflex examples, which is a scanner for the Java language. In the Readme file it says:

The scanner (without parser attached) can be test with:
java TestLexer <inputfiles>

But when I tried this in cmd, I got an error message instead, saying 'Could not find or load main class TestLexer'.Does anyone know why? Thank you in advance.

phil
  • 255
  • 4
  • 16

1 Answers1

0

To test the lexer for Java, JFlex has a depency to the CUP parser generator, did you installed it?

Then there is several commands to make before being able to run the lexer:

jflex unicode.flex
jflex java.flex
java java_cup.Main -interface < java12.cup
javac JavaParser.java TestLexer.java

For the third command, you need to have the java-cup-11a.jar somewhere in your classpath.

Only then you would be able to test the parser:

java JavaParser <inputfiles>

or the scanner:

java TestLexer <inputfiles>
Seki
  • 11,135
  • 7
  • 46
  • 70
  • I tried again, but when executing the third line, I still got 'Could not find or load main class java_cup.Main. – phil Jan 28 '14 at 00:24
  • Try with `java -cp path_to_your_java-cup.jar java_cup.Main -interface < java12.cup` is it better? – Seki Jan 28 '14 at 13:14
  • Nope, I got 'The system cannot find the file specified'. But I have added the directory of java cup file to PATH variable. – phil Jan 28 '14 at 17:04
  • what is the name of the java-cup jar file? for a jar file, you need to add the directory to the `CLASSPATH` variable, not `PATH`, then you could omit the `-cp parameter` – Seki Jan 28 '14 at 19:04