P.D. Terry, Rhodes University
(Last updated 17 September 2021)
This directory contains instructions for downloading and installing the Exercises Kit for Compiling with C# and Java by P.D. Terry (Pearson Education, 2005, 2017).
*** This version of the Exercises Kit is designed for case studies that would match the "static" release of Coco/R. In that release, the generated classes export static methods only, as is the case for all the case studies discussed in the text book.
Software developed by Pat Terry, Rhodes University, Grahamstown, South Africa. (p.terry@ru.ac.za)
The instructions are given from the perspective of a user running a 32-bit version of the Microsoft (tm) Windows operating system, and it is assumed that the user has installed either or both of a .NET SDK (Software Development Kit) or a Java SDK.
http://msdn.microsoft.com/netframework/downloads/
This includes the .NET framework with the CLR, the .NET class library, the C# compiler and other tools, and the entire API documentation. (Note that Visual Studio .NET is not included, as the Visual Studio software is not free of charge.)
http://java.sun.com
For efficiency, the components of the Exercises Kit are supplied in the form of a set of compressed (.zip) files; the files were compressed with the 32-bit version of Info-ZIP's compression utility, but can be decompressed using Info-ZIP's software or some other decompressor such as WinZip.
Before downloading any of the components of the Exercises Kit, create a top level directory (folder) into which the compressed files can be saved. In the descriptions that follow it will be assumed that this directory is called
c:\exercise
From a "Dos Window" this directory can be created with a command like
mkdir c:\exerciseIt can, of course, also be created from within Windows Explorer.
Once the top level directory has been created, save in it those of the following files for the components of the Exercises Kit that you wish to install:
These are essential downloads. If these files are saved and then uncompressed from the top level directory c:\exercise they will add the following components to the Exercises Kit hierarchy:
c:\exercise Top level c:\exercise\probtext\Chap*.pdf PDF versions of suggested exercise discussion c:\exercise\probtext\Chap*.htm HTML (web) versions of suggested exercise discussion c:\exercise\probsrce\chap01 Source code and other files for Chapter 1 c:\exercise\probsrce\chap02 Source code and other files for Chapter 2 .... c:\exercise\probsrce\chap32 Source code and other files for Chapter 32 c:\exercise\exercises.html Local website index
If you have already downloaded and installed the "Resource Kit" for the textbook itself - say to C:\resource - there should be no need to download the following files:
If these files are uncompressed from the top level directory they will add the following components to the Exercises Kit hierarchy:
c:\exercise\command Instructions and specimen batch files for running the programs c:\exercise\libsource Library source c:\exercise\classes Library classes
This is an essential download if you plan to experiment with the C# version of Coco/R, and is supplied in terms of the GNU GPL licence. If this file is uncompressed from the top level directory it will add the following components to the Exercises Kit hierarchy:
c:\exercise Top level c:\exercise\cococ Coco/R for C# (GNU software) c:\exercise\cococ\frames Frame files for Coco/R for C# c:\exercise\cococ\sources Source code of Coco/R for C#
This is an essential download if you plan to experiment with the Java version of Coco/R, and is supplied in terms of the GNU GPL licence. If this file is uncompressed from the top level directory it will add the following components to the Exercises Kit hierarchy:
c:\exercise Top level c:\exercise\cocoj Coco/R for Java (GNU software) c:\exercise\cococ\frames Frame files for Coco/R for Java c:\exercise\cococ\sources Source code of Coco/R for Java
If this file is uncompressed from the top level directory it will add the following components to the Exercises Kit hierarchy:
c:\exercise\exercises.html HTML index page
A local copy of the Solution website can then be browsed by pointing your browser at
file:///C:/exercise/exercises.html
After downloading and uncompressing the essential components of the Exercises Kit, then, if you have not previously installed the Resource Kit for the textbook, some further action may have to be taken before it can be used:
The PATH environment variable may be modified in several ways - a simple one being to issue a command like
PATH=%PATH%;c:\exercise\command
from a command prompt. However, it may be preferable to modify the default setting for the PATH so that this change comes into effect automatically each time the system is started.
The RESOURCE environment variable may be defined in several ways - a simple one being to issue a command like
set RESOURCE=C:\exercise
from a command prompt. However, once again it may be preferable to modify the default list of environment variables for your setup so that this variable is defined automatically each time the system is started.
The setting of the CLASSPATH variable will depend on other software that you already have installed, such as the version of the Java runtime system. A command like
set CLASSPATH=.;%RESOURCE%\classes;
might suffice (assuming that you have already defined the RESOURCE environment variable).
Developing your own applications, or experimenting with the case studies in the kit, is conveniently carried out as follows:
Arrange your source and support files into part of a working directory hierarchy. For illustration the top level of this system is assumed to be C:\work. We assume the attributed Cocol grammar to be stored in a file Grammar.atg, that a driver frame file has been stored in a file Grammar.frame and that there are some support routines in a file Support.cs or Support.java (again, these names are used merely for illustration).
For the C# version the files should be set up as:
C:\work Grammar.atg Grammar.frame C:\work\Grammar\ Support.cs
and for the Java version the files should be set up differently:
C:\work C:\work\Grammar\ Grammar.atg Grammar.frame Grammar.manifest Support.java
Grammar.manifest (which applies only to the Java version) is optional; if present it would typically read
Manifest-Version: 1.0 Main-Class: Grammar/Grammar
and can be used by the system to build a jar file for the application, named Grammar.jar.
It is possible for both sets of files to coexist. For example, in the "chap06" directory of the source, once installed, you would find
C:\exercise\probsrce\chap06 work directory Parva.atg C# version of attributed grammar Parva.frame C# version of driver frame file C:\exercise\probsrce\chap06\parva subdirectory Parva.atg Java version of attributed grammar Parva.frame Java version of driver frame file Parva.manifest Manifest file to build Parva.jar Table.cs C# version of symbol table class Table.java Java version of symbol table class . . .
Clearly there are other ways of arranging the system, and experienced users may wish to experiment in this regard.
The C:\exercise\command directory contains various batch files/scripts to expedite the use of Coco/R. They can only be immediately useful if the PATH environment variable has been modified to include this "command" directory, if the environment variable RESOURCE is defined to point to the top level of the Source Kit directory hierarchy, and the CLASSPATH environment variable defined so as to gain access to specialised library classes. Instructions for this were given earlier.
The following batch files execute Coco/R, but do not compile and link the application:
Run Coco/R for C# to generate scanner, parser and driver from a Cocol grammar
Run Coco/R for Java to generate scanner, parser and driver from a Cocol grammar
The following batch files allow for applications to be built completely from a Cocol attributed grammar:
Run Coco/R for C# to generate scanner, parser and driver from a Cocol grammar and then compile and link the resulting system using a C# compiler.
Example: C:\exercise\chap06\> ccMake Parva
Note that the grammar file (Parva.atg) is specified without extension; this is added automatically.
Run Coco/R for Java to generate scanner, parser and driver from a Cocol grammar and then compile and link the resulting system using the "javac" compiler.
Example: C:\exercise\chap06\> cjMake Parva -options NC
Execute a Java application built with Coco/R for Java
Example: C:\exercise\chap06\> cjRun Parva hello.pav
The following batch commands may need editing. They provide ways of dealing with some of the environment variables needed by the rest of the system.
Sample batch file for setting CLASSPATH environment variable (needs modification to suit your setup).
Sample batch file for setting RESOURCE environment variable (needs modification to suit your setup).
Batch file to unset RESOURCE environment variable
While every attempt has been made to ensure that the material in this distribution performs properly, the author can accept no liability for any damage or loss, including special, incidental, or consequential, caused by the use of the software, directly or indirectly.
However, please bring any problems that you may experience to the attention of the author.
Pat TerryDate of this release: 17 September 2021
Computer Science Department
Rhodes University
GRAHAMSTOWN 6140
South Africa
Tel: +27-46-603-8292 (Office)
Tel: +27-73-728-6329 (Mobile)
e-mail: p.terry@ru.ac.za