Related articles |
---|
ANN. Free C++ Algebraic Types (good esp. for compilers etc.) nelan@home.com (George Nelan) (1999-10-03) |
From: | George Nelan <nelan@home.com> |
Newsgroups: | comp.compilers |
Date: | 3 Oct 1999 03:29:33 -0400 |
Organization: | @Home Network |
Keywords: | tools, available |
I sent this out to comp.lang.c++ and comp.lang.functional a few days
ago, then got to thinking maybe this would be a good place too. App
is a C++ preprocessor (see below) and internally it's like a small
compiler; it generates ASTs that are instances of algebraic types, and
all of the AST manipulating code after the parser proper is written in
itself. That code turned out to be exceedingly cool IMHO and so from
that perspective I would like to invite you to check it out.
=== (original announcement follows) ===>
Not to peg the hype-o-meter, but app 1.0 is available.
'App' is a preprocessor for C++ that accepts as input arbitrary C++
code that may contain embedded constructs for specifying algebraic
data types and associated pattern matching operations, and produces as
output the same code with all such constructs translated to normal
C++. What app essentially does is provide for C++ pretty much the
same capabilities that functional languages have regarding algebraic
types. In a sense app can be viewed as bringing C++ closer to the
functional programming world, although perhaps just as well app can be
viewed as directly supporting certain kinds of visitor-style patterns
in C++, insofar as algebraic types can be viewed as supporting such
patterns.
App is free software distributed under the terms of the GPL/LGPL.
This software was developed on a W95 Intel platform using MS VC++ 5.0,
and is initially targeted for similar platforms, though it should be
easy enough to retarget for most any platform supporting a relatively
modern C++ compiler. The source code is not -- or at least should not
be -- MS specific. Substantial portions of app are written in itself.
You can download the software and browse the documentation at:
http://www.primenet.com/~georgen/app.html
Here's a short example; function foo() produces "Y:{42}".
$base I(int x) {
bool print(ostream& os) {
os << x();
return true;
}
};
$data W<class A> $forward;
$data X<class A> = Y(A a) | Z(W<A> a);
$data W<class A> = V(X<A> a);
void foo() {
$match (V<I>(Y<I>(42))) {
(V<I>(y)) => {cout << y << endl;}
}
}
--
George Nelan
mailto:nelan@home.com
Return to the
comp.compilers page.
Search the
comp.compilers archives again.