removed PyLR

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@198 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2000-11-16 10:45:34 +00:00
parent 1a0a757eef
commit 258967883f
19 changed files with 0 additions and 1879 deletions

View file

@ -1,319 +0,0 @@
# Generated automatically from Makefile.pre by makesetup.
# Generated automatically from Makefile.pre.in by sedscript.
# Universal Unix Makefile for Python extensions
# =============================================
# Short Instructions
# ------------------
# 1. Build and install Python (1.5 or newer).
# 2. "make -f Makefile.pre.in boot"
# 3. "make"
# You should now have a shared library.
# Long Instructions
# -----------------
# Build *and install* the basic Python 1.5 distribution. See the
# Python README for instructions. (This version of Makefile.pre.in
# only withs with Python 1.5, alpha 3 or newer.)
# Create a file Setup.in for your extension. This file follows the
# format of the Modules/Setup.in file; see the instructions there.
# For a simple module called "spam" on file "spammodule.c", it can
# contain a single line:
# spam spammodule.c
# You can build as many modules as you want in the same directory --
# just have a separate line for each of them in the Setup.in file.
# If you want to build your extension as a shared library, insert a
# line containing just the string
# *shared*
# at the top of your Setup.in file.
# Note that the build process copies Setup.in to Setup, and then works
# with Setup. It doesn't overwrite Setup when Setup.in is changed, so
# while you're in the process of debugging your Setup.in file, you may
# want to edit Setup instead, and copy it back to Setup.in later.
# (All this is done so you can distribute your extension easily and
# someone else can select the modules they actually want to build by
# commenting out lines in the Setup file, without editing the
# original. Editing Setup is also used to specify nonstandard
# locations for include or library files.)
# Copy this file (Misc/Makefile.pre.in) to the directory containing
# your extension.
# Run "make -f Makefile.pre.in boot". This creates Makefile
# (producing Makefile.pre and sedscript as intermediate files) and
# config.c, incorporating the values for sys.prefix, sys.exec_prefix
# and sys.version from the installed Python binary. For this to work,
# the python binary must be on your path. If this fails, try
# make -f Makefile.pre.in Makefile VERSION=1.5 installdir=<prefix>
# where <prefix> is the prefix used to install Python for installdir
# (and possibly similar for exec_installdir=<exec_prefix>).
# Note: "make boot" implies "make clobber" -- it assumes that when you
# bootstrap you may have changed platforms so it removes all previous
# output files.
# If you are building your extension as a shared library (your
# Setup.in file starts with *shared*), run "make" or "make sharedmods"
# to build the shared library files. If you are building a statically
# linked Python binary (the only solution of your platform doesn't
# support shared libraries, and sometimes handy if you want to
# distribute or install the resulting Python binary), run "make
# python".
# Note: Each time you edit Makefile.pre.in or Setup, you must run
# "make Makefile" before running "make".
# Hint: if you want to use VPATH, you can start in an empty
# subdirectory and say (e.g.):
# make -f ../Makefile.pre.in boot srcdir=.. VPATH=..
# === Bootstrap variables (edited through "make boot") ===
# The prefix used by "make inclinstall libainstall" of core python
installdir= /usr
# The exec_prefix used by the same
exec_installdir=/usr
# Source directory and VPATH in case you want to use VPATH.
# (You will have to edit these two lines yourself -- there is no
# automatic support as the Makefile is not generated by
# config.status.)
srcdir= .
VPATH= .
# === Variables that you may want to customize (rarely) ===
# (Static) build target
TARGET= python
# Installed python binary (used only by boot target)
PYTHON= python
# Add more -I and -D options here
CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(EXECINCLUDEPY) $(DEFS)
# These two variables can be set in Setup to merge extensions.
# See example[23].
BASELIB=
BASESETUP=
# === Variables set by makesetup ===
MODOBJS=
MODLIBS= $(LOCALMODLIBS) $(BASEMODLIBS)
# === Definitions added by makesetup ===
LOCALMODLIBS=
BASEMODLIBS=
SHAREDMODS= PyLRenginemodule$(SO)
TKPATH=:lib-tk
GLHACK=-Dclear=__GLclear
PYTHONPATH=$(COREPYTHONPATH)
COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(MACHDEPPATH)$(STDWINPATH)$(TKPATH)
MACHDEPPATH=:plat-$(MACHDEP)
TESTPATH=
SITEPATH=
DESTPATH=
MACHDESTLIB=$(BINLIBDEST)
DESTLIB=$(LIBDEST)
# === Variables from configure (through sedscript) ===
VERSION= 1.5
CC= gcc
LINKCC= $(CC)
SGI_ABI= @SGI_ABI@
OPT= -g -O2
LDFLAGS=
DEFS= -DHAVE_CONFIG_H
LIBS= -lieee -ldl -lpthread
LIBM= -lm
LIBC=
RANLIB= ranlib
MACHDEP= linux2
SO= .so
LDSHARED= gcc -shared -lc
CCSHARED= -fPIC
LINKFORSHARED= -Xlinker -export-dynamic
CCC=g++
# Install prefix for architecture-independent files
prefix= /usr
# Install prefix for architecture-dependent files
exec_prefix= ${prefix}
# === Fixed definitions ===
# Shell used by make (some versions default to the login shell, which is bad)
SHELL= /bin/sh
# Expanded directories
BINDIR= $(exec_installdir)/bin
LIBDIR= $(exec_prefix)/lib
MANDIR= $(installdir)/man
INCLUDEDIR= $(installdir)/include
SCRIPTDIR= $(prefix)/lib
# Detailed destination directories
BINLIBDEST= $(LIBDIR)/python$(VERSION)
LIBDEST= $(SCRIPTDIR)/python$(VERSION)
INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
EXECINCLUDEPY= $(exec_installdir)/include/python$(VERSION)
LIBP= $(exec_installdir)/lib/python$(VERSION)
DESTSHARED= $(BINLIBDEST)/site-packages
LIBPL= $(LIBP)/config
PYTHONLIBS= $(LIBPL)/libpython$(VERSION).a
MAKESETUP= $(LIBPL)/makesetup
MAKEFILE= $(LIBPL)/Makefile
CONFIGC= $(LIBPL)/config.c
CONFIGCIN= $(LIBPL)/config.c.in
SETUP= $(LIBPL)/Setup
SYSLIBS= $(LIBM) $(LIBC)
ADDOBJS= $(LIBPL)/python.o config.o
# Portable install script (configure doesn't always guess right)
INSTALL= $(LIBPL)/install-sh -c
# Shared libraries must be installed with executable mode on some systems;
# rather than figuring out exactly which, we always give them executable mode.
# Also, making them read-only seems to be a good idea...
INSTALL_SHARED= ${INSTALL} -m 555
# === Fixed rules ===
# Default target. This builds shared libraries only
default: sharedmods
# Build everything
all: static sharedmods
# Build shared libraries from our extension modules
sharedmods: $(SHAREDMODS)
# Build a static Python binary containing our extension modules
static: $(TARGET)
$(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
$(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \
$(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
-o $(TARGET)
install: sharedmods
if test ! -d $(DESTSHARED) ; then \
mkdir $(DESTSHARED) ; else true ; fi
-for i in X $(SHAREDMODS); do \
if test $$i != X; \
then $(INSTALL_SHARED) $$i $(DESTSHARED)/$$i; \
fi; \
done
# Build the library containing our extension modules
lib.a: $(MODOBJS)
-rm -f lib.a
ar cr lib.a $(MODOBJS)
-$(RANLIB) lib.a
# This runs makesetup *twice* to use the BASESETUP definition from Setup
config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
$(MAKESETUP) \
-m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
$(MAKE) -f Makefile do-it-again
# Internal target to run makesetup for the second time
do-it-again:
$(MAKESETUP) \
-m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
# Make config.o from the config.c created by makesetup
config.o: config.c
$(CC) $(CFLAGS) -c config.c
# Setup is copied from Setup.in *only* if it doesn't yet exist
Setup:
cp $(srcdir)/Setup.in Setup
# Make the intermediate Makefile.pre from Makefile.pre.in
Makefile.pre: Makefile.pre.in sedscript
sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre
# Shortcuts to make the sed arguments on one line
P=prefix
E=exec_prefix
H=Generated automatically from Makefile.pre.in by sedscript.
L=LINKFORSHARED
# Make the sed script used to create Makefile.pre from Makefile.pre.in
sedscript: $(MAKEFILE)
sed -n \
-e '1s/.*/1i\\/p' \
-e '2s%.*%# $H%p' \
-e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
-e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
-e '/^CCC=/s/^CCC=[ ]*\(.*\)/s%#@SET_CCC[@]%CCC=\1%/p' \
-e '/^LINKCC=/s/^LINKCC=[ ]*\(.*\)/s%@LINKCC[@]%\1%/p' \
-e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \
-e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
-e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
-e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
-e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
-e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
-e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
-e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
-e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
-e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
-e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
-e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \
-e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
-e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
$(MAKEFILE) >sedscript
echo "/^CCC=g++/d" >>sedscript
echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript
echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript
echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript
echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript
echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript
echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript
# Bootstrap target
boot: clobber
VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \
installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \
exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \
$(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
VERSION=$$VERSION \
installdir=$$installdir \
exec_installdir=$$exec_installdir \
Makefile
# Handy target to remove intermediate files and backups
clean:
-rm -f *.o *~
# Handy target to remove everything that is easily regenerated
clobber: clean
-rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript
-rm -f *.so *.sl so_locations
# Handy target to remove everything you don't want to distribute
distclean: clobber
-rm -f Makefile Setup
# Rules appended by makedepend
PyLRenginemodule.o: $(srcdir)/PyLRenginemodule.c; $(CC) $(CCSHARED) $(CFLAGS) -c $(srcdir)/PyLRenginemodule.c
PyLRenginemodule$(SO): PyLRenginemodule.o; $(LDSHARED) PyLRenginemodule.o -o PyLRenginemodule$(SO)

View file

@ -1,298 +0,0 @@
# Generated automatically from Makefile.pre.in by sedscript.
# Universal Unix Makefile for Python extensions
# =============================================
# Short Instructions
# ------------------
# 1. Build and install Python (1.5 or newer).
# 2. "make -f Makefile.pre.in boot"
# 3. "make"
# You should now have a shared library.
# Long Instructions
# -----------------
# Build *and install* the basic Python 1.5 distribution. See the
# Python README for instructions. (This version of Makefile.pre.in
# only withs with Python 1.5, alpha 3 or newer.)
# Create a file Setup.in for your extension. This file follows the
# format of the Modules/Setup.in file; see the instructions there.
# For a simple module called "spam" on file "spammodule.c", it can
# contain a single line:
# spam spammodule.c
# You can build as many modules as you want in the same directory --
# just have a separate line for each of them in the Setup.in file.
# If you want to build your extension as a shared library, insert a
# line containing just the string
# *shared*
# at the top of your Setup.in file.
# Note that the build process copies Setup.in to Setup, and then works
# with Setup. It doesn't overwrite Setup when Setup.in is changed, so
# while you're in the process of debugging your Setup.in file, you may
# want to edit Setup instead, and copy it back to Setup.in later.
# (All this is done so you can distribute your extension easily and
# someone else can select the modules they actually want to build by
# commenting out lines in the Setup file, without editing the
# original. Editing Setup is also used to specify nonstandard
# locations for include or library files.)
# Copy this file (Misc/Makefile.pre.in) to the directory containing
# your extension.
# Run "make -f Makefile.pre.in boot". This creates Makefile
# (producing Makefile.pre and sedscript as intermediate files) and
# config.c, incorporating the values for sys.prefix, sys.exec_prefix
# and sys.version from the installed Python binary. For this to work,
# the python binary must be on your path. If this fails, try
# make -f Makefile.pre.in Makefile VERSION=1.5 installdir=<prefix>
# where <prefix> is the prefix used to install Python for installdir
# (and possibly similar for exec_installdir=<exec_prefix>).
# Note: "make boot" implies "make clobber" -- it assumes that when you
# bootstrap you may have changed platforms so it removes all previous
# output files.
# If you are building your extension as a shared library (your
# Setup.in file starts with *shared*), run "make" or "make sharedmods"
# to build the shared library files. If you are building a statically
# linked Python binary (the only solution of your platform doesn't
# support shared libraries, and sometimes handy if you want to
# distribute or install the resulting Python binary), run "make
# python".
# Note: Each time you edit Makefile.pre.in or Setup, you must run
# "make Makefile" before running "make".
# Hint: if you want to use VPATH, you can start in an empty
# subdirectory and say (e.g.):
# make -f ../Makefile.pre.in boot srcdir=.. VPATH=..
# === Bootstrap variables (edited through "make boot") ===
# The prefix used by "make inclinstall libainstall" of core python
installdir= /usr
# The exec_prefix used by the same
exec_installdir=/usr
# Source directory and VPATH in case you want to use VPATH.
# (You will have to edit these two lines yourself -- there is no
# automatic support as the Makefile is not generated by
# config.status.)
srcdir= .
VPATH= .
# === Variables that you may want to customize (rarely) ===
# (Static) build target
TARGET= python
# Installed python binary (used only by boot target)
PYTHON= python
# Add more -I and -D options here
CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(EXECINCLUDEPY) $(DEFS)
# These two variables can be set in Setup to merge extensions.
# See example[23].
BASELIB=
BASESETUP=
# === Variables set by makesetup ===
MODOBJS= _MODOBJS_
MODLIBS= _MODLIBS_
# === Definitions added by makesetup ===
# === Variables from configure (through sedscript) ===
VERSION= 1.5
CC= gcc
LINKCC= $(CC)
SGI_ABI= @SGI_ABI@
OPT= -g -O2
LDFLAGS=
DEFS= -DHAVE_CONFIG_H
LIBS= -lieee -ldl -lpthread
LIBM= -lm
LIBC=
RANLIB= ranlib
MACHDEP= linux2
SO= .so
LDSHARED= gcc -shared -lc
CCSHARED= -fPIC
LINKFORSHARED= -Xlinker -export-dynamic
CCC=g++
# Install prefix for architecture-independent files
prefix= /usr
# Install prefix for architecture-dependent files
exec_prefix= ${prefix}
# === Fixed definitions ===
# Shell used by make (some versions default to the login shell, which is bad)
SHELL= /bin/sh
# Expanded directories
BINDIR= $(exec_installdir)/bin
LIBDIR= $(exec_prefix)/lib
MANDIR= $(installdir)/man
INCLUDEDIR= $(installdir)/include
SCRIPTDIR= $(prefix)/lib
# Detailed destination directories
BINLIBDEST= $(LIBDIR)/python$(VERSION)
LIBDEST= $(SCRIPTDIR)/python$(VERSION)
INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
EXECINCLUDEPY= $(exec_installdir)/include/python$(VERSION)
LIBP= $(exec_installdir)/lib/python$(VERSION)
DESTSHARED= $(BINLIBDEST)/site-packages
LIBPL= $(LIBP)/config
PYTHONLIBS= $(LIBPL)/libpython$(VERSION).a
MAKESETUP= $(LIBPL)/makesetup
MAKEFILE= $(LIBPL)/Makefile
CONFIGC= $(LIBPL)/config.c
CONFIGCIN= $(LIBPL)/config.c.in
SETUP= $(LIBPL)/Setup
SYSLIBS= $(LIBM) $(LIBC)
ADDOBJS= $(LIBPL)/python.o config.o
# Portable install script (configure doesn't always guess right)
INSTALL= $(LIBPL)/install-sh -c
# Shared libraries must be installed with executable mode on some systems;
# rather than figuring out exactly which, we always give them executable mode.
# Also, making them read-only seems to be a good idea...
INSTALL_SHARED= ${INSTALL} -m 555
# === Fixed rules ===
# Default target. This builds shared libraries only
default: sharedmods
# Build everything
all: static sharedmods
# Build shared libraries from our extension modules
sharedmods: $(SHAREDMODS)
# Build a static Python binary containing our extension modules
static: $(TARGET)
$(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
$(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \
$(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
-o $(TARGET)
install: sharedmods
if test ! -d $(DESTSHARED) ; then \
mkdir $(DESTSHARED) ; else true ; fi
-for i in X $(SHAREDMODS); do \
if test $$i != X; \
then $(INSTALL_SHARED) $$i $(DESTSHARED)/$$i; \
fi; \
done
# Build the library containing our extension modules
lib.a: $(MODOBJS)
-rm -f lib.a
ar cr lib.a $(MODOBJS)
-$(RANLIB) lib.a
# This runs makesetup *twice* to use the BASESETUP definition from Setup
config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
$(MAKESETUP) \
-m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
$(MAKE) -f Makefile do-it-again
# Internal target to run makesetup for the second time
do-it-again:
$(MAKESETUP) \
-m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
# Make config.o from the config.c created by makesetup
config.o: config.c
$(CC) $(CFLAGS) -c config.c
# Setup is copied from Setup.in *only* if it doesn't yet exist
Setup:
cp $(srcdir)/Setup.in Setup
# Make the intermediate Makefile.pre from Makefile.pre.in
Makefile.pre: Makefile.pre.in sedscript
sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre
# Shortcuts to make the sed arguments on one line
P=prefix
E=exec_prefix
H=Generated automatically from Makefile.pre.in by sedscript.
L=LINKFORSHARED
# Make the sed script used to create Makefile.pre from Makefile.pre.in
sedscript: $(MAKEFILE)
sed -n \
-e '1s/.*/1i\\/p' \
-e '2s%.*%# $H%p' \
-e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
-e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
-e '/^CCC=/s/^CCC=[ ]*\(.*\)/s%#@SET_CCC[@]%CCC=\1%/p' \
-e '/^LINKCC=/s/^LINKCC=[ ]*\(.*\)/s%@LINKCC[@]%\1%/p' \
-e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \
-e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
-e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
-e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
-e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
-e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
-e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
-e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
-e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
-e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
-e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
-e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \
-e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
-e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
$(MAKEFILE) >sedscript
echo "/^CCC=g++/d" >>sedscript
echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript
echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript
echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript
echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript
echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript
echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript
# Bootstrap target
boot: clobber
VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \
installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \
exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \
$(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
VERSION=$$VERSION \
installdir=$$installdir \
exec_installdir=$$exec_installdir \
Makefile
# Handy target to remove intermediate files and backups
clean:
-rm -f *.o *~
# Handy target to remove everything that is easily regenerated
clobber: clean
-rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript
-rm -f *.so *.sl so_locations
# Handy target to remove everything you don't want to distribute
distclean: clobber
-rm -f Makefile Setup

View file

@ -1,297 +0,0 @@
# Universal Unix Makefile for Python extensions
# =============================================
# Short Instructions
# ------------------
# 1. Build and install Python (1.5 or newer).
# 2. "make -f Makefile.pre.in boot"
# 3. "make"
# You should now have a shared library.
# Long Instructions
# -----------------
# Build *and install* the basic Python 1.5 distribution. See the
# Python README for instructions. (This version of Makefile.pre.in
# only withs with Python 1.5, alpha 3 or newer.)
# Create a file Setup.in for your extension. This file follows the
# format of the Modules/Setup.in file; see the instructions there.
# For a simple module called "spam" on file "spammodule.c", it can
# contain a single line:
# spam spammodule.c
# You can build as many modules as you want in the same directory --
# just have a separate line for each of them in the Setup.in file.
# If you want to build your extension as a shared library, insert a
# line containing just the string
# *shared*
# at the top of your Setup.in file.
# Note that the build process copies Setup.in to Setup, and then works
# with Setup. It doesn't overwrite Setup when Setup.in is changed, so
# while you're in the process of debugging your Setup.in file, you may
# want to edit Setup instead, and copy it back to Setup.in later.
# (All this is done so you can distribute your extension easily and
# someone else can select the modules they actually want to build by
# commenting out lines in the Setup file, without editing the
# original. Editing Setup is also used to specify nonstandard
# locations for include or library files.)
# Copy this file (Misc/Makefile.pre.in) to the directory containing
# your extension.
# Run "make -f Makefile.pre.in boot". This creates Makefile
# (producing Makefile.pre and sedscript as intermediate files) and
# config.c, incorporating the values for sys.prefix, sys.exec_prefix
# and sys.version from the installed Python binary. For this to work,
# the python binary must be on your path. If this fails, try
# make -f Makefile.pre.in Makefile VERSION=1.5 installdir=<prefix>
# where <prefix> is the prefix used to install Python for installdir
# (and possibly similar for exec_installdir=<exec_prefix>).
# Note: "make boot" implies "make clobber" -- it assumes that when you
# bootstrap you may have changed platforms so it removes all previous
# output files.
# If you are building your extension as a shared library (your
# Setup.in file starts with *shared*), run "make" or "make sharedmods"
# to build the shared library files. If you are building a statically
# linked Python binary (the only solution of your platform doesn't
# support shared libraries, and sometimes handy if you want to
# distribute or install the resulting Python binary), run "make
# python".
# Note: Each time you edit Makefile.pre.in or Setup, you must run
# "make Makefile" before running "make".
# Hint: if you want to use VPATH, you can start in an empty
# subdirectory and say (e.g.):
# make -f ../Makefile.pre.in boot srcdir=.. VPATH=..
# === Bootstrap variables (edited through "make boot") ===
# The prefix used by "make inclinstall libainstall" of core python
installdir= /usr/local
# The exec_prefix used by the same
exec_installdir=$(installdir)
# Source directory and VPATH in case you want to use VPATH.
# (You will have to edit these two lines yourself -- there is no
# automatic support as the Makefile is not generated by
# config.status.)
srcdir= .
VPATH= .
# === Variables that you may want to customize (rarely) ===
# (Static) build target
TARGET= python
# Installed python binary (used only by boot target)
PYTHON= python
# Add more -I and -D options here
CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(EXECINCLUDEPY) $(DEFS)
# These two variables can be set in Setup to merge extensions.
# See example[23].
BASELIB=
BASESETUP=
# === Variables set by makesetup ===
MODOBJS= _MODOBJS_
MODLIBS= _MODLIBS_
# === Definitions added by makesetup ===
# === Variables from configure (through sedscript) ===
VERSION= @VERSION@
CC= @CC@
LINKCC= @LINKCC@
SGI_ABI= @SGI_ABI@
OPT= @OPT@
LDFLAGS= @LDFLAGS@
DEFS= @DEFS@
LIBS= @LIBS@
LIBM= @LIBM@
LIBC= @LIBC@
RANLIB= @RANLIB@
MACHDEP= @MACHDEP@
SO= @SO@
LDSHARED= @LDSHARED@
CCSHARED= @CCSHARED@
LINKFORSHARED= @LINKFORSHARED@
#@SET_CCC@
# Install prefix for architecture-independent files
prefix= /usr/local
# Install prefix for architecture-dependent files
exec_prefix= $(prefix)
# === Fixed definitions ===
# Shell used by make (some versions default to the login shell, which is bad)
SHELL= /bin/sh
# Expanded directories
BINDIR= $(exec_installdir)/bin
LIBDIR= $(exec_prefix)/lib
MANDIR= $(installdir)/man
INCLUDEDIR= $(installdir)/include
SCRIPTDIR= $(prefix)/lib
# Detailed destination directories
BINLIBDEST= $(LIBDIR)/python$(VERSION)
LIBDEST= $(SCRIPTDIR)/python$(VERSION)
INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
EXECINCLUDEPY= $(exec_installdir)/include/python$(VERSION)
LIBP= $(exec_installdir)/lib/python$(VERSION)
DESTSHARED= $(BINLIBDEST)/site-packages
LIBPL= $(LIBP)/config
PYTHONLIBS= $(LIBPL)/libpython$(VERSION).a
MAKESETUP= $(LIBPL)/makesetup
MAKEFILE= $(LIBPL)/Makefile
CONFIGC= $(LIBPL)/config.c
CONFIGCIN= $(LIBPL)/config.c.in
SETUP= $(LIBPL)/Setup
SYSLIBS= $(LIBM) $(LIBC)
ADDOBJS= $(LIBPL)/python.o config.o
# Portable install script (configure doesn't always guess right)
INSTALL= $(LIBPL)/install-sh -c
# Shared libraries must be installed with executable mode on some systems;
# rather than figuring out exactly which, we always give them executable mode.
# Also, making them read-only seems to be a good idea...
INSTALL_SHARED= ${INSTALL} -m 555
# === Fixed rules ===
# Default target. This builds shared libraries only
default: sharedmods
# Build everything
all: static sharedmods
# Build shared libraries from our extension modules
sharedmods: $(SHAREDMODS)
# Build a static Python binary containing our extension modules
static: $(TARGET)
$(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
$(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \
$(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
-o $(TARGET)
install: sharedmods
if test ! -d $(DESTSHARED) ; then \
mkdir $(DESTSHARED) ; else true ; fi
-for i in X $(SHAREDMODS); do \
if test $$i != X; \
then $(INSTALL_SHARED) $$i $(DESTSHARED)/$$i; \
fi; \
done
# Build the library containing our extension modules
lib.a: $(MODOBJS)
-rm -f lib.a
ar cr lib.a $(MODOBJS)
-$(RANLIB) lib.a
# This runs makesetup *twice* to use the BASESETUP definition from Setup
config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
$(MAKESETUP) \
-m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
$(MAKE) -f Makefile do-it-again
# Internal target to run makesetup for the second time
do-it-again:
$(MAKESETUP) \
-m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
# Make config.o from the config.c created by makesetup
config.o: config.c
$(CC) $(CFLAGS) -c config.c
# Setup is copied from Setup.in *only* if it doesn't yet exist
Setup:
cp $(srcdir)/Setup.in Setup
# Make the intermediate Makefile.pre from Makefile.pre.in
Makefile.pre: Makefile.pre.in sedscript
sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre
# Shortcuts to make the sed arguments on one line
P=prefix
E=exec_prefix
H=Generated automatically from Makefile.pre.in by sedscript.
L=LINKFORSHARED
# Make the sed script used to create Makefile.pre from Makefile.pre.in
sedscript: $(MAKEFILE)
sed -n \
-e '1s/.*/1i\\/p' \
-e '2s%.*%# $H%p' \
-e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
-e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
-e '/^CCC=/s/^CCC=[ ]*\(.*\)/s%#@SET_CCC[@]%CCC=\1%/p' \
-e '/^LINKCC=/s/^LINKCC=[ ]*\(.*\)/s%@LINKCC[@]%\1%/p' \
-e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \
-e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
-e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
-e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
-e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
-e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
-e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
-e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
-e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
-e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
-e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
-e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \
-e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
-e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
$(MAKEFILE) >sedscript
echo "/^#@SET_CCC@/d" >>sedscript
echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript
echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript
echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript
echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript
echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript
echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript
# Bootstrap target
boot: clobber
VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \
installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \
exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \
$(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
VERSION=$$VERSION \
installdir=$$installdir \
exec_installdir=$$exec_installdir \
Makefile
# Handy target to remove intermediate files and backups
clean:
-rm -f *.o *~
# Handy target to remove everything that is easily regenerated
clobber: clean
-rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript
-rm -f *.so *.sl so_locations
# Handy target to remove everything you don't want to distribute
distclean: clobber
-rm -f Makefile Setup

View file

@ -1,81 +0,0 @@
#ifndef Py_PYLRENGINE_H
#define Py_PYLRENGINE_H
#ifdef __cplusplus
extern "C" {
#endif
#define EOBUF -1
struct inbufdatum {
PyObject* pylrval;
int tok;
};
struct inbufdata {
struct inbufdatum** chunk;
struct inbufdata* next;
};
typedef struct inbuf_struct {
struct inbufdata* data;
int bi;
int nextinput;
int chunksize;
} inbuftype;
struct stackdatum {
int state;
int tok;
PyObject* pylrval;
};
struct stackdata {
struct stackdatum** bucket;
struct stackdata* next;
};
typedef struct stack_struct {
struct stackdata* data;
int si;
int chunksize;
} stacktype;
typedef struct prodinfo_struct {
int len;
PyObject* func;
int lhsi;
} prodinfo_type;
typedef struct actionstruct{
int arg;
short act;
} actiontype;
/***********************************************************************
* the possible values of the action table
***********************************************************************/
#define SHIFT 's'
#define REDUCE 'r'
#define ACCEPT 'a'
typedef struct {
PyObject_HEAD
inbuftype* inbuf;
stacktype* stack;
prodinfo_type** prodinfo;
int prodinfosize;
int** gototable;
int goto_x;
int goto_y;
actiontype*** actiontable;
int act_x;
int act_y;
int toksadded;
} parserobject;
#ifdef __cplusplus
}
#endif
#endif /* !Py_PYLRENGINE_H */

View file

@ -1,44 +0,0 @@
You must have python 1.5b1 or newer to run PyLR, as it works with the
builtin package support of that version.
To build:
1) decide whether you want the PyLRengine module to be a shared library.
If not, comment out the '*shared*' line in Setup.
2)type make -f Makefile boot; make
that should build the package.
To install:
If you want to install PyLR in your python distribution, just copy
over the PyLR directory to your site-packages directory. If you want
to save a little space, take a look at the __init__ file doc string in
the top directory and it shows the necessary files (distribution minus
Makefile, sedscript, etc). Also, there is a script (pgen.py) you may want
in /usr/local/bin or something more accessible as executable from your shell.
There is html documentation in the doc/ directory.
To test:
pgen.py PyLR/tstpspec tst
diff tst PyLR/Parsers/gram.py
the only difference should be the date line.
Feedback:
send comments/suggestions/bugreports/contributions to
scott@chronis.icgroup.com
thanks,
scott

View file

@ -1,2 +0,0 @@
*shared*
PyLRengine PyLRenginemodule.c

View file

@ -1,2 +0,0 @@
*shared*
PyLRengine PyLRenginemodule.c

View file

@ -1,142 +0,0 @@
<html>
<body bgcolor="#ffffff">
<title> PyLR -- Fast LR parsing in python </title>
<!-- Changed by: Scott, 15-Dec-1997 -->
<center>
<h2>PyLR -- Fast LR parsing in python</h2>
<hr>
</center>
<ul>
<li> <a href="#whatis"> What is PyLR? </a>
<li> <a href="#status"> What is the current state of PyLR? </a>
<li> <a href="#where"> Where do I get PyLR? </a>
<li> <a href="#directions"> What will be added to PyLR? </a>
<li> <a href="#parsing"> Where do I find out about parsing theory? </a>
<li> <a href="#contrib"> How can I contribute to PyLR? </a>
</ul>
<hr>
<p><p>
<a name="whatis"><h2>What is PyLR?</h2></a>
PyLR is a package of tools for creating efficient parsers in python,
commonly known as a compiler compiler. PyLR is currently under
development. A ful release is almost complete, but there are still a few missing
features that would make it much nicer.
<p>
PyLR (pronounced 'pillar') was motivated by the frequencly with which parsers are hand
coded in python, the performance demands that these parsers are subject to (you just can't beat
native machine code for speed...), and academic curiosity (I wanted to really know how LR
parsing works).
<p><p>
<a name="status"> <h2>What is the current state of PyLR? </h2></a>
PyLR currently has class interfaces to a Grammar, a Lexer, an extension module
defining a parsing engine builtin type, and a parser generator script. All of these components
are based on sound parsing theory, but nevertheless haven't been tested by anyone but it's author.
The code as is stands can definitely be of use to anyone hand writing a parser in python, but some
of the nicer things in the complete package <em> just haven't been done yet </em>. <p>
PyLR is therefore under development, as it will always be. PyLR will be given a release number
once it supplies the following tools:
<ul>
<LI> write an 'engine' module that implements the LR parsing
algorythm in C with callbacks to python functions. (done) </LI>
<LI> write a Lexer class using re (done)</LI>
<LI> write a Grammar class that will take as input a context
free grammar and produce the parsing tables necessary to complement
the engine. This is to be done with LR(1) grammars (done and then
deleted -- extremely inefficient) and LALR(1) Grammars(done,
except with epsilon (empty) productions,<EM> much</EM> more efficient). </LI>
<LI> add a user interface -- manually write a lexer and Grammar
using the exisiting classes to parse lexer and grammar specifications
modelled after lex/flex and yacc/bison. (done for Grammars)
</LI>
<LI> write documentation. (usable, but not done)
</LI>
<LI> (post release) add grammars to various languages to the
distribution.
</LI>
</ul>
In addtion, I have the following plan for the project:
<UL>
<LI> make 'epsilon' (empty) productions work (many of them work now, but not all) </LI>
<LI> optimize the Lexer. Try to join it into one regular expression and derive
function calls from match object data. (done, still the slowest part of parsing)</LI>
<LI> add error specification routines. </LI>
<LI> change the parser generation algorithm to use only kernel LALR(1) items
in the computation of shift actions and gotos in the goto table. This
should significantly enhance the rate of parser generation, which is currently
a bit slow, but certainly acceptable for medium-sized grammars (&lt; ~100 productions)
(done!) this version
</LI>
<LI> write a Parser for sql, as used in <A HREF="http://www.pythonpros.com/arw/kwParsing/">gadfly</A>
</LI>
<LI> add operator precedence as an option to the parser specification (further down the road...)</LI>
</UL>
These things will probably be done over the next month or two (as I only have free time to give
to this project...Ahemmm...).
<p><p>
<a name="where"><h2>Where do I get PyLR? </h2></a>
You can get PyLR in one of two places, <a href="ftp://chronis.icgroup.com/pub/">here</a>
or <a href="PyLR.tgz"> here</a>. Both versions will be in sync with each other.
<p><p>
<a name="directions"><h2>What will be added to PyLR? </h2></a>
In addition to the <a href ="#status">list of things to finish </a> before a full release,
is published, PyLR could be used as the basis for an efficient datapath analyzer (optimizer),
for a front end to translation from one language to another, for type checking code, etc.<p>
As soon as the first release is completed, Tools to aid in all these things could well be added
to the package. Also, anyone wanting to contribute parser specifications for
languages of general use is most welcome.
<p><p>
<a name="parsing"> <h2>Where do I find out more about parsing? </h2></a>
Parsing was for a long time a big challenge for computer scientists. The need for
computer parsing originally came about with the first writing of compilers. Since then, the
theory behind parsing has been studied in depth and has pretty much stabilized as it no longer
really presents a big problem in terms of speed or size in terms of parsing todays computer
languages. One standard means of parsing that has been used for years because of its efficiency
is LR parsing (more particularly, LALR parsing). A lot of good information is in
<a href="http://www.amazon.com/exec/obidos/ISBN=1565920007">
Lex and Yacc</a> ,
<a href="http://www.amazon.com/exec/obidos/ISBN=0201100886">
The Dragon Book </a>, and
it seems like the only place to find good info on LALR parsing is in
<pre>
DeRemer, F.; and Pennello, T.Efficient computation of LALR(1) look-ahead sets, ACM Trans.
Program. Lang. Syst. 4 (1982), 615-649.
</pre>
Finally, to find out how to use PyLR, see the<A HREF="manual.html">PyLR manual</A>
<a name="contrib"> <h2>How do I contribute to PyLR? </h2></a>
<a href="mailto:scott@chronis.icgroup.com">mail me. </a>

View file

@ -1,313 +0,0 @@
<html>
<title> PyLR maual </title>
<!-- Changed by: Scott, 12-Dec-1997 -->
<body bgcolor="#ffffff">
<CENTER>
<h2>PyLR Manual</h2>
</CENTER>
This is the PyLR parser generator manual. PyLR is a parser generator package for
use with python (version 1.5b1 or better). This manual addresses how to use the
package to produce parsers.
<p>
<UL>
<LI> <A HREF="#Audience">Intended Audience</A> </LI>
<LI> <A HREF="#Basics">The Basics</A> </LI>
<UL>
<LI> <A HREF="#Lexer">Writing a Lexer</A> </LI>
<LI> <A HREF="#Grammar">Writing a Grammar</A> </LI>
<LI> <A HREF="#Parser">Putting it together, producing the parser</A> </LI>
</UL>
<LI> <A HREF="#Struct">PyLR Structure Overview</A> </LI>
<LI> <A HREF="#API">Programming with the Classes</A> </LI>
</UL>
<HR>
<p>
<p>
<A NAME="Audience"> <center> <h3> Audience </h3></center></A>
Parsing can be very complicated stuff, and it helps to understand what exactly is
happening when something is parsed when writing a parser. Unfortunately (for the impatient),
the topic of Parsing has been the subject of many a dissertation. This document will present
two views on the data it presents. One is a technical view which will contain terms <EM>without
defining them</EM>. These terms are generally understood by those who have studied parsing theory
(such as LALR, shift-reduce, etc), and probably not understood by those that haven't. For this
reason, I have attempted to include an intuitive view whenever possible, particularly in the
section <A HREF="#Basics">The Basics</A>. There should be enough in that section to let anyone
interested who is interested and familiar with python write a parser.
<HR><p>
<A NAME="Basics"><center><h3>The Basics</h3></center></A> <br>
This section refers to writing lexers, Grammars, and then producing a parser with
these parts. In PyLR, a lexer is part of a parser. This simplifies the interface to
actually doing the parsing. There is an 'engine' which takes the output of the lexer and triggers
the back end of parsing. So we'll start with writing a lexer.
<UL>
<LI>
<A NAME="Lexer"><h4>Writing a Lexer</h4></A><br>
When some text is to be parsed, it first has to go through lexical analysis. This
process is done with a lexer. PyLR provides a base Lexer class to help write a lexer.
The process isn't hard. A lexer just returns the atomic parts of the text. You define what is
atomic by using regular expressions to match the atomic parts. Each atomic definition
you give is automatically given a token value (an int). When the lexer scans text, it returns
a stream of <TT>(token, value)</TT> pairs where the the token is the token value that was assigned
to the match definition and the the value is an arbitrary python value (class, string, int, whatever).
The <TT>(token, value)</TT> pair is then passed to the parser for further processing.
<p>
Frequently, lexers will return the matched text as the
<TT>value</TT> in the <TT>(token, value)</TT> pair. This is the
default when you subclass the provided Lexer class. However, there
are a lot of different things you may want to happen upon finding a
match. For example, sometimes you will want to match something but
not use the match or pass it on to the parser.
<p>
There is a function in the base class that
provides for all these and more options. It is the <br>
<TT>.addmatch(compiled_regex, tokenname="", function=None,
flags=MAPTOK|EXECFN)</TT> <br> method. This method requires only a regular
expression as its argument, but in practice, token names should be passed along with
the re. This practice will make your grammar more readable and easier
to write later. <br> The <TT>function</TT> argument, if specified, will make the
lexer execute that function with the resulting match object as it's
one and only argument. The lexer will then return the return value of
the function as the <TT>value</TT> in the <TT>(token, value)</TT> pair
it returns. By default, the lexer will just return the token and the associated
matched text.
<br>
The <TT>flags</TT> argument not only defaults to the reasonable MAPTOK|EXECFN, but also adopts to
the values of the other arguments you pass. This way, you dont' have to bother with them much. The one
time it's common to use the flags is when you want the lexer to match something but not return anything until
the next match. It is common to have whitespace treated in this fashion. For this option, you use
<TT>.addmatch(re.compile(r"\s+"), "", None, Lexer.SKIPTOK)</TT>. The example below utilizes all these
options.
<p>
Finally, please note the call of the <TT>.seteof()</TT> function at the end of the <TT>__init__</TT>
method. This is necessary for all subclassed lexers. The reason it is there is that the token value
of EOF is expected to be one greater than any other token value by the parser. <EM>Your lexer will not
work with the parser api without this call.</EM>
<p>
Example
<pre>
from PyLR import Lexer
import re, string
#
# this function will handle matches to an integer. It passes the
# integer value to the parser and does the conversion here.
#
def intfunc(m):
return string.atoi(m.group(0))
class mathlex(Lexer.Lexer):
#
# define the atomic parts with regular expressions
#
INT = re.compile(r"([1-9]([0-9]+)?)|0") # matches an integer
LPAREN = re.compile(r"\(") # matches '('
RPAREN = re.compile(r"\)") # matches ')'
TIMES = re.compile(r"\*") # matches '*'
PLUS = re.compile(r"\+") # matches '+'
WS = re.compile(r"\s+") # matches whitespace
def __init__(self):
#
# initialize with the base class
#
Lexer.Lexer.__init__(self)
#
# addmatch examples
#
self.addmatch(self.INT, idfunc, "INT")
for p,t in ( (self.PLUS, "PLUS"), (self.TIMES,"TIMES"),
(self.LPAREN, "LPAREN"), (self.RPAREN, "RPAREN"),):
self.addmatch(p, None, t)
self.addmatch(self.ws, None, "", Lexer.SKIPTOK)
self.seteof()
# create the lexer
lexer = mathlex()
# test it with the interactivetest method
lexer.interactivetest()
</pre>
</LI>
<hr>
<LI> <A NAME="Grammar"><h4>Writing a Grammar</h4></A><br>
The grammar you write is somewhat easier than the lexer. You don't have
to code anything. There is a program in the PyLR distribution called <TT>pgen.py</TT>
that will take your Grammar specification and produce a parser for you. The parser that is
produced is of the shift-reduce variety of LR parsers and uses LALR(1) items to help produce
the parsing tables. In other words, it uses a parsing algorithm that is quite efficient (implemented
in C) and will handle most modern day programming language constructs without a problem. These
qualities have made this parsing algorithm a very commonly used one in compiler construction since
October 1982.
<p>
When you write a grammar, you are specifying a <EM>context free grammar</EM> in normal form,
with a few addons to help generate the parser in Python. In other words, you specify a series
of productions. For example, to specify a very simple math grammar that will work with the
above lexer, you may state something like this:
<pre>
expression: expression PLUS term
| term;
term: term TIMES factor
| factor;
factor: LPAREN expression RPAREN
| INT;
</pre>
The identifiers in all uppercase are conventionally <EM>terminal symbols</EM>.
These will be identified by the lexer and returned to the parser. The identifiers
in all lowercase are the <EM>nonterminal symbols</EM>. Each nonterminal must appear
on the left somewhere. The corresponding right side may have terminals or non terminals.
You may not have empty (epsilon) right hand sides (yet).
<p>
Whenever the parser recognizes a production, it will call a function. You may specify
the name of the method of the parser class to be invoked for a production by adding
a parenthesized name to the right of the production. The above grammar rewritten with
method name specifications looks like this (This part will become more clear after the next step,
stay with it!).
<pre>
expression: expression PLUS term (addfunc)
| term;
term: term TIMES factor (timesfunc)
| factor;
factor: LPAREN expression RPAREN (parenfunc)
| INT;
</pre>
</LI>
<LI> <A NAME="Parser"><h4>Putting it all together: making the parser</h4></A><br>
When you create a parser, you are creating a class that is intended to act like
a class in library code. That is, it will mostly be used by subclassing that class.
The parser you create will parse what it was intended to, but it won't do anything
with the parse tree unless you subclass it and define some special methods.
<p>
Those methods must have the name specified in the grammar you wrote. For example, if you
built a parser for the above grammar, in order for it to actually add things together,
you would have to subclass the class that was produced and then define the methods
<TT>addfunc</TT>, <TT>timesfunc</TT>, and <TT>parenfunc</TT>. When each of these methods is called
it will be passed the values on the right hand side of the corresponding production as arguments.
Those values are either the value returned by the lexer, if the symbol is terminal, or
a value returned by one of these special methods, if the symbol is a nonterminal.
<p>
In the above example, since the rest of the productions only have one item, it doesn't really matter
whether or not they have methods, the parser just calls a reasonable default.
<p>
As you can see, we've defined most of what is necessary for building a parser. But the above should tell
you that there are a few other things that you may want to define, like the name of the class that
is produced, or what lexer is used with the parser. Describing these things along with a grammar like
the example above is writing a parser specification for PyLR. A reasonable parser specification for the
example we've been following:
<pre>
_class SimpleMathParser
_lex mathlex.mathlex()
_code from PyLR.Lexers import mathlex
"""
expression: expression PLUS term (addfunc)
| term;
term: term TIMES factor (timesfunc)
| factor;
factor: LPAREN expression RPAREN (parenfunc)
| INT;
"""
</pre>
the <TT>_class </TT> keyword defines the name of the class that the parser will take
the <TT>_lex</TT> keyword defines the code used to intialize that parser's lexer
the <TT>_code</TT> keyword defines extra code at the top of the output file. Multiple
instances of this keyword will cause the extra source code (in python) to be accumulated.
the triple quotes delimit the grammar section.
<p><em>
Please note, the above syntax is subject to change as this is an alpha release and I feel
that it can be improved upon.</em>
<p>
now you can create a parser. Just use the <TT>pgen.py</TT> script and it will output
your source code:
<pre>
pgen.py mathparserspec tst.py
chronis 3:34am $ python
Python 1.5b1 (#1, Nov 27 1997, 19:51:47) [GCC 2.7.2] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import tst
>>> dir(tst)
['PyLR', 'SimpleMathParser', '__builtins__', '__doc__', '__file__', '__name__', '_actiontable', '_gototable', '_prodinfo', 'mathlex']
>>> print tst.SimpleMathParser.__doc__
this class was produced automatically by the PyLR parser generator.
It is meant to be subclassed to produce a parser for the grammar
expression -> expression PLUS term (addfunc)
| term; (unspecified)
term -> term TIMES factor (timesfunc)
| factor; (unspecified)
factor -> LPAREN expression RPAREN (parenfunc)
| INT; (unspecified)
While parsing input, if one of the above productions is recognized,
a method of your sub-class (whose name is indicated in parens to the
right) will be invoked. Names marked 'unspecified' will not me invoked.
usage:
class MySimpleMathParser(SimpleMathParser):
# ...define the methods for the productions...
p = MySimpleMathParser(); p.parse(text)
>>> class MP(tst.SimpleMathParser):
... def __init__(self):
... tst.SimpleMathParser.__init__(self)
... def addfunc(self, left, plus, right):
... print "%d + %d" % (left, right)
... return left + right
... def parenfunc(self, lp, expr, rp):
... print "handling parens"
... return expr
... def timesfunc(self, left, times, right):
... print "%d * %d" % (left, right)
... return left * right
...
>>> mp = mathparser()
>>> mp.parse("4 * (3 + 2 * 5)")
2 * 5
3 + 10
handling parens
4 * 13
</pre>
</LI>
</UL>
<A NAME="Struct"><center><h3>Structure</h3></center></A>
Nothing yet, sorry it's an alpha, read the source.
<A NAME="API"><center><h3>API</h3></center></A>
Nothing yet, sorry it's an alpha. Read the source.
</html>

View file

@ -1,28 +0,0 @@
1i\
# Generated automatically from Makefile.pre.in by sedscript.
s%@VERSION[@]%1.5%
s%#@SET_CCC[@]%CCC=g++%
s%@CC[@]%gcc%
s%@RANLIB[@]%ranlib%
s%@OPT[@]%-g -O2%
s%@LDFLAGS[@]%%
s%@DEFS[@]%-DHAVE_CONFIG_H%
s%@LIBS[@]%-lieee -ldl -lpthread%
s%@LIBM[@]%-lm%
s%@LIBC[@]%%
s%@MACHDEP[@]%linux2%
s%^prefix=.*%prefix= /usr%
s%^exec_prefix=.*%exec_prefix= ${prefix}%
s%@SO[@]%.so%
s%@LDSHARED[@]%gcc -shared -lc%
s%@CCSHARED[@]%-fPIC%
s%@LINKFORSHARED[@]%-Xlinker -export-dynamic%
s%@LINKCC[@]%$(CC)%
/^#@SET_CCC@/d
/^installdir=/s%=.*%= /usr%
/^exec_installdir=/s%=.*%=/usr%
/^srcdir=/s%=.*%= .%
/^VPATH=/s%=.*%= .%
/^LINKPATH=/s%=.*%= %
/^BASELIB=/s%=.*%= %
/^BASESETUP=/s%=.*%= %

View file

@ -1,3 +0,0 @@
all:
python MySimpleParser.py
# python MyMathParser.py

View file

@ -1,15 +0,0 @@
import PyLR
def _intfunc(m):
return int(m.group(0))
class MathLexer(PyLR.Lexer):
def __init__(self):
PyLR.Lexer.__init__(self)
self.addpat(r"([1-9]([0-9]+)?)|0", "INT", _intfunc)
self.addpat(r"\+", "PLUS")
self.addpat(r"\*","TIMES")
self.addpat(r"\(", "LPAR")
self.addpat(r"\)", "RPAR")
self.addpat(r"\s+", "WS", None, 1)

View file

@ -1,110 +0,0 @@
"""
tests/MathParser.py -- created Mon Feb 28 00:06:56 2000
This file was automatically generated by the PyLR parser generator.
It defines the tables 'actiontable', 'gototable', and 'prodinfo'. These
tables are used to give functionality to a parsing engine. It also defines
A Parser class called MathParser which will use this engine. It's usage
is indicated in MathParser's doc-string.
"""
#
# this section contains source code added by the user
# plus 'import PyLR'
#
import MathLexer
import PyLR
#
# the action table means
# ('s', -1) shift
# ('r', <n>) reduce with production n
# ('a', -1) accept
# ('', -1) error
# each row represents a state and each column a terminal lookahead symbol
# Lexer symbols are:
# ['EOF', 'INT', 'PLUS', 'TIMES', 'LPAR', 'RPAR']
#
_actiontable = [
[('', -1), ('s', 4), ('', -1), ('', -1), ('s', 5), ('', -1)],
[('a', -1), ('', -1), ('s', 6), ('', -1), ('', -1), ('', -1)],
[('r', 2), ('', -1), ('r', 2), ('s', 7), ('', -1), ('r', 2)],
[('r', 4), ('', -1), ('r', 4), ('r', 4), ('', -1), ('r', 4)],
[('r', 6), ('', -1), ('r', 6), ('r', 6), ('', -1), ('r', 6)],
[('', -1), ('s', 4), ('', -1), ('', -1), ('s', 5), ('', -1)],
[('', -1), ('s', 4), ('', -1), ('', -1), ('s', 5), ('', -1)],
[('', -1), ('s', 4), ('', -1), ('', -1), ('s', 5), ('', -1)],
[('', -1), ('', -1), ('s', 6), ('', -1), ('', -1), ('s', 11)],
[('r', 1), ('', -1), ('r', 1), ('s', 7), ('', -1), ('r', 1)],
[('r', 3), ('', -1), ('r', 3), ('r', 3), ('', -1), ('r', 3)],
[('r', 5), ('', -1), ('r', 5), ('r', 5), ('', -1), ('r', 5)]
]
#
# the goto table, each row represents a state
# and each column the nonterminal that was on the lhs of the
# reduction
#
_gototable = [
[1, 1, 2, 2, 3, 3],
[None, None, None, None, None, None],
[None, None, None, None, None, None],
[None, None, None, None, None, None],
[None, None, None, None, None, None],
[8, 8, 2, 2, 3, 3],
[None, None, 9, 9, 3, 3],
[None, None, None, None, 10, 10],
[None, None, None, None, None, None],
[None, None, None, None, None, None],
[None, None, None, None, None, None],
[None, None, None, None, None, None]
]
#
# This is the prodinfo table. each row represents a production
# the entries are the length of the production, the name of a method
# in an instance of the MathParser class below that gets called
# when that production occurs, and the index of the lhs in the
# nonterminals (as in the gototable)
#
_prodinfo = [
(3, 'addfunc', 0), # expression: expression 2 term (addfunc)
(1, 'unspecified', 0), # expression: term (unspecified)
(3, 'timesfunc', 2), # term: term 3 factor (timesfunc)
(1, 'unspecified', 2), # term: factor (unspecified)
(3, 'parenfunc', 4), # factor: 4 expression 5 (parenfunc)
(1, 'unspecified', 4), # factor: 1 (unspecified)
]
class MathParser(PyLR.Parser):
"""
this class was produced automatically by the PyLR parser generator.
It is meant to be subclassed to produce a parser for the grammar
expression: expression PLUS term (addfunc);
expression: term (unspecified);
term: term TIMES factor (timesfunc);
term: factor (unspecified);
factor: LPAR expression RPAR (parenfunc);
factor: INT (unspecified);
While parsing input, if one of the above productions is recognized,
a method of your sub-class (whose name is indicated in parens to the
right) will be invoked. Names marked 'unspecified' should be ignored.
usage:
class MyMathParser(MathParser):
# ...define the methods for the productions...
p = MyMathParser(); p.parse(text)
"""
def __init__(self):
lexer = MathLexer.MathLexer()
PyLR.Parser.__init__(self, lexer, _actiontable, _gototable, _prodinfo)

View file

@ -1,19 +0,0 @@
import MathParser
class MyMathParser(MathParser.MathParser):
def addfunc(self, left, plus, right):
print "%d + %d" % (left, right)
return left + right
def parenfunc(self, lp, expr, rp):
print "handling parens"
return expr
def timesfunc(self, left, times, right):
print "%d * %d" % (left, right)
return left * right
def _test():
p = MyMathParser()
p.parse("4 * (3 + 2 * 5)", 1)
if __name__=='__main__':
_test()

View file

@ -1,13 +0,0 @@
from SimpleParser import SimpleParser
class mysimpleparser(SimpleParser):
pass
def _test():
p = mysimpleparser()
p.pyparse("c",1)
if __name__=='__main__':
_test()

View file

@ -1,7 +0,0 @@
import PyLR
class SimpleLexer(PyLR.Lexer):
def __init__(self):
PyLR.Lexer.__init__(self)
self.addpat(r"c", "c")
self.addpat(r"d", "d")

View file

@ -1,86 +0,0 @@
"""
tests/SimpleParser.py -- created Mon Feb 28 13:13:57 2000
This file was automatically generated by the PyLR parser generator.
It defines the tables 'actiontable', 'gototable', and 'prodinfo'. These
tables are used to give functionality to a parsing engine. It also defines
A Parser class called SimpleParser which will use this engine. It's usage
is indicated in SimpleParser's doc-string.
"""
#
# this section contains source code added by the user
# plus 'import PyLR'
#
import SimpleLexer
import PyLR
#
# the action table means
# ('s', -1) shift
# ('r', <n>) reduce with production n
# ('a', -1) accept
# ('', -1) error
# each row represents a state and each column a terminal lookahead symbol
# Lexer symbols are:
# ['EOF', 'c', 'd']
#
_actiontable = [
[('r', 2), ('r', 2), ('', -1)],
[('a', -1), ('s', 2), ('', -1)],
[('a', -1), ('', -1), ('s', 3)],
[('r', 1), ('r', 1), ('', -1)]
]
#
# the goto table, each row represents a state
# and each column the nonterminal that was on the lhs of the
# reduction
#
_gototable = [
[1],
[None],
[None],
[None]
]
#
# This is the prodinfo table. each row represents a production
# the entries are the length of the production, the name of a method
# in an instance of the SimpleParser class below that gets called
# when that production occurs, and the index of the lhs in the
# nonterminals (as in the gototable)
#
_prodinfo = [
(3, 'unspecified', 0), # S: S 1 2 (unspecified)
(0, 'unspecified', 0), # S: (unspecified)
]
class SimpleParser(PyLR.Parser):
"""
this class was produced automatically by the PyLR parser generator.
It is meant to be subclassed to produce a parser for the grammar
S: S c d (unspecified);
S: (unspecified);
While parsing input, if one of the above productions is recognized,
a method of your sub-class (whose name is indicated in parens to the
right) will be invoked. Names marked 'unspecified' should be ignored.
usage:
class MySimpleParser(SimpleParser):
# ...define the methods for the productions...
p = MySimpleParser(); p.parse(text)
"""
def __init__(self):
lexer = SimpleLexer.SimpleLexer()
PyLR.Parser.__init__(self, lexer, _actiontable, _gototable, _prodinfo)

View file

@ -1,51 +0,0 @@
#
# this is a Grammar Spec for parsing PyLR style
# Grammars
#
#
# this is the pydefs section, where you name the output class
# , add code, state how to initialize the lexer
#
_class GrammarParser
_code import PyLR.Lexers
_code import PyLR.Parser
_lex PyLR.Lexers.GrammarLex()
#
# this is the Grammar spec part, where you specify
# the productions and optionally their corresponding
# method names in the generated Parser class (or subclasses
# of it)
#
"""
pspec: gspec |
pydefs gspec;
gspec: GDEL lhsdeflist GDEL;
pydefs: pydefs pydef |
pydef;
pydef: LEX (lexdef) |
CODE (addcode) |
CLASS (classname);
lhsdeflist: lhsdeflist lhsdef |
lhsdef;
lhsdef: ID COLON rhslist SCOLON (lhsdef);
rhslist: rhs (singletolist) |
rhslist OR rhs (rhslist_OR_rhs);
rhs: rhsidlist (rhs_idlist) |
rhsidlist LPAREN ID RPAREN (rhs_idlist_func);
rhsidlist: idlist
| (rhseps);
idlist: idlist ID (idl_idlistID) |
ID (idlistID);
"""

View file

@ -1,49 +0,0 @@
#
# this is a Grammar Spec for parsing PyLR style
# Grammars
#
#
# this is the pydefs section, where you name the output class
# , add code, state how to initialize the lexer
#
_class GrammarParser
_lex PyLR.GrammarLexer()
#
# this is the Grammar spec part, where you specify
# the productions and optionally their corresponding
# method names in the generated Parser class (or subclasses
# of it)
#
"""
pspec: gspec |
pydefs gspec;
gspec: GDEL lhsdeflist GDEL;
pydefs: pydefs pydef |
pydef;
pydef: LEX (lexdef) |
CODE (addcode) |
CLASS (classname);
lhsdeflist: lhsdeflist lhsdef |
lhsdef;
lhsdef: ID COLON rhslist SCOLON (lhsdef);
rhslist: rhs (singletolist) |
rhslist OR rhs (rhslist_OR_rhs);
rhs: rhsidlist (rhs_idlist) |
rhsidlist LPAREN ID RPAREN (rhs_idlist_func);
rhsidlist: idlist
| (rhseps);
idlist: idlist ID (idl_idlistID) |
ID (idlistID);
"""