Skip to content
cocolab8Public

About

Cocktail Toolbox for compiler construction - generated source code in C

Resources

Stars

14 stars

Watchers

3 watching

Forks

Repository files navigation

Cocktail Toolbox

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

Building on Linux

Requirements

  • 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.

Commands

The commands for building Cocktail on Linux are as follows:

  1. Clone or download and unpack the source code of Cocktail:

    git clone https://github.com/cocolab8/cocktail.git
    cd cocktail
    

    Alternatively, you can download a zip archive from github and unpack:

    unzip cocktail-master.zip
    cd cocktail-master
    
  2. Run config script:

    ./config CC="cc -m32"
    
  3. 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
    
  4. 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
    
  5. Optionally, test the Cocktail tools:

    make test DIR=/usr/local
    
  6. Optionally, clean the file tree:

    make clean
    

Building on Windows

Requirements

The following software must be available:

  1. 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)\gnuwin32
    

    Unfortunately, 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.

  2. 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
    
  3. 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-Zip
    

    On 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

  4. 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.

  5. 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" x86
    

    or

    "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd" -arch=x86
    

Commands

The commands for building Cocktail on Windows from the command line are as follows:

  1. Download a zip archive with the source code of Cocktail from github.

  2. Unpack the source code archive of Cocktail:

    7z x cocktail-master.zip
    cd cocktail-master
    
  3. 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
    
  4. 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
    
  5. 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.

  6. Optionally, test the Cocktail tools:

    nmake /c /f Makefile.mvc test
    
  7. Optionally, clean the file tree:

    nmake /c /f Makefile.mvc clean
    

Documentation

User manuals and other documentation in the formats PDF and plain text can be found in the directories doc.pdf and doc.txt.

About

Cocktail Toolbox for compiler construction - generated source code in C

Resources

Stars

14 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages