设置 javacc 以使用命令提示符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18674474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 10:04:59  来源:igfitidea点击:

Setting javacc to work with command prompt

javapathjavacc

提问by HBeel

I've been trying to set up javacc but am having problems. When I type javacc adder.jj (in the directory where adder.jj is) I am getting "'javacc' is not recognized as an internal or external command, operable program or batch file".

我一直在尝试设置 javacc,但遇到了问题。当我键入 javacc adder.jj(在 adder.jj 所在的目录中)时,我得到“'javacc' 未被识别为内部或外部命令、可运行的程序或批处理文件”。

To my understanding I have to go to environmental variables, TEMP and change PATH to have C:\javacc-6.0\bin; added to the start. (I extracted the javacc zip to C:). I have tried this and restarted my computer with no luck. I also tried adding C:\javacc-6.0\bin\lib but again no luck. I did this when I installed java to get cmd to recognise javac and it worked!

据我了解,我必须转到环境变量、TEMP 并将 PATH 更改为 C:\javacc-6.0\bin; 添加到开始。(我将 javacc zip 解压缩到 C:)。我已经尝试过这个并重新启动了我的电脑,但没有运气。我也尝试添加 C:\javacc-6.0\bin\lib 但再次没有运气。我在安装 java 以使 cmd 识别 javac 时这样做了,并且它起作用了!

This is probably trivial but I just can't get it to work!

这可能是微不足道的,但我就是无法让它工作!

Thank you

谢谢

Henry

亨利

采纳答案by A4L

In the version 6.0the bindirectory is missing the scripts which run javacc. That is why you are getting the error from the windows command prompt.

6.0版中,该bin目录缺少运行javacc. 这就是为什么您从 Windows 命令提示符处收到错误的原因。

What you have is a jar file javacc.jarlocated in the lib directory. All you need is to add that jar file to your classpathand run the java.exeand pass the main class which runs javacc, the later happens to be named javacctoo, so to run javaccjust proceed like this:

您拥有的是javacc.jar位于 lib 目录中的 jar 文件。您所需要的只是将该 jar 文件添加到您的classpath并运行java.exe并传递运行的主类javacc,后者恰好也被命名javacc,因此运行javacc只需像这样继续:

cmd>  java -cp C:\javacc-6.0\bin\lib\javacc.jar javacc

In the latest version they seem to have forgotten to add the scripts in the binfolder of the package. You can download version 5.0, it containes all the script files you need, among others a file with the name javacc.bat, this is the one the window commad prompt is looking for and not finding in your case.

在最新版本中,他们似乎忘记bin在包的文件夹中添加脚本。您可以下载5.0 版,它包含您需要的所有脚本文件,其中包括一个名为 的文件javacc.bat,这是窗口命令提示符正在寻找但在您的情况下找不到的文件。

Of course, you can just copy those scripts from the 5.0version to the bindirectory of the 6.0version, they will also work. and since you already have set the path to contain C:\javacc-6.0\binthen you can run it like you have tried before, without closing the command prompt window or even restarting your whole computer!

当然,您可以将这些脚本从5.0版本复制到版本bin目录6.0,它们也可以工作。并且由于您已经将路径设置为包含,C:\javacc-6.0\bin因此您可以像以前尝试过的那样运行它,而无需关闭命令提示符窗口,甚至无需重新启动整个计算机!

Edit - new links

编辑 - 新链接

The links above are unfortunately no longer valid, luckily the content has been moved to github. here the new links:

不幸的是,上面的链接不再有效,幸运的是内容已移至github。这里的新链接:

Project url: https://javacc.org/

项目网址:https: //javacc.org/

Project url on github: https://javacc.github.io/javacc/

github上的项目网址:https: //javacc.github.io/javacc/

Earlier versions: https://github.com/javacc/javacc/branches/

早期版本:https: //github.com/javacc/javacc/branches/

回答by Shu Zhang

  1. open cmd
  2. cd to the directory where the javacc (calculator_2.jj) file loacted
  3. type in the cmd java -cp D:\S2018\CS661\javacc-6.0\javacc-6.0\bin\lib\javacc.jar javacc calculator_2.jj
  1. 打开cmd
  2. cd 到 javacc (calculator_2.jj) 文件所在的目录
  3. 输入cmd java -cp D:\S2018\CS661\javacc-6.0\javacc-6.0\bin\lib\javacc.jar javacccalculator_2.jj

回答by Emmanuel Hernández Hernández

Solution

解决方案

  • Download version 5.0, copy the files that come in the bin folder, except the lib folder (they are .bat files)
  • Paste those files in the same location, but in version 6.0 and resolved issue.
  • 下载 5.0 版本,复制 bin 文件夹中的文件,除了 lib 文件夹(它们是.bat files
  • 将这些文件粘贴到同一位置,但在 6.0 版中并已解决问题。

The error is that they did not add the executables in the bin folder.

错误是他们没有在 bin 文件夹中添加可执行文件。