171 lines
7.6 KiB
HTML
171 lines
7.6 KiB
HTML
<!--startcut ==========================================================-->
|
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
|
<HTML>
|
|
<HEAD>
|
|
<title>Compiler Construction Tools Part II LG #41</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<meta name="GENERATOR" content="Mozilla/4.5 [en] (X11; I; Linux 2.0.36 i686) [Netscape]">
|
|
</HEAD>
|
|
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
|
|
ALINK="#FF0000">
|
|
<!--endcut ============================================================-->
|
|
|
|
<H4>
|
|
"Linux Gazette...<I>making Linux just a little more fun!</I>"
|
|
</H4>
|
|
|
|
<P> <HR> <P>
|
|
<!--===================================================================-->
|
|
|
|
<center>
|
|
<H1><font color="maroon">Compiler Construction Tools</font></H1>
|
|
<H4>By <a href="mailto:rsevenic@penguin.sirti.org">Richard A. Sevenich</a></H4>
|
|
</center>
|
|
<P> <HR> <P>
|
|
|
|
<h1>
|
|
Part II: Installing JFlex and CUP - Specific Instructions</h1>
|
|
by Richard A. Sevenich, Department of Computer Science
|
|
<br>April 26, 1999
|
|
<p>This is the second of a series whose first article appeared in the April,
|
|
1999 issue of Linux Gazette. [see: <a href="http://www.linuxgazette.com/issue39/sevenich.html">Compiler
|
|
Construction Tools, Part I</a> ]. The traditional example, the calculator,
|
|
is provided in <A HREF="./lopes/lopes.html">Part III</A>, which is intended as a companion to this part
|
|
and also appears in this issue.
|
|
<p><b><font size=+1>0.0 Background</font></b>
|
|
<p>The JFlex and CUP software packages come with installation instructions.
|
|
These are well written and straightforward. Nevertheless this document
|
|
was written to give a very specific installation scenario. In the author's
|
|
experience, this specificity can be useful to certain new users who find
|
|
the generality and flexibility of less specific installation instructions
|
|
somewhat difficult upon first exposure. The downside is that this specificity
|
|
takes away flexibility.
|
|
<p>These instructions are intended for use with a Linux box, with bash
|
|
as the default shell and with the tcsh also installed, but not as default.
|
|
It is assumed that the user has a version of jdk (Java Development Kit),
|
|
or some equivalent, installed already. If not, you can find such at <a href="http://www.blackdown.org/">www.blackdown.org/.</a>
|
|
In the system used by the author, the compressed tarball of jdk1.1.5-v5-glibc.tar.gz
|
|
from blackdown was downloaded into /usr/lib and exploded there.
|
|
<p>The author would appreciate corrections and constructive suggestions.
|
|
He can be contacted at: rsevenich@ewu.edu
|
|
<p><b><font size=+1>1.0 System Preparation</font></b>
|
|
<p>Note that the specific choices made in this section are arbitrary. For
|
|
starters, it is assumed that you have logged into your home directory,
|
|
say, /home/jsmith. All paths will be relative to that position within the
|
|
file hierarchy. Make new directories as follows:
|
|
<p>> mkdir javatools
|
|
<br>> mkdir javatools/CUP
|
|
<p>Next revise your .bash_profile and .bashrc files to have the needed
|
|
java CLASSPATH etc. Here are some example lines:
|
|
<p>JAVB=/usr/lib/jdk1.1
|
|
<br>JAVT=/home/jsmith/javatools
|
|
<br>CLASSPATH=./:$JAVB/lib/classes.zip:$JAVT/JFlex/lib/JFlex.jar:$JAVT/CUP
|
|
<br>PATH=$PATH:$JAVB/bin:$JAVT/JFlex/bin
|
|
<br>export PATH CLASSPATH
|
|
<p>Note: The directory /usr/lib/jdk1.1 is meant to denote the site of the
|
|
java files exploded from the blackdown tarball. In the author's case it
|
|
was a symbolic link to /usr/lib/jdk1.1.5v5-980311/.
|
|
<p>For these changes to take effect you must log out and log back in.
|
|
<p><b><font size=+1>2.0 JFlex</font></b>
|
|
<p><u>2.1 Obtaining JFlex</u>
|
|
<p>JFlex is available from <a href="http://www.informatik.tu-muenchen.de/~kleing/jflex/index.html#Download">www.informatik.tu-muenchen.de/~kleing/jflex/index.html#Download</a>
|
|
<br>in a tar.gz format. At this writing the file name was 'jflex-1.2.tar.gz'.
|
|
This tarball includes an extensive manual with its own installation instructions.
|
|
<p><u>2.2 A Specific Installation Scenario</u>
|
|
<ul>
|
|
<li>
|
|
Download the tarball, jflex-1.2.tar.gz, into directory javatools/</li>
|
|
|
|
<li>
|
|
from within the javatools/ directory explode the tarball at the command
|
|
line by typing 'tar xvfz jflex-1.2.tar.gz'</li>
|
|
</ul>
|
|
This will create the directory 'JFlex' with associated subdirectory hierarchy.
|
|
It should contain everyting needed, including documentation in the 'doc'
|
|
subdirectory. The manual found there is comprehensive and indicates how
|
|
JFlex can be used to produce stand alone lexical analyzers (as in the example
|
|
in section 2.3, below) or lexical analyzers to be used with parsers produced
|
|
by other utilities, such as CUP. In directory JFlex/bin you will find the
|
|
shell script 'jflex' which should be modified as follows:
|
|
<ul>
|
|
<li>
|
|
change JFLEX_HOME to be your equivalent of 'JFLEX_HOME=/home/jsmith/javatools/JFlex'</li>
|
|
|
|
<li>
|
|
change JAVA_HOME to be your equivalent of 'JAVA_HOME=/usr/lib/jdk1.1'</li>
|
|
</ul>
|
|
|
|
<p><br><u>2.3 Testing the Installation</u>
|
|
<ul>
|
|
<li>
|
|
Change directory to javatools/JFlex/examples/standalone (e.g. 'cd /home/jsmith/javatools/JFlex/examples/standalone/')</li>
|
|
|
|
<li>
|
|
Follow the instructions in the README file found in that directory, which
|
|
should result in this screen output:</li>
|
|
</ul>
|
|
Hello someone !
|
|
<p> This is a sample
|
|
input file for the
|
|
<br> standalone example
|
|
scanner.
|
|
<p> Have a
|
|
nice day!
|
|
<br>
|
|
<p><b><font size=+1>3.0 CUP</font></b>
|
|
<p><u>3.1 Obtaining CUP</u>
|
|
<p>CUP is available from <a href="http://www.cs.princeton.edu/~appel/modern/java/">www.cs.princeton.edu/~appel/modern/java/.</a>
|
|
There you'll find the needed source code (compressed tarball) and a user
|
|
manual. The manual can be downloaded in html to provide an on-line manual
|
|
or in a form (e.g. postscript) suitable for printing. The next section
|
|
deals with downloading the source file.
|
|
<br>Note: The above website also contains an alternative to JFlex, called
|
|
JLex.
|
|
<p><u>3.2 A Specific Installation Scenario for CUP with test</u>
|
|
<ul>
|
|
<li>
|
|
Download the compressed tarball into directory javatools/CUP</li>
|
|
|
|
<li>
|
|
Change to that directory (e.g. cd /home/jsmith/javatools/CUP)</li>
|
|
|
|
<li>
|
|
Explode the tarball</li>
|
|
|
|
<li>
|
|
Run the installation/testing file by typing at the command line './INSTALL'
|
|
.Note that install is a script to be executed by csh, or its equivalent,
|
|
tcsh. So tcsh should be available.</li>
|
|
</ul>
|
|
This should result in activity ending with a success message, e.g. 'Install
|
|
and test was successful'.
|
|
<br>
|
|
<p><b><font size=+1>4.0 What Next?</font></b>
|
|
<p>The manuals downloaded with JFlex and CUP provide enough information
|
|
so that users can get up and running.
|
|
|
|
<P> <HR> <P>
|
|
<center><H4>Previous ``Compiler Construction Tools'' Columns</H4></center>
|
|
<p>
|
|
<A HREF="../issue39/sevenich.html">Compiler Construction Tools Part I, April 1998</A><BR>
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<center><H5>Copyright © 1999, Richard A. Sevenich <BR>
|
|
Published in Issue 41 of <i>Linux Gazette</i>, May 1999</H5></center>
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
|
|
ALT="[ TABLE OF CONTENTS ]"></A>
|
|
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
|
|
ALT="[ FRONT PAGE ]"></A>
|
|
<A HREF="./nielsen1.html"><IMG SRC="../gx/back2.gif"
|
|
ALT=" Back "></A>
|
|
<A HREF="./lopes/lopes.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
|
|
<P> <hr> <P>
|
|
<!--startcut ==========================================================-->
|
|
</BODY>
|
|
</HTML>
|
|
<!--endcut ============================================================-->
|