[antlr-interest] Java-lite install?
Evan Lavelle
ml-antlr at riverside-machines.co.uk
Thu May 5 06:42:51 PDT 2005
All fixed - summary, for the interested:
I installed from source and am running a C++ generator without needing
or using a Java runtime (no JDK, JRE, jars, CLASSPATHs, whatever). In
fact, Java is completely unnecessary, except that a Java compiler is
needed to build the ANTLR executable.
The source installation created libantlr.a from lib/cpp/src, but it
didn't attempt to build ANTLR itself, because I don't have a Java
runtime (although I do have gcj). configure doesn't attempt to build
ANTLR using gcj by itself.
To build ANTLR, I used Luca's makefile, which requires gcj; I couldn't
find Ric's makefile. Wolfgang thinks there's a problem with 2.7.5 and
Luca's makefile, but I haven't yet run into any issues.
I would have preferred a dynamic library, but cantlr and libantlr.a (and
the header files) are all that's required. It would be nice if the
distribution had an option to do a minimal install of this sort.
On the issue of dependencies, I'm on RedHat 7.2, with recent
gcc/gcj/libc. antlr-2.7.5-1.i586.rpm requires a new coreutils, coreutils
requires a new libacl, libselinux, and tetex, and so on. They all
require libc.so.6, which I have, but I can't persuade rpm that I've got
it. This is all bizzarely complicated for such a simple install (why on
earth should I install a 16Mbyte tetex to run ANTLR?!)
I modded the cut-n-paste example to produce a C++ version (step 2 on the
'getting started' page); the existing one is Java-centric. I've attached
the two files, together with a simple makefile. It might be nice to put
this on the webpage, for the Java-illiterati like myself.
Thanks -
Evan
-------------- next part --------------
header {
#include <iostream>
using std::cout;
using std::endl;
}
options {
language="Cpp";
}
class P extends Parser;
startRule
: n:NAME
{cout << "Hi there, " << n->getText() << endl;}
;
class L extends Lexer;
// one-or-more letters followed by a newline
NAME: ( 'a'..'z'|'A'..'Z' )+ NEWLINE
;
NEWLINE
: '\r' '\n' // DOS
| '\n' // UNIX
;
-------------- next part --------------
LIBDIR = /usr/local/lib
LIBS = -lantlr
CC = g++
ANTLR = cantlr
CFLAGS = -c -g -Wall
SRCS = main L P
OBJS = $(addsuffix .o, $(SRCS))
.SUFFIXES:
main : $(OBJS)
$(CC) $(OBJS) -o $@ -L$(LIBDIR) $(LIBS) 2>&1 | c++filt
main.o : main.cpp L.hpp P.hpp
$(CC) $(CFLAGS) main.cpp -o $@
%.o : %.cpp
$(CC) $(CFLAGS) $< -o $@
# this is a pattern rule, to ensure that $(ANTLR) is run only once, not 4 times
L.cp% L.hp% P.cp% P.hp% : t.g
$(ANTLR) $<
# stop make from deleting intermediate files
.SECONDARY : L.cpp P.cpp
clean :
rm -f main *.o L.* P.* PTokenTypes.* *~
-------------- next part --------------
#include <iostream>
#include "L.hpp"
#include "P.hpp"
int main()
{
ANTLR_USING_NAMESPACE(std)
ANTLR_USING_NAMESPACE(antlr)
try {
L lexer(std::cin);
P parser(lexer);
parser.startRule();
}
catch( ANTLRException& e )
{
cerr << "exception: " << e.getMessage() << endl;
return -1;
}
catch( exception& e )
{
cerr << "exception: " << e.what() << endl;
return -1;
}
return 0;
}
More information about the antlr-interest
mailing list