我正在尝试在 Ubuntu 上学习有关 JFlex 和 Cup 工具的知识,因为我必须将它们用于学校项目。所以我下载并安装了 JFlex 和 Cup。“jflex-1.6.1/examples”中有一些示例,所以我尝试运行其中一个。特别是我尝试按照自述文件中的说明运行“jflex-1.6.1/examples/cup”中的那个:
编译:
jflex lcalc.flex
java java_cup.Main < ycalc.cup
javac Main.java
跑步:
java Main test.txt
文件:
"Main.java" demo of a main program
"Makefile " makefile to compile and test the example
"README"
"lcalc.flex" the lexer spec
"output.good " how the output should look like for the test
"ycalc.cup" the parser spec
"test.txt " sample input for testing
历经千辛万苦,终于能够编译,然后顺利完成前三条指令。现在我尝试运行时出现错误:java Main test.txt。特别是我得到这个错误:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: java_cup/runtime/Scanner
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: java_cup.runtime.Scanner
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
我不知道如何解决这个问题。我也尝试了其他示例,但结果相同。我希望你能帮助我。谢谢!