The Cocktail Toolbox is a set of programs for compiler construction. It contains the following tools:
| Tool | Purpose |
|---|---|
| Rex | generator for lexical analyzers |
| Lark | LR(1) and LALR(2) parser generator with backtracking and predicates |
| Ell | LL(1) parser generator |
| Ast | generator for abstract syntax trees |
| Ag | generator for attribute evaluators |
| Puma | transformation of attributed trees using pattern matching |
The development of the Cocktail Toolbox started around 1987 at the Forschungsstelle für Programmstrukturen an der Universität Karlsruhe, a subsidiary of GMD (Gesellschaft für Mathematik und Datenverarbeitung mbH). From 1994 until 2021 the Cocktail Toolbox was a commercial product of CoCoLab in Karlsruhe, Germany.
Compiler modules can be generated in the target languages C, C++, and Modula-2. The Cocktail Toolbox is implemented using Cocktail itself and in Modula-2. This version of Cocktail contains C source code generated from the original sources.
If you are just interested in a working copy of the Cocktail Toolbox, then this project is right for you. If you want to modify the original source code, then you will additionally need the project cocktail-src.
A build of Cocktail should be possible on every Unix operating system, on Windows and probably on other operating systems as well. The build process as described here has been executed successfully under the following operating systems:
SUSE Linux
SunOS 4.1.1
Debian Linux 8.9 (Jessie)
Arch Linux
Windows 10
- C compiler capable of generating 32 bit code
- git
Note, the restriction to 32 bit code originates from the Modula-2 language and limitations in the Modula-2 to C translator mtc2. In some cases 64 bit code might work by chance. However, e. g. position independent code as generated by newer versions of gcc is known to fail.
The commands for building Cocktail on Linux are as follows:
-
Clone or download and unpack the source code of Cocktail:
git clone https://github.com/cocolab8/cocktail.git cd cocktailAlternatively, you can download a zip archive from github and unpack:
unzip cocktail-master.zip cd cocktail-master -
Run config script:
./config CC="cc -m32" -
Compile the Cocktail tools (build from the C sources):
The files in the directories */m2c contain obfuscated C source code.
Follow the instructions in the file README, section "Installation of Source Release". Typically, the commands are:
make -
Install the created binaries of the Cocktail tools:
make install DIR=...The tools can be installed at any place. This might require root (admin) privileges. For example:
make install DIR=/usr/local -
Optionally, test the Cocktail tools:
make test DIR=/usr/local -
Optionally, clean the file tree:
make clean
The following software must be available:
-
The following (Unix) utilities are needed:
cat, sed, awk and unzip or 7z
If not already available, the utilities cat, sed, and awk can be downloaded from sourceforge -> Packages.
The package names and the file names are as follows:
Package File FileUtils coreutils-5.3.0.exe Gawk gawk-3.1.6-1-setup.exe Sed sed-4.2.1-setup.exe These utilities can be installed for example in the folder
C:\Program Files (x86)\gnuwin32Unfortunately, the first package above installs lots of superfluous programs. Actually, only cat.exe is needed from this package. All the others could be removed. In particular, this package installs dir.exe, link.exe, sort.exe, and date.exe, which clash with Windows utilities. These 4 programs should be removed or renamed in any case.
-
The utility unzip from the above location did not work for me. As a workaround, the program 7z can be used. If not already available, it can be downloaded from 7-zip.
The program 7z1900.exe can be installed for example in the folder
C:\Program Files (x86)\7-Zip -
The previously installed utilities must be made available for command line use by extending the environment variable PATH by the following folders:
C:\Program Files (x86)\gnuwin32\bin C:\Program Files (x86)\7-ZipOn Windows 10 the environment variables can be manipulated e. g. here:
Settings -> System -> Info -> System Properties -> Advanced -> Environment Variables -> User Variables -> Path
or here:
Settings -> System -> About -> Advanced System Settings -> Environment Variables -> User Variables -> Path
-
If not already available, install a C/C++ compiler. For example "Microsoft Visual Studio Express 2012 (Version 11)" including the "Microsoft C/C++ compiler (Version 17)" for 32 bit or "Microsoft Visual Studio 2022". These two have been tested. Other versions might work as well.
-
Enable the C/C++ compilers and utilities such as nmake for command line use, e. g.:
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86or
"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd" -arch=x86
The commands for building Cocktail on Windows from the command line are as follows:
-
Download a zip archive with the source code of Cocktail from github.
-
Unpack the source code archive of Cocktail:
7z x cocktail-master.zip cd cocktail-master -
Compile the Cocktail tools (build from the C sources):
The files in the folders *\m2c contain obfuscated C source code.
nmake /c /f Makefile.mvc compile -
Install the created binaries of the Cocktail tools:
The tools can be installed at any place. This might require admin privileges. For example:
set CT_DIR=C:\Program Files (x86)\Cocktail nmake /c /f Makefile.mvc install -
Define environment variables:
set CT_DIR=C:\Program Files (x86)\Cocktail set PATH=%CT_DIR%\bin;%PATH%The definition of the environment variable CT_DIR and the extension of the environment variable PATH by the folder with the installed Cocktail binaries is needed everytime Cocktail tools are used. These settings could be added permanently to the list of environment variables, for example.
-
Optionally, test the Cocktail tools:
nmake /c /f Makefile.mvc test -
Optionally, clean the file tree:
nmake /c /f Makefile.mvc clean
User manuals and other documentation in the formats PDF and plain text can be found in the directories doc.pdf and doc.txt.