Working with the JACCL Parser

To enable you to start your compilers "in the middle", I have constructed a syntactic analyzer for JACCL that you can use as a front-end as you implement the semantic processing and code generation phases of the compiler.

The directory ~tom/pub/434 contains the code which you will need to use my syntactic analyzer. Within this directory, you will find sub-directories for each of the major assigned phases of the project (phase1, phase2, and phase3). Each of these directories will contain versions of my parser specialized to the corresponding phase of the project. Within each of the phase subdirectories, I will store files named syntree.h, syntax.h and symtab.h which contains type definitions describing the structure of the syntax trees and symbol table entries produced by the JACCL syntax analyzer I have provided. Such files are called "header" files (hence the use of the ".h" suffix). These directories will also contain object files (".o" files) containing the executable code for the parser, scanner, and symbol table routines.

Within the directory ~tom/pub/434 you will also find a sub-directory named startup. The most important file in the startup subdirectory is named Makefile. There is also a short source file named main.c. You should copy both of these files from ~tom/pub/434/startup into the directory in which you plan to create the files needed to complete the phase. While you may want to copy other files from ~tom/pub/434, the files Makefile and main.c are the only files you should copy.

The Makefile is intended for use as input to the Unix "make" utility. In case you are unfamiliar with "make" it is a utility which takes a file describing how to build an object program from one or more source files and performs needed compilation steps to build the object program when invoked. For example, after you have copied Makefile and main.c into one of your directories, make that directory your current working directory and then type

make
The system will perform the necessary steps to create an executable parser for JACCL from the main.c file and the object files provided in ~tom/pub/434. The directory ~tom/pub/434/samples contains some sample JACCL programs. So, you can test the parser produced by typing
jaccl ~tom/pub/434/samples/allsyntax.j
The result should be a printed display of the syntax tree built by the parser.

In the remainder of this handout, I will attempt to tell you all you need to know to work with Makefile, at least for this phase of the project. In addition, those of you unfamiliar with make may wish to read the document Make -- A Program for Maintaining Computer Programs. Copies of this document may be found in the filing cabinet in the Sun lab. While I suspect this (ancient) document is still a good introduction to make, I should warn you that the version of make we will be using has many extensions beyond those described in this handout. If you become curious about the advanced features there is a complete manual for "gnu make" online.

Makefile has been designed to enable you to easily combine your code with my code through all the phases of the project. The file starts with about 20 lines describing variables you can (and must) set to customize the file to your compiler and parameters (targets) you can specify when invoking make to alter the way in which it interprets the contents of Makefile.

The most important variables at this point are HDR and SRC. You will find their definitions shortly after the comment lines. The definitions look like:

HDR =
SRC = main.c
The value of SRC should be a list of the names of the source files for the compiler kept in your directory. Initially, the main.c file you copied from ~tom/pub/434 will be the only such file. When you create other source files, however, you should add their names. For example, if you create a file named resolve.c to hold the code for this phase, you should edit Makefile changing the definition of SRC to
SRC = main.c resolve.c

The variable HDR should be set equal to a list of the names of all the header files kept within your directory. The header files I have provided for you should not be included here. These files will be included because of the setting of the HDRs variable.

Two other variable definitions you will need to change eventually are those for PHASE and SUBPHASE. The PHASE variable determines which subdirectory of the pub directory will be used to access my header files and object files. You will need to change it as you move on to later phases. The main function of the SUBPHASE variable is to enable my scripts to place your finished product in the right container when you submit it for grading. If you forget to change it before you submit subphase 2 or 3 of a particular phase of the project you may overwrite your earlier submission.

When you simply want make to compile a new version of your compiler, you will invoke it as shown above by simply typing its name. The make program can also be used to perform several other useful functions by invoking it with one of the parameters described below.

Make's operation depends on having, within Makefile, a collection of lines specifying how each object file needed to create an executable version of your compiler depends on the source and header files you and I construct. Whenever you create a new source file or add a #include to a file, this information changes. Typing

make depend
will cause make to read through all of your source files and edit Makefile to update the collection of dependency specifications as appropriate. Do not forget to run this command after making such changes to your source files.

To simplify the task of keeping current listings of your code, I have included two definitions for targets named list and listall in Makefile. It you type

make listall
listings of all of your source and header files (and of your Makefile) will be sent to the laserwriter. If you type
make list
listings of only those files that have changed since you last typed either make list or make listing will be produced.

To provide a means to quickly and reliably distribute information (like corrections to errors in handouts) to you, I will maintain a file name PROJECTNEWS in the ~tom/pub/434 directory. When you execute the simple command make, the system will check to see if this file has changed since you last read its contents. If it has, it will inform you that you should read it. To read the file, type

make meread
This will show you the contents of the file and update the information make uses to tell when you last read the file.

At several points during the semester, I will ask that you submit your source files electronically. To do this, simply type

make submit

Computer Science 434
Department of Computer Science
Williams College