tmikov / c99

C preprocessor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

C99pp

C99pp is intended to be a fast, production quality C preprocessor compliant with ISO/IEC 9899:2011 (C11) and ISO/IEC 9899:1999 (C99).

It is written in Java and can be used as a standalone application or as a library.

Status

It supports the full preprocessor functionality as defined by the standard, as well as some GCC extensions like named variable arguments and comma elimination.

Special attention has been paid to standard compliance and robustness.

It is still considered 'alpha' quality because it is a part of a larger project which is under active development, it hasn’t been packaged for easy standalone usage yet, and it still hasn’t undergone extensive independent testing.

Usage

A precompiled binary distribution isn’t available yet. You need JDK 1.6 and Apache Ant to build the preprocessor.

After getting the source, change into the root project directory and build it by running ant without any parameters.

On success the build will produce java/out/artifacts/c99j_jar/c99j.jar. It can be ran simply with java -jar java/out/artifacts/c99j_jar/c99j.jarr.

There is a simple script cpp.sh provided in the project directory which makes it easier to invoke from the directory without worrying about paths.

To preprocess a file invoke it in the following manner:

$projectdir/cpp.sh -Iinclude_path -Iinclude_path input.c > input.i

Motivation

The C preprocessor is a part of a bigger project encompassing a C compiler and other tools written in Java.

Why write yet another C preprocessor (and compiler) when so many other high quality alternatives already exist?

First of all, because it is fun. Contributing to an existing project like GCC, Clang, LCC, OpenWatcom, etc, at their current stage, doesn’t really provide the same opportunity for delving into every exciting detail.

Secondly, I chose Java because there aren’t that many high quality C front-ends written in Java. Implementing another compiler in C++ (which would be my language of choice), when the excellent LLVM and Clang already exist, is too much of a stretch even for the most enthusiastic compiler developer. On the other hand, Java, for all of its horrific problems and unquestionable lack of expressive power, provides some benefits which are interesting to explore in a project of this nature. And, of course, garbage collection makes some aspects of compiler development much easier to deal with.

License

All code is licensed under the MIT License included in this directory.

About

C preprocessor

License:MIT License


Languages

Language:Java 79.9%Language:Bison 16.1%Language:C 2.2%Language:Diff 1.6%Language:Shell 0.3%