As long as the copyright notice appears in the distributed product, you can freely use CUP:
CUP comes with a generator part and a runtime part. Working with CUP comprises two phases:
Parser generation is done by creating a .cup
file, that represents a parser specification. These
specifications need to be processed by the parser generator. This can be achieved with a call like
java -jar java-cup-11b.jar myparserspec.cup
. This will create the corresponding
parser as a .java
file, that can be integrated into Java projects as usual.
During parser runtime, the generated parser needs a few classes, on which it is dependent. These classes
are contained in the java-cup-11b-runtime.jar
file. This Java package needs to be included into
the target project's classpath. The original generator package java-cup-11b.jar
however does not
need to be distributed alongside the target project.
CUP comes with an ANT task, so you can integrate it with any Java environment, that supports build.xml
based project files.
CUP needs to generate sources, that have to be integrated into the main project sources, before compilation can succeed. This can be
achieved, by introducing a target for generated sources, on which the main compilation target depends. Additionally, you should consider
to clean up your generated sources, whenever the project itself is cleaned. Basic support for this is sketched in the following
build script. You can also see, how the scanner generator JFlex is integrated into the same build.
<project name="Compiler" default ="compile" basedir="."> <property name="cup" location="src/cup" /> <property name="jflex" location="src/jflex" /> <property name="java" location="src/java" /> <property name="classes" location="bin" /> <property name="lib" location="lib" /> <property name="tools" location="tools" /> <taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="${tools}/JFlex.jar" /> <taskdef name="cup" classname="java_cup.anttask.CUPTask" classpath="${tools}/java-cup-11b.jar" /> <target name="generate"> <jflex file="${jflex}/Scanner.jflex" destdir="${java}" /> <cup srcfile="${cup}/Parser.cup" destdir="${java}" parser="Parser" interface="true" locations="false" /> </target> <path id="libraries"> <files includes="${lib}/java-cup-11b-runtime.jar" /> </path> <target name="compile" depends="generate"> <javac srcdir="${java}" destdir="${classes}" > <classpath refid="libraries" /> </javac> </target> <target name="clean"> <delete file="${java}/Parser.java" /> <delete file="${java}/sym.java" /> <delete file="${java}/Scanner.java" /> <delete dir="${classes}" /> </target> </project>
We have also prepared a very minimalistic project, to be used as a starting ground for your own project; you can get it from here!