Getting started with JavaCC

三世轮回 提交于 2019-12-21 11:28:28

问题


I am new to JavaCC and cannot figure out how to get it running. I am using Mac OS X and I installed javacc-6.0.zip and unzipped it. I am unable to make the javacc script accessible from my path as on typing javacc on the terminal I get the following message:

    -bash: javacc: command not found

How do I make the javacc script accessible from my path?

My unzipped folder javacc-6.0 is in the following directory: /Users/Rishabh/Desktop/javacc

So I do the following on the terminal:

    PATH=$PATH\:/Users/Rishabh/Desktop/javacc/javacc-6.0/

Typing javacc next gives me the same message.


回答1:


The version of JavaCC 6.0 that I downloaded today (2013.07.22) did not have a complete bin directory. It was missing all the script files! Hopefully this will be remedied soon.

For OS X and other unix/linux variants, the missing script file is called javacc, should be executable, and should contain the following:

#!/bin/sh
JAR="`dirname $0`/lib/javacc.jar"

case "`uname`" in
     CYGWIN*) JAR="`cygpath --windows -- "$JAR"`" ;;
esac

java -classpath "$JAR" javacc "$@"

Add the bin directory to your PATH (omitting the backslash -- as pointed out by Ahmed Masud) and all should be ticketty boo. If your OS comes from Redmond or you want to run jjtree or jjdoc, just download javacc-5.0 and copy the script files (NOT the lib directory!!!!) from the 5.0 bin directory to the 6.0 bin directory.




回答2:


more javacc:

#!/bin/sh JAR="`dirname $0`/lib/javacc.jar"

case "`uname`" in
     CYGWIN*) JAR="`cygpath --windows -- "$JAR"`" ;; esac

java -classpath "$JAR" javacc "$@"

more jjtree:

#!/bin/sh JAR="`dirname $0`/lib/javacc.jar"

case "`uname`" in
     CYGWIN*) JAR="`cygpath --windows -- "$JAR"`" ;; esac

java -classpath "$JAR" jjtree "$@"

Create these scripts in the bin folder of your javacc-6.0/bin.

make a chmod :

chmod 755 javacc
chmod 755 jjtree



回答3:


On Mac OS X & Linux I just use a single script and two symbolic links:

echo 'java -cp /path/to/javacc.jar $(basename $0) "$@"' > javacc
chmod 755 javacc
ln -s javacc jjtree
ln -s javacc jjdoc

The first two lines create the script and make it executable. The second two lines reuse the javacc script for jjtree and jjdoc, since it all comes from the same JAR.




回答4:


In Windows, I also had no javacc and have to use

java -cp bin\lib\javacc.jar javacc

instead. This is very frustrating because all docs propose to use javacc, which we miss. Yet, I see that javacc was defined in the old javacc 5.0. I see javacc.bat there

java -classpath "%~dp0lib\javacc.jar;%~dp0lib\javacc.jar;%~f0\..\lib\javacc.jar" javacc %1 %2 %3 %4 %5 %6 %7 %8 %9



回答5:


You need to first unzip the package, and add location where your javacc is located in your PATH environment variable.

like: set path=%path%;<location_of_your_javacc>;




回答6:


Check if you have javacc and jjtree in the bin/ directory of your javacc-6.0.zip. When you get javacc6.0 from https://javacc.java.net/, this bin directory is empty.

javacc & jjtree are scripts.

Actually i'm using Java 5.0 and i'm modified my .profile file to add (I put javacc in my Applications folder):

export
PATH=/opt/local/bin:/opt/local/sbin:/Applications/javacc-5.0/bin/:$PATH

It's working perfectly.



来源:https://stackoverflow.com/questions/17776132/getting-started-with-javacc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!