summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorManoj Srivastava <srivasta@golden-gryphon.com>2006-02-26 11:25:45 -0800
committerManoj Srivastava <srivasta@golden-gryphon.com>2006-02-26 11:25:45 -0800
commit8b69e240c2db8dd998a1f285a33a9dc7952c5a4d (patch)
treecc09f9873e88f53ad1549606451e5c7c250f8b83 /doc
parent174cabe1a0b3cc6b2a061106f74e9b1c04252eec (diff)
Imported Upstream version 2.5.34
Diffstat (limited to 'doc')
-rw-r--r--doc/Makefile.am17
-rw-r--r--doc/Makefile.in283
-rw-r--r--doc/flex.126
-rw-r--r--doc/flex.info471
-rw-r--r--doc/flex.info-16595
-rw-r--r--doc/flex.info-2bin52131 -> 52175 bytes
-rw-r--r--doc/flex.info-31371
-rw-r--r--doc/flex.info-41255
-rw-r--r--doc/flex.info-51330
-rw-r--r--doc/flex.info-61134
-rw-r--r--doc/flex.info-7601
-rw-r--r--doc/flex.pdfbin0 -> 697748 bytes
-rw-r--r--doc/flex.texi403
-rwxr-xr-xdoc/mdate-sh84
-rw-r--r--doc/stamp-vti8
-rw-r--r--doc/texinfo.tex6210
-rw-r--r--doc/version.texi8
17 files changed, 10706 insertions, 9090 deletions
diff --git a/doc/Makefile.am b/doc/Makefile.am
index f1a6084..bfed30d 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,19 +1,16 @@
help2man = @HELP2MAN@
info_TEXINFOS = flex.texi
-man_MANS = flex.1
-
-MAINTAINERCLEANFILES = \
- flex.1
+dist_man_MANS = flex.1
+EXTRA_DIST = flex.pdf
CLEANFILES = \
flex.hks \
flex.ops
-EXTRA_DIST = \
- $(man_MANS)
-
-$(man_MANS): $(top_srcdir)/main.c
- for i in $(man_MANS) ; do \
- $(help2man) --name='fast lexical analyzer generator' --section=`echo $$i|rev|cut -f 1 -d .|rev` ../flex > $$i ; \
+$(dist_man_MANS): $(top_srcdir)/main.c
+ for i in $(dist_man_MANS) ; do \
+ $(help2man) --name='$(PACKAGE_NAME)' \
+ --section=`echo $$i | sed -e 's/.*\.\([^.]*\)$$/\1/'` \
+ ../flex$(EXEEXT) > $$i || rm -f $$i ; \
done
diff --git a/doc/Makefile.in b/doc/Makefile.in
index f38e413..b5a7f5b 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -1,8 +1,8 @@
-# Makefile.in generated by automake 1.7.5 from Makefile.am.
+# Makefile.in generated by automake 1.9.6 from Makefile.am.
# @configure_input@
-# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-# Free Software Foundation, Inc.
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -13,7 +13,6 @@
# PARTICULAR PURPOSE.
@SET_MAKE@
-
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
@@ -21,7 +20,6 @@ pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
-
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
@@ -35,8 +33,44 @@ POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
+build_triplet = @build@
host_triplet = @host@
+subdir = doc
+DIST_COMMON = $(dist_man_MANS) $(srcdir)/Makefile.am \
+ $(srcdir)/Makefile.in $(srcdir)/stamp-vti \
+ $(srcdir)/version.texi mdate-sh texinfo.tex
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \
+ $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \
+ $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
+ $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \
+ $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+SOURCES =
+DIST_SOURCES =
+INFO_DEPS = $(srcdir)/flex.info
+am__TEXINFO_TEX_DIR = $(srcdir)
+DVIS = flex.dvi
+PDFS = flex.pdf
+PSS = flex.ps
+HTMLS = flex.html
+TEXINFOS = flex.texi
+TEXI2DVI = texi2dvi
+TEXI2PDF = $(TEXI2DVI) --pdf --batch
+MAKEINFOHTML = $(MAKEINFO) --html
+AM_MAKEINFOHTMLFLAGS = $(AM_MAKEINFOFLAGS)
+DVIPS = dvips
+am__installdirs = "$(DESTDIR)$(infodir)" "$(DESTDIR)$(man1dir)"
+man1dir = $(mandir)/man1
+NROFF = nroff
+MANS = $(dist_man_MANS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
@@ -114,6 +148,8 @@ am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
@@ -134,6 +170,7 @@ libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
+mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
@@ -142,101 +179,128 @@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
help2man = @HELP2MAN@
-
info_TEXINFOS = flex.texi
-man_MANS = flex.1
-
-MAINTAINERCLEANFILES = \
- flex.1
-
-
+dist_man_MANS = flex.1
+EXTRA_DIST = flex.pdf
CLEANFILES = \
flex.hks \
flex.ops
-
-EXTRA_DIST = \
- $(man_MANS)
-
-subdir = doc
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
-CONFIG_HEADER = $(top_builddir)/config.h
-CONFIG_CLEAN_FILES =
-DIST_SOURCES =
-am__TEXINFO_TEX_DIR = $(srcdir)
-INFO_DEPS = flex.info
-DVIS = flex.dvi
-PDFS = flex.pdf
-PSS = flex.ps
-TEXINFOS = flex.texi
-
-NROFF = nroff
-MANS = $(man_MANS)
-DIST_COMMON = Makefile.am Makefile.in mdate-sh stamp-vti texinfo.tex \
- version.texi
all: all-am
.SUFFIXES:
-.SUFFIXES: .dvi .info .pdf .ps .texi
-$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+.SUFFIXES: .dvi .html .info .pdf .ps .texi
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnits doc/Makefile'; \
cd $(top_srcdir) && \
- $(AUTOMAKE) --gnu doc/Makefile
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
- cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
+ $(AUTOMAKE) --gnits doc/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
.texi.info:
- @rm -f $@ $@-[0-9] $@-[0-9][0-9] $(@:.info=).i[0-9] $(@:.info=).i[0-9][0-9]
- $(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) \
- -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
+ restore=: && backupdir="$(am__leading_dot)am$$$$" && \
+ am__cwd=`pwd` && cd $(srcdir) && \
+ rm -rf $$backupdir && mkdir $$backupdir && \
+ if ($(MAKEINFO) --version) >/dev/null 2>&1; then \
+ for f in $@ $@-[0-9] $@-[0-9][0-9] $(@:.info=).i[0-9] $(@:.info=).i[0-9][0-9]; do \
+ if test -f $$f; then mv $$f $$backupdir; restore=mv; else :; fi; \
+ done; \
+ else :; fi && \
+ cd "$$am__cwd"; \
+ if $(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) \
+ -o $@ $<; \
+ then \
+ rc=0; \
+ cd $(srcdir); \
+ else \
+ rc=$$?; \
+ cd $(srcdir) && \
+ $$restore $$backupdir/* `echo "./$@" | sed 's|[^/]*$$||'`; \
+ fi; \
+ rm -rf $$backupdir; exit $$rc
.texi.dvi:
TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir)' \
- $(TEXI2DVI) `test -f '$<' || echo '$(srcdir)/'`$<
+ $(TEXI2DVI) $<
.texi.pdf:
TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir)' \
- $(TEXI2PDF) `test -f '$<' || echo '$(srcdir)/'`$<
-flex.info: flex.texi version.texi
-flex.dvi: flex.texi version.texi
-flex.pdf: flex.texi version.texi
-version.texi: stamp-vti
-stamp-vti: flex.texi $(top_srcdir)/configure
+ $(TEXI2PDF) $<
+
+.texi.html:
+ rm -rf $(@:.html=.htp)
+ if $(MAKEINFOHTML) $(AM_MAKEINFOHTMLFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) \
+ -o $(@:.html=.htp) $<; \
+ then \
+ rm -rf $@; \
+ if test ! -d $(@:.html=.htp) && test -d $(@:.html=); then \
+ mv $(@:.html=) $@; else mv $(@:.html=.htp) $@; fi; \
+ else \
+ if test ! -d $(@:.html=.htp) && test -d $(@:.html=); then \
+ rm -rf $(@:.html=); else rm -Rf $(@:.html=.htp) $@; fi; \
+ exit 1; \
+ fi
+$(srcdir)/flex.info: flex.texi $(srcdir)/version.texi
+flex.dvi: flex.texi $(srcdir)/version.texi
+flex.pdf: flex.texi $(srcdir)/version.texi
+flex.html: flex.texi $(srcdir)/version.texi
+$(srcdir)/version.texi: $(srcdir)/stamp-vti
+$(srcdir)/stamp-vti: flex.texi $(top_srcdir)/configure
@(dir=.; test -f ./flex.texi || dir=$(srcdir); \
set `$(SHELL) $(srcdir)/mdate-sh $$dir/flex.texi`; \
echo "@set UPDATED $$1 $$2 $$3"; \
echo "@set UPDATED-MONTH $$2 $$3"; \
echo "@set EDITION $(VERSION)"; \
echo "@set VERSION $(VERSION)") > vti.tmp
- @cmp -s vti.tmp version.texi \
- || (echo "Updating version.texi"; \
- cp vti.tmp version.texi)
+ @cmp -s vti.tmp $(srcdir)/version.texi \
+ || (echo "Updating $(srcdir)/version.texi"; \
+ cp vti.tmp $(srcdir)/version.texi)
-@rm -f vti.tmp
- @cp version.texi $@
+ @cp $(srcdir)/version.texi $@
mostlyclean-vti:
-rm -f vti.tmp
maintainer-clean-vti:
- -rm -f stamp-vti version.texi
-TEXI2DVI = texi2dvi
-
-TEXI2PDF = $(TEXI2DVI) --pdf --batch
-DVIPS = dvips
+ -rm -f $(srcdir)/stamp-vti $(srcdir)/version.texi
.dvi.ps:
+ TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
$(DVIPS) -o $@ $<
uninstall-info-am:
- $(PRE_UNINSTALL)
+ @$(PRE_UNINSTALL)
@if (install-info --version && \
- install-info --version | grep -i -v debian) >/dev/null 2>&1; then \
+ install-info --version 2>&1 | sed 1q | grep -i -v debian) >/dev/null 2>&1; then \
list='$(INFO_DEPS)'; \
for file in $$list; do \
relfile=`echo "$$file" | sed 's|^.*/||'`; \
- echo " install-info --info-dir=$(DESTDIR)$(infodir) --remove $(DESTDIR)$(infodir)/$$relfile"; \
- install-info --info-dir=$(DESTDIR)$(infodir) --remove $(DESTDIR)$(infodir)/$$relfile; \
+ echo " install-info --info-dir='$(DESTDIR)$(infodir)' --remove '$(DESTDIR)$(infodir)/$$relfile'"; \
+ install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$$relfile"; \
done; \
else :; fi
@$(NORMAL_UNINSTALL)
@@ -244,15 +308,19 @@ uninstall-info-am:
for file in $$list; do \
relfile=`echo "$$file" | sed 's|^.*/||'`; \
relfile_i=`echo "$$relfile" | sed 's|\.info$$||;s|$$|.i|'`; \
- (if cd $(DESTDIR)$(infodir); then \
- echo " rm -f $$relfile $$relfile-[0-9] $$relfile-[0-9][0-9] $$relfile_i[0-9] $$relfile_i[0-9][0-9])"; \
+ (if cd "$(DESTDIR)$(infodir)"; then \
+ echo " cd '$(DESTDIR)$(infodir)' && rm -f $$relfile $$relfile-[0-9] $$relfile-[0-9][0-9] $$relfile_i[0-9] $$relfile_i[0-9][0-9]"; \
rm -f $$relfile $$relfile-[0-9] $$relfile-[0-9][0-9] $$relfile_i[0-9] $$relfile_i[0-9][0-9]; \
else :; fi); \
done
dist-info: $(INFO_DEPS)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
list='$(INFO_DEPS)'; \
for base in $$list; do \
+ case $$base in \
+ $(srcdir)/*) base=`echo "$$base" | sed "s|^$$srcdirstrip/||"`;; \
+ esac; \
if test -f $$base; then d=.; else d=$(srcdir); fi; \
for file in $$d/$$base*; do \
relfile=`expr "$$file" : "$$d/\(.*\)"`; \
@@ -262,10 +330,10 @@ dist-info: $(INFO_DEPS)
done
mostlyclean-aminfo:
- -rm -f flex.aux flex.cp flex.cps flex.fn flex.fns flex.hk flex.hks flex.ky \
+ -rm -rf flex.aux flex.cp flex.cps flex.fn flex.fns flex.hk flex.hks flex.ky \
flex.kys flex.log flex.op flex.ops flex.pg flex.pgs flex.tmp \
flex.toc flex.tp flex.tps flex.vr flex.vrs flex.dvi flex.pdf \
- flex.ps
+ flex.ps flex.html
maintainer-clean-aminfo:
@list='$(INFO_DEPS)'; for i in $$list; do \
@@ -273,11 +341,9 @@ maintainer-clean-aminfo:
echo " rm -f $$i $$i-[0-9] $$i-[0-9][0-9] $$i_i[0-9] $$i_i[0-9][0-9]"; \
rm -f $$i $$i-[0-9] $$i-[0-9][0-9] $$i_i[0-9] $$i_i[0-9][0-9]; \
done
-
-man1dir = $(mandir)/man1
install-man1: $(man1_MANS) $(man_MANS)
@$(NORMAL_INSTALL)
- $(mkinstalldirs) $(DESTDIR)$(man1dir)
+ test -z "$(man1dir)" || $(mkdir_p) "$(DESTDIR)$(man1dir)"
@list='$(man1_MANS) $(dist_man1_MANS) $(nodist_man1_MANS)'; \
l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \
for i in $$l2; do \
@@ -296,8 +362,8 @@ install-man1: $(man1_MANS) $(man_MANS)
inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \
inst=`echo $$inst | sed -e 's/^.*\///'`; \
inst=`echo $$inst | sed '$(transform)'`.$$ext; \
- echo " $(INSTALL_DATA) $$file $(DESTDIR)$(man1dir)/$$inst"; \
- $(INSTALL_DATA) $$file $(DESTDIR)$(man1dir)/$$inst; \
+ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \
+ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst"; \
done
uninstall-man1:
@$(NORMAL_UNINSTALL)
@@ -317,8 +383,8 @@ uninstall-man1:
inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \
inst=`echo $$inst | sed -e 's/^.*\///'`; \
inst=`echo $$inst | sed '$(transform)'`.$$ext; \
- echo " rm -f $(DESTDIR)$(man1dir)/$$inst"; \
- rm -f $(DESTDIR)$(man1dir)/$$inst; \
+ echo " rm -f '$(DESTDIR)$(man1dir)/$$inst'"; \
+ rm -f "$(DESTDIR)$(man1dir)/$$inst"; \
done
tags: TAGS
TAGS:
@@ -326,10 +392,6 @@ TAGS:
ctags: CTAGS
CTAGS:
-DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-
-top_distdir = ..
-distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
@@ -343,7 +405,7 @@ distdir: $(DISTFILES)
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
- $(mkinstalldirs) "$(distdir)$$dir"; \
+ $(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
@@ -364,9 +426,10 @@ distdir: $(DISTFILES)
check-am: all-am
check: check-am
all-am: Makefile $(INFO_DEPS) $(MANS)
-
installdirs:
- $(mkinstalldirs) $(DESTDIR)$(infodir) $(DESTDIR)$(man1dir)
+ for dir in "$(DESTDIR)$(infodir)" "$(DESTDIR)$(man1dir)"; do \
+ test -z "$$dir" || $(mkdir_p) "$$dir"; \
+ done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
@@ -378,7 +441,7 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
- INSTALL_STRIP_FLAG=-s \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
@@ -387,24 +450,27 @@ clean-generic:
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
- -rm -f Makefile $(CONFIG_CLEAN_FILES)
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
- -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
clean: clean-am
clean-am: clean-generic mostlyclean-am
distclean: distclean-am
-
+ -rm -f Makefile
distclean-am: clean-am distclean-generic
dvi: dvi-am
dvi-am: $(DVIS)
+html: html-am
+
+html-am: $(HTMLS)
+
info: info-am
info-am: $(INFO_DEPS)
@@ -417,28 +483,32 @@ install-info: install-info-am
install-info-am: $(INFO_DEPS)
@$(NORMAL_INSTALL)
- $(mkinstalldirs) $(DESTDIR)$(infodir)
- @list='$(INFO_DEPS)'; \
+ test -z "$(infodir)" || $(mkdir_p) "$(DESTDIR)$(infodir)"
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+ list='$(INFO_DEPS)'; \
for file in $$list; do \
+ case $$file in \
+ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+ esac; \
if test -f $$file; then d=.; else d=$(srcdir); fi; \
file_i=`echo "$$file" | sed 's|\.info$$||;s|$$|.i|'`; \
for ifile in $$d/$$file $$d/$$file-[0-9] $$d/$$file-[0-9][0-9] \
$$d/$$file_i[0-9] $$d/$$file_i[0-9][0-9] ; do \
if test -f $$ifile; then \
relfile=`echo "$$ifile" | sed 's|^.*/||'`; \
- echo " $(INSTALL_DATA) $$ifile $(DESTDIR)$(infodir)/$$relfile"; \
- $(INSTALL_DATA) $$ifile $(DESTDIR)$(infodir)/$$relfile; \
+ echo " $(INSTALL_DATA) '$$ifile' '$(DESTDIR)$(infodir)/$$relfile'"; \
+ $(INSTALL_DATA) "$$ifile" "$(DESTDIR)$(infodir)/$$relfile"; \
else : ; fi; \
done; \
done
@$(POST_INSTALL)
@if (install-info --version && \
- install-info --version | grep -i -v debian) >/dev/null 2>&1; then \
+ install-info --version 2>&1 | sed 1q | grep -i -v debian) >/dev/null 2>&1; then \
list='$(INFO_DEPS)'; \
for file in $$list; do \
relfile=`echo "$$file" | sed 's|^.*/||'`; \
- echo " install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$relfile";\
- install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$relfile || :;\
+ echo " install-info --info-dir='$(DESTDIR)$(infodir)' '$(DESTDIR)$(infodir)/$$relfile'";\
+ install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$$relfile" || :;\
done; \
else : ; fi
install-man: install-man1
@@ -446,7 +516,7 @@ install-man: install-man1
installcheck-am:
maintainer-clean: maintainer-clean-am
-
+ -rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-aminfo \
maintainer-clean-generic maintainer-clean-vti
@@ -467,20 +537,23 @@ uninstall-am: uninstall-info-am uninstall-man
uninstall-man: uninstall-man1
.PHONY: all all-am check check-am clean clean-generic dist-info \
- distclean distclean-generic distdir dvi dvi-am info info-am \
- install install-am install-data install-data-am install-exec \
- install-exec-am install-info install-info-am install-man \
- install-man1 install-strip installcheck installcheck-am \
- installdirs maintainer-clean maintainer-clean-aminfo \
- maintainer-clean-generic maintainer-clean-vti mostlyclean \
- mostlyclean-aminfo mostlyclean-generic mostlyclean-vti pdf \
- pdf-am ps ps-am uninstall uninstall-am uninstall-info-am \
- uninstall-man uninstall-man1
-
-
-$(man_MANS): $(top_srcdir)/main.c
- for i in $(man_MANS) ; do \
- $(help2man) --name='fast lexical analyzer generator' --section=`echo $$i|rev|cut -f 1 -d .|rev` ../flex > $$i ; \
+ distclean distclean-generic distdir dvi dvi-am html html-am \
+ info info-am install install-am install-data install-data-am \
+ install-exec install-exec-am install-info install-info-am \
+ install-man install-man1 install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-aminfo maintainer-clean-generic \
+ maintainer-clean-vti mostlyclean mostlyclean-aminfo \
+ mostlyclean-generic mostlyclean-vti pdf pdf-am ps ps-am \
+ uninstall uninstall-am uninstall-info-am uninstall-man \
+ uninstall-man1
+
+
+$(dist_man_MANS): $(top_srcdir)/main.c
+ for i in $(dist_man_MANS) ; do \
+ $(help2man) --name='$(PACKAGE_NAME)' \
+ --section=`echo $$i | sed -e 's/.*\.\([^.]*\)$$/\1/'` \
+ ../flex$(EXEEXT) > $$i || rm -f $$i ; \
done
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
diff --git a/doc/flex.1 b/doc/flex.1
index 5218e17..8c3db79 100644
--- a/doc/flex.1
+++ b/doc/flex.1
@@ -1,12 +1,12 @@
-.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.29.
-.TH FLEX "1" "February 2006" "flex 2.5.33" "User Commands"
+.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36.
+.TH FLEX "1" "December 2007" "flex 2.5.34" "User Commands"
.SH NAME
-flex \- fast lexical analyzer generator
+flex \- the fast lexical analyser generator
.SH SYNOPSIS
.B flex
[\fIOPTIONS\fR] [\fIFILE\fR]...
.SH DESCRIPTION
-Generates programs that perform pattern-matching on text.
+Generates programs that perform pattern\-matching on text.
.SS "Table Compression:"
.TP
\fB\-Ca\fR, \fB\-\-align\fR
@@ -22,7 +22,7 @@ do not compress tables; use \fB\-f\fR representation
do not compress tables; use \fB\-F\fR representation
.TP
\fB\-Cm\fR, \fB\-\-meta\-ecs\fR
-construct meta-equivalence classes
+construct meta\-equivalence classes
.TP
\fB\-Cr\fR, \fB\-\-read\fR
use read() instead of stdio for scanner input
@@ -41,7 +41,7 @@ default compression (same as \fB\-\-ecs\fR \fB\-\-meta\-ecs\fR)
enable debug mode in scanner
.TP
\fB\-b\fR, \fB\-\-backup\fR
-write backing-up information to lex.backup
+write backing\-up information to lex.backup
.TP
\fB\-p\fR, \fB\-\-perf\-report\fR
write performance report to stderr
@@ -78,10 +78,10 @@ create a C header file in addition to the scanner
.SS "Scanner behavior:"
.TP
\fB\-7\fR, \fB\-\-7bit\fR
-generate 7-bit scanner
+generate 7\-bit scanner
.TP
\fB\-8\fR, \fB\-\-8bit\fR
-generate 8-bit scanner
+generate 8\-bit scanner
.TP
\fB\-B\fR, \fB\-\-batch\fR
generate batch scanner (opposite of \fB\-I\fR)
@@ -102,7 +102,7 @@ generate interactive scanner (opposite of \fB\-B\fR)
track line count in yylineno
.SS "Generated code:"
.TP
--+, \fB\-\-c\fR++
+\-+, \fB\-\-c\fR++
generate C++ scanner class
.TP
\fB\-Dmacro\fR[=\fIdefn\fR]
@@ -126,7 +126,7 @@ include yylloc support.
\fB\-\-stdinit\fR
initialize yyin/yyout to stdin/stdout
.HP
-\fB\-\-noansi\-definitions\fR old-style function definitions
+\fB\-\-noansi\-definitions\fR old\-style function definitions
.TP
\fB\-\-noansi\-prototypes\fR
empty parameter list in prototypes
@@ -139,12 +139,12 @@ do not generate a particular FUNCTION
.SS "Miscellaneous:"
.TP
\fB\-c\fR
-do-nothing POSIX option
+do\-nothing POSIX option
.TP
\fB\-n\fR
-do-nothing POSIX option
+do\-nothing POSIX option
.HP
--?
+\-?
.TP
\fB\-h\fR, \fB\-\-help\fR
produce this help message
diff --git a/doc/flex.info b/doc/flex.info
index d32eadc..fddd792 100644
--- a/doc/flex.info
+++ b/doc/flex.info
@@ -1,14 +1,16 @@
-This is flex.info, produced by makeinfo version 4.5 from flex.texi.
+This is flex.info, produced by makeinfo version 4.8 from flex.texi.
INFO-DIR-SECTION Programming
START-INFO-DIR-ENTRY
* flex: (flex). Fast lexical analyzer generator (lex replacement).
END-INFO-DIR-ENTRY
-
The flex manual is placed under the same licensing conditions as the
rest of flex:
+ Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 The Flex
+Project.
+
Copyright (C) 1990, 1997 The Regents of the University of California.
All rights reserved.
@@ -30,6 +32,7 @@ met:
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.
+
Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
@@ -37,241 +40,243 @@ without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+

Indirect:
-flex.info-1: 1542
-flex.info-2: 44385
-flex.info-3: 94974
-flex.info-4: 144097
-flex.info-5: 193935
-flex.info-6: 243586
-flex.info-7: 281964
+flex.info-1: 1620
+flex.info-2: 287921

Tag Table:
(Indirect)
-Node: Top1542
-Node: Copyright7508
-Node: Reporting Bugs8942
-Node: Introduction9238
-Node: Simple Examples10065
-Node: Format13454
-Node: Definitions Section13867
-Ref: Definitions Section-Footnote-116125
-Node: Rules Section16193
-Node: User Code Section17346
-Node: Comments in the Input17779
-Node: Patterns19148
-Ref: case and character ranges24406
-Node: Matching27081
-Node: Actions30366
-Node: Generated Scanner39368
-Node: Start Conditions44385
-Node: Multiple Input Buffers55097
-Ref: Scanning Strings61715
-Node: EOF63331
-Node: Misc Macros64926
-Node: User Values67778
-Node: Yacc70106
-Node: Scanner Options71009
-Node: Options for Specifing Filenames73769
-Ref: option-header73982
-Ref: option-outfile74694
-Ref: option-stdout75019
-Node: Options Affecting Scanner Behavior76001
-Ref: option-case-insensitive76231
-Ref: option-lex-compat76664
-Ref: option-batch77196
-Ref: option-interactive77720
-Ref: option-7bit79074
-Ref: option-8bit80378
-Ref: option-default80790
-Ref: option-always-interactive80854
-Ref: option-posix81458
-Ref: option-stack82605
-Ref: option-stdinit82713
-Ref: option-yylineno83191
-Ref: option-yywrap83634
-Node: Code-Level And API Options83902
-Ref: option-ansi-definitions84119
-Ref: option-ansi-prototypes84371
-Ref: option-bison-bridge84618
-Ref: option-bison-locations84957
-Ref: option-noline85217
-Ref: option-reentrant85731
-Ref: option-c++86342
-Ref: option-array86468
-Ref: option-pointer86566
-Ref: option-prefix86694
-Ref: option-main88223
-Ref: option-nounistd88407
-Ref: option-yyclass88915
-Node: Options for Scanner Speed and Size89395
-Ref: option-align89934
-Ref: option-ecs90435
-Ref: option-meta-ecs91471
-Ref: option-read91958
-Ref: option-full93841
-Ref: option-fast94036
-Node: Debugging Options94974
-Ref: option-backup95151
-Ref: option-debug95696
-Ref: option-perf-report96419
-Ref: option-nodefault97045
-Ref: option-trace97363
-Ref: option-nowarn97654
-Ref: option-verbose97722
-Ref: option-warn98151
-Node: Miscellaneous Options98370
-Node: Performance98844
-Node: Cxx109181
-Node: Reentrant116780
-Node: Reentrant Uses117454
-Node: Reentrant Overview119055
-Node: Reentrant Example119847
-Node: Reentrant Detail120604
-Node: Specify Reentrant121030
-Node: Extra Reentrant Argument121666
-Node: Global Replacement122907
-Node: Init and Destroy Functions124125
-Node: Accessor Methods126278
-Node: Extra Data127611
-Node: About yyscan_t129782
-Node: Reentrant Functions130167
-Ref: bison-functions131649
-Node: Lex and Posix132390
-Node: Memory Management139771
-Ref: memory-management139911
-Node: The Default Memory Management140142
-Ref: The Default Memory Management-Footnote-1143944
-Node: Overriding The Default Memory Management144097
-Ref: Overriding The Default Memory Management-Footnote-1146535
-Node: A Note About yytext And Memory146699
-Node: Serialized Tables147925
-Ref: serialization148063
-Node: Creating Serialized Tables148831
-Node: Loading and Unloading Serialized Tables150434
-Node: Tables File Format152193
-Node: Diagnostics159202
-Node: Limitations162610
-Node: Bibliography164555
-Node: FAQ165225
-Node: When was flex born?169457
-Node: How do I expand \ escape sequences in C-style quoted strings?169829
-Node: Why do flex scanners call fileno if it is not ANSI compatible?171112
-Node: Does flex support recursive pattern definitions?171902
-Node: How do I skip huge chunks of input (tens of megabytes) while using flex?172752
-Node: Flex is not matching my patterns in the same order that I defined them.173222
-Node: My actions are executing out of order or sometimes not at all.174971
-Node: How can I have multiple input sources feed into the same scanner at the same time?175759
-Node: Can I build nested parsers that work with the same input file?177750
-Node: How can I match text only at the end of a file?178759
-Node: How can I make REJECT cascade across start condition boundaries?179567
-Node: Why cant I use fast or full tables with interactive mode?180586
-Node: How much faster is -F or -f than -C?181848
-Node: If I have a simple grammar cant I just parse it with flex?182163
-Node: Why doesnt yyrestart() set the start state back to INITIAL?182646
-Node: How can I match C-style comments?183275
-Node: The period isnt working the way I expected.184090
-Node: Can I get the flex manual in another format?185339
-Node: Does there exist a "faster" NDFA->DFA algorithm?185830
-Node: How does flex compile the DFA so quickly?186342
-Node: How can I use more than 8192 rules?187312
-Node: How do I abandon a file in the middle of a scan and switch to a new file?188726
-Node: How do I execute code only during initialization (only before the first scan)?189282
-Node: How do I execute code at termination?190044
-Node: Where else can I find help?190373
-Node: Can I include comments in the "rules" section of the file?190749
-Node: I get an error about undefined yywrap().191131
-Node: How can I change the matching pattern at run time?191611
-Node: How can I expand macros in the input?191976
-Node: How can I build a two-pass scanner?193017
-Node: How do I match any string not matched in the preceding rules?193935
-Node: I am trying to port code from AT&T lex that uses yysptr and yysbuf.194848
-Node: Is there a way to make flex treat NULL like a regular character?195646
-Node: Whenever flex can not match the input it says "flex scanner jammed".196170
-Node: Why doesnt flex have non-greedy operators like perl does?196821
-Node: Memory leak - 16386 bytes allocated by malloc.198176
-Ref: faq-memory-leak198473
-Node: How do I track the byte offset for lseek()?199444
-Node: How do I use my own I/O classes in a C++ scanner?200955
-Node: How do I skip as many chars as possible?201801
-Node: deleteme00202881
-Node: Are certain equivalent patterns faster than others?203327
-Node: Is backing up a big deal?206816
-Node: Can I fake multi-byte character support?208788
-Node: deleteme01210265
-Node: Can you discuss some flex internals?211390
-Node: unput() messes up yy_at_bol213680
-Node: The | operator is not doing what I want214818
-Node: Why can't flex understand this variable trailing context pattern?216410
-Node: The ^ operator isn't working217675
-Node: Trailing context is getting confused with trailing optional patterns218946
-Node: Is flex GNU or not?220215
-Node: ERASEME53221929
-Node: I need to scan if-then-else blocks and while loops222725
-Node: ERASEME55223945
-Node: ERASEME56225059
-Node: ERASEME57226453
-Node: Is there a repository for flex scanners?227487
-Node: How can I conditionally compile or preprocess my flex input file?227805
-Node: Where can I find grammars for lex and yacc?228281
-Node: I get an end-of-buffer message for each character scanned.228631
-Node: unnamed-faq-62229229
-Node: unnamed-faq-63230278
-Node: unnamed-faq-64231591
-Node: unnamed-faq-65232593
-Node: unnamed-faq-66233395
-Node: unnamed-faq-67234526
-Node: unnamed-faq-68235529
-Node: unnamed-faq-69236687
-Node: unnamed-faq-70237421
-Node: unnamed-faq-71238198
-Node: unnamed-faq-72239428
-Node: unnamed-faq-73240497
-Node: unnamed-faq-74241442
-Node: unnamed-faq-75242413
-Node: unnamed-faq-76243586
-Node: unnamed-faq-77244308
-Node: unnamed-faq-78245217
-Node: unnamed-faq-79246231
-Node: unnamed-faq-80247967
-Node: unnamed-faq-81249311
-Node: unnamed-faq-82252152
-Node: unnamed-faq-83253135
-Node: unnamed-faq-84254941
-Node: unnamed-faq-85256060
-Node: unnamed-faq-86257108
-Node: unnamed-faq-87258082
-Node: unnamed-faq-88258744
-Node: unnamed-faq-90259601
-Node: unnamed-faq-91260900
-Node: unnamed-faq-92263384
-Node: unnamed-faq-93263899
-Node: unnamed-faq-94264842
-Node: unnamed-faq-95266285
-Node: unnamed-faq-96267819
-Node: unnamed-faq-97268604
-Node: unnamed-faq-98269287
-Node: unnamed-faq-99269978
-Node: unnamed-faq-100270938
-Node: unnamed-faq-101271664
-Node: What is the difference between YYLEX_PARAM and YY_DECL?272498
-Node: Why do I get "conflicting types for yylex" error?273023
-Node: How do I access the values set in a Flex action from within a Bison action?273556
-Node: Appendices273990
-Node: Makefiles and Flex274157
-Ref: Makefiles and Flex-Footnote-1277374
-Ref: Makefiles and Flex-Footnote-2277491
-Node: Bison Bridge277542
-Ref: Bison Bridge-Footnote-1280216
-Node: M4 Dependency280408
-Ref: M4 Dependency-Footnote-1281591
-Node: Indices281726
-Node: Concept Index281964
-Node: Index of Functions and Macros298838
-Node: Index of Variables302057
-Node: Index of Data Types303284
-Node: Index of Hooks303888
-Node: Index of Scanner Options304390
+Node: Top1620
+Node: Copyright7690
+Node: Reporting Bugs9203
+Node: Introduction9508
+Node: Simple Examples10336
+Node: Format13646
+Node: Definitions Section14060
+Ref: Definitions Section-Footnote-116323
+Node: Rules Section16391
+Node: User Code Section17549
+Node: Comments in the Input17987
+Node: Patterns19355
+Ref: case and character ranges26186
+Node: Matching30201
+Node: Actions33487
+Node: Generated Scanner42466
+Node: Start Conditions47484
+Node: Multiple Input Buffers58043
+Ref: Scanning Strings64581
+Node: EOF66211
+Node: Misc Macros67799
+Node: User Values70653
+Node: Yacc72984
+Node: Scanner Options73880
+Node: Options for Specifying Filenames76638
+Ref: option-header76864
+Ref: option-outfile77576
+Ref: option-stdout77901
+Node: Options Affecting Scanner Behavior78883
+Ref: option-case-insensitive79124
+Ref: option-lex-compat79557
+Ref: option-batch80089
+Ref: option-interactive80613
+Ref: option-7bit81967
+Ref: option-8bit83271
+Ref: option-default83683
+Ref: option-always-interactive83747
+Ref: option-posix84351
+Ref: option-stack85498
+Ref: option-stdinit85606
+Ref: option-yylineno86084
+Ref: option-yywrap86527
+Node: Code-Level And API Options86795
+Ref: option-ansi-definitions87022
+Ref: option-ansi-prototypes87274
+Ref: option-bison-bridge87521
+Ref: option-bison-locations87860
+Ref: option-noline88120
+Ref: option-reentrant88634
+Ref: option-c++89245
+Ref: option-array89371
+Ref: option-pointer89469
+Ref: option-prefix89597
+Ref: option-main91126
+Ref: option-nounistd91310
+Ref: option-yyclass91818
+Node: Options for Scanner Speed and Size92304
+Ref: option-align92853
+Ref: option-ecs93354
+Ref: option-meta-ecs94390
+Ref: option-read94877
+Ref: option-full96760
+Ref: option-fast96955
+Node: Debugging Options97881
+Ref: option-backup98068
+Ref: option-debug98613
+Ref: option-perf-report99336
+Ref: option-nodefault99962
+Ref: option-trace100280
+Ref: option-nowarn100571
+Ref: option-verbose100639
+Ref: option-warn101068
+Node: Miscellaneous Options101287
+Node: Performance101744
+Node: Cxx112008
+Node: Reentrant119531
+Node: Reentrant Uses120208
+Node: Reentrant Overview121771
+Node: Reentrant Example122570
+Node: Reentrant Detail123345
+Node: Specify Reentrant123778
+Node: Extra Reentrant Argument124425
+Node: Global Replacement125677
+Node: Init and Destroy Functions126906
+Node: Accessor Methods129418
+Node: Extra Data130762
+Node: About yyscan_t133029
+Node: Reentrant Functions133425
+Ref: bison-functions134909
+Node: Lex and Posix135650
+Node: Memory Management143034
+Ref: memory-management143180
+Node: The Default Memory Management143408
+Ref: The Default Memory Management-Footnote-1147217
+Node: Overriding The Default Memory Management147370
+Ref: Overriding The Default Memory Management-Footnote-1149769
+Node: A Note About yytext And Memory149933
+Node: Serialized Tables151166
+Ref: serialization151310
+Node: Creating Serialized Tables152075
+Node: Loading and Unloading Serialized Tables153685
+Node: Tables File Format155453
+Node: Diagnostics162468
+Node: Limitations165879
+Node: Bibliography167828
+Node: FAQ168501
+Node: When was flex born?172741
+Node: How do I expand backslash-escape sequences in C-style quoted strings?173118
+Node: Why do flex scanners call fileno if it is not ANSI compatible?174422
+Node: Does flex support recursive pattern definitions?175217
+Node: How do I skip huge chunks of input (tens of megabytes) while using flex?176064
+Node: Flex is not matching my patterns in the same order that I defined them.176531
+Node: My actions are executing out of order or sometimes not at all.178277
+Node: How can I have multiple input sources feed into the same scanner at the same time?179052
+Node: Can I build nested parsers that work with the same input file?181040
+Node: How can I match text only at the end of a file?182046
+Node: How can I make REJECT cascade across start condition boundaries?182851
+Node: Why cant I use fast or full tables with interactive mode?183866
+Node: How much faster is -F or -f than -C?185124
+Node: If I have a simple grammar cant I just parse it with flex?185436
+Node: Why doesn't yyrestart() set the start state back to INITIAL?185917
+Node: How can I match C-style comments?186544
+Node: The period isn't working the way I expected.187358
+Node: Can I get the flex manual in another format?188605
+Node: Does there exist a "faster" NDFA->DFA algorithm?189094
+Node: How does flex compile the DFA so quickly?189604
+Node: How can I use more than 8192 rules?190571
+Node: How do I abandon a file in the middle of a scan and switch to a new file?191983
+Node: How do I execute code only during initialization (only before the first scan)?192536
+Node: How do I execute code at termination?193314
+Node: Where else can I find help?193640
+Node: Can I include comments in the "rules" section of the file?194013
+Node: I get an error about undefined yywrap().194392
+Node: How can I change the matching pattern at run time?194869
+Node: How can I expand macros in the input?195231
+Node: How can I build a two-pass scanner?196264
+Node: How do I match any string not matched in the preceding rules?197180
+Node: I am trying to port code from AT&T lex that uses yysptr and yysbuf.198090
+Node: Is there a way to make flex treat NULL like a regular character?198885
+Node: Whenever flex can not match the input it says "flex scanner jammed".199406
+Node: Why doesn't flex have non-greedy operators like perl does?200050
+Node: Memory leak - 16386 bytes allocated by malloc.201403
+Ref: faq-memory-leak201701
+Node: How do I track the byte offset for lseek()?202669
+Node: How do I use my own I/O classes in a C++ scanner?204180
+Node: How do I skip as many chars as possible?205023
+Node: deleteme00206100
+Node: Are certain equivalent patterns faster than others?206541
+Node: Is backing up a big deal?209960
+Node: Can I fake multi-byte character support?211867
+Node: deleteme01213309
+Node: Can you discuss some flex internals?214419
+Node: unput() messes up yy_at_bol216664
+Node: The | operator is not doing what I want217767
+Node: Why can't flex understand this variable trailing context pattern?219314
+Node: The ^ operator isn't working220564
+Node: Trailing context is getting confused with trailing optional patterns221800
+Node: Is flex GNU or not?223044
+Node: ERASEME53224718
+Node: I need to scan if-then-else blocks and while loops225489
+Node: ERASEME55226689
+Node: ERASEME56227788
+Node: ERASEME57229147
+Node: Is there a repository for flex scanners?230146
+Node: How can I conditionally compile or preprocess my flex input file?230461
+Node: Where can I find grammars for lex and yacc?230934
+Node: I get an end-of-buffer message for each character scanned.231281
+Node: unnamed-faq-62231876
+Node: unnamed-faq-63232895
+Node: unnamed-faq-64234193
+Node: unnamed-faq-65235160
+Node: unnamed-faq-66235947
+Node: unnamed-faq-67237063
+Node: unnamed-faq-68238051
+Node: unnamed-faq-69239194
+Node: unnamed-faq-70239908
+Node: unnamed-faq-71240670
+Node: unnamed-faq-72241880
+Node: unnamed-faq-73242924
+Node: unnamed-faq-74243849
+Node: unnamed-faq-75244795
+Node: unnamed-faq-76245928
+Node: unnamed-faq-77246635
+Node: unnamed-faq-78247529
+Node: unnamed-faq-79248528
+Node: unnamed-faq-80250229
+Node: unnamed-faq-81251548
+Node: unnamed-faq-82254349
+Node: unnamed-faq-83255307
+Node: unnamed-faq-84257088
+Node: unnamed-faq-85258192
+Node: unnamed-faq-86259200
+Node: unnamed-faq-87260139
+Node: unnamed-faq-88260786
+Node: unnamed-faq-90261618
+Node: unnamed-faq-91262882
+Node: unnamed-faq-92265311
+Node: unnamed-faq-93265811
+Node: unnamed-faq-94266739
+Node: unnamed-faq-95268152
+Node: unnamed-faq-96269671
+Node: unnamed-faq-97270431
+Node: unnamed-faq-98271099
+Node: unnamed-faq-99271765
+Node: unnamed-faq-100272695
+Node: unnamed-faq-101273406
+Node: What is the difference between YYLEX_PARAM and YY_DECL?274220
+Node: Why do I get "conflicting types for yylex" error?274742
+Node: How do I access the values set in a Flex action from within a Bison action?275272
+Node: Appendices275703
+Node: Makefiles and Flex275912
+Ref: Makefiles and Flex-Footnote-1279112
+Ref: Makefiles and Flex-Footnote-2279229
+Ref: Makefiles and Flex-Footnote-3279415
+Node: Bison Bridge279466
+Ref: Bison Bridge-Footnote-1282135
+Node: M4 Dependency282327
+Ref: M4 Dependency-Footnote-1283732
+Node: Common Patterns283867
+Node: Numbers284158
+Node: Identifiers285135
+Node: Quoted Constructs285964
+Node: Addresses287017
+Node: Indices287683
+Node: Concept Index287921
+Node: Index of Functions and Macros313204
+Node: Index of Variables318100
+Node: Index of Data Types319766
+Node: Index of Hooks320654
+Node: Index of Scanner Options321222

End Tag Table
diff --git a/doc/flex.info-1 b/doc/flex.info-1
index da0d581..2131353 100644
--- a/doc/flex.info-1
+++ b/doc/flex.info-1
@@ -1,14 +1,16 @@
-This is flex.info, produced by makeinfo version 4.5 from flex.texi.
+This is flex.info, produced by makeinfo version 4.8 from flex.texi.
INFO-DIR-SECTION Programming
START-INFO-DIR-ENTRY
* flex: (flex). Fast lexical analyzer generator (lex replacement).
END-INFO-DIR-ENTRY
-
The flex manual is placed under the same licensing conditions as the
rest of flex:
+ Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 The Flex
+Project.
+
Copyright (C) 1990, 1997 The Regents of the University of California.
All rights reserved.
@@ -30,6 +32,7 @@ met:
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.
+
Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
@@ -37,18 +40,21 @@ without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+

File: flex.info, Node: Top, Next: Copyright, Prev: (dir), Up: (dir)
flex
****
- This manual describes `flex', a tool for generating programs that
+This manual describes `flex', a tool for generating programs that
perform pattern-matching on text. The manual includes both tutorial and
reference sections.
- This edition of `The flex Manual' documents `flex' version 2.5.33.
-It was last updated on 20 February 2006.
+ This edition of `The flex Manual' documents `flex' version 2.5.34.
+It was last updated on 10 September 2007.
+
+ This manual was written by Vern Paxson, Will Estes and John Millaway.
* Menu:
@@ -92,7 +98,7 @@ Format of the Input File
Scanner Options
-* Options for Specifing Filenames::
+* Options for Specifying Filenames::
* Options Affecting Scanner Behavior::
* Code-Level And API Options::
* Options for Scanner Speed and Size::
@@ -132,7 +138,7 @@ Serialized Tables
FAQ
* When was flex born?::
-* How do I expand \ escape sequences in C-style quoted strings?::
+* How do I expand backslash-escape sequences in C-style quoted strings?::
* Why do flex scanners call fileno if it is not ANSI compatible?::
* Does flex support recursive pattern definitions?::
* How do I skip huge chunks of input (tens of megabytes) while using flex?::
@@ -145,9 +151,9 @@ FAQ
* Why cant I use fast or full tables with interactive mode?::
* How much faster is -F or -f than -C?::
* If I have a simple grammar cant I just parse it with flex?::
-* Why doesnt yyrestart() set the start state back to INITIAL?::
+* Why doesn't yyrestart() set the start state back to INITIAL?::
* How can I match C-style comments?::
-* The period isnt working the way I expected.::
+* The period isn't working the way I expected.::
* Can I get the flex manual in another format?::
* Does there exist a "faster" NDFA->DFA algorithm?::
* How does flex compile the DFA so quickly?::
@@ -165,7 +171,7 @@ FAQ
* I am trying to port code from AT&T lex that uses yysptr and yysbuf.::
* Is there a way to make flex treat NULL like a regular character?::
* Whenever flex can not match the input it says "flex scanner jammed".::
-* Why doesnt flex have non-greedy operators like perl does?::
+* Why doesn't flex have non-greedy operators like perl does?::
* Memory leak - 16386 bytes allocated by malloc.::
* How do I track the byte offset for lseek()?::
* How do I use my own I/O classes in a C++ scanner?::
@@ -239,6 +245,7 @@ Appendices
* Makefiles and Flex::
* Bison Bridge::
* M4 Dependency::
+* Common Patterns::
Indices
@@ -252,13 +259,15 @@ Indices

File: flex.info, Node: Copyright, Next: Reporting Bugs, Prev: Top, Up: Top
-Copyright
-*********
-
+1 Copyright
+***********
- The flex manual is placed under the same licensing conditions as the
+The flex manual is placed under the same licensing conditions as the
rest of flex:
+ Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 The Flex
+Project.
+
Copyright (C) 1990, 1997 The Regents of the University of California.
All rights reserved.
@@ -280,6 +289,7 @@ met:
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.
+
Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
@@ -287,23 +297,24 @@ without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+

File: flex.info, Node: Reporting Bugs, Next: Introduction, Prev: Copyright, Up: Top
-Reporting Bugs
-**************
+2 Reporting Bugs
+****************
- If you have problems with `flex' or think you have found a bug,
-please send mail detailing your problem to
-<flex-help@lists.sourceforge.net>. Patches are always welcome.
+If you find a bug in `flex', please report it using the SourceForge Bug
+Tracking facilities which can be found on flex's SourceForge Page
+(http://sourceforge.net/projects/flex).

File: flex.info, Node: Introduction, Next: Simple Examples, Prev: Reporting Bugs, Up: Top
-Introduction
-************
+3 Introduction
+**************
- `flex' is a tool for generating "scanners". A scanner is a program
+`flex' is a tool for generating "scanners". A scanner is a program
which recognizes lexical patterns in text. The `flex' program reads
the given input files, or its standard input if no file names are
given, for a description of a scanner to generate. The description is
@@ -318,10 +329,10 @@ corresponding C code.

File: flex.info, Node: Simple Examples, Next: Format, Prev: Introduction, Up: Top
-Some Simple Examples
-********************
+4 Some Simple Examples
+**********************
- First some simple examples to get the flavor of how one uses `flex'.
+First some simple examples to get the flavor of how one uses `flex'.
The following `flex' input specifies a scanner which, when it
encounters the string `username' will replace it with the user's login
@@ -342,11 +353,11 @@ rules.
int num_lines = 0, num_chars = 0;
-
+
%%
\n ++num_lines; ++num_chars;
. ++num_chars;
-
+
%%
main()
{
@@ -368,43 +379,43 @@ other than a newline (indicated by the `.' regular expression).
/* scanner for a toy Pascal-like language */
-
+
%{
/* need this for the call to atof() below */
#include math.h>
%}
-
+
DIGIT [0-9]
ID [a-z][a-z0-9]*
-
+
%%
-
+
{DIGIT}+ {
printf( "An integer: %s (%d)\n", yytext,
atoi( yytext ) );
}
-
+
{DIGIT}+"."{DIGIT}* {
printf( "A float: %s (%g)\n", yytext,
atof( yytext ) );
}
-
+
if|then|begin|end|procedure|function {
printf( "A keyword: %s\n", yytext );
}
-
+
{ID} printf( "An identifier: %s\n", yytext );
-
+
"+"|"-"|"*"|"/" printf( "An operator: %s\n", yytext );
-
+
"{"[\^{}}\n]*"}" /* eat up one-line comments */
-
+
[ \t\n]+ /* eat up whitespace */
-
+
. printf( "Unrecognized character: %s\n", yytext );
-
+
%%
-
+
main( argc, argv )
int argc;
char **argv;
@@ -414,7 +425,7 @@ other than a newline (indicated by the `.' regular expression).
yyin = fopen( argv[0], "r" );
else
yyin = stdin;
-
+
yylex();
}
@@ -428,11 +439,11 @@ sections.

File: flex.info, Node: Format, Next: Patterns, Prev: Simple Examples, Up: Top
-Format of the Input File
-************************
+5 Format of the Input File
+**************************
- The `flex' input file consists of three sections, separated by a
-line containing only `%%'.
+The `flex' input file consists of three sections, separated by a line
+containing only `%%'.
definitions
@@ -451,10 +462,10 @@ line containing only `%%'.

File: flex.info, Node: Definitions Section, Next: Rules Section, Prev: Format, Up: Format
-Format of the Definitions Section
-=================================
+5.1 Format of the Definitions Section
+=====================================
- The "definitions section" contains declarations of simple "name"
+The "definitions section" contains declarations of simple "name"
definitions to simplify the scanner specification, and declarations of
"start conditions", which are explained in a later section.
@@ -519,11 +530,11 @@ included before the generated code. The single characters, `{' and

File: flex.info, Node: Rules Section, Next: User Code Section, Prev: Definitions Section, Up: Format
-Format of the Rules Section
-===========================
+5.2 Format of the Rules Section
+===============================
- The "rules" section of the `flex' input contains a series of rules
-of the form:
+The "rules" section of the `flex' input contains a series of rules of
+the form:
pattern action
@@ -548,21 +559,21 @@ and %} symbols must appear unindented on lines by themselves.

File: flex.info, Node: User Code Section, Next: Comments in the Input, Prev: Rules Section, Up: Format
-Format of the User Code Section
-===============================
+5.3 Format of the User Code Section
+===================================
- The user code section is simply copied to `lex.yy.c' verbatim. It
-is used for companion routines which call or are called by the scanner.
+The user code section is simply copied to `lex.yy.c' verbatim. It is
+used for companion routines which call or are called by the scanner.
The presence of this section is optional; if it is missing, the second
`%%' in the input file may be skipped, too.

File: flex.info, Node: Comments in the Input, Prev: User Code Section, Up: Format
-Comments in the Input
-=====================
+5.4 Comments in the Input
+=========================
- Flex supports C-style comments, that is, anything between /* and */
+Flex supports C-style comments, that is, anything between `/*' and `*/'
is considered a comment. Whenever flex encounters a comment, it copies
the entire comment verbatim to the generated source code. Comments may
appear just about anywhere, but with the following exceptions:
@@ -585,10 +596,10 @@ new line, with one or more whitespace characters before the initial
%{
/* code block */
%}
-
+
/* Definitions Section */
%x STATE_X
-
+
%%
/* Rules Section */
ruleA /* after regex */ { /* code block */ } /* after code block */
@@ -606,11 +617,11 @@ new line, with one or more whitespace characters before the initial

File: flex.info, Node: Patterns, Next: Matching, Prev: Format, Up: Top
-Patterns
-********
+6 Patterns
+**********
- The patterns in the input (see *Note Rules Section::) are written
-using an extended set of regular expressions. These are:
+The patterns in the input (see *Note Rules Section::) are written using
+an extended set of regular expressions. These are:
`x'
match the character 'x'
@@ -633,6 +644,9 @@ using an extended set of regular expressions. These are:
`[^A-Z\n]'
any character EXCEPT an uppercase letter or a newline
+`[a-z]{-}[aeiou]'
+ the lowercase consonants
+
`r*'
zero or more r's, where r is any regular expression
@@ -675,6 +689,43 @@ using an extended set of regular expressions. These are:
match an `r'; parentheses are used to override precedence (see
below)
+`(?r-s:pattern)'
+ apply option `r' and omit option `s' while interpreting pattern.
+ Options may be zero or more of the characters `i', `s', or `x'.
+
+ `i' means case-insensitive. `-i' means case-sensitive.
+
+ `s' alters the meaning of the `.' syntax to match any single byte
+ whatsoever. `-s' alters the meaning of `.' to match any byte
+ except `\n'.
+
+ `x' ignores comments and whitespace in patterns. Whitespace is
+ ignored unless it is backslash-escaped, contained within `""'s, or
+ appears inside a character class.
+
+ The following are all valid:
+
+
+ (?:foo) same as (foo)
+ (?i:ab7) same as ([aA][bB]7)
+ (?-i:ab) same as (ab)
+ (?s:.) same as [\x00-\xFF]
+ (?-s:.) same as [^\n]
+ (?ix-s: a . b) same as ([Aa][^\n][bB])
+ (?x:a b) same as ("ab")
+ (?x:a\ b) same as ("a b")
+ (?x:a" "b) same as ("a b")
+ (?x:a[ ]b) same as ("a b")
+ (?x:a
+ /* comment */
+ b
+ c) same as (abc)
+
+`(?# comment )'
+ omit everything within `()'. The first `)' character encountered
+ ends the pattern. It is not possible to for the comment to contain
+ a `)' character. The comment may span lines.
+
`rs'
the regular expression `r' followed by the regular expression `s';
called "concatenation"
@@ -780,7 +831,11 @@ any alphabetic or numeric character. Some systems don't provide
[[:alpha:][0-9]]
[a-zA-Z0-9]
- Some notes on patterns are in order.
+ A word of caution. Character classes are expanded immediately when
+seen in the `flex' input. This means the character classes are
+sensitive to the locale in which `flex' is executed, and the resulting
+scanner will not be sensitive to the runtime locale. This may or may
+not be desirable.
* If your scanner is case-insensitive (the `-i' flag), then
`[:upper:]' and `[:lower:]' are equivalent to `[:alpha:]'.
@@ -813,6 +868,34 @@ any alphabetic or numeric character. Some systems don't provide
can match the entire input unless there's another quote in the
input.
+ Flex allows negation of character class expressions by prepending
+ `^' to the POSIX character class name.
+
+
+ [:^alnum:] [:^alpha:] [:^blank:]
+ [:^cntrl:] [:^digit:] [:^graph:]
+ [:^lower:] [:^print:] [:^punct:]
+ [:^space:] [:^upper:] [:^xdigit:]
+
+ Flex will issue a warning if the expressions `[:^upper:]' and
+ `[:^lower:]' appear in a case-insensitive scanner, since their
+ meaning is unclear. The current behavior is to skip them entirely,
+ but this may change without notice in future revisions of flex.
+
+ * The `{-}' operator computes the difference of two character
+ classes. For example, `[a-c]{-}[b-z]' represents all the
+ characters in the class `[a-c]' that are not in the class `[b-z]'
+ (which in this case, is just the single character `a'). The `{-}'
+ operator is left associative, so `[abc]{-}[b]{-}[c]' is the same
+ as `[a]'. Be careful not to accidentally create an empty set,
+ which will never match.
+
+ * The `{+}' operator computes the union of two character classes.
+ For example, `[a-z]{+}[0-9]' is the same as `[a-z0-9]'. This
+ operator is useful when preceded by the result of a difference
+ operation, as in, `[[:alpha:]]{-}[[:lower:]]{+}[q]', which is
+ equivalent to `[A-Zq]' in the "C" locale.
+
* A rule can have at most one instance of trailing context (the `/'
operator or the `$' operator). The start condition, `^', and
`<<EOF>>' patterns can only occur at the beginning of a pattern,
@@ -850,10 +933,10 @@ any alphabetic or numeric character. Some systems don't provide

File: flex.info, Node: Matching, Next: Actions, Prev: Patterns, Up: Top
-How the Input Is Matched
-************************
+7 How the Input Is Matched
+**************************
- When the generated scanner is run, it analyzes its input looking for
+When the generated scanner is run, it analyzes its input looking for
strings which match any of its patterns. If it finds more than one
match, it takes the one matching the most text (for trailing context
rules, this includes the length of the trailing part, even though it
@@ -920,11 +1003,11 @@ too much text being pushed back; instead, a run-time error results.

File: flex.info, Node: Actions, Next: Generated Scanner, Prev: Matching, Up: Top
-Actions
-*******
+8 Actions
+*********
- Each pattern in a rule has a corresponding "action", which can be
-any arbitrary C statement. The pattern ends at the first non-escaped
+Each pattern in a rule has a corresponding "action", which can be any
+arbitrary C statement. The pattern ends at the first non-escaped
whitespace character; the remainder of the line is its action. If the
action is empty, then when the pattern is matched the input token is
simply discarded. For example, here is the specification for a program
@@ -945,7 +1028,7 @@ single blank, and throws away whitespace found at the end of a line:
[ \t]+ putchar( ' ' );
[ \t]+$ /* ignore this token */
- If the action contains a `}', then the action spans till the
+ If the action contains a `{', then the action spans till the
balancing `}' is found, and the action may cross multiple lines.
`flex' knows about C strings and comments and won't be fooled by braces
found within them, but also allows actions to begin with `%{' and will
@@ -993,11 +1076,11 @@ within an action:
int word_count = 0;
%%
-
+
frob special(); REJECT;
[^ \t\n]+ ++word_count;
- Without the `REJECT', any occurences of `frob' in the input would
+ Without the `REJECT', any occurrences of `frob' in the input would
not be counted as words, since the scanner normally executes only
one action per token. Multiple uses of `REJECT' are allowed, each
one finding the next best choice to the currently active rule. For
@@ -1022,7 +1105,7 @@ within an action:
Scanner Options::).
Note also that unlike the other special actions, `REJECT' is a
- _branch_. code immediately following it in the action will _not_
+ _branch_. Code immediately following it in the action will _not_
be executed.
`yymore()'
@@ -1105,13 +1188,13 @@ example, the following is one way to eat up C comments:
%%
"/*" {
register int c;
-
+
for ( ; ; )
{
while ( (c = input()) != '*' &&
c != EOF )
; /* eat up text of comment */
-
+
if ( c == '*' )
{
while ( (c = input()) == '*' )
@@ -1119,7 +1202,7 @@ example, the following is one way to eat up C comments:
if ( c == '/' )
break; /* found the end */
}
-
+
if ( c == EOF )
{
error( "EOF in comment" );
@@ -1147,10 +1230,10 @@ redefined.

File: flex.info, Node: Generated Scanner, Next: Start Conditions, Prev: Actions, Up: Top
-The Generated Scanner
-*********************
+9 The Generated Scanner
+***********************
- The output of `flex' is the file `lex.yy.c', which contains the
+The output of `flex' is the file `lex.yy.c', which contains the
scanning routine `yylex()', a number of tables used by it for matching
tokens, and a number of auxiliary routines and macros. By default,
`yylex()' is declared as follows:
@@ -1252,3 +1335,6349 @@ the default version of the routine, which always returns 1.
`stdout'), which may be redefined by the user simply by assigning it to
some other `FILE' pointer.
+
+File: flex.info, Node: Start Conditions, Next: Multiple Input Buffers, Prev: Generated Scanner, Up: Top
+
+10 Start Conditions
+*******************
+
+`flex' provides a mechanism for conditionally activating rules. Any
+rule whose pattern is prefixed with `<sc>' will only be active when the
+scanner is in the "start condition" named `sc'. For example,
+
+
+ <STRING>[^"]* { /* eat up the string body ... */
+ ...
+ }
+
+ will be active only when the scanner is in the `STRING' start
+condition, and
+
+
+ <INITIAL,STRING,QUOTE>\. { /* handle an escape ... */
+ ...
+ }
+
+ will be active only when the current start condition is either
+`INITIAL', `STRING', or `QUOTE'.
+
+ Start conditions are declared in the definitions (first) section of
+the input using unindented lines beginning with either `%s' or `%x'
+followed by a list of names. The former declares "inclusive" start
+conditions, the latter "exclusive" start conditions. A start condition
+is activated using the `BEGIN' action. Until the next `BEGIN' action
+is executed, rules with the given start condition will be active and
+rules with other start conditions will be inactive. If the start
+condition is inclusive, then rules with no start conditions at all will
+also be active. If it is exclusive, then _only_ rules qualified with
+the start condition will be active. A set of rules contingent on the
+same exclusive start condition describe a scanner which is independent
+of any of the other rules in the `flex' input. Because of this,
+exclusive start conditions make it easy to specify "mini-scanners"
+which scan portions of the input that are syntactically different from
+the rest (e.g., comments).
+
+ If the distinction between inclusive and exclusive start conditions
+is still a little vague, here's a simple example illustrating the
+connection between the two. The set of rules:
+
+
+ %s example
+ %%
+
+ <example>foo do_something();
+
+ bar something_else();
+
+ is equivalent to
+
+
+ %x example
+ %%
+
+ <example>foo do_something();
+
+ <INITIAL,example>bar something_else();
+
+ Without the `<INITIAL,example>' qualifier, the `bar' pattern in the
+second example wouldn't be active (i.e., couldn't match) when in start
+condition `example'. If we just used `<example>' to qualify `bar',
+though, then it would only be active in `example' and not in `INITIAL',
+while in the first example it's active in both, because in the first
+example the `example' start condition is an inclusive `(%s)' start
+condition.
+
+ Also note that the special start-condition specifier `<*>' matches
+every start condition. Thus, the above example could also have been
+written:
+
+
+ %x example
+ %%
+
+ <example>foo do_something();
+
+ <*>bar something_else();
+
+ The default rule (to `ECHO' any unmatched character) remains active
+in start conditions. It is equivalent to:
+
+
+ <*>.|\n ECHO;
+
+ `BEGIN(0)' returns to the original state where only the rules with
+no start conditions are active. This state can also be referred to as
+the start-condition `INITIAL', so `BEGIN(INITIAL)' is equivalent to
+`BEGIN(0)'. (The parentheses around the start condition name are not
+required but are considered good style.)
+
+ `BEGIN' actions can also be given as indented code at the beginning
+of the rules section. For example, the following will cause the scanner
+to enter the `SPECIAL' start condition whenever `yylex()' is called and
+the global variable `enter_special' is true:
+
+
+ int enter_special;
+
+ %x SPECIAL
+ %%
+ if ( enter_special )
+ BEGIN(SPECIAL);
+
+ <SPECIAL>blahblahblah
+ ...more rules follow...
+
+ To illustrate the uses of start conditions, here is a scanner which
+provides two different interpretations of a string like `123.456'. By
+default it will treat it as three tokens, the integer `123', a dot
+(`.'), and the integer `456'. But if the string is preceded earlier in
+the line by the string `expect-floats' it will treat it as a single
+token, the floating-point number `123.456':
+
+
+ %{
+ #include <math.h>
+ %}
+ %s expect
+
+ %%
+ expect-floats BEGIN(expect);
+
+ <expect>[0-9]+@samp{.}[0-9]+ {
+ printf( "found a float, = %f\n",
+ atof( yytext ) );
+ }
+ <expect>\n {
+ /* that's the end of the line, so
+ * we need another "expect-number"
+ * before we'll recognize any more
+ * numbers
+ */
+ BEGIN(INITIAL);
+ }
+
+ [0-9]+ {
+ printf( "found an integer, = %d\n",
+ atoi( yytext ) );
+ }
+
+ "." printf( "found a dot\n" );
+
+ Here is a scanner which recognizes (and discards) C comments while
+maintaining a count of the current input line.
+
+
+ %x comment
+ %%
+ int line_num = 1;
+
+ "/*" BEGIN(comment);
+
+ <comment>[^*\n]* /* eat anything that's not a '*' */
+ <comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
+ <comment>\n ++line_num;
+ <comment>"*"+"/" BEGIN(INITIAL);
+
+ This scanner goes to a bit of trouble to match as much text as
+possible with each rule. In general, when attempting to write a
+high-speed scanner try to match as much possible in each rule, as it's
+a big win.
+
+ Note that start-conditions names are really integer values and can
+be stored as such. Thus, the above could be extended in the following
+fashion:
+
+
+ %x comment foo
+ %%
+ int line_num = 1;
+ int comment_caller;
+
+ "/*" {
+ comment_caller = INITIAL;
+ BEGIN(comment);
+ }
+
+ ...
+
+ <foo>"/*" {
+ comment_caller = foo;
+ BEGIN(comment);
+ }
+
+ <comment>[^*\n]* /* eat anything that's not a '*' */
+ <comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
+ <comment>\n ++line_num;
+ <comment>"*"+"/" BEGIN(comment_caller);
+
+ Furthermore, you can access the current start condition using the
+integer-valued `YY_START' macro. For example, the above assignments to
+`comment_caller' could instead be written
+
+
+ comment_caller = YY_START;
+
+ Flex provides `YYSTATE' as an alias for `YY_START' (since that is
+what's used by AT&T `lex').
+
+ For historical reasons, start conditions do not have their own
+name-space within the generated scanner. The start condition names are
+unmodified in the generated scanner and generated header. *Note
+option-header::. *Note option-prefix::.
+
+ Finally, here's an example of how to match C-style quoted strings
+using exclusive start conditions, including expanded escape sequences
+(but not including checking for a string that's too long):
+
+
+ %x str
+
+ %%
+ char string_buf[MAX_STR_CONST];
+ char *string_buf_ptr;
+
+
+ \" string_buf_ptr = string_buf; BEGIN(str);
+
+ <str>\" { /* saw closing quote - all done */
+ BEGIN(INITIAL);
+ *string_buf_ptr = '\0';
+ /* return string constant token type and
+ * value to parser
+ */
+ }
+
+ <str>\n {
+ /* error - unterminated string constant */
+ /* generate error message */
+ }
+
+ <str>\\[0-7]{1,3} {
+ /* octal escape sequence */
+ int result;
+
+ (void) sscanf( yytext + 1, "%o", &result );
+
+ if ( result > 0xff )
+ /* error, constant is out-of-bounds */
+
+ *string_buf_ptr++ = result;
+ }
+
+ <str>\\[0-9]+ {
+ /* generate error - bad escape sequence; something
+ * like '\48' or '\0777777'
+ */
+ }
+
+ <str>\\n *string_buf_ptr++ = '\n';
+ <str>\\t *string_buf_ptr++ = '\t';
+ <str>\\r *string_buf_ptr++ = '\r';
+ <str>\\b *string_buf_ptr++ = '\b';
+ <str>\\f *string_buf_ptr++ = '\f';
+
+ <str>\\(.|\n) *string_buf_ptr++ = yytext[1];
+
+ <str>[^\\\n\"]+ {
+ char *yptr = yytext;
+
+ while ( *yptr )
+ *string_buf_ptr++ = *yptr++;
+ }
+
+ Often, such as in some of the examples above, you wind up writing a
+whole bunch of rules all preceded by the same start condition(s). Flex
+makes this a little easier and cleaner by introducing a notion of start
+condition "scope". A start condition scope is begun with:
+
+
+ <SCs>{
+
+ where `SCs' is a list of one or more start conditions. Inside the
+start condition scope, every rule automatically has the prefix `SCs>'
+applied to it, until a `}' which matches the initial `{'. So, for
+example,
+
+
+ <ESC>{
+ "\\n" return '\n';
+ "\\r" return '\r';
+ "\\f" return '\f';
+ "\\0" return '\0';
+ }
+
+ is equivalent to:
+
+
+ <ESC>"\\n" return '\n';
+ <ESC>"\\r" return '\r';
+ <ESC>"\\f" return '\f';
+ <ESC>"\\0" return '\0';
+
+ Start condition scopes may be nested.
+
+ The following routines are available for manipulating stacks of
+start conditions:
+
+ -- Function: void yy_push_state ( int `new_state' )
+ pushes the current start condition onto the top of the start
+ condition stack and switches to `new_state' as though you had used
+ `BEGIN new_state' (recall that start condition names are also
+ integers).
+
+ -- Function: void yy_pop_state ()
+ pops the top of the stack and switches to it via `BEGIN'.
+
+ -- Function: int yy_top_state ()
+ returns the top of the stack without altering the stack's contents.
+
+ The start condition stack grows dynamically and so has no built-in
+size limitation. If memory is exhausted, program execution aborts.
+
+ To use start condition stacks, your scanner must include a `%option
+stack' directive (*note Scanner Options::).
+
+
+File: flex.info, Node: Multiple Input Buffers, Next: EOF, Prev: Start Conditions, Up: Top
+
+11 Multiple Input Buffers
+*************************
+
+Some scanners (such as those which support "include" files) require
+reading from several input streams. As `flex' scanners do a large
+amount of buffering, one cannot control where the next input will be
+read from by simply writing a `YY_INPUT()' which is sensitive to the
+scanning context. `YY_INPUT()' is only called when the scanner reaches
+the end of its buffer, which may be a long time after scanning a
+statement such as an `include' statement which requires switching the
+input source.
+
+ To negotiate these sorts of problems, `flex' provides a mechanism
+for creating and switching between multiple input buffers. An input
+buffer is created by using:
+
+ -- Function: YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size )
+
+ which takes a `FILE' pointer and a size and creates a buffer
+associated with the given file and large enough to hold `size'
+characters (when in doubt, use `YY_BUF_SIZE' for the size). It returns
+a `YY_BUFFER_STATE' handle, which may then be passed to other routines
+(see below). The `YY_BUFFER_STATE' type is a pointer to an opaque
+`struct yy_buffer_state' structure, so you may safely initialize
+`YY_BUFFER_STATE' variables to `((YY_BUFFER_STATE) 0)' if you wish, and
+also refer to the opaque structure in order to correctly declare input
+buffers in source files other than that of your scanner. Note that the
+`FILE' pointer in the call to `yy_create_buffer' is only used as the
+value of `yyin' seen by `YY_INPUT'. If you redefine `YY_INPUT()' so it
+no longer uses `yyin', then you can safely pass a NULL `FILE' pointer to
+`yy_create_buffer'. You select a particular buffer to scan from using:
+
+ -- Function: void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer )
+
+ The above function switches the scanner's input buffer so subsequent
+tokens will come from `new_buffer'. Note that `yy_switch_to_buffer()'
+may be used by `yywrap()' to set things up for continued scanning,
+instead of opening a new file and pointing `yyin' at it. If you are
+looking for a stack of input buffers, then you want to use
+`yypush_buffer_state()' instead of this function. Note also that
+switching input sources via either `yy_switch_to_buffer()' or
+`yywrap()' does _not_ change the start condition.
+
+ -- Function: void yy_delete_buffer ( YY_BUFFER_STATE buffer )
+
+ is used to reclaim the storage associated with a buffer. (`buffer'
+can be NULL, in which case the routine does nothing.) You can also
+clear the current contents of a buffer using:
+
+ -- Function: void yypush_buffer_state ( YY_BUFFER_STATE buffer )
+
+ This function pushes the new buffer state onto an internal stack.
+The pushed state becomes the new current state. The stack is maintained
+by flex and will grow as required. This function is intended to be used
+instead of `yy_switch_to_buffer', when you want to change states, but
+preserve the current state for later use.
+
+ -- Function: void yypop_buffer_state ( )
+
+ This function removes the current state from the top of the stack,
+and deletes it by calling `yy_delete_buffer'. The next state on the
+stack, if any, becomes the new current state.
+
+ -- Function: void yy_flush_buffer ( YY_BUFFER_STATE buffer )
+
+ This function discards the buffer's contents, so the next time the
+scanner attempts to match a token from the buffer, it will first fill
+the buffer anew using `YY_INPUT()'.
+
+ -- Function: YY_BUFFER_STATE yy_new_buffer ( FILE *file, int size )
+
+ is an alias for `yy_create_buffer()', provided for compatibility
+with the C++ use of `new' and `delete' for creating and destroying
+dynamic objects.
+
+ `YY_CURRENT_BUFFER' macro returns a `YY_BUFFER_STATE' handle to the
+current buffer. It should not be used as an lvalue.
+
+ Here are two examples of using these features for writing a scanner
+which expands include files (the `<<EOF>>' feature is discussed below).
+
+ This first example uses yypush_buffer_state and yypop_buffer_state.
+Flex maintains the stack internally.
+
+
+ /* the "incl" state is used for picking up the name
+ * of an include file
+ */
+ %x incl
+ %%
+ include BEGIN(incl);
+
+ [a-z]+ ECHO;
+ [^a-z\n]*\n? ECHO;
+
+ <incl>[ \t]* /* eat the whitespace */
+ <incl>[^ \t\n]+ { /* got the include file name */
+ yyin = fopen( yytext, "r" );
+
+ if ( ! yyin )
+ error( ... );
+
+ yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE ));
+
+ BEGIN(INITIAL);
+ }
+
+ <<EOF>> {
+ yypop_buffer_state();
+
+ if ( !YY_CURRENT_BUFFER )
+ {
+ yyterminate();
+ }
+ }
+
+ The second example, below, does the same thing as the previous
+example did, but manages its own input buffer stack manually (instead
+of letting flex do it).
+
+
+ /* the "incl" state is used for picking up the name
+ * of an include file
+ */
+ %x incl
+
+ %{
+ #define MAX_INCLUDE_DEPTH 10
+ YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+ int include_stack_ptr = 0;
+ %}
+
+ %%
+ include BEGIN(incl);
+
+ [a-z]+ ECHO;
+ [^a-z\n]*\n? ECHO;
+
+ <incl>[ \t]* /* eat the whitespace */
+ <incl>[^ \t\n]+ { /* got the include file name */
+ if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
+ {
+ fprintf( stderr, "Includes nested too deeply" );
+ exit( 1 );
+ }
+
+ include_stack[include_stack_ptr++] =
+ YY_CURRENT_BUFFER;
+
+ yyin = fopen( yytext, "r" );
+
+ if ( ! yyin )
+ error( ... );
+
+ yy_switch_to_buffer(
+ yy_create_buffer( yyin, YY_BUF_SIZE ) );
+
+ BEGIN(INITIAL);
+ }
+
+ <<EOF>> {
+ if ( --include_stack_ptr 0 )
+ {
+ yyterminate();
+ }
+
+ else
+ {
+ yy_delete_buffer( YY_CURRENT_BUFFER );
+ yy_switch_to_buffer(
+ include_stack[include_stack_ptr] );
+ }
+ }
+
+ The following routines are available for setting up input buffers for
+scanning in-memory strings instead of files. All of them create a new
+input buffer for scanning the string, and return a corresponding
+`YY_BUFFER_STATE' handle (which you should delete with
+`yy_delete_buffer()' when done with it). They also switch to the new
+buffer using `yy_switch_to_buffer()', so the next call to `yylex()'
+will start scanning the string.
+
+ -- Function: YY_BUFFER_STATE yy_scan_string ( const char *str )
+ scans a NUL-terminated string.
+
+ -- Function: YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int
+ len )
+ scans `len' bytes (including possibly `NUL's) starting at location
+ `bytes'.
+
+ Note that both of these functions create and scan a _copy_ of the
+string or bytes. (This may be desirable, since `yylex()' modifies the
+contents of the buffer it is scanning.) You can avoid the copy by
+using:
+
+ -- Function: YY_BUFFER_STATE yy_scan_buffer (char *base, yy_size_t
+ size)
+ which scans in place the buffer starting at `base', consisting of
+ `size' bytes, the last two bytes of which _must_ be
+ `YY_END_OF_BUFFER_CHAR' (ASCII NUL). These last two bytes are not
+ scanned; thus, scanning consists of `base[0]' through
+ `base[size-2]', inclusive.
+
+ If you fail to set up `base' in this manner (i.e., forget the final
+two `YY_END_OF_BUFFER_CHAR' bytes), then `yy_scan_buffer()' returns a
+NULL pointer instead of creating a new input buffer.
+
+ -- Data type: yy_size_t
+ is an integral type to which you can cast an integer expression
+ reflecting the size of the buffer.
+
+
+File: flex.info, Node: EOF, Next: Misc Macros, Prev: Multiple Input Buffers, Up: Top
+
+12 End-of-File Rules
+********************
+
+The special rule `<<EOF>>' indicates actions which are to be taken when
+an end-of-file is encountered and `yywrap()' returns non-zero (i.e.,
+indicates no further files to process). The action must finish by
+doing one of the following things:
+
+ * assigning `yyin' to a new input file (in previous versions of
+ `flex', after doing the assignment you had to call the special
+ action `YY_NEW_FILE'. This is no longer necessary.)
+
+ * executing a `return' statement;
+
+ * executing the special `yyterminate()' action.
+
+ * or, switching to a new buffer using `yy_switch_to_buffer()' as
+ shown in the example above.
+
+ <<EOF>> rules may not be used with other patterns; they may only be
+qualified with a list of start conditions. If an unqualified <<EOF>>
+rule is given, it applies to _all_ start conditions which do not
+already have <<EOF>> actions. To specify an <<EOF>> rule for only the
+initial start condition, use:
+
+
+ <INITIAL><<EOF>>
+
+ These rules are useful for catching things like unclosed comments.
+An example:
+
+
+ %x quote
+ %%
+
+ ...other rules for dealing with quotes...
+
+ <quote><<EOF>> {
+ error( "unterminated quote" );
+ yyterminate();
+ }
+ <<EOF>> {
+ if ( *++filelist )
+ yyin = fopen( *filelist, "r" );
+ else
+ yyterminate();
+ }
+
+
+File: flex.info, Node: Misc Macros, Next: User Values, Prev: EOF, Up: Top
+
+13 Miscellaneous Macros
+***********************
+
+The macro `YY_USER_ACTION' can be defined to provide an action which is
+always executed prior to the matched rule's action. For example, it
+could be #define'd to call a routine to convert yytext to lower-case.
+When `YY_USER_ACTION' is invoked, the variable `yy_act' gives the
+number of the matched rule (rules are numbered starting with 1).
+Suppose you want to profile how often each of your rules is matched.
+The following would do the trick:
+
+
+ #define YY_USER_ACTION ++ctr[yy_act]
+
+ where `ctr' is an array to hold the counts for the different rules.
+Note that the macro `YY_NUM_RULES' gives the total number of rules
+(including the default rule), even if you use `-s)', so a correct
+declaration for `ctr' is:
+
+
+ int ctr[YY_NUM_RULES];
+
+ The macro `YY_USER_INIT' may be defined to provide an action which
+is always executed before the first scan (and before the scanner's
+internal initializations are done). For example, it could be used to
+call a routine to read in a data table or open a logging file.
+
+ The macro `yy_set_interactive(is_interactive)' can be used to
+control whether the current buffer is considered "interactive". An
+interactive buffer is processed more slowly, but must be used when the
+scanner's input source is indeed interactive to avoid problems due to
+waiting to fill buffers (see the discussion of the `-I' flag in *Note
+Scanner Options::). A non-zero value in the macro invocation marks the
+buffer as interactive, a zero value as non-interactive. Note that use
+of this macro overrides `%option always-interactive' or `%option
+never-interactive' (*note Scanner Options::). `yy_set_interactive()'
+must be invoked prior to beginning to scan the buffer that is (or is
+not) to be considered interactive.
+
+ The macro `yy_set_bol(at_bol)' can be used to control whether the
+current buffer's scanning context for the next token match is done as
+though at the beginning of a line. A non-zero macro argument makes
+rules anchored with `^' active, while a zero argument makes `^' rules
+inactive.
+
+ The macro `YY_AT_BOL()' returns true if the next token scanned from
+the current buffer will have `^' rules active, false otherwise.
+
+ In the generated scanner, the actions are all gathered in one large
+switch statement and separated using `YY_BREAK', which may be
+redefined. By default, it is simply a `break', to separate each rule's
+action from the following rule's. Redefining `YY_BREAK' allows, for
+example, C++ users to #define YY_BREAK to do nothing (while being very
+careful that every rule ends with a `break' or a `return'!) to avoid
+suffering from unreachable statement warnings where because a rule's
+action ends with `return', the `YY_BREAK' is inaccessible.
+
+
+File: flex.info, Node: User Values, Next: Yacc, Prev: Misc Macros, Up: Top
+
+14 Values Available To the User
+*******************************
+
+This chapter summarizes the various values available to the user in the
+rule actions.
+
+`char *yytext'
+ holds the text of the current token. It may be modified but not
+ lengthened (you cannot append characters to the end).
+
+ If the special directive `%array' appears in the first section of
+ the scanner description, then `yytext' is instead declared `char
+ yytext[YYLMAX]', where `YYLMAX' is a macro definition that you can
+ redefine in the first section if you don't like the default value
+ (generally 8KB). Using `%array' results in somewhat slower
+ scanners, but the value of `yytext' becomes immune to calls to
+ `unput()', which potentially destroy its value when `yytext' is a
+ character pointer. The opposite of `%array' is `%pointer', which
+ is the default.
+
+ You cannot use `%array' when generating C++ scanner classes (the
+ `-+' flag).
+
+`int yyleng'
+ holds the length of the current token.
+
+`FILE *yyin'
+ is the file which by default `flex' reads from. It may be
+ redefined but doing so only makes sense before scanning begins or
+ after an EOF has been encountered. Changing it in the midst of
+ scanning will have unexpected results since `flex' buffers its
+ input; use `yyrestart()' instead. Once scanning terminates
+ because an end-of-file has been seen, you can assign `yyin' at the
+ new input file and then call the scanner again to continue
+ scanning.
+
+`void yyrestart( FILE *new_file )'
+ may be called to point `yyin' at the new input file. The
+ switch-over to the new file is immediate (any previously
+ buffered-up input is lost). Note that calling `yyrestart()' with
+ `yyin' as an argument thus throws away the current input buffer
+ and continues scanning the same input file.
+
+`FILE *yyout'
+ is the file to which `ECHO' actions are done. It can be reassigned
+ by the user.
+
+`YY_CURRENT_BUFFER'
+ returns a `YY_BUFFER_STATE' handle to the current buffer.
+
+`YY_START'
+ returns an integer value corresponding to the current start
+ condition. You can subsequently use this value with `BEGIN' to
+ return to that start condition.
+
+
+File: flex.info, Node: Yacc, Next: Scanner Options, Prev: User Values, Up: Top
+
+15 Interfacing with Yacc
+************************
+
+One of the main uses of `flex' is as a companion to the `yacc'
+parser-generator. `yacc' parsers expect to call a routine named
+`yylex()' to find the next input token. The routine is supposed to
+return the type of the next token as well as putting any associated
+value in the global `yylval'. To use `flex' with `yacc', one specifies
+the `-d' option to `yacc' to instruct it to generate the file `y.tab.h'
+containing definitions of all the `%tokens' appearing in the `yacc'
+input. This file is then included in the `flex' scanner. For example,
+if one of the tokens is `TOK_NUMBER', part of the scanner might look
+like:
+
+
+ %{
+ #include "y.tab.h"
+ %}
+
+ %%
+
+ [0-9]+ yylval = atoi( yytext ); return TOK_NUMBER;
+
+
+File: flex.info, Node: Scanner Options, Next: Performance, Prev: Yacc, Up: Top
+
+16 Scanner Options
+******************
+
+The various `flex' options are categorized by function in the following
+menu. If you want to lookup a particular option by name, *Note Index of
+Scanner Options::.
+
+* Menu:
+
+* Options for Specifying Filenames::
+* Options Affecting Scanner Behavior::
+* Code-Level And API Options::
+* Options for Scanner Speed and Size::
+* Debugging Options::
+* Miscellaneous Options::
+
+ Even though there are many scanner options, a typical scanner might
+only specify the following options:
+
+
+ %option 8bit reentrant bison-bridge
+ %option warn nodefault
+ %option yylineno
+ %option outfile="scanner.c" header-file="scanner.h"
+
+ The first line specifies the general type of scanner we want. The
+second line specifies that we are being careful. The third line asks
+flex to track line numbers. The last line tells flex what to name the
+files. (The options can be specified in any order. We just divided
+them.)
+
+ `flex' also provides a mechanism for controlling options within the
+scanner specification itself, rather than from the flex command-line.
+This is done by including `%option' directives in the first section of
+the scanner specification. You can specify multiple options with a
+single `%option' directive, and multiple directives in the first
+section of your flex input file.
+
+ Most options are given simply as names, optionally preceded by the
+word `no' (with no intervening whitespace) to negate their meaning.
+The names are the same as their long-option equivalents (but without the
+leading `--' ).
+
+ `flex' scans your rule actions to determine whether you use the
+`REJECT' or `yymore()' features. The `REJECT' and `yymore' options are
+available to override its decision as to whether you use the options,
+either by setting them (e.g., `%option reject)' to indicate the feature
+is indeed used, or unsetting them to indicate it actually is not used
+(e.g., `%option noyymore)'.
+
+ A number of options are available for lint purists who want to
+suppress the appearance of unneeded routines in the generated scanner.
+Each of the following, if unset (e.g., `%option nounput'), results in
+the corresponding routine not appearing in the generated scanner:
+
+
+ input, unput
+ yy_push_state, yy_pop_state, yy_top_state
+ yy_scan_buffer, yy_scan_bytes, yy_scan_string
+
+ yyget_extra, yyset_extra, yyget_leng, yyget_text,
+ yyget_lineno, yyset_lineno, yyget_in, yyset_in,
+ yyget_out, yyset_out, yyget_lval, yyset_lval,
+ yyget_lloc, yyset_lloc, yyget_debug, yyset_debug
+
+ (though `yy_push_state()' and friends won't appear anyway unless you
+use `%option stack)'.
+
+
+File: flex.info, Node: Options for Specifying Filenames, Next: Options Affecting Scanner Behavior, Prev: Scanner Options, Up: Scanner Options
+
+16.1 Options for Specifying Filenames
+=====================================
+
+`--header-file=FILE, `%option header-file="FILE"''
+ instructs flex to write a C header to `FILE'. This file contains
+ function prototypes, extern variables, and types used by the
+ scanner. Only the external API is exported by the header file.
+ Many macros that are usable from within scanner actions are not
+ exported to the header file. This is due to namespace problems and
+ the goal of a clean external API.
+
+ While in the header, the macro `yyIN_HEADER' is defined, where `yy'
+ is substituted with the appropriate prefix.
+
+ The `--header-file' option is not compatible with the `--c++'
+ option, since the C++ scanner provides its own header in
+ `yyFlexLexer.h'.
+
+`-oFILE, --outfile=FILE, `%option outfile="FILE"''
+ directs flex to write the scanner to the file `FILE' instead of
+ `lex.yy.c'. If you combine `--outfile' with the `--stdout' option,
+ then the scanner is written to `stdout' but its `#line' directives
+ (see the `-l' option above) refer to the file `FILE'.
+
+`-t, --stdout, `%option stdout''
+ instructs `flex' to write the scanner it generates to standard
+ output instead of `lex.yy.c'.
+
+`-SFILE, --skel=FILE'
+ overrides the default skeleton file from which `flex' constructs
+ its scanners. You'll never need this option unless you are doing
+ `flex' maintenance or development.
+
+`--tables-file=FILE'
+ Write serialized scanner dfa tables to FILE. The generated scanner
+ will not contain the tables, and requires them to be loaded at
+ runtime. *Note serialization::.
+
+`--tables-verify'
+ This option is for flex development. We document it here in case
+ you stumble upon it by accident or in case you suspect some
+ inconsistency in the serialized tables. Flex will serialize the
+ scanner dfa tables but will also generate the in-code tables as it
+ normally does. At runtime, the scanner will verify that the
+ serialized tables match the in-code tables, instead of loading
+ them.
+
+
+
+File: flex.info, Node: Options Affecting Scanner Behavior, Next: Code-Level And API Options, Prev: Options for Specifying Filenames, Up: Scanner Options
+
+16.2 Options Affecting Scanner Behavior
+=======================================
+
+`-i, --case-insensitive, `%option case-insensitive''
+ instructs `flex' to generate a "case-insensitive" scanner. The
+ case of letters given in the `flex' input patterns will be ignored,
+ and tokens in the input will be matched regardless of case. The
+ matched text given in `yytext' will have the preserved case (i.e.,
+ it will not be folded). For tricky behavior, see *Note case and
+ character ranges::.
+
+`-l, --lex-compat, `%option lex-compat''
+ turns on maximum compatibility with the original AT&T `lex'
+ implementation. Note that this does not mean _full_ compatibility.
+ Use of this option costs a considerable amount of performance, and
+ it cannot be used with the `--c++', `--full', `--fast', `-Cf', or
+ `-CF' options. For details on the compatibilities it provides, see
+ *Note Lex and Posix::. This option also results in the name
+ `YY_FLEX_LEX_COMPAT' being `#define''d in the generated scanner.
+
+`-B, --batch, `%option batch''
+ instructs `flex' to generate a "batch" scanner, the opposite of
+ _interactive_ scanners generated by `--interactive' (see below).
+ In general, you use `-B' when you are _certain_ that your scanner
+ will never be used interactively, and you want to squeeze a
+ _little_ more performance out of it. If your goal is instead to
+ squeeze out a _lot_ more performance, you should be using the
+ `-Cf' or `-CF' options, which turn on `--batch' automatically
+ anyway.
+
+`-I, --interactive, `%option interactive''
+ instructs `flex' to generate an interactive scanner. An
+ interactive scanner is one that only looks ahead to decide what
+ token has been matched if it absolutely must. It turns out that
+ always looking one extra character ahead, even if the scanner has
+ already seen enough text to disambiguate the current token, is a
+ bit faster than only looking ahead when necessary. But scanners
+ that always look ahead give dreadful interactive performance; for
+ example, when a user types a newline, it is not recognized as a
+ newline token until they enter _another_ token, which often means
+ typing in another whole line.
+
+ `flex' scanners default to `interactive' unless you use the `-Cf'
+ or `-CF' table-compression options (*note Performance::). That's
+ because if you're looking for high-performance you should be using
+ one of these options, so if you didn't, `flex' assumes you'd
+ rather trade off a bit of run-time performance for intuitive
+ interactive behavior. Note also that you _cannot_ use
+ `--interactive' in conjunction with `-Cf' or `-CF'. Thus, this
+ option is not really needed; it is on by default for all those
+ cases in which it is allowed.
+
+ You can force a scanner to _not_ be interactive by using `--batch'
+
+`-7, --7bit, `%option 7bit''
+ instructs `flex' to generate a 7-bit scanner, i.e., one which can
+ only recognize 7-bit characters in its input. The advantage of
+ using `--7bit' is that the scanner's tables can be up to half the
+ size of those generated using the `--8bit'. The disadvantage is
+ that such scanners often hang or crash if their input contains an
+ 8-bit character.
+
+ Note, however, that unless you generate your scanner using the
+ `-Cf' or `-CF' table compression options, use of `--7bit' will
+ save only a small amount of table space, and make your scanner
+ considerably less portable. `Flex''s default behavior is to
+ generate an 8-bit scanner unless you use the `-Cf' or `-CF', in
+ which case `flex' defaults to generating 7-bit scanners unless
+ your site was always configured to generate 8-bit scanners (as will
+ often be the case with non-USA sites). You can tell whether flex
+ generated a 7-bit or an 8-bit scanner by inspecting the flag
+ summary in the `--verbose' output as described above.
+
+ Note that if you use `-Cfe' or `-CFe' `flex' still defaults to
+ generating an 8-bit scanner, since usually with these compression
+ options full 8-bit tables are not much more expensive than 7-bit
+ tables.
+
+`-8, --8bit, `%option 8bit''
+ instructs `flex' to generate an 8-bit scanner, i.e., one which can
+ recognize 8-bit characters. This flag is only needed for scanners
+ generated using `-Cf' or `-CF', as otherwise flex defaults to
+ generating an 8-bit scanner anyway.
+
+ See the discussion of `--7bit' above for `flex''s default behavior
+ and the tradeoffs between 7-bit and 8-bit scanners.
+
+`--default, `%option default''
+ generate the default rule.
+
+`--always-interactive, `%option always-interactive''
+ instructs flex to generate a scanner which always considers its
+ input _interactive_. Normally, on each new input file the scanner
+ calls `isatty()' in an attempt to determine whether the scanner's
+ input source is interactive and thus should be read a character at
+ a time. When this option is used, however, then no such call is
+ made.
+
+`--never-interactive, `--never-interactive''
+ instructs flex to generate a scanner which never considers its
+ input interactive. This is the opposite of `always-interactive'.
+
+`-X, --posix, `%option posix''
+ turns on maximum compatibility with the POSIX 1003.2-1992
+ definition of `lex'. Since `flex' was originally designed to
+ implement the POSIX definition of `lex' this generally involves
+ very few changes in behavior. At the current writing the known
+ differences between `flex' and the POSIX standard are:
+
+ * In POSIX and AT&T `lex', the repeat operator, `{}', has lower
+ precedence than concatenation (thus `ab{3}' yields `ababab').
+ Most POSIX utilities use an Extended Regular Expression (ERE)
+ precedence that has the precedence of the repeat operator
+ higher than concatenation (which causes `ab{3}' to yield
+ `abbb'). By default, `flex' places the precedence of the
+ repeat operator higher than concatenation which matches the
+ ERE processing of other POSIX utilities. When either
+ `--posix' or `-l' are specified, `flex' will use the
+ traditional AT&T and POSIX-compliant precedence for the
+ repeat operator where concatenation has higher precedence
+ than the repeat operator.
+
+`--stack, `%option stack''
+ enables the use of start condition stacks (*note Start
+ Conditions::).
+
+`--stdinit, `%option stdinit''
+ if set (i.e., %option stdinit) initializes `yyin' and `yyout' to
+ `stdin' and `stdout', instead of the default of `NULL'. Some
+ existing `lex' programs depend on this behavior, even though it is
+ not compliant with ANSI C, which does not require `stdin' and
+ `stdout' to be compile-time constant. In a reentrant scanner,
+ however, this is not a problem since initialization is performed
+ in `yylex_init' at runtime.
+
+`--yylineno, `%option yylineno''
+ directs `flex' to generate a scanner that maintains the number of
+ the current line read from its input in the global variable
+ `yylineno'. This option is implied by `%option lex-compat'. In a
+ reentrant C scanner, the macro `yylineno' is accessible regardless
+ of the value of `%option yylineno', however, its value is not
+ modified by `flex' unless `%option yylineno' is enabled.
+
+`--yywrap, `%option yywrap''
+ if unset (i.e., `--noyywrap)', makes the scanner not call
+ `yywrap()' upon an end-of-file, but simply assume that there are no
+ more files to scan (until the user points `yyin' at a new file and
+ calls `yylex()' again).
+
+
+
+File: flex.info, Node: Code-Level And API Options, Next: Options for Scanner Speed and Size, Prev: Options Affecting Scanner Behavior, Up: Scanner Options
+
+16.3 Code-Level And API Options
+===============================
+
+`--ansi-definitions, `%option ansi-definitions''
+ instruct flex to generate ANSI C99 definitions for functions.
+ This option is enabled by default. If `%option
+ noansi-definitions' is specified, then the obsolete style is
+ generated.
+
+`--ansi-prototypes, `%option ansi-prototypes''
+ instructs flex to generate ANSI C99 prototypes for functions.
+ This option is enabled by default. If `noansi-prototypes' is
+ specified, then prototypes will have empty parameter lists.
+
+`--bison-bridge, `%option bison-bridge''
+ instructs flex to generate a C scanner that is meant to be called
+ by a `GNU bison' parser. The scanner has minor API changes for
+ `bison' compatibility. In particular, the declaration of `yylex'
+ is modified to take an additional parameter, `yylval'. *Note
+ Bison Bridge::.
+
+`--bison-locations, `%option bison-locations''
+ instruct flex that `GNU bison' `%locations' are being used. This
+ means `yylex' will be passed an additional parameter, `yylloc'.
+ This option implies `%option bison-bridge'. *Note Bison Bridge::.
+
+`-L, --noline, `%option noline''
+ instructs `flex' not to generate `#line' directives. Without this
+ option, `flex' peppers the generated scanner with `#line'
+ directives so error messages in the actions will be correctly
+ located with respect to either the original `flex' input file (if
+ the errors are due to code in the input file), or `lex.yy.c' (if
+ the errors are `flex''s fault - you should report these sorts of
+ errors to the email address given in *Note Reporting Bugs::).
+
+`-R, --reentrant, `%option reentrant''
+ instructs flex to generate a reentrant C scanner. The generated
+ scanner may safely be used in a multi-threaded environment. The
+ API for a reentrant scanner is different than for a non-reentrant
+ scanner *note Reentrant::). Because of the API difference between
+ reentrant and non-reentrant `flex' scanners, non-reentrant flex
+ code must be modified before it is suitable for use with this
+ option. This option is not compatible with the `--c++' option.
+
+ The option `--reentrant' does not affect the performance of the
+ scanner.
+
+`-+, --c++, `%option c++''
+ specifies that you want flex to generate a C++ scanner class.
+ *Note Cxx::, for details.
+
+`--array, `%option array''
+ specifies that you want yytext to be an array instead of a char*
+
+`--pointer, `%option pointer''
+ specify that `yytext' should be a `char *', not an array. This
+ default is `char *'.
+
+`-PPREFIX, --prefix=PREFIX, `%option prefix="PREFIX"''
+ changes the default `yy' prefix used by `flex' for all
+ globally-visible variable and function names to instead be
+ `PREFIX'. For example, `--prefix=foo' changes the name of
+ `yytext' to `footext'. It also changes the name of the default
+ output file from `lex.yy.c' to `lex.foo.c'. Here is a partial
+ list of the names affected:
+
+
+ yy_create_buffer
+ yy_delete_buffer
+ yy_flex_debug
+ yy_init_buffer
+ yy_flush_buffer
+ yy_load_buffer_state
+ yy_switch_to_buffer
+ yyin
+ yyleng
+ yylex
+ yylineno
+ yyout
+ yyrestart
+ yytext
+ yywrap
+ yyalloc
+ yyrealloc
+ yyfree
+
+ (If you are using a C++ scanner, then only `yywrap' and
+ `yyFlexLexer' are affected.) Within your scanner itself, you can
+ still refer to the global variables and functions using either
+ version of their name; but externally, they have the modified name.
+
+ This option lets you easily link together multiple `flex' programs
+ into the same executable. Note, though, that using this option
+ also renames `yywrap()', so you now _must_ either provide your own
+ (appropriately-named) version of the routine for your scanner, or
+ use `%option noyywrap', as linking with `-lfl' no longer provides
+ one for you by default.
+
+`--main, `%option main''
+ directs flex to provide a default `main()' program for the
+ scanner, which simply calls `yylex()'. This option implies
+ `noyywrap' (see below).
+
+`--nounistd, `%option nounistd''
+ suppresses inclusion of the non-ANSI header file `unistd.h'. This
+ option is meant to target environments in which `unistd.h' does
+ not exist. Be aware that certain options may cause flex to
+ generate code that relies on functions normally found in
+ `unistd.h', (e.g. `isatty()', `read()'.) If you wish to use these
+ functions, you will have to inform your compiler where to find
+ them. *Note option-always-interactive::. *Note option-read::.
+
+`--yyclass=NAME, `%option yyclass="NAME"''
+ only applies when generating a C++ scanner (the `--c++' option).
+ It informs `flex' that you have derived `NAME' as a subclass of
+ `yyFlexLexer', so `flex' will place your actions in the member
+ function `foo::yylex()' instead of `yyFlexLexer::yylex()'. It
+ also generates a `yyFlexLexer::yylex()' member function that emits
+ a run-time error (by invoking `yyFlexLexer::LexerError())' if
+ called. *Note Cxx::.
+
+
+
+File: flex.info, Node: Options for Scanner Speed and Size, Next: Debugging Options, Prev: Code-Level And API Options, Up: Scanner Options
+
+16.4 Options for Scanner Speed and Size
+=======================================
+
+`-C[aefFmr]'
+ controls the degree of table compression and, more generally,
+ trade-offs between small scanners and fast scanners.
+
+ `-C'
+ A lone `-C' specifies that the scanner tables should be
+ compressed but neither equivalence classes nor
+ meta-equivalence classes should be used.
+
+ `-Ca, --align, `%option align''
+ ("align") instructs flex to trade off larger tables in the
+ generated scanner for faster performance because the elements
+ of the tables are better aligned for memory access and
+ computation. On some RISC architectures, fetching and
+ manipulating longwords is more efficient than with
+ smaller-sized units such as shortwords. This option can
+ quadruple the size of the tables used by your scanner.
+
+ `-Ce, --ecs, `%option ecs''
+ directs `flex' to construct "equivalence classes", i.e., sets
+ of characters which have identical lexical properties (for
+ example, if the only appearance of digits in the `flex' input
+ is in the character class "[0-9]" then the digits '0', '1',
+ ..., '9' will all be put in the same equivalence class).
+ Equivalence classes usually give dramatic reductions in the
+ final table/object file sizes (typically a factor of 2-5) and
+ are pretty cheap performance-wise (one array look-up per
+ character scanned).
+
+ `-Cf'
+ specifies that the "full" scanner tables should be generated -
+ `flex' should not compress the tables by taking advantages of
+ similar transition functions for different states.
+
+ `-CF'
+ specifies that the alternate fast scanner representation
+ (described above under the `--fast' flag) should be used.
+ This option cannot be used with `--c++'.
+
+ `-Cm, --meta-ecs, `%option meta-ecs''
+ directs `flex' to construct "meta-equivalence classes", which
+ are sets of equivalence classes (or characters, if equivalence
+ classes are not being used) that are commonly used together.
+ Meta-equivalence classes are often a big win when using
+ compressed tables, but they have a moderate performance
+ impact (one or two `if' tests and one array look-up per
+ character scanned).
+
+ `-Cr, --read, `%option read''
+ causes the generated scanner to _bypass_ use of the standard
+ I/O library (`stdio') for input. Instead of calling
+ `fread()' or `getc()', the scanner will use the `read()'
+ system call, resulting in a performance gain which varies
+ from system to system, but in general is probably negligible
+ unless you are also using `-Cf' or `-CF'. Using `-Cr' can
+ cause strange behavior if, for example, you read from `yyin'
+ using `stdio' prior to calling the scanner (because the
+ scanner will miss whatever text your previous reads left in
+ the `stdio' input buffer). `-Cr' has no effect if you define
+ `YY_INPUT()' (*note Generated Scanner::).
+
+ The options `-Cf' or `-CF' and `-Cm' do not make sense together -
+ there is no opportunity for meta-equivalence classes if the table
+ is not being compressed. Otherwise the options may be freely
+ mixed, and are cumulative.
+
+ The default setting is `-Cem', which specifies that `flex' should
+ generate equivalence classes and meta-equivalence classes. This
+ setting provides the highest degree of table compression. You can
+ trade off faster-executing scanners at the cost of larger tables
+ with the following generally being true:
+
+
+ slowest & smallest
+ -Cem
+ -Cm
+ -Ce
+ -C
+ -C{f,F}e
+ -C{f,F}
+ -C{f,F}a
+ fastest & largest
+
+ Note that scanners with the smallest tables are usually generated
+ and compiled the quickest, so during development you will usually
+ want to use the default, maximal compression.
+
+ `-Cfe' is often a good compromise between speed and size for
+ production scanners.
+
+`-f, --full, `%option full''
+ specifies "fast scanner". No table compression is done and
+ `stdio' is bypassed. The result is large but fast. This option
+ is equivalent to `--Cfr'
+
+`-F, --fast, `%option fast''
+ specifies that the _fast_ scanner table representation should be
+ used (and `stdio' bypassed). This representation is about as fast
+ as the full table representation `--full', and for some sets of
+ patterns will be considerably smaller (and for others, larger). In
+ general, if the pattern set contains both _keywords_ and a
+ catch-all, _identifier_ rule, such as in the set:
+
+
+ "case" return TOK_CASE;
+ "switch" return TOK_SWITCH;
+ ...
+ "default" return TOK_DEFAULT;
+ [a-z]+ return TOK_ID;
+
+ then you're better off using the full table representation. If
+ only the _identifier_ rule is present and you then use a hash
+ table or some such to detect the keywords, you're better off using
+ `--fast'.
+
+ This option is equivalent to `-CFr'. It cannot be used with
+ `--c++'.
+
+
+
+File: flex.info, Node: Debugging Options, Next: Miscellaneous Options, Prev: Options for Scanner Speed and Size, Up: Scanner Options
+
+16.5 Debugging Options
+======================
+
+`-b, --backup, `%option backup''
+ Generate backing-up information to `lex.backup'. This is a list of
+ scanner states which require backing up and the input characters on
+ which they do so. By adding rules one can remove backing-up
+ states. If _all_ backing-up states are eliminated and `-Cf' or
+ `-CF' is used, the generated scanner will run faster (see the
+ `--perf-report' flag). Only users who wish to squeeze every last
+ cycle out of their scanners need worry about this option. (*note
+ Performance::).
+
+`-d, --debug, `%option debug''
+ makes the generated scanner run in "debug" mode. Whenever a
+ pattern is recognized and the global variable `yy_flex_debug' is
+ non-zero (which is the default), the scanner will write to
+ `stderr' a line of the form:
+
+
+ -accepting rule at line 53 ("the matched text")
+
+ The line number refers to the location of the rule in the file
+ defining the scanner (i.e., the file that was fed to flex).
+ Messages are also generated when the scanner backs up, accepts the
+ default rule, reaches the end of its input buffer (or encounters a
+ NUL; at this point, the two look the same as far as the scanner's
+ concerned), or reaches an end-of-file.
+
+`-p, --perf-report, `%option perf-report''
+ generates a performance report to `stderr'. The report consists of
+ comments regarding features of the `flex' input file which will
+ cause a serious loss of performance in the resulting scanner. If
+ you give the flag twice, you will also get comments regarding
+ features that lead to minor performance losses.
+
+ Note that the use of `REJECT', and variable trailing context
+ (*note Limitations::) entails a substantial performance penalty;
+ use of `yymore()', the `^' operator, and the `--interactive' flag
+ entail minor performance penalties.
+
+`-s, --nodefault, `%option nodefault''
+ causes the _default rule_ (that unmatched scanner input is echoed
+ to `stdout)' to be suppressed. If the scanner encounters input
+ that does not match any of its rules, it aborts with an error.
+ This option is useful for finding holes in a scanner's rule set.
+
+`-T, --trace, `%option trace''
+ makes `flex' run in "trace" mode. It will generate a lot of
+ messages to `stderr' concerning the form of the input and the
+ resultant non-deterministic and deterministic finite automata.
+ This option is mostly for use in maintaining `flex'.
+
+`-w, --nowarn, `%option nowarn''
+ suppresses warning messages.
+
+`-v, --verbose, `%option verbose''
+ specifies that `flex' should write to `stderr' a summary of
+ statistics regarding the scanner it generates. Most of the
+ statistics are meaningless to the casual `flex' user, but the
+ first line identifies the version of `flex' (same as reported by
+ `--version'), and the next line the flags used when generating the
+ scanner, including those that are on by default.
+
+`--warn, `%option warn''
+ warn about certain things. In particular, if the default rule can
+ be matched but no default rule has been given, the flex will warn
+ you. We recommend using this option always.
+
+
+
+File: flex.info, Node: Miscellaneous Options, Prev: Debugging Options, Up: Scanner Options
+
+16.6 Miscellaneous Options
+==========================
+
+`-c'
+ A do-nothing option included for POSIX compliance.
+
+`-h, -?, --help'
+ generates a "help" summary of `flex''s options to `stdout' and
+ then exits.
+
+`-n'
+ Another do-nothing option included for POSIX compliance.
+
+`-V, --version'
+ prints the version number to `stdout' and exits.
+
+
+
+File: flex.info, Node: Performance, Next: Cxx, Prev: Scanner Options, Up: Top
+
+17 Performance Considerations
+*****************************
+
+The main design goal of `flex' is that it generate high-performance
+scanners. It has been optimized for dealing well with large sets of
+rules. Aside from the effects on scanner speed of the table compression
+`-C' options outlined above, there are a number of options/actions
+which degrade performance. These are, from most expensive to least:
+
+
+ REJECT
+ arbitrary trailing context
+
+ pattern sets that require backing up
+ %option yylineno
+ %array
+
+ %option interactive
+ %option always-interactive
+
+ @samp{^} beginning-of-line operator
+ yymore()
+
+ with the first two all being quite expensive and the last two being
+quite cheap. Note also that `unput()' is implemented as a routine call
+that potentially does quite a bit of work, while `yyless()' is a
+quite-cheap macro. So if you are just putting back some excess text you
+scanned, use `yyless()'.
+
+ `REJECT' should be avoided at all costs when performance is
+important. It is a particularly expensive option.
+
+ There is one case when `%option yylineno' can be expensive. That is
+when your patterns match long tokens that could _possibly_ contain a
+newline character. There is no performance penalty for rules that can
+not possibly match newlines, since flex does not need to check them for
+newlines. In general, you should avoid rules such as `[^f]+', which
+match very long tokens, including newlines, and may possibly match your
+entire file! A better approach is to separate `[^f]+' into two rules:
+
+
+ %option yylineno
+ %%
+ [^f\n]+
+ \n+
+
+ The above scanner does not incur a performance penalty.
+
+ Getting rid of backing up is messy and often may be an enormous
+amount of work for a complicated scanner. In principal, one begins by
+using the `-b' flag to generate a `lex.backup' file. For example, on
+the input:
+
+
+ %%
+ foo return TOK_KEYWORD;
+ foobar return TOK_KEYWORD;
+
+ the file looks like:
+
+
+ State #6 is non-accepting -
+ associated rule line numbers:
+ 2 3
+ out-transitions: [ o ]
+ jam-transitions: EOF [ \001-n p-\177 ]
+
+ State #8 is non-accepting -
+ associated rule line numbers:
+ 3
+ out-transitions: [ a ]
+ jam-transitions: EOF [ \001-` b-\177 ]
+
+ State #9 is non-accepting -
+ associated rule line numbers:
+ 3
+ out-transitions: [ r ]
+ jam-transitions: EOF [ \001-q s-\177 ]
+
+ Compressed tables always back up.
+
+ The first few lines tell us that there's a scanner state in which it
+can make a transition on an 'o' but not on any other character, and
+that in that state the currently scanned text does not match any rule.
+The state occurs when trying to match the rules found at lines 2 and 3
+in the input file. If the scanner is in that state and then reads
+something other than an 'o', it will have to back up to find a rule
+which is matched. With a bit of headscratching one can see that this
+must be the state it's in when it has seen `fo'. When this has
+happened, if anything other than another `o' is seen, the scanner will
+have to back up to simply match the `f' (by the default rule).
+
+ The comment regarding State #8 indicates there's a problem when
+`foob' has been scanned. Indeed, on any character other than an `a',
+the scanner will have to back up to accept "foo". Similarly, the
+comment for State #9 concerns when `fooba' has been scanned and an `r'
+does not follow.
+
+ The final comment reminds us that there's no point going to all the
+trouble of removing backing up from the rules unless we're using `-Cf'
+or `-CF', since there's no performance gain doing so with compressed
+scanners.
+
+ The way to remove the backing up is to add "error" rules:
+
+
+ %%
+ foo return TOK_KEYWORD;
+ foobar return TOK_KEYWORD;
+
+ fooba |
+ foob |
+ fo {
+ /* false alarm, not really a keyword */
+ return TOK_ID;
+ }
+
+ Eliminating backing up among a list of keywords can also be done
+using a "catch-all" rule:
+
+
+ %%
+ foo return TOK_KEYWORD;
+ foobar return TOK_KEYWORD;
+
+ [a-z]+ return TOK_ID;
+
+ This is usually the best solution when appropriate.
+
+ Backing up messages tend to cascade. With a complicated set of rules
+it's not uncommon to get hundreds of messages. If one can decipher
+them, though, it often only takes a dozen or so rules to eliminate the
+backing up (though it's easy to make a mistake and have an error rule
+accidentally match a valid token. A possible future `flex' feature
+will be to automatically add rules to eliminate backing up).
+
+ It's important to keep in mind that you gain the benefits of
+eliminating backing up only if you eliminate _every_ instance of
+backing up. Leaving just one means you gain nothing.
+
+ _Variable_ trailing context (where both the leading and trailing
+parts do not have a fixed length) entails almost the same performance
+loss as `REJECT' (i.e., substantial). So when possible a rule like:
+
+
+ %%
+ mouse|rat/(cat|dog) run();
+
+ is better written:
+
+
+ %%
+ mouse/cat|dog run();
+ rat/cat|dog run();
+
+ or as
+
+
+ %%
+ mouse|rat/cat run();
+ mouse|rat/dog run();
+
+ Note that here the special '|' action does _not_ provide any
+savings, and can even make things worse (*note Limitations::).
+
+ Another area where the user can increase a scanner's performance (and
+one that's easier to implement) arises from the fact that the longer the
+tokens matched, the faster the scanner will run. This is because with
+long tokens the processing of most input characters takes place in the
+(short) inner scanning loop, and does not often have to go through the
+additional work of setting up the scanning environment (e.g., `yytext')
+for the action. Recall the scanner for C comments:
+
+
+ %x comment
+ %%
+ int line_num = 1;
+
+ "/*" BEGIN(comment);
+
+ <comment>[^*\n]*
+ <comment>"*"+[^*/\n]*
+ <comment>\n ++line_num;
+ <comment>"*"+"/" BEGIN(INITIAL);
+
+ This could be sped up by writing it as:
+
+
+ %x comment
+ %%
+ int line_num = 1;
+
+ "/*" BEGIN(comment);
+
+ <comment>[^*\n]*
+ <comment>[^*\n]*\n ++line_num;
+ <comment>"*"+[^*/\n]*
+ <comment>"*"+[^*/\n]*\n ++line_num;
+ <comment>"*"+"/" BEGIN(INITIAL);
+
+ Now instead of each newline requiring the processing of another
+action, recognizing the newlines is distributed over the other rules to
+keep the matched text as long as possible. Note that _adding_ rules
+does _not_ slow down the scanner! The speed of the scanner is
+independent of the number of rules or (modulo the considerations given
+at the beginning of this section) how complicated the rules are with
+regard to operators such as `*' and `|'.
+
+ A final example in speeding up a scanner: suppose you want to scan
+through a file containing identifiers and keywords, one per line and
+with no other extraneous characters, and recognize all the keywords. A
+natural first approach is:
+
+
+ %%
+ asm |
+ auto |
+ break |
+ ... etc ...
+ volatile |
+ while /* it's a keyword */
+
+ .|\n /* it's not a keyword */
+
+ To eliminate the back-tracking, introduce a catch-all rule:
+
+
+ %%
+ asm |
+ auto |
+ break |
+ ... etc ...
+ volatile |
+ while /* it's a keyword */
+
+ [a-z]+ |
+ .|\n /* it's not a keyword */
+
+ Now, if it's guaranteed that there's exactly one word per line, then
+we can reduce the total number of matches by a half by merging in the
+recognition of newlines with that of the other tokens:
+
+
+ %%
+ asm\n |
+ auto\n |
+ break\n |
+ ... etc ...
+ volatile\n |
+ while\n /* it's a keyword */
+
+ [a-z]+\n |
+ .|\n /* it's not a keyword */
+
+ One has to be careful here, as we have now reintroduced backing up
+into the scanner. In particular, while _we_ know that there will never
+be any characters in the input stream other than letters or newlines,
+`flex' can't figure this out, and it will plan for possibly needing to
+back up when it has scanned a token like `auto' and then the next
+character is something other than a newline or a letter. Previously it
+would then just match the `auto' rule and be done, but now it has no
+`auto' rule, only a `auto\n' rule. To eliminate the possibility of
+backing up, we could either duplicate all rules but without final
+newlines, or, since we never expect to encounter such an input and
+therefore don't how it's classified, we can introduce one more
+catch-all rule, this one which doesn't include a newline:
+
+
+ %%
+ asm\n |
+ auto\n |
+ break\n |
+ ... etc ...
+ volatile\n |
+ while\n /* it's a keyword */
+
+ [a-z]+\n |
+ [a-z]+ |
+ .|\n /* it's not a keyword */
+
+ Compiled with `-Cf', this is about as fast as one can get a `flex'
+scanner to go for this particular problem.
+
+ A final note: `flex' is slow when matching `NUL's, particularly when
+a token contains multiple `NUL's. It's best to write rules which match
+_short_ amounts of text if it's anticipated that the text will often
+include `NUL's.
+
+ Another final note regarding performance: as mentioned in *Note
+Matching::, dynamically resizing `yytext' to accommodate huge tokens is
+a slow process because it presently requires that the (huge) token be
+rescanned from the beginning. Thus if performance is vital, you should
+attempt to match "large" quantities of text but not "huge" quantities,
+where the cutoff between the two is at about 8K characters per token.
+
+
+File: flex.info, Node: Cxx, Next: Reentrant, Prev: Performance, Up: Top
+
+18 Generating C++ Scanners
+**************************
+
+*IMPORTANT*: the present form of the scanning class is _experimental_
+and may change considerably between major releases.
+
+ `flex' provides two different ways to generate scanners for use with
+C++. The first way is to simply compile a scanner generated by `flex'
+using a C++ compiler instead of a C compiler. You should not encounter
+any compilation errors (*note Reporting Bugs::). You can then use C++
+code in your rule actions instead of C code. Note that the default
+input source for your scanner remains `yyin', and default echoing is
+still done to `yyout'. Both of these remain `FILE *' variables and not
+C++ _streams_.
+
+ You can also use `flex' to generate a C++ scanner class, using the
+`-+' option (or, equivalently, `%option c++)', which is automatically
+specified if the name of the `flex' executable ends in a '+', such as
+`flex++'. When using this option, `flex' defaults to generating the
+scanner to the file `lex.yy.cc' instead of `lex.yy.c'. The generated
+scanner includes the header file `FlexLexer.h', which defines the
+interface to two C++ classes.
+
+ The first class, `FlexLexer', provides an abstract base class
+defining the general scanner class interface. It provides the
+following member functions:
+
+`const char* YYText()'
+ returns the text of the most recently matched token, the
+ equivalent of `yytext'.
+
+`int YYLeng()'
+ returns the length of the most recently matched token, the
+ equivalent of `yyleng'.
+
+`int lineno() const'
+ returns the current input line number (see `%option yylineno)', or
+ `1' if `%option yylineno' was not used.
+
+`void set_debug( int flag )'
+ sets the debugging flag for the scanner, equivalent to assigning to
+ `yy_flex_debug' (*note Scanner Options::). Note that you must
+ build the scanner using `%option debug' to include debugging
+ information in it.
+
+`int debug() const'
+ returns the current setting of the debugging flag.
+
+ Also provided are member functions equivalent to
+`yy_switch_to_buffer()', `yy_create_buffer()' (though the first
+argument is an `istream*' object pointer and not a `FILE*)',
+`yy_flush_buffer()', `yy_delete_buffer()', and `yyrestart()' (again,
+the first argument is a `istream*' object pointer).
+
+ The second class defined in `FlexLexer.h' is `yyFlexLexer', which is
+derived from `FlexLexer'. It defines the following additional member
+functions:
+
+`yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )'
+ constructs a `yyFlexLexer' object using the given streams for input
+ and output. If not specified, the streams default to `cin' and
+ `cout', respectively.
+
+`virtual int yylex()'
+ performs the same role is `yylex()' does for ordinary `flex'
+ scanners: it scans the input stream, consuming tokens, until a
+ rule's action returns a value. If you derive a subclass `S' from
+ `yyFlexLexer' and want to access the member functions and variables
+ of `S' inside `yylex()', then you need to use `%option
+ yyclass="S"' to inform `flex' that you will be using that subclass
+ instead of `yyFlexLexer'. In this case, rather than generating
+ `yyFlexLexer::yylex()', `flex' generates `S::yylex()' (and also
+ generates a dummy `yyFlexLexer::yylex()' that calls
+ `yyFlexLexer::LexerError()' if called).
+
+`virtual void switch_streams(istream* new_in = 0, ostream* new_out = 0)'
+ reassigns `yyin' to `new_in' (if non-null) and `yyout' to
+ `new_out' (if non-null), deleting the previous input buffer if
+ `yyin' is reassigned.
+
+`int yylex( istream* new_in, ostream* new_out = 0 )'
+ first switches the input streams via `switch_streams( new_in,
+ new_out )' and then returns the value of `yylex()'.
+
+ In addition, `yyFlexLexer' defines the following protected virtual
+functions which you can redefine in derived classes to tailor the
+scanner:
+
+`virtual int LexerInput( char* buf, int max_size )'
+ reads up to `max_size' characters into `buf' and returns the
+ number of characters read. To indicate end-of-input, return 0
+ characters. Note that `interactive' scanners (see the `-B' and
+ `-I' flags in *Note Scanner Options::) define the macro
+ `YY_INTERACTIVE'. If you redefine `LexerInput()' and need to take
+ different actions depending on whether or not the scanner might be
+ scanning an interactive input source, you can test for the
+ presence of this name via `#ifdef' statements.
+
+`virtual void LexerOutput( const char* buf, int size )'
+ writes out `size' characters from the buffer `buf', which, while
+ `NUL'-terminated, may also contain internal `NUL's if the
+ scanner's rules can match text with `NUL's in them.
+
+`virtual void LexerError( const char* msg )'
+ reports a fatal error message. The default version of this
+ function writes the message to the stream `cerr' and exits.
+
+ Note that a `yyFlexLexer' object contains its _entire_ scanning
+state. Thus you can use such objects to create reentrant scanners, but
+see also *Note Reentrant::. You can instantiate multiple instances of
+the same `yyFlexLexer' class, and you can also combine multiple C++
+scanner classes together in the same program using the `-P' option
+discussed above.
+
+ Finally, note that the `%array' feature is not available to C++
+scanner classes; you must use `%pointer' (the default).
+
+ Here is an example of a simple C++ scanner:
+
+
+ // An example of using the flex C++ scanner class.
+
+ %{
+ int mylineno = 0;
+ %}
+
+ string \"[^\n"]+\"
+
+ ws [ \t]+
+
+ alpha [A-Za-z]
+ dig [0-9]
+ name ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$])*
+ num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)?
+ num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
+ number {num1}|{num2}
+
+ %%
+
+ {ws} /* skip blanks and tabs */
+
+ "/*" {
+ int c;
+
+ while((c = yyinput()) != 0)
+ {
+ if(c == '\n')
+ ++mylineno;
+
+ else if(c == @samp{*})
+ {
+ if((c = yyinput()) == '/')
+ break;
+ else
+ unput(c);
+ }
+ }
+ }
+
+ {number} cout "number " YYText() '\n';
+
+ \n mylineno++;
+
+ {name} cout "name " YYText() '\n';
+
+ {string} cout "string " YYText() '\n';
+
+ %%
+
+ int main( int /* argc */, char** /* argv */ )
+ {
+ @code{flex}Lexer* lexer = new yyFlexLexer;
+ while(lexer->yylex() != 0)
+ ;
+ return 0;
+ }
+
+ If you want to create multiple (different) lexer classes, you use the
+`-P' flag (or the `prefix=' option) to rename each `yyFlexLexer' to
+some other `xxFlexLexer'. You then can include `<FlexLexer.h>' in your
+other sources once per lexer class, first renaming `yyFlexLexer' as
+follows:
+
+
+ #undef yyFlexLexer
+ #define yyFlexLexer xxFlexLexer
+ #include <FlexLexer.h>
+
+ #undef yyFlexLexer
+ #define yyFlexLexer zzFlexLexer
+ #include <FlexLexer.h>
+
+ if, for example, you used `%option prefix="xx"' for one of your
+scanners and `%option prefix="zz"' for the other.
+
+
+File: flex.info, Node: Reentrant, Next: Lex and Posix, Prev: Cxx, Up: Top
+
+19 Reentrant C Scanners
+***********************
+
+`flex' has the ability to generate a reentrant C scanner. This is
+accomplished by specifying `%option reentrant' (`-R') The generated
+scanner is both portable, and safe to use in one or more separate
+threads of control. The most common use for reentrant scanners is from
+within multi-threaded applications. Any thread may create and execute
+a reentrant `flex' scanner without the need for synchronization with
+other threads.
+
+* Menu:
+
+* Reentrant Uses::
+* Reentrant Overview::
+* Reentrant Example::
+* Reentrant Detail::
+* Reentrant Functions::
+
+
+File: flex.info, Node: Reentrant Uses, Next: Reentrant Overview, Prev: Reentrant, Up: Reentrant
+
+19.1 Uses for Reentrant Scanners
+================================
+
+However, there are other uses for a reentrant scanner. For example, you
+could scan two or more files simultaneously to implement a `diff' at
+the token level (i.e., instead of at the character level):
+
+
+ /* Example of maintaining more than one active scanner. */
+
+ do {
+ int tok1, tok2;
+
+ tok1 = yylex( scanner_1 );
+ tok2 = yylex( scanner_2 );
+
+ if( tok1 != tok2 )
+ printf("Files are different.");
+
+ } while ( tok1 && tok2 );
+
+ Another use for a reentrant scanner is recursion. (Note that a
+recursive scanner can also be created using a non-reentrant scanner and
+buffer states. *Note Multiple Input Buffers::.)
+
+ The following crude scanner supports the `eval' command by invoking
+another instance of itself.
+
+
+ /* Example of recursive invocation. */
+
+ %option reentrant
+
+ %%
+ "eval(".+")" {
+ yyscan_t scanner;
+ YY_BUFFER_STATE buf;
+
+ yylex_init( &scanner );
+ yytext[yyleng-1] = ' ';
+
+ buf = yy_scan_string( yytext + 5, scanner );
+ yylex( scanner );
+
+ yy_delete_buffer(buf,scanner);
+ yylex_destroy( scanner );
+ }
+ ...
+ %%
+
+
+File: flex.info, Node: Reentrant Overview, Next: Reentrant Example, Prev: Reentrant Uses, Up: Reentrant
+
+19.2 An Overview of the Reentrant API
+=====================================
+
+The API for reentrant scanners is different than for non-reentrant
+scanners. Here is a quick overview of the API:
+
+ `%option reentrant' must be specified.
+
+ * All functions take one additional argument: `yyscanner'
+
+ * All global variables are replaced by their macro equivalents. (We
+ tell you this because it may be important to you during debugging.)
+
+ * `yylex_init' and `yylex_destroy' must be called before and after
+ `yylex', respectively.
+
+ * Accessor methods (get/set functions) provide access to common
+ `flex' variables.
+
+ * User-specific data can be stored in `yyextra'.
+
+
+File: flex.info, Node: Reentrant Example, Next: Reentrant Detail, Prev: Reentrant Overview, Up: Reentrant
+
+19.3 Reentrant Example
+======================
+
+First, an example of a reentrant scanner:
+
+ /* This scanner prints "//" comments. */
+
+ %option reentrant stack noyywrap
+ %x COMMENT
+
+ %%
+
+ "//" yy_push_state( COMMENT, yyscanner);
+ .|\n
+
+ <COMMENT>\n yy_pop_state( yyscanner );
+ <COMMENT>[^\n]+ fprintf( yyout, "%s\n", yytext);
+
+ %%
+
+ int main ( int argc, char * argv[] )
+ {
+ yyscan_t scanner;
+
+ yylex_init ( &scanner );
+ yylex ( scanner );
+ yylex_destroy ( scanner );
+ return 0;
+ }
+
+
+File: flex.info, Node: Reentrant Detail, Next: Reentrant Functions, Prev: Reentrant Example, Up: Reentrant
+
+19.4 The Reentrant API in Detail
+================================
+
+Here are the things you need to do or know to use the reentrant C API of
+`flex'.
+
+* Menu:
+
+* Specify Reentrant::
+* Extra Reentrant Argument::
+* Global Replacement::
+* Init and Destroy Functions::
+* Accessor Methods::
+* Extra Data::
+* About yyscan_t::
+
+
+File: flex.info, Node: Specify Reentrant, Next: Extra Reentrant Argument, Prev: Reentrant Detail, Up: Reentrant Detail
+
+19.4.1 Declaring a Scanner As Reentrant
+---------------------------------------
+
+%option reentrant (-reentrant) must be specified.
+
+ Notice that `%option reentrant' is specified in the above example
+(*note Reentrant Example::. Had this option not been specified, `flex'
+would have happily generated a non-reentrant scanner without
+complaining. You may explicitly specify `%option noreentrant', if you
+do _not_ want a reentrant scanner, although it is not necessary. The
+default is to generate a non-reentrant scanner.
+
+
+File: flex.info, Node: Extra Reentrant Argument, Next: Global Replacement, Prev: Specify Reentrant, Up: Reentrant Detail
+
+19.4.2 The Extra Argument
+-------------------------
+
+All functions take one additional argument: `yyscanner'.
+
+ Notice that the calls to `yy_push_state' and `yy_pop_state' both
+have an argument, `yyscanner' , that is not present in a non-reentrant
+scanner. Here are the declarations of `yy_push_state' and
+`yy_pop_state' in the reentrant scanner:
+
+
+ static void yy_push_state ( int new_state , yyscan_t yyscanner ) ;
+ static void yy_pop_state ( yyscan_t yyscanner ) ;
+
+ Notice that the argument `yyscanner' appears in the declaration of
+both functions. In fact, all `flex' functions in a reentrant scanner
+have this additional argument. It is always the last argument in the
+argument list, it is always of type `yyscan_t' (which is typedef'd to
+`void *') and it is always named `yyscanner'. As you may have guessed,
+`yyscanner' is a pointer to an opaque data structure encapsulating the
+current state of the scanner. For a list of function declarations, see
+*Note Reentrant Functions::. Note that preprocessor macros, such as
+`BEGIN', `ECHO', and `REJECT', do not take this additional argument.
+
+
+File: flex.info, Node: Global Replacement, Next: Init and Destroy Functions, Prev: Extra Reentrant Argument, Up: Reentrant Detail
+
+19.4.3 Global Variables Replaced By Macros
+------------------------------------------
+
+All global variables in traditional flex have been replaced by macro
+equivalents.
+
+ Note that in the above example, `yyout' and `yytext' are not plain
+variables. These are macros that will expand to their equivalent lvalue.
+All of the familiar `flex' globals have been replaced by their macro
+equivalents. In particular, `yytext', `yyleng', `yylineno', `yyin',
+`yyout', `yyextra', `yylval', and `yylloc' are macros. You may safely
+use these macros in actions as if they were plain variables. We only
+tell you this so you don't expect to link to these variables
+externally. Currently, each macro expands to a member of an internal
+struct, e.g.,
+
+
+ #define yytext (((struct yyguts_t*)yyscanner)->yytext_r)
+
+ One important thing to remember about `yytext' and friends is that
+`yytext' is not a global variable in a reentrant scanner, you can not
+access it directly from outside an action or from other functions. You
+must use an accessor method, e.g., `yyget_text', to accomplish this.
+(See below).
+
+
+File: flex.info, Node: Init and Destroy Functions, Next: Accessor Methods, Prev: Global Replacement, Up: Reentrant Detail
+
+19.4.4 Init and Destroy Functions
+---------------------------------
+
+`yylex_init' and `yylex_destroy' must be called before and after
+`yylex', respectively.
+
+
+ int yylex_init ( yyscan_t * ptr_yy_globals ) ;
+ int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t * ptr_yy_globals ) ;
+ int yylex ( yyscan_t yyscanner ) ;
+ int yylex_destroy ( yyscan_t yyscanner ) ;
+
+ The function `yylex_init' must be called before calling any other
+function. The argument to `yylex_init' is the address of an
+uninitialized pointer to be filled in by `yylex_init', overwriting any
+previous contents. The function `yylex_init_extra' may be used instead,
+taking as its first argument a variable of type `YY_EXTRA_TYPE'. See
+the section on yyextra, below, for more details.
+
+ The value stored in `ptr_yy_globals' should thereafter be passed to
+`yylex' and `yylex_destroy'. Flex does not save the argument passed to
+`yylex_init', so it is safe to pass the address of a local pointer to
+`yylex_init' so long as it remains in scope for the duration of all
+calls to the scanner, up to and including the call to `yylex_destroy'.
+
+ The function `yylex' should be familiar to you by now. The reentrant
+version takes one argument, which is the value returned (via an
+argument) by `yylex_init'. Otherwise, it behaves the same as the
+non-reentrant version of `yylex'.
+
+ Both `yylex_init' and `yylex_init_extra' returns 0 (zero) on success,
+or non-zero on failure, in which case errno is set to one of the
+following values:
+
+ * ENOMEM Memory allocation error. *Note memory-management::.
+
+ * EINVAL Invalid argument.
+
+ The function `yylex_destroy' should be called to free resources used
+by the scanner. After `yylex_destroy' is called, the contents of
+`yyscanner' should not be used. Of course, there is no need to destroy
+a scanner if you plan to reuse it. A `flex' scanner (both reentrant
+and non-reentrant) may be restarted by calling `yyrestart'.
+
+ Below is an example of a program that creates a scanner, uses it,
+then destroys it when done:
+
+
+ int main ()
+ {
+ yyscan_t scanner;
+ int tok;
+
+ yylex_init(&scanner);
+
+ while ((tok=yylex()) > 0)
+ printf("tok=%d yytext=%s\n", tok, yyget_text(scanner));
+
+ yylex_destroy(scanner);
+ return 0;
+ }
+
+
+File: flex.info, Node: Accessor Methods, Next: Extra Data, Prev: Init and Destroy Functions, Up: Reentrant Detail
+
+19.4.5 Accessing Variables with Reentrant Scanners
+--------------------------------------------------
+
+Accessor methods (get/set functions) provide access to common `flex'
+variables.
+
+ Many scanners that you build will be part of a larger project.
+Portions of your project will need access to `flex' values, such as
+`yytext'. In a non-reentrant scanner, these values are global, so
+there is no problem accessing them. However, in a reentrant scanner,
+there are no global `flex' values. You can not access them directly.
+Instead, you must access `flex' values using accessor methods (get/set
+functions). Each accessor method is named `yyget_NAME' or `yyset_NAME',
+where `NAME' is the name of the `flex' variable you want. For example:
+
+
+ /* Set the last character of yytext to NULL. */
+ void chop ( yyscan_t scanner )
+ {
+ int len = yyget_leng( scanner );
+ yyget_text( scanner )[len - 1] = '\0';
+ }
+
+ The above code may be called from within an action like this:
+
+
+ %%
+ .+\n { chop( yyscanner );}
+
+ You may find that `%option header-file' is particularly useful for
+generating prototypes of all the accessor functions. *Note
+option-header::.
+
+
+File: flex.info, Node: Extra Data, Next: About yyscan_t, Prev: Accessor Methods, Up: Reentrant Detail
+
+19.4.6 Extra Data
+-----------------
+
+User-specific data can be stored in `yyextra'.
+
+ In a reentrant scanner, it is unwise to use global variables to
+communicate with or maintain state between different pieces of your
+program. However, you may need access to external data or invoke
+external functions from within the scanner actions. Likewise, you may
+need to pass information to your scanner (e.g., open file descriptors,
+or database connections). In a non-reentrant scanner, the only way to
+do this would be through the use of global variables. `Flex' allows
+you to store arbitrary, "extra" data in a scanner. This data is
+accessible through the accessor methods `yyget_extra' and `yyset_extra'
+from outside the scanner, and through the shortcut macro `yyextra' from
+within the scanner itself. They are defined as follows:
+
+
+ #define YY_EXTRA_TYPE void*
+ YY_EXTRA_TYPE yyget_extra ( yyscan_t scanner );
+ void yyset_extra ( YY_EXTRA_TYPE arbitrary_data , yyscan_t scanner);
+
+ In addition, an extra form of `yylex_init' is provided,
+`yylex_init_extra'. This function is provided so that the yyextra value
+can be accessed from within the very first yyalloc, used to allocate
+the scanner itself.
+
+ By default, `YY_EXTRA_TYPE' is defined as type `void *'. You may
+redefine this type using `%option extra-type="your_type"' in the
+scanner:
+
+
+ /* An example of overriding YY_EXTRA_TYPE. */
+ %{
+ #include <sys/stat.h>
+ #include <unistd.h>
+ %}
+ %option reentrant
+ %option extra-type="struct stat *"
+ %%
+
+ __filesize__ printf( "%ld", yyextra->st_size );
+ __lastmod__ printf( "%ld", yyextra->st_mtime );
+ %%
+ void scan_file( char* filename )
+ {
+ yyscan_t scanner;
+ struct stat buf;
+ FILE *in;
+
+ in = fopen( filename, "r" );
+ stat( filename, &buf );
+
+ yylex_init_extra( buf, &scanner );
+ yyset_in( in, scanner );
+ yylex( scanner );
+ yylex_destroy( scanner );
+
+ fclose( in );
+ }
+
+
+File: flex.info, Node: About yyscan_t, Prev: Extra Data, Up: Reentrant Detail
+
+19.4.7 About yyscan_t
+---------------------
+
+`yyscan_t' is defined as:
+
+
+ typedef void* yyscan_t;
+
+ It is initialized by `yylex_init()' to point to an internal
+structure. You should never access this value directly. In particular,
+you should never attempt to free it (use `yylex_destroy()' instead.)
+
+
+File: flex.info, Node: Reentrant Functions, Prev: Reentrant Detail, Up: Reentrant
+
+19.5 Functions and Macros Available in Reentrant C Scanners
+===========================================================
+
+The following Functions are available in a reentrant scanner:
+
+
+ char *yyget_text ( yyscan_t scanner );
+ int yyget_leng ( yyscan_t scanner );
+ FILE *yyget_in ( yyscan_t scanner );
+ FILE *yyget_out ( yyscan_t scanner );
+ int yyget_lineno ( yyscan_t scanner );
+ YY_EXTRA_TYPE yyget_extra ( yyscan_t scanner );
+ int yyget_debug ( yyscan_t scanner );
+
+ void yyset_debug ( int flag, yyscan_t scanner );
+ void yyset_in ( FILE * in_str , yyscan_t scanner );
+ void yyset_out ( FILE * out_str , yyscan_t scanner );
+ void yyset_lineno ( int line_number , yyscan_t scanner );
+ void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t scanner );
+
+ There are no "set" functions for yytext and yyleng. This is
+intentional.
+
+ The following Macro shortcuts are available in actions in a reentrant
+scanner:
+
+
+ yytext
+ yyleng
+ yyin
+ yyout
+ yylineno
+ yyextra
+ yy_flex_debug
+
+ In a reentrant C scanner, support for yylineno is always present
+(i.e., you may access yylineno), but the value is never modified by
+`flex' unless `%option yylineno' is enabled. This is to allow the user
+to maintain the line count independently of `flex'.
+
+ The following functions and macros are made available when `%option
+bison-bridge' (`--bison-bridge') is specified:
+
+
+ YYSTYPE * yyget_lval ( yyscan_t scanner );
+ void yyset_lval ( YYSTYPE * yylvalp , yyscan_t scanner );
+ yylval
+
+ The following functions and macros are made available when `%option
+bison-locations' (`--bison-locations') is specified:
+
+
+ YYLTYPE *yyget_lloc ( yyscan_t scanner );
+ void yyset_lloc ( YYLTYPE * yyllocp , yyscan_t scanner );
+ yylloc
+
+ Support for yylval assumes that `YYSTYPE' is a valid type. Support
+for yylloc assumes that `YYSLYPE' is a valid type. Typically, these
+types are generated by `bison', and are included in section 1 of the
+`flex' input.
+
+
+File: flex.info, Node: Lex and Posix, Next: Memory Management, Prev: Reentrant, Up: Top
+
+20 Incompatibilities with Lex and Posix
+***************************************
+
+`flex' is a rewrite of the AT&T Unix _lex_ tool (the two
+implementations do not share any code, though), with some extensions and
+incompatibilities, both of which are of concern to those who wish to
+write scanners acceptable to both implementations. `flex' is fully
+compliant with the POSIX `lex' specification, except that when using
+`%pointer' (the default), a call to `unput()' destroys the contents of
+`yytext', which is counter to the POSIX specification. In this section
+we discuss all of the known areas of incompatibility between `flex',
+AT&T `lex', and the POSIX specification. `flex''s `-l' option turns on
+maximum compatibility with the original AT&T `lex' implementation, at
+the cost of a major loss in the generated scanner's performance. We
+note below which incompatibilities can be overcome using the `-l'
+option. `flex' is fully compatible with `lex' with the following
+exceptions:
+
+ * The undocumented `lex' scanner internal variable `yylineno' is not
+ supported unless `-l' or `%option yylineno' is used.
+
+ * `yylineno' should be maintained on a per-buffer basis, rather than
+ a per-scanner (single global variable) basis.
+
+ * `yylineno' is not part of the POSIX specification.
+
+ * The `input()' routine is not redefinable, though it may be called
+ to read characters following whatever has been matched by a rule.
+ If `input()' encounters an end-of-file the normal `yywrap()'
+ processing is done. A "real" end-of-file is returned by `input()'
+ as `EOF'.
+
+ * Input is instead controlled by defining the `YY_INPUT()' macro.
+
+ * The `flex' restriction that `input()' cannot be redefined is in
+ accordance with the POSIX specification, which simply does not
+ specify any way of controlling the scanner's input other than by
+ making an initial assignment to `yyin'.
+
+ * The `unput()' routine is not redefinable. This restriction is in
+ accordance with POSIX.
+
+ * `flex' scanners are not as reentrant as `lex' scanners. In
+ particular, if you have an interactive scanner and an interrupt
+ handler which long-jumps out of the scanner, and the scanner is
+ subsequently called again, you may get the following message:
+
+
+ fatal @code{flex} scanner internal error--end of buffer missed
+
+ To reenter the scanner, first use:
+
+
+ yyrestart( yyin );
+
+ Note that this call will throw away any buffered input; usually
+ this isn't a problem with an interactive scanner. *Note
+ Reentrant::, for `flex''s reentrant API.
+
+ * Also note that `flex' C++ scanner classes _are_ reentrant, so if
+ using C++ is an option for you, you should use them instead.
+ *Note Cxx::, and *Note Reentrant:: for details.
+
+ * `output()' is not supported. Output from the ECHO macro is done
+ to the file-pointer `yyout' (default `stdout)'.
+
+ * `output()' is not part of the POSIX specification.
+
+ * `lex' does not support exclusive start conditions (%x), though they
+ are in the POSIX specification.
+
+ * When definitions are expanded, `flex' encloses them in parentheses.
+ With `lex', the following:
+
+
+ NAME [A-Z][A-Z0-9]*
+ %%
+ foo{NAME}? printf( "Found it\n" );
+ %%
+
+ will not match the string `foo' because when the macro is expanded
+ the rule is equivalent to `foo[A-Z][A-Z0-9]*?' and the precedence
+ is such that the `?' is associated with `[A-Z0-9]*'. With `flex',
+ the rule will be expanded to `foo([A-Z][A-Z0-9]*)?' and so the
+ string `foo' will match.
+
+ * Note that if the definition begins with `^' or ends with `$' then
+ it is _not_ expanded with parentheses, to allow these operators to
+ appear in definitions without losing their special meanings. But
+ the `<s>', `/', and `<<EOF>>' operators cannot be used in a `flex'
+ definition.
+
+ * Using `-l' results in the `lex' behavior of no parentheses around
+ the definition.
+
+ * The POSIX specification is that the definition be enclosed in
+ parentheses.
+
+ * Some implementations of `lex' allow a rule's action to begin on a
+ separate line, if the rule's pattern has trailing whitespace:
+
+
+ %%
+ foo|bar<space here>
+ { foobar_action();}
+
+ `flex' does not support this feature.
+
+ * The `lex' `%r' (generate a Ratfor scanner) option is not
+ supported. It is not part of the POSIX specification.
+
+ * After a call to `unput()', _yytext_ is undefined until the next
+ token is matched, unless the scanner was built using `%array'.
+ This is not the case with `lex' or the POSIX specification. The
+ `-l' option does away with this incompatibility.
+
+ * The precedence of the `{,}' (numeric range) operator is different.
+ The AT&T and POSIX specifications of `lex' interpret `abc{1,3}'
+ as match one, two, or three occurrences of `abc'", whereas `flex'
+ interprets it as "match `ab' followed by one, two, or three
+ occurrences of `c'". The `-l' and `--posix' options do away with
+ this incompatibility.
+
+ * The precedence of the `^' operator is different. `lex' interprets
+ `^foo|bar' as "match either 'foo' at the beginning of a line, or
+ 'bar' anywhere", whereas `flex' interprets it as "match either
+ `foo' or `bar' if they come at the beginning of a line". The
+ latter is in agreement with the POSIX specification.
+
+ * The special table-size declarations such as `%a' supported by
+ `lex' are not required by `flex' scanners.. `flex' ignores them.
+
+ * The name `FLEX_SCANNER' is `#define''d so scanners may be written
+ for use with either `flex' or `lex'. Scanners also include
+ `YY_FLEX_MAJOR_VERSION', `YY_FLEX_MINOR_VERSION' and
+ `YY_FLEX_SUBMINOR_VERSION' indicating which version of `flex'
+ generated the scanner. For example, for the 2.5.22 release, these
+ defines would be 2, 5 and 22 respectively. If the version of
+ `flex' being used is a beta version, then the symbol `FLEX_BETA'
+ is defined.
+
+ * The symbols `[[' and `]]' in the code sections of the input may
+ conflict with the m4 delimiters. *Note M4 Dependency::.
+
+
+ The following `flex' features are not included in `lex' or the POSIX
+specification:
+
+ * C++ scanners
+
+ * %option
+
+ * start condition scopes
+
+ * start condition stacks
+
+ * interactive/non-interactive scanners
+
+ * yy_scan_string() and friends
+
+ * yyterminate()
+
+ * yy_set_interactive()
+
+ * yy_set_bol()
+
+ * YY_AT_BOL() <<EOF>>
+
+ * <*>
+
+ * YY_DECL
+
+ * YY_START
+
+ * YY_USER_ACTION
+
+ * YY_USER_INIT
+
+ * #line directives
+
+ * %{}'s around actions
+
+ * reentrant C API
+
+ * multiple actions on a line
+
+ * almost all of the `flex' command-line options
+
+ The feature "multiple actions on a line" refers to the fact that
+with `flex' you can put multiple actions on the same line, separated
+with semi-colons, while with `lex', the following:
+
+
+ foo handle_foo(); ++num_foos_seen;
+
+ is (rather surprisingly) truncated to
+
+
+ foo handle_foo();
+
+ `flex' does not truncate the action. Actions that are not enclosed
+in braces are simply terminated at the end of the line.
+
+
+File: flex.info, Node: Memory Management, Next: Serialized Tables, Prev: Lex and Posix, Up: Top
+
+21 Memory Management
+********************
+
+This chapter describes how flex handles dynamic memory, and how you can
+override the default behavior.
+
+* Menu:
+
+* The Default Memory Management::
+* Overriding The Default Memory Management::
+* A Note About yytext And Memory::
+
+
+File: flex.info, Node: The Default Memory Management, Next: Overriding The Default Memory Management, Prev: Memory Management, Up: Memory Management
+
+21.1 The Default Memory Management
+==================================
+
+Flex allocates dynamic memory during initialization, and once in a
+while from within a call to yylex(). Initialization takes place during
+the first call to yylex(). Thereafter, flex may reallocate more memory
+if it needs to enlarge a buffer. As of version 2.5.9 Flex will clean up
+all memory when you call `yylex_destroy' *Note faq-memory-leak::.
+
+ Flex allocates dynamic memory for four purposes, listed below (1)
+
+16kB for the input buffer.
+ Flex allocates memory for the character buffer used to perform
+ pattern matching. Flex must read ahead from the input stream and
+ store it in a large character buffer. This buffer is typically
+ the largest chunk of dynamic memory flex consumes. This buffer
+ will grow if necessary, doubling the size each time. Flex frees
+ this memory when you call yylex_destroy(). The default size of
+ this buffer (16384 bytes) is almost always too large. The ideal
+ size for this buffer is the length of the longest token expected,
+ in bytes, plus a little more. Flex will allocate a few extra
+ bytes for housekeeping. Currently, to override the size of the
+ input buffer you must `#define YY_BUF_SIZE' to whatever number of
+ bytes you want. We don't plan to change this in the near future,
+ but we reserve the right to do so if we ever add a more robust
+ memory management API.
+
+64kb for the REJECT state. This will only be allocated if you use REJECT.
+ The size is the large enough to hold the same number of states as
+ characters in the input buffer. If you override the size of the
+ input buffer (via `YY_BUF_SIZE'), then you automatically override
+ the size of this buffer as well.
+
+100 bytes for the start condition stack.
+ Flex allocates memory for the start condition stack. This is the
+ stack used for pushing start states, i.e., with yy_push_state().
+ It will grow if necessary. Since the states are simply integers,
+ this stack doesn't consume much memory. This stack is not present
+ if `%option stack' is not specified. You will rarely need to tune
+ this buffer. The ideal size for this stack is the maximum depth
+ expected. The memory for this stack is automatically destroyed
+ when you call yylex_destroy(). *Note option-stack::.
+
+40 bytes for each YY_BUFFER_STATE.
+ Flex allocates memory for each YY_BUFFER_STATE. The buffer state
+ itself is about 40 bytes, plus an additional large character
+ buffer (described above.) The initial buffer state is created
+ during initialization, and with each call to yy_create_buffer().
+ You can't tune the size of this, but you can tune the character
+ buffer as described above. Any buffer state that you explicitly
+ create by calling yy_create_buffer() is _NOT_ destroyed
+ automatically. You must call yy_delete_buffer() to free the
+ memory. The exception to this rule is that flex will delete the
+ current buffer automatically when you call yylex_destroy(). If you
+ delete the current buffer, be sure to set it to NULL. That way,
+ flex will not try to delete the buffer a second time (possibly
+ crashing your program!) At the time of this writing, flex does not
+ provide a growable stack for the buffer states. You have to
+ manage that yourself. *Note Multiple Input Buffers::.
+
+84 bytes for the reentrant scanner guts
+ Flex allocates about 84 bytes for the reentrant scanner structure
+ when you call yylex_init(). It is destroyed when the user calls
+ yylex_destroy().
+
+
+ ---------- Footnotes ----------
+
+ (1) The quantities given here are approximate, and may vary due to
+host architecture, compiler configuration, or due to future
+enhancements to flex.
+
+
+File: flex.info, Node: Overriding The Default Memory Management, Next: A Note About yytext And Memory, Prev: The Default Memory Management, Up: Memory Management
+
+21.2 Overriding The Default Memory Management
+=============================================
+
+Flex calls the functions `yyalloc', `yyrealloc', and `yyfree' when it
+needs to allocate or free memory. By default, these functions are
+wrappers around the standard C functions, `malloc', `realloc', and
+`free', respectively. You can override the default implementations by
+telling flex that you will provide your own implementations.
+
+ To override the default implementations, you must do two things:
+
+ 1. Suppress the default implementations by specifying one or more of
+ the following options:
+
+ * `%option noyyalloc'
+
+ * `%option noyyrealloc'
+
+ * `%option noyyfree'.
+
+ 2. Provide your own implementation of the following functions: (1)
+
+
+ // For a non-reentrant scanner
+ void * yyalloc (size_t bytes);
+ void * yyrealloc (void * ptr, size_t bytes);
+ void yyfree (void * ptr);
+
+ // For a reentrant scanner
+ void * yyalloc (size_t bytes, void * yyscanner);
+ void * yyrealloc (void * ptr, size_t bytes, void * yyscanner);
+ void yyfree (void * ptr, void * yyscanner);
+
+
+ In the following example, we will override all three memory
+routines. We assume that there is a custom allocator with garbage
+collection. In order to make this example interesting, we will use a
+reentrant scanner, passing a pointer to the custom allocator through
+`yyextra'.
+
+
+ %{
+ #include "some_allocator.h"
+ %}
+
+ /* Suppress the default implementations. */
+ %option noyyalloc noyyrealloc noyyfree
+ %option reentrant
+
+ /* Initialize the allocator. */
+ #define YY_EXTRA_TYPE struct allocator*
+ #define YY_USER_INIT yyextra = allocator_create();
+
+ %%
+ .|\n ;
+ %%
+
+ /* Provide our own implementations. */
+ void * yyalloc (size_t bytes, void* yyscanner) {
+ return allocator_alloc (yyextra, bytes);
+ }
+
+ void * yyrealloc (void * ptr, size_t bytes, void* yyscanner) {
+ return allocator_realloc (yyextra, bytes);
+ }
+
+ void yyfree (void * ptr, void * yyscanner) {
+ /* Do nothing -- we leave it to the garbage collector. */
+ }
+
+ ---------- Footnotes ----------
+
+ (1) It is not necessary to override all (or any) of the memory
+management routines. You may, for example, override `yyrealloc', but
+not `yyfree' or `yyalloc'.
+
+
+File: flex.info, Node: A Note About yytext And Memory, Prev: Overriding The Default Memory Management, Up: Memory Management
+
+21.3 A Note About yytext And Memory
+===================================
+
+When flex finds a match, `yytext' points to the first character of the
+match in the input buffer. The string itself is part of the input
+buffer, and is _NOT_ allocated separately. The value of yytext will be
+overwritten the next time yylex() is called. In short, the value of
+yytext is only valid from within the matched rule's action.
+
+ Often, you want the value of yytext to persist for later processing,
+i.e., by a parser with non-zero lookahead. In order to preserve yytext,
+you will have to copy it with strdup() or a similar function. But this
+introduces some headache because your parser is now responsible for
+freeing the copy of yytext. If you use a yacc or bison parser,
+(commonly used with flex), you will discover that the error recovery
+mechanisms can cause memory to be leaked.
+
+ To prevent memory leaks from strdup'd yytext, you will have to track
+the memory somehow. Our experience has shown that a garbage collection
+mechanism or a pooled memory mechanism will save you a lot of grief
+when writing parsers.
+
+
+File: flex.info, Node: Serialized Tables, Next: Diagnostics, Prev: Memory Management, Up: Top
+
+22 Serialized Tables
+********************
+
+A `flex' scanner has the ability to save the DFA tables to a file, and
+load them at runtime when needed. The motivation for this feature is
+to reduce the runtime memory footprint. Traditionally, these tables
+have been compiled into the scanner as C arrays, and are sometimes
+quite large. Since the tables are compiled into the scanner, the
+memory used by the tables can never be freed. This is a waste of
+memory, especially if an application uses several scanners, but none of
+them at the same time.
+
+ The serialization feature allows the tables to be loaded at runtime,
+before scanning begins. The tables may be discarded when scanning is
+finished.
+
+* Menu:
+
+* Creating Serialized Tables::
+* Loading and Unloading Serialized Tables::
+* Tables File Format::
+
+
+File: flex.info, Node: Creating Serialized Tables, Next: Loading and Unloading Serialized Tables, Prev: Serialized Tables, Up: Serialized Tables
+
+22.1 Creating Serialized Tables
+===============================
+
+You may create a scanner with serialized tables by specifying:
+
+
+ %option tables-file=FILE
+ or
+ --tables-file=FILE
+
+ These options instruct flex to save the DFA tables to the file FILE.
+The tables will _not_ be embedded in the generated scanner. The scanner
+will not function on its own. The scanner will be dependent upon the
+serialized tables. You must load the tables from this file at runtime
+before you can scan anything.
+
+ If you do not specify a filename to `--tables-file', the tables will
+be saved to `lex.yy.tables', where `yy' is the appropriate prefix.
+
+ If your project uses several different scanners, you can concatenate
+the serialized tables into one file, and flex will find the correct set
+of tables, using the scanner prefix as part of the lookup key. An
+example follows:
+
+
+ $ flex --tables-file --prefix=cpp cpp.l
+ $ flex --tables-file --prefix=c c.l
+ $ cat lex.cpp.tables lex.c.tables > all.tables
+
+ The above example created two scanners, `cpp', and `c'. Since we did
+not specify a filename, the tables were serialized to `lex.c.tables' and
+`lex.cpp.tables', respectively. Then, we concatenated the two files
+together into `all.tables', which we will distribute with our project.
+At runtime, we will open the file and tell flex to load the tables from
+it. Flex will find the correct tables automatically. (See next
+section).
+
+
+File: flex.info, Node: Loading and Unloading Serialized Tables, Next: Tables File Format, Prev: Creating Serialized Tables, Up: Serialized Tables
+
+22.2 Loading and Unloading Serialized Tables
+============================================
+
+If you've built your scanner with `%option tables-file', then you must
+load the scanner tables at runtime. This can be accomplished with the
+following function:
+
+ -- Function: int yytables_fload (FILE* FP [, yyscan_t SCANNER])
+ Locates scanner tables in the stream pointed to by FP and loads
+ them. Memory for the tables is allocated via `yyalloc'. You must
+ call this function before the first call to `yylex'. The argument
+ SCANNER only appears in the reentrant scanner. This function
+ returns `0' (zero) on success, or non-zero on error.
+
+ The loaded tables are *not* automatically destroyed (unloaded) when
+you call `yylex_destroy'. The reason is that you may create several
+scanners of the same type (in a reentrant scanner), each of which needs
+access to these tables. To avoid a nasty memory leak, you must call
+the following function:
+
+ -- Function: int yytables_destroy ([yyscan_t SCANNER])
+ Unloads the scanner tables. The tables must be loaded again before
+ you can scan any more data. The argument SCANNER only appears in
+ the reentrant scanner. This function returns `0' (zero) on
+ success, or non-zero on error.
+
+ *The functions `yytables_fload' and `yytables_destroy' are not
+thread-safe.* You must ensure that these functions are called exactly
+once (for each scanner type) in a threaded program, before any thread
+calls `yylex'. After the tables are loaded, they are never written to,
+and no thread protection is required thereafter - until you destroy
+them.
+
+
+File: flex.info, Node: Tables File Format, Prev: Loading and Unloading Serialized Tables, Up: Serialized Tables
+
+22.3 Tables File Format
+=======================
+
+This section defines the file format of serialized `flex' tables.
+
+ The tables format allows for one or more sets of tables to be
+specified, where each set corresponds to a given scanner. Scanners are
+indexed by name, as described below. The file format is as follows:
+
+
+ TABLE SET 1
+ +-------------------------------+
+ Header | uint32 th_magic; |
+ | uint32 th_hsize; |
+ | uint32 th_ssize; |
+ | uint16 th_flags; |
+ | char th_version[]; |
+ | char th_name[]; |
+ | uint8 th_pad64[]; |
+ +-------------------------------+
+ Table 1 | uint16 td_id; |
+ | uint16 td_flags; |
+ | uint32 td_lolen; |
+ | uint32 td_hilen; |
+ | void td_data[]; |
+ | uint8 td_pad64[]; |
+ +-------------------------------+
+ Table 2 | |
+ . . .
+ . . .
+ . . .
+ . . .
+ Table n | |
+ +-------------------------------+
+ TABLE SET 2
+ .
+ .
+ .
+ TABLE SET N
+
+ The above diagram shows that a complete set of tables consists of a
+header followed by multiple individual tables. Furthermore, multiple
+complete sets may be present in the same file, each set with its own
+header and tables. The sets are contiguous in the file. The only way to
+know if another set follows is to check the next four bytes for the
+magic number (or check for EOF). The header and tables sections are
+padded to 64-bit boundaries. Below we describe each field in detail.
+This format does not specify how the scanner will expand the given
+data, i.e., data may be serialized as int8, but expanded to an int32
+array at runtime. This is to reduce the size of the serialized data
+where possible. Remember, _all integer values are in network byte
+order_.
+
+Fields of a table header:
+
+`th_magic'
+ Magic number, always 0xF13C57B1.
+
+`th_hsize'
+ Size of this entire header, in bytes, including all fields plus
+ any padding.
+
+`th_ssize'
+ Size of this entire set, in bytes, including the header, all
+ tables, plus any padding.
+
+`th_flags'
+ Bit flags for this table set. Currently unused.
+
+`th_version[]'
+ Flex version in NULL-terminated string format. e.g., `2.5.13a'.
+ This is the version of flex that was used to create the serialized
+ tables.
+
+`th_name[]'
+ Contains the name of this table set. The default is `yytables',
+ and is prefixed accordingly, e.g., `footables'. Must be
+ NULL-terminated.
+
+`th_pad64[]'
+ Zero or more NULL bytes, padding the entire header to the next
+ 64-bit boundary as calculated from the beginning of the header.
+
+Fields of a table:
+
+`td_id'
+ Specifies the table identifier. Possible values are:
+ `YYTD_ID_ACCEPT (0x01)'
+ `yy_accept'
+
+ `YYTD_ID_BASE (0x02)'
+ `yy_base'
+
+ `YYTD_ID_CHK (0x03)'
+ `yy_chk'
+
+ `YYTD_ID_DEF (0x04)'
+ `yy_def'
+
+ `YYTD_ID_EC (0x05)'
+ `yy_ec '
+
+ `YYTD_ID_META (0x06)'
+ `yy_meta'
+
+ `YYTD_ID_NUL_TRANS (0x07)'
+ `yy_NUL_trans'
+
+ `YYTD_ID_NXT (0x08)'
+ `yy_nxt'. This array may be two dimensional. See the
+ `td_hilen' field below.
+
+ `YYTD_ID_RULE_CAN_MATCH_EOL (0x09)'
+ `yy_rule_can_match_eol'
+
+ `YYTD_ID_START_STATE_LIST (0x0A)'
+ `yy_start_state_list'. This array is handled specially
+ because it is an array of pointers to structs. See the
+ `td_flags' field below.
+
+ `YYTD_ID_TRANSITION (0x0B)'
+ `yy_transition'. This array is handled specially because it
+ is an array of structs. See the `td_lolen' field below.
+
+ `YYTD_ID_ACCLIST (0x0C)'
+ `yy_acclist'
+
+`td_flags'
+ Bit flags describing how to interpret the data in `td_data'. The
+ data arrays are one-dimensional by default, but may be two
+ dimensional as specified in the `td_hilen' field.
+
+ `YYTD_DATA8 (0x01)'
+ The data is serialized as an array of type int8.
+
+ `YYTD_DATA16 (0x02)'
+ The data is serialized as an array of type int16.
+
+ `YYTD_DATA32 (0x04)'
+ The data is serialized as an array of type int32.
+
+ `YYTD_PTRANS (0x08)'
+ The data is a list of indexes of entries in the expanded
+ `yy_transition' array. Each index should be expanded to a
+ pointer to the corresponding entry in the `yy_transition'
+ array. We count on the fact that the `yy_transition' array
+ has already been seen.
+
+ `YYTD_STRUCT (0x10)'
+ The data is a list of yy_trans_info structs, each of which
+ consists of two integers. There is no padding between struct
+ elements or between structs. The type of each member is
+ determined by the `YYTD_DATA*' bits.
+
+`td_lolen'
+ Specifies the number of elements in the lowest dimension array. If
+ this is a one-dimensional array, then it is simply the number of
+ elements in this array. The element size is determined by the
+ `td_flags' field.
+
+`td_hilen'
+ If `td_hilen' is non-zero, then the data is a two-dimensional
+ array. Otherwise, the data is a one-dimensional array. `td_hilen'
+ contains the number of elements in the higher dimensional array,
+ and `td_lolen' contains the number of elements in the lowest
+ dimension.
+
+ Conceptually, `td_data' is either `sometype td_data[td_lolen]', or
+ `sometype td_data[td_hilen][td_lolen]', where `sometype' is
+ specified by the `td_flags' field. It is possible for both
+ `td_lolen' and `td_hilen' to be zero, in which case `td_data' is a
+ zero length array, and no data is loaded, i.e., this table is
+ simply skipped. Flex does not currently generate tables of zero
+ length.
+
+`td_data[]'
+ The table data. This array may be a one- or two-dimensional array,
+ of type `int8', `int16', `int32', `struct yy_trans_info', or
+ `struct yy_trans_info*', depending upon the values in the
+ `td_flags', `td_lolen', and `td_hilen' fields.
+
+`td_pad64[]'
+ Zero or more NULL bytes, padding the entire table to the next
+ 64-bit boundary as calculated from the beginning of this table.
+
+
+File: flex.info, Node: Diagnostics, Next: Limitations, Prev: Serialized Tables, Up: Top
+
+23 Diagnostics
+**************
+
+The following is a list of `flex' diagnostic messages:
+
+ * `warning, rule cannot be matched' indicates that the given rule
+ cannot be matched because it follows other rules that will always
+ match the same text as it. For example, in the following `foo'
+ cannot be matched because it comes after an identifier "catch-all"
+ rule:
+
+
+ [a-z]+ got_identifier();
+ foo got_foo();
+
+ Using `REJECT' in a scanner suppresses this warning.
+
+ * `warning, -s option given but default rule can be matched' means
+ that it is possible (perhaps only in a particular start condition)
+ that the default rule (match any single character) is the only one
+ that will match a particular input. Since `-s' was given,
+ presumably this is not intended.
+
+ * `reject_used_but_not_detected undefined' or
+ `yymore_used_but_not_detected undefined'. These errors can occur
+ at compile time. They indicate that the scanner uses `REJECT' or
+ `yymore()' but that `flex' failed to notice the fact, meaning that
+ `flex' scanned the first two sections looking for occurrences of
+ these actions and failed to find any, but somehow you snuck some in
+ (via a #include file, for example). Use `%option reject' or
+ `%option yymore' to indicate to `flex' that you really do use
+ these features.
+
+ * `flex scanner jammed'. a scanner compiled with `-s' has
+ encountered an input string which wasn't matched by any of its
+ rules. This error can also occur due to internal problems.
+
+ * `token too large, exceeds YYLMAX'. your scanner uses `%array' and
+ one of its rules matched a string longer than the `YYLMAX'
+ constant (8K bytes by default). You can increase the value by
+ #define'ing `YYLMAX' in the definitions section of your `flex'
+ input.
+
+ * `scanner requires -8 flag to use the character 'x''. Your scanner
+ specification includes recognizing the 8-bit character `'x'' and
+ you did not specify the -8 flag, and your scanner defaulted to
+ 7-bit because you used the `-Cf' or `-CF' table compression
+ options. See the discussion of the `-7' flag, *Note Scanner
+ Options::, for details.
+
+ * `flex scanner push-back overflow'. you used `unput()' to push back
+ so much text that the scanner's buffer could not hold both the
+ pushed-back text and the current token in `yytext'. Ideally the
+ scanner should dynamically resize the buffer in this case, but at
+ present it does not.
+
+ * `input buffer overflow, can't enlarge buffer because scanner uses
+ REJECT'. the scanner was working on matching an extremely large
+ token and needed to expand the input buffer. This doesn't work
+ with scanners that use `REJECT'.
+
+ * `fatal flex scanner internal error--end of buffer missed'. This can
+ occur in a scanner which is reentered after a long-jump has jumped
+ out (or over) the scanner's activation frame. Before reentering
+ the scanner, use:
+
+ yyrestart( yyin );
+ or, as noted above, switch to using the C++ scanner class.
+
+ * `too many start conditions in <> construct!' you listed more start
+ conditions in a <> construct than exist (so you must have listed at
+ least one of them twice).
+
+
+File: flex.info, Node: Limitations, Next: Bibliography, Prev: Diagnostics, Up: Top
+
+24 Limitations
+**************
+
+Some trailing context patterns cannot be properly matched and generate
+warning messages (`dangerous trailing context'). These are patterns
+where the ending of the first part of the rule matches the beginning of
+the second part, such as `zx*/xy*', where the 'x*' matches the 'x' at
+the beginning of the trailing context. (Note that the POSIX draft
+states that the text matched by such patterns is undefined.) For some
+trailing context rules, parts which are actually fixed-length are not
+recognized as such, leading to the abovementioned performance loss. In
+particular, parts using `|' or `{n}' (such as `foo{3}') are always
+considered variable-length. Combining trailing context with the
+special `|' action can result in _fixed_ trailing context being turned
+into the more expensive _variable_ trailing context. For example, in
+the following:
+
+
+ %%
+ abc |
+ xyz/def
+
+ Use of `unput()' invalidates yytext and yyleng, unless the `%array'
+directive or the `-l' option has been used. Pattern-matching of `NUL's
+is substantially slower than matching other characters. Dynamic
+resizing of the input buffer is slow, as it entails rescanning all the
+text matched so far by the current (generally huge) token. Due to both
+buffering of input and read-ahead, you cannot intermix calls to
+`<stdio.h>' routines, such as, getchar(), with `flex' rules and expect
+it to work. Call `input()' instead. The total table entries listed by
+the `-v' flag excludes the number of table entries needed to determine
+what rule has been matched. The number of entries is equal to the
+number of DFA states if the scanner does not use `REJECT', and somewhat
+greater than the number of states if it does. `REJECT' cannot be used
+with the `-f' or `-F' options.
+
+ The `flex' internal algorithms need documentation.
+
+
+File: flex.info, Node: Bibliography, Next: FAQ, Prev: Limitations, Up: Top
+
+25 Additional Reading
+*********************
+
+You may wish to read more about the following programs:
+ * lex
+
+ * yacc
+
+ * sed
+
+ * awk
+
+ The following books may contain material of interest:
+
+ John Levine, Tony Mason, and Doug Brown, _Lex & Yacc_, O'Reilly and
+Associates. Be sure to get the 2nd edition.
+
+ M. E. Lesk and E. Schmidt, _LEX - Lexical Analyzer Generator_
+
+ Alfred Aho, Ravi Sethi and Jeffrey Ullman, _Compilers: Principles,
+Techniques and Tools_, Addison-Wesley (1986). Describes the
+pattern-matching techniques used by `flex' (deterministic finite
+automata).
+
+
+File: flex.info, Node: FAQ, Next: Appendices, Prev: Bibliography, Up: Top
+
+FAQ
+***
+
+From time to time, the `flex' maintainer receives certain questions.
+Rather than repeat answers to well-understood problems, we publish them
+here.
+
+* Menu:
+
+* When was flex born?::
+* How do I expand backslash-escape sequences in C-style quoted strings?::
+* Why do flex scanners call fileno if it is not ANSI compatible?::
+* Does flex support recursive pattern definitions?::
+* How do I skip huge chunks of input (tens of megabytes) while using flex?::
+* Flex is not matching my patterns in the same order that I defined them.::
+* My actions are executing out of order or sometimes not at all.::
+* How can I have multiple input sources feed into the same scanner at the same time?::
+* Can I build nested parsers that work with the same input file?::
+* How can I match text only at the end of a file?::
+* How can I make REJECT cascade across start condition boundaries?::
+* Why cant I use fast or full tables with interactive mode?::
+* How much faster is -F or -f than -C?::
+* If I have a simple grammar cant I just parse it with flex?::
+* Why doesn't yyrestart() set the start state back to INITIAL?::
+* How can I match C-style comments?::
+* The period isn't working the way I expected.::
+* Can I get the flex manual in another format?::
+* Does there exist a "faster" NDFA->DFA algorithm?::
+* How does flex compile the DFA so quickly?::
+* How can I use more than 8192 rules?::
+* How do I abandon a file in the middle of a scan and switch to a new file?::
+* How do I execute code only during initialization (only before the first scan)?::
+* How do I execute code at termination?::
+* Where else can I find help?::
+* Can I include comments in the "rules" section of the file?::
+* I get an error about undefined yywrap().::
+* How can I change the matching pattern at run time?::
+* How can I expand macros in the input?::
+* How can I build a two-pass scanner?::
+* How do I match any string not matched in the preceding rules?::
+* I am trying to port code from AT&T lex that uses yysptr and yysbuf.::
+* Is there a way to make flex treat NULL like a regular character?::
+* Whenever flex can not match the input it says "flex scanner jammed".::
+* Why doesn't flex have non-greedy operators like perl does?::
+* Memory leak - 16386 bytes allocated by malloc.::
+* How do I track the byte offset for lseek()?::
+* How do I use my own I/O classes in a C++ scanner?::
+* How do I skip as many chars as possible?::
+* deleteme00::
+* Are certain equivalent patterns faster than others?::
+* Is backing up a big deal?::
+* Can I fake multi-byte character support?::
+* deleteme01::
+* Can you discuss some flex internals?::
+* unput() messes up yy_at_bol::
+* The | operator is not doing what I want::
+* Why can't flex understand this variable trailing context pattern?::
+* The ^ operator isn't working::
+* Trailing context is getting confused with trailing optional patterns::
+* Is flex GNU or not?::
+* ERASEME53::
+* I need to scan if-then-else blocks and while loops::
+* ERASEME55::
+* ERASEME56::
+* ERASEME57::
+* Is there a repository for flex scanners?::
+* How can I conditionally compile or preprocess my flex input file?::
+* Where can I find grammars for lex and yacc?::
+* I get an end-of-buffer message for each character scanned.::
+* unnamed-faq-62::
+* unnamed-faq-63::
+* unnamed-faq-64::
+* unnamed-faq-65::
+* unnamed-faq-66::
+* unnamed-faq-67::
+* unnamed-faq-68::
+* unnamed-faq-69::
+* unnamed-faq-70::
+* unnamed-faq-71::
+* unnamed-faq-72::
+* unnamed-faq-73::
+* unnamed-faq-74::
+* unnamed-faq-75::
+* unnamed-faq-76::
+* unnamed-faq-77::
+* unnamed-faq-78::
+* unnamed-faq-79::
+* unnamed-faq-80::
+* unnamed-faq-81::
+* unnamed-faq-82::
+* unnamed-faq-83::
+* unnamed-faq-84::
+* unnamed-faq-85::
+* unnamed-faq-86::
+* unnamed-faq-87::
+* unnamed-faq-88::
+* unnamed-faq-90::
+* unnamed-faq-91::
+* unnamed-faq-92::
+* unnamed-faq-93::
+* unnamed-faq-94::
+* unnamed-faq-95::
+* unnamed-faq-96::
+* unnamed-faq-97::
+* unnamed-faq-98::
+* unnamed-faq-99::
+* unnamed-faq-100::
+* unnamed-faq-101::
+* What is the difference between YYLEX_PARAM and YY_DECL?::
+* Why do I get "conflicting types for yylex" error?::
+* How do I access the values set in a Flex action from within a Bison action?::
+
+
+File: flex.info, Node: When was flex born?, Next: How do I expand backslash-escape sequences in C-style quoted strings?, Up: FAQ
+
+When was flex born?
+===================
+
+Vern Paxson took over the `Software Tools' lex project from Jef
+Poskanzer in 1982. At that point it was written in Ratfor. Around
+1987 or so, Paxson translated it into C, and a legend was born :-).
+
+
+File: flex.info, Node: How do I expand backslash-escape sequences in C-style quoted strings?, Next: Why do flex scanners call fileno if it is not ANSI compatible?, Prev: When was flex born?, Up: FAQ
+
+How do I expand backslash-escape sequences in C-style quoted strings?
+=====================================================================
+
+A key point when scanning quoted strings is that you cannot (easily)
+write a single rule that will precisely match the string if you allow
+things like embedded escape sequences and newlines. If you try to
+match strings with a single rule then you'll wind up having to rescan
+the string anyway to find any escape sequences.
+
+ Instead you can use exclusive start conditions and a set of rules,
+one for matching non-escaped text, one for matching a single escape,
+one for matching an embedded newline, and one for recognizing the end
+of the string. Each of these rules is then faced with the question of
+where to put its intermediary results. The best solution is for the
+rules to append their local value of `yytext' to the end of a "string
+literal" buffer. A rule like the escape-matcher will append to the
+buffer the meaning of the escape sequence rather than the literal text
+in `yytext'. In this way, `yytext' does not need to be modified at all.
+
+
+File: flex.info, Node: Why do flex scanners call fileno if it is not ANSI compatible?, Next: Does flex support recursive pattern definitions?, Prev: How do I expand backslash-escape sequences in C-style quoted strings?, Up: FAQ
+
+Why do flex scanners call fileno if it is not ANSI compatible?
+==============================================================
+
+Flex scanners call `fileno()' in order to get the file descriptor
+corresponding to `yyin'. The file descriptor may be passed to
+`isatty()' or `read()', depending upon which `%options' you specified.
+If your system does not have `fileno()' support, to get rid of the
+`read()' call, do not specify `%option read'. To get rid of the
+`isatty()' call, you must specify one of `%option always-interactive' or
+`%option never-interactive'.
+
+
+File: flex.info, Node: Does flex support recursive pattern definitions?, Next: How do I skip huge chunks of input (tens of megabytes) while using flex?, Prev: Why do flex scanners call fileno if it is not ANSI compatible?, Up: FAQ
+
+Does flex support recursive pattern definitions?
+================================================
+
+e.g.,
+
+
+ %%
+ block "{"({block}|{statement})*"}"
+
+ No. You cannot have recursive definitions. The pattern-matching
+power of regular expressions in general (and therefore flex scanners,
+too) is limited. In particular, regular expressions cannot "balance"
+parentheses to an arbitrary degree. For example, it's impossible to
+write a regular expression that matches all strings containing the same
+number of '{'s as '}'s. For more powerful pattern matching, you need a
+parser, such as `GNU bison'.
+
+
+File: flex.info, Node: How do I skip huge chunks of input (tens of megabytes) while using flex?, Next: Flex is not matching my patterns in the same order that I defined them., Prev: Does flex support recursive pattern definitions?, Up: FAQ
+
+How do I skip huge chunks of input (tens of megabytes) while using flex?
+========================================================================
+
+Use `fseek()' (or `lseek()') to position yyin, then call `yyrestart()'.
+
+
+File: flex.info, Node: Flex is not matching my patterns in the same order that I defined them., Next: My actions are executing out of order or sometimes not at all., Prev: How do I skip huge chunks of input (tens of megabytes) while using flex?, Up: FAQ
+
+Flex is not matching my patterns in the same order that I defined them.
+=======================================================================
+
+`flex' picks the rule that matches the most text (i.e., the longest
+possible input string). This is because `flex' uses an entirely
+different matching technique ("deterministic finite automata") that
+actually does all of the matching simultaneously, in parallel. (Seems
+impossible, but it's actually a fairly simple technique once you
+understand the principles.)
+
+ A side-effect of this parallel matching is that when the input
+matches more than one rule, `flex' scanners pick the rule that matched
+the _most_ text. This is explained further in the manual, in the
+section *Note Matching::.
+
+ If you want `flex' to choose a shorter match, then you can work
+around this behavior by expanding your short rule to match more text,
+then put back the extra:
+
+
+ data_.* yyless( 5 ); BEGIN BLOCKIDSTATE;
+
+ Another fix would be to make the second rule active only during the
+`<BLOCKIDSTATE>' start condition, and make that start condition
+exclusive by declaring it with `%x' instead of `%s'.
+
+ A final fix is to change the input language so that the ambiguity for
+`data_' is removed, by adding characters to it that don't match the
+identifier rule, or by removing characters (such as `_') from the
+identifier rule so it no longer matches `data_'. (Of course, you might
+also not have the option of changing the input language.)
+
+
+File: flex.info, Node: My actions are executing out of order or sometimes not at all., Next: How can I have multiple input sources feed into the same scanner at the same time?, Prev: Flex is not matching my patterns in the same order that I defined them., Up: FAQ
+
+My actions are executing out of order or sometimes not at all.
+==============================================================
+
+Most likely, you have (in error) placed the opening `{' of the action
+block on a different line than the rule, e.g.,
+
+
+ ^(foo|bar)
+ { <<<--- WRONG!
+
+ }
+
+ `flex' requires that the opening `{' of an action associated with a
+rule begin on the same line as does the rule. You need instead to
+write your rules as follows:
+
+
+ ^(foo|bar) { // CORRECT!
+
+ }
+
+
+File: flex.info, Node: How can I have multiple input sources feed into the same scanner at the same time?, Next: Can I build nested parsers that work with the same input file?, Prev: My actions are executing out of order or sometimes not at all., Up: FAQ
+
+How can I have multiple input sources feed into the same scanner at the same time?
+==================================================================================
+
+If ...
+ * your scanner is free of backtracking (verified using `flex''s `-b'
+ flag),
+
+ * AND you run your scanner interactively (`-I' option; default
+ unless using special table compression options),
+
+ * AND you feed it one character at a time by redefining `YY_INPUT'
+ to do so,
+
+ then every time it matches a token, it will have exhausted its input
+buffer (because the scanner is free of backtracking). This means you
+can safely use `select()' at the point and only call `yylex()' for
+another token if `select()' indicates there's data available.
+
+ That is, move the `select()' out from the input function to a point
+where it determines whether `yylex()' gets called for the next token.
+
+ With this approach, you will still have problems if your input can
+arrive piecemeal; `select()' could inform you that the beginning of a
+token is available, you call `yylex()' to get it, but it winds up
+blocking waiting for the later characters in the token.
+
+ Here's another way: Move your input multiplexing inside of
+`YY_INPUT'. That is, whenever `YY_INPUT' is called, it `select()''s to
+see where input is available. If input is available for the scanner,
+it reads and returns the next byte. If input is available from another
+source, it calls whatever function is responsible for reading from that
+source. (If no input is available, it blocks until some input is
+available.) I've used this technique in an interpreter I wrote that
+both reads keyboard input using a `flex' scanner and IPC traffic from
+sockets, and it works fine.
+
+
+File: flex.info, Node: Can I build nested parsers that work with the same input file?, Next: How can I match text only at the end of a file?, Prev: How can I have multiple input sources feed into the same scanner at the same time?, Up: FAQ
+
+Can I build nested parsers that work with the same input file?
+==============================================================
+
+This is not going to work without some additional effort. The reason is
+that `flex' block-buffers the input it reads from `yyin'. This means
+that the "outermost" `yylex()', when called, will automatically slurp
+up the first 8K of input available on yyin, and subsequent calls to
+other `yylex()''s won't see that input. You might be tempted to work
+around this problem by redefining `YY_INPUT' to only return a small
+amount of text, but it turns out that that approach is quite difficult.
+Instead, the best solution is to combine all of your scanners into one
+large scanner, using a different exclusive start condition for each.
+
+
+File: flex.info, Node: How can I match text only at the end of a file?, Next: How can I make REJECT cascade across start condition boundaries?, Prev: Can I build nested parsers that work with the same input file?, Up: FAQ
+
+How can I match text only at the end of a file?
+===============================================
+
+There is no way to write a rule which is "match this text, but only if
+it comes at the end of the file". You can fake it, though, if you
+happen to have a character lying around that you don't allow in your
+input. Then you redefine `YY_INPUT' to call your own routine which, if
+it sees an `EOF', returns the magic character first (and remembers to
+return a real `EOF' next time it's called). Then you could write:
+
+
+ <COMMENT>(.|\n)*{EOF_CHAR} /* saw comment at EOF */
+
+
+File: flex.info, Node: How can I make REJECT cascade across start condition boundaries?, Next: Why cant I use fast or full tables with interactive mode?, Prev: How can I match text only at the end of a file?, Up: FAQ
+
+How can I make REJECT cascade across start condition boundaries?
+================================================================
+
+You can do this as follows. Suppose you have a start condition `A', and
+after exhausting all of the possible matches in `<A>', you want to try
+matches in `<INITIAL>'. Then you could use the following:
+
+
+ %x A
+ %%
+ <A>rule_that_is_long ...; REJECT;
+ <A>rule ...; REJECT; /* shorter rule */
+ <A>etc.
+ ...
+ <A>.|\n {
+ /* Shortest and last rule in <A>, so
+ * cascaded REJECTs will eventually
+ * wind up matching this rule. We want
+ * to now switch to the initial state
+ * and try matching from there instead.
+ */
+ yyless(0); /* put back matched text */
+ BEGIN(INITIAL);
+ }
+
+
+File: flex.info, Node: Why cant I use fast or full tables with interactive mode?, Next: How much faster is -F or -f than -C?, Prev: How can I make REJECT cascade across start condition boundaries?, Up: FAQ
+
+Why can't I use fast or full tables with interactive mode?
+==========================================================
+
+One of the assumptions flex makes is that interactive applications are
+inherently slow (they're waiting on a human after all). It has to do
+with how the scanner detects that it must be finished scanning a token.
+For interactive scanners, after scanning each character the current
+state is looked up in a table (essentially) to see whether there's a
+chance of another input character possibly extending the length of the
+match. If not, the scanner halts. For non-interactive scanners, the
+end-of-token test is much simpler, basically a compare with 0, so no
+memory bus cycles. Since the test occurs in the innermost scanning
+loop, one would like to make it go as fast as possible.
+
+ Still, it seems reasonable to allow the user to choose to trade off
+a bit of performance in this area to gain the corresponding
+flexibility. There might be another reason, though, why fast scanners
+don't support the interactive option.
+
+
+File: flex.info, Node: How much faster is -F or -f than -C?, Next: If I have a simple grammar cant I just parse it with flex?, Prev: Why cant I use fast or full tables with interactive mode?, Up: FAQ
+
+How much faster is -F or -f than -C?
+====================================
+
+Much faster (factor of 2-3).
+
+
+File: flex.info, Node: If I have a simple grammar cant I just parse it with flex?, Next: Why doesn't yyrestart() set the start state back to INITIAL?, Prev: How much faster is -F or -f than -C?, Up: FAQ
+
+If I have a simple grammar can't I just parse it with flex?
+===========================================================
+
+Is your grammar recursive? That's almost always a sign that you're
+better off using a parser/scanner rather than just trying to use a
+scanner alone.
+
+
+File: flex.info, Node: Why doesn't yyrestart() set the start state back to INITIAL?, Next: How can I match C-style comments?, Prev: If I have a simple grammar cant I just parse it with flex?, Up: FAQ
+
+Why doesn't yyrestart() set the start state back to INITIAL?
+============================================================
+
+There are two reasons. The first is that there might be programs that
+rely on the start state not changing across file changes. The second
+is that beginning with `flex' version 2.4, use of `yyrestart()' is no
+longer required, so fixing the problem there doesn't solve the more
+general problem.
+
+
+File: flex.info, Node: How can I match C-style comments?, Next: The period isn't working the way I expected., Prev: Why doesn't yyrestart() set the start state back to INITIAL?, Up: FAQ
+
+How can I match C-style comments?
+=================================
+
+You might be tempted to try something like this:
+
+
+ "/*".*"*/" // WRONG!
+
+ or, worse, this:
+
+
+ "/*"(.|\n)"*/" // WRONG!
+
+ The above rules will eat too much input, and blow up on things like:
+
+
+ /* a comment */ do_my_thing( "oops */" );
+
+ Here is one way which allows you to track line information:
+
+
+ <INITIAL>{
+ "/*" BEGIN(IN_COMMENT);
+ }
+ <IN_COMMENT>{
+ "*/" BEGIN(INITIAL);
+ [^*\n]+ // eat comment in chunks
+ "*" // eat the lone star
+ \n yylineno++;
+ }
+
+
+File: flex.info, Node: The period isn't working the way I expected., Next: Can I get the flex manual in another format?, Prev: How can I match C-style comments?, Up: FAQ
+
+The '.' isn't working the way I expected.
+=========================================
+
+Here are some tips for using `.':
+
+ * A common mistake is to place the grouping parenthesis AFTER an
+ operator, when you really meant to place the parenthesis BEFORE
+ the operator, e.g., you probably want this `(foo|bar)+' and NOT
+ this `(foo|bar+)'.
+
+ The first pattern matches the words `foo' or `bar' any number of
+ times, e.g., it matches the text `barfoofoobarfoo'. The second
+ pattern matches a single instance of `foo' or a single instance of
+ `bar' followed by one or more `r's, e.g., it matches the text
+ `barrrr' .
+
+ * A `.' inside `[]''s just means a literal`.' (period), and NOT "any
+ character except newline".
+
+ * Remember that `.' matches any character EXCEPT `\n' (and `EOF').
+ If you really want to match ANY character, including newlines,
+ then use `(.|\n)' Beware that the regex `(.|\n)+' will match your
+ entire input!
+
+ * Finally, if you want to match a literal `.' (a period), then use
+ `[.]' or `"."'
+
+
+File: flex.info, Node: Can I get the flex manual in another format?, Next: Does there exist a "faster" NDFA->DFA algorithm?, Prev: The period isn't working the way I expected., Up: FAQ
+
+Can I get the flex manual in another format?
+============================================
+
+The `flex' source distribution includes a texinfo manual. You are free
+to convert that texinfo into whatever format you desire. The `texinfo'
+package includes tools for conversion to a number of formats.
+
+
+File: flex.info, Node: Does there exist a "faster" NDFA->DFA algorithm?, Next: How does flex compile the DFA so quickly?, Prev: Can I get the flex manual in another format?, Up: FAQ
+
+Does there exist a "faster" NDFA->DFA algorithm?
+================================================
+
+There's no way around the potential exponential running time - it can
+take you exponential time just to enumerate all of the DFA states. In
+practice, though, the running time is closer to linear, or sometimes
+quadratic.
+
+
+File: flex.info, Node: How does flex compile the DFA so quickly?, Next: How can I use more than 8192 rules?, Prev: Does there exist a "faster" NDFA->DFA algorithm?, Up: FAQ
+
+How does flex compile the DFA so quickly?
+=========================================
+
+There are two big speed wins that `flex' uses:
+
+ 1. It analyzes the input rules to construct equivalence classes for
+ those characters that always make the same transitions. It then
+ rewrites the NFA using equivalence classes for transitions instead
+ of characters. This cuts down the NFA->DFA computation time
+ dramatically, to the point where, for uncompressed DFA tables, the
+ DFA generation is often I/O bound in writing out the tables.
+
+ 2. It maintains hash values for previously computed DFA states, so
+ testing whether a newly constructed DFA state is equivalent to a
+ previously constructed state can be done very quickly, by first
+ comparing hash values.
+
+
+File: flex.info, Node: How can I use more than 8192 rules?, Next: How do I abandon a file in the middle of a scan and switch to a new file?, Prev: How does flex compile the DFA so quickly?, Up: FAQ
+
+How can I use more than 8192 rules?
+===================================
+
+`Flex' is compiled with an upper limit of 8192 rules per scanner. If
+you need more than 8192 rules in your scanner, you'll have to recompile
+`flex' with the following changes in `flexdef.h':
+
+
+ < #define YY_TRAILING_MASK 0x2000
+ < #define YY_TRAILING_HEAD_MASK 0x4000
+ --
+ > #define YY_TRAILING_MASK 0x20000000
+ > #define YY_TRAILING_HEAD_MASK 0x40000000
+
+ This should work okay as long as your C compiler uses 32 bit
+integers. But you might want to think about whether using such a huge
+number of rules is the best way to solve your problem.
+
+ The following may also be relevant:
+
+ With luck, you should be able to increase the definitions in
+flexdef.h for:
+
+
+ #define JAMSTATE -32766 /* marks a reference to the state that always jams */
+ #define MAXIMUM_MNS 31999
+ #define BAD_SUBSCRIPT -32767
+
+ recompile everything, and it'll all work. Flex only has these
+16-bit-like values built into it because a long time ago it was
+developed on a machine with 16-bit ints. I've given this advice to
+others in the past but haven't heard back from them whether it worked
+okay or not...
+
+
+File: flex.info, Node: How do I abandon a file in the middle of a scan and switch to a new file?, Next: How do I execute code only during initialization (only before the first scan)?, Prev: How can I use more than 8192 rules?, Up: FAQ
+
+How do I abandon a file in the middle of a scan and switch to a new file?
+=========================================================================
+
+Just call `yyrestart(newfile)'. Be sure to reset the start state if you
+want a "fresh start, since `yyrestart' does NOT reset the start state
+back to `INITIAL'.
+
+
+File: flex.info, Node: How do I execute code only during initialization (only before the first scan)?, Next: How do I execute code at termination?, Prev: How do I abandon a file in the middle of a scan and switch to a new file?, Up: FAQ
+
+How do I execute code only during initialization (only before the first scan)?
+==============================================================================
+
+You can specify an initial action by defining the macro `YY_USER_INIT'
+(though note that `yyout' may not be available at the time this macro
+is executed). Or you can add to the beginning of your rules section:
+
+
+ %%
+ /* Must be indented! */
+ static int did_init = 0;
+
+ if ( ! did_init ){
+ do_my_init();
+ did_init = 1;
+ }
+
+
+File: flex.info, Node: How do I execute code at termination?, Next: Where else can I find help?, Prev: How do I execute code only during initialization (only before the first scan)?, Up: FAQ
+
+How do I execute code at termination?
+=====================================
+
+You can specify an action for the `<<EOF>>' rule.
+
+
+File: flex.info, Node: Where else can I find help?, Next: Can I include comments in the "rules" section of the file?, Prev: How do I execute code at termination?, Up: FAQ
+
+Where else can I find help?
+===========================
+
+You can find the flex homepage on the web at
+`http://flex.sourceforge.net/'. See that page for details about flex
+mailing lists as well.
+
+
+File: flex.info, Node: Can I include comments in the "rules" section of the file?, Next: I get an error about undefined yywrap()., Prev: Where else can I find help?, Up: FAQ
+
+Can I include comments in the "rules" section of the file?
+==========================================================
+
+Yes, just about anywhere you want to. See the manual for the specific
+syntax.
+
+
+File: flex.info, Node: I get an error about undefined yywrap()., Next: How can I change the matching pattern at run time?, Prev: Can I include comments in the "rules" section of the file?, Up: FAQ
+
+I get an error about undefined yywrap().
+========================================
+
+You must supply a `yywrap()' function of your own, or link to `libfl.a'
+(which provides one), or use
+
+
+ %option noyywrap
+
+ in your source to say you don't want a `yywrap()' function.
+
+
+File: flex.info, Node: How can I change the matching pattern at run time?, Next: How can I expand macros in the input?, Prev: I get an error about undefined yywrap()., Up: FAQ
+
+How can I change the matching pattern at run time?
+==================================================
+
+You can't, it's compiled into a static table when flex builds the
+scanner.
+
+
+File: flex.info, Node: How can I expand macros in the input?, Next: How can I build a two-pass scanner?, Prev: How can I change the matching pattern at run time?, Up: FAQ
+
+How can I expand macros in the input?
+=====================================
+
+The best way to approach this problem is at a higher level, e.g., in
+the parser.
+
+ However, you can do this using multiple input buffers.
+
+
+ %%
+ macro/[a-z]+ {
+ /* Saw the macro "macro" followed by extra stuff. */
+ main_buffer = YY_CURRENT_BUFFER;
+ expansion_buffer = yy_scan_string(expand(yytext));
+ yy_switch_to_buffer(expansion_buffer);
+ }
+
+ <<EOF>> {
+ if ( expansion_buffer )
+ {
+ // We were doing an expansion, return to where
+ // we were.
+ yy_switch_to_buffer(main_buffer);
+ yy_delete_buffer(expansion_buffer);
+ expansion_buffer = 0;
+ }
+ else
+ yyterminate();
+ }
+
+ You probably will want a stack of expansion buffers to allow nested
+macros. From the above though hopefully the idea is clear.
+
+
+File: flex.info, Node: How can I build a two-pass scanner?, Next: How do I match any string not matched in the preceding rules?, Prev: How can I expand macros in the input?, Up: FAQ
+
+How can I build a two-pass scanner?
+===================================
+
+One way to do it is to filter the first pass to a temporary file, then
+process the temporary file on the second pass. You will probably see a
+performance hit, due to all the disk I/O.
+
+ When you need to look ahead far forward like this, it almost always
+means that the right solution is to build a parse tree of the entire
+input, then walk it after the parse in order to generate the output.
+In a sense, this is a two-pass approach, once through the text and once
+through the parse tree, but the performance hit for the latter is
+usually an order of magnitude smaller, since everything is already
+classified, in binary format, and residing in memory.
+
+
+File: flex.info, Node: How do I match any string not matched in the preceding rules?, Next: I am trying to port code from AT&T lex that uses yysptr and yysbuf., Prev: How can I build a two-pass scanner?, Up: FAQ
+
+How do I match any string not matched in the preceding rules?
+=============================================================
+
+One way to assign precedence, is to place the more specific rules
+first. If two rules would match the same input (same sequence of
+characters) then the first rule listed in the `flex' input wins, e.g.,
+
+
+ %%
+ foo[a-zA-Z_]+ return FOO_ID;
+ bar[a-zA-Z_]+ return BAR_ID;
+ [a-zA-Z_]+ return GENERIC_ID;
+
+ Note that the rule `[a-zA-Z_]+' must come *after* the others. It
+will match the same amount of text as the more specific rules, and in
+that case the `flex' scanner will pick the first rule listed in your
+scanner as the one to match.
+
+
+File: flex.info, Node: I am trying to port code from AT&T lex that uses yysptr and yysbuf., Next: Is there a way to make flex treat NULL like a regular character?, Prev: How do I match any string not matched in the preceding rules?, Up: FAQ
+
+I am trying to port code from AT&T lex that uses yysptr and yysbuf.
+===================================================================
+
+Those are internal variables pointing into the AT&T scanner's input
+buffer. I imagine they're being manipulated in user versions of the
+`input()' and `unput()' functions. If so, what you need to do is
+analyze those functions to figure out what they're doing, and then
+replace `input()' with an appropriate definition of `YY_INPUT'. You
+shouldn't need to (and must not) replace `flex''s `unput()' function.
+
+
+File: flex.info, Node: Is there a way to make flex treat NULL like a regular character?, Next: Whenever flex can not match the input it says "flex scanner jammed"., Prev: I am trying to port code from AT&T lex that uses yysptr and yysbuf., Up: FAQ
+
+Is there a way to make flex treat NULL like a regular character?
+================================================================
+
+Yes, `\0' and `\x00' should both do the trick. Perhaps you have an
+ancient version of `flex'. The latest release is version 2.5.34.
+
+
+File: flex.info, Node: Whenever flex can not match the input it says "flex scanner jammed"., Next: Why doesn't flex have non-greedy operators like perl does?, Prev: Is there a way to make flex treat NULL like a regular character?, Up: FAQ
+
+Whenever flex can not match the input it says "flex scanner jammed".
+====================================================================
+
+You need to add a rule that matches the otherwise-unmatched text, e.g.,
+
+
+ %option yylineno
+ %%
+ [[a bunch of rules here]]
+
+ . printf("bad input character '%s' at line %d\n", yytext, yylineno);
+
+ See `%option default' for more information.
+
+
+File: flex.info, Node: Why doesn't flex have non-greedy operators like perl does?, Next: Memory leak - 16386 bytes allocated by malloc., Prev: Whenever flex can not match the input it says "flex scanner jammed"., Up: FAQ
+
+Why doesn't flex have non-greedy operators like perl does?
+==========================================================
+
+A DFA can do a non-greedy match by stopping the first time it enters an
+accepting state, instead of consuming input until it determines that no
+further matching is possible (a "jam" state). This is actually easier
+to implement than longest leftmost match (which flex does).
+
+ But it's also much less useful than longest leftmost match. In
+general, when you find yourself wishing for non-greedy matching, that's
+usually a sign that you're trying to make the scanner do some parsing.
+That's generally the wrong approach, since it lacks the power to do a
+decent job. Better is to either introduce a separate parser, or to
+split the scanner into multiple scanners using (exclusive) start
+conditions.
+
+ You might have a separate start state once you've seen the `BEGIN'.
+In that state, you might then have a regex that will match `END' (to
+kick you out of the state), and perhaps `(.|\n)' to get a single
+character within the chunk ...
+
+ This approach also has much better error-reporting properties.
+
+
+File: flex.info, Node: Memory leak - 16386 bytes allocated by malloc., Next: How do I track the byte offset for lseek()?, Prev: Why doesn't flex have non-greedy operators like perl does?, Up: FAQ
+
+Memory leak - 16386 bytes allocated by malloc.
+==============================================
+
+UPDATED 2002-07-10: As of `flex' version 2.5.9, this leak means that
+you did not call `yylex_destroy()'. If you are using an earlier version
+of `flex', then read on.
+
+ The leak is about 16426 bytes. That is, (8192 * 2 + 2) for the
+read-buffer, and about 40 for `struct yy_buffer_state' (depending upon
+alignment). The leak is in the non-reentrant C scanner only (NOT in the
+reentrant scanner, NOT in the C++ scanner). Since `flex' doesn't know
+when you are done, the buffer is never freed.
+
+ However, the leak won't multiply since the buffer is reused no
+matter how many times you call `yylex()'.
+
+ If you want to reclaim the memory when you are completely done
+scanning, then you might try this:
+
+
+ /* For non-reentrant C scanner only. */
+ yy_delete_buffer(YY_CURRENT_BUFFER);
+ yy_init = 1;
+
+ Note: `yy_init' is an "internal variable", and hasn't been tested in
+this situation. It is possible that some other globals may need
+resetting as well.
+
+
+File: flex.info, Node: How do I track the byte offset for lseek()?, Next: How do I use my own I/O classes in a C++ scanner?, Prev: Memory leak - 16386 bytes allocated by malloc., Up: FAQ
+
+How do I track the byte offset for lseek()?
+===========================================
+
+
+ > We thought that it would be possible to have this number through the
+ > evaluation of the following expression:
+ >
+ > seek_position = (no_buffers)*YY_READ_BUF_SIZE + yy_c_buf_p - YY_CURRENT_BUFFER->yy_ch_buf
+
+ While this is the right idea, it has two problems. The first is that
+it's possible that `flex' will request less than `YY_READ_BUF_SIZE'
+during an invocation of `YY_INPUT' (or that your input source will
+return less even though `YY_READ_BUF_SIZE' bytes were requested). The
+second problem is that when refilling its internal buffer, `flex' keeps
+some characters from the previous buffer (because usually it's in the
+middle of a match, and needs those characters to construct `yytext' for
+the match once it's done). Because of this, `yy_c_buf_p -
+YY_CURRENT_BUFFER->yy_ch_buf' won't be exactly the number of characters
+already read from the current buffer.
+
+ An alternative solution is to count the number of characters you've
+matched since starting to scan. This can be done by using
+`YY_USER_ACTION'. For example,
+
+
+ #define YY_USER_ACTION num_chars += yyleng;
+
+ (You need to be careful to update your bookkeeping if you use
+`yymore('), `yyless()', `unput()', or `input()'.)
+
+
+File: flex.info, Node: How do I use my own I/O classes in a C++ scanner?, Next: How do I skip as many chars as possible?, Prev: How do I track the byte offset for lseek()?, Up: FAQ
+
+How do I use my own I/O classes in a C++ scanner?
+=================================================
+
+When the flex C++ scanning class rewrite finally happens, then this
+sort of thing should become much easier.
+
+ You can do this by passing the various functions (such as
+`LexerInput()' and `LexerOutput()') NULL `iostream*''s, and then
+dealing with your own I/O classes surreptitiously (i.e., stashing them
+in special member variables). This works because the only assumption
+about the lexer regarding what's done with the iostream's is that
+they're ultimately passed to `LexerInput()' and `LexerOutput', which
+then do whatever is necessary with them.
+
+
+File: flex.info, Node: How do I skip as many chars as possible?, Next: deleteme00, Prev: How do I use my own I/O classes in a C++ scanner?, Up: FAQ
+
+How do I skip as many chars as possible?
+========================================
+
+How do I skip as many chars as possible - without interfering with the
+other patterns?
+
+ In the example below, we want to skip over characters until we see
+the phrase "endskip". The following will _NOT_ work correctly (do you
+see why not?)
+
+
+ /* INCORRECT SCANNER */
+ %x SKIP
+ %%
+ <INITIAL>startskip BEGIN(SKIP);
+ ...
+ <SKIP>"endskip" BEGIN(INITIAL);
+ <SKIP>.* ;
+
+ The problem is that the pattern .* will eat up the word "endskip."
+The simplest (but slow) fix is:
+
+
+ <SKIP>"endskip" BEGIN(INITIAL);
+ <SKIP>. ;
+
+ The fix involves making the second rule match more, without making
+it match "endskip" plus something else. So for example:
+
+
+ <SKIP>"endskip" BEGIN(INITIAL);
+ <SKIP>[^e]+ ;
+ <SKIP>. ;/* so you eat up e's, too */
+
+
+File: flex.info, Node: deleteme00, Next: Are certain equivalent patterns faster than others?, Prev: How do I skip as many chars as possible?, Up: FAQ
+
+deleteme00
+==========
+
+
+ QUESTION:
+ When was flex born?
+
+ Vern Paxson took over
+ the Software Tools lex project from Jef Poskanzer in 1982. At that point it
+ was written in Ratfor. Around 1987 or so, Paxson translated it into C, and
+ a legend was born :-).
+
+
+File: flex.info, Node: Are certain equivalent patterns faster than others?, Next: Is backing up a big deal?, Prev: deleteme00, Up: FAQ
+
+Are certain equivalent patterns faster than others?
+===================================================
+
+
+ To: Adoram Rogel <adoram@orna.hybridge.com>
+ Subject: Re: Flex 2.5.2 performance questions
+ In-reply-to: Your message of Wed, 18 Sep 96 11:12:17 EDT.
+ Date: Wed, 18 Sep 96 10:51:02 PDT
+ From: Vern Paxson <vern>
+
+ [Note, the most recent flex release is 2.5.4, which you can get from
+ ftp.ee.lbl.gov. It has bug fixes over 2.5.2 and 2.5.3.]
+
+ > 1. Using the pattern
+ > ([Ff](oot)?)?[Nn](ote)?(\.)?
+ > instead of
+ > (((F|f)oot(N|n)ote)|((N|n)ote)|((N|n)\.)|((F|f)(N|n)(\.)))
+ > (in a very complicated flex program) caused the program to slow from
+ > 300K+/min to 100K/min (no other changes were done).
+
+ These two are not equivalent. For example, the first can match "footnote."
+ but the second can only match "footnote". This is almost certainly the
+ cause in the discrepancy - the slower scanner run is matching more tokens,
+ and/or having to do more backing up.
+
+ > 2. Which of these two are better: [Ff]oot or (F|f)oot ?
+
+ From a performance point of view, they're equivalent (modulo presumably
+ minor effects such as memory cache hit rates; and the presence of trailing
+ context, see below). From a space point of view, the first is slightly
+ preferable.
+
+ > 3. I have a pattern that look like this:
+ > pats {p1}|{p2}|{p3}|...|{p50} (50 patterns ORd)
+ >
+ > running yet another complicated program that includes the following rule:
+ > <snext>{and}/{no4}{bb}{pats}
+ >
+ > gets me to "too complicated - over 32,000 states"...
+
+ I can't tell from this example whether the trailing context is variable-length
+ or fixed-length (it could be the latter if {and} is fixed-length). If it's
+ variable length, which flex -p will tell you, then this reflects a basic
+ performance problem, and if you can eliminate it by restructuring your
+ scanner, you will see significant improvement.
+
+ > so I divided {pats} to {pats1}, {pats2},..., {pats5} each consists of about
+ > 10 patterns and changed the rule to be 5 rules.
+ > This did compile, but what is the rule of thumb here ?
+
+ The rule is to avoid trailing context other than fixed-length, in which for
+ a/b, either the 'a' pattern or the 'b' pattern have a fixed length. Use
+ of the '|' operator automatically makes the pattern variable length, so in
+ this case '[Ff]oot' is preferred to '(F|f)oot'.
+
+ > 4. I changed a rule that looked like this:
+ > <snext8>{and}{bb}/{ROMAN}[^A-Za-z] { BEGIN...
+ >
+ > to the next 2 rules:
+ > <snext8>{and}{bb}/{ROMAN}[A-Za-z] { ECHO;}
+ > <snext8>{and}{bb}/{ROMAN} { BEGIN...
+ >
+ > Again, I understand the using [^...] will cause a great performance loss
+
+ Actually, it doesn't cause any sort of performance loss. It's a surprising
+ fact about regular expressions that they always match in linear time
+ regardless of how complex they are.
+
+ > but are there any specific rules about it ?
+
+ See the "Performance Considerations" section of the man page, and also
+ the example in MISC/fastwc/.
+
+ Vern
+
+
+File: flex.info, Node: Is backing up a big deal?, Next: Can I fake multi-byte character support?, Prev: Are certain equivalent patterns faster than others?, Up: FAQ
+
+Is backing up a big deal?
+=========================
+
+
+ To: Adoram Rogel <adoram@hybridge.com>
+ Subject: Re: Flex 2.5.2 performance questions
+ In-reply-to: Your message of Thu, 19 Sep 96 10:16:04 EDT.
+ Date: Thu, 19 Sep 96 09:58:00 PDT
+ From: Vern Paxson <vern>
+
+ > a lot about the backing up problem.
+ > I believe that there lies my biggest problem, and I'll try to improve
+ > it.
+
+ Since you have variable trailing context, this is a bigger performance
+ problem. Fixing it is usually easier than fixing backing up, which in a
+ complicated scanner (yours seems to fit the bill) can be extremely
+ difficult to do correctly.
+
+ You also don't mention what flags you are using for your scanner.
+ -f makes a large speed difference, and -Cfe buys you nearly as much
+ speed but the resulting scanner is considerably smaller.
+
+ > I have an | operator in {and} and in {pats} so both of them are variable
+ > length.
+
+ -p should have reported this.
+
+ > Is changing one of them to fixed-length is enough ?
+
+ Yes.
+
+ > Is it possible to change the 32,000 states limit ?
+
+ Yes. I've appended instructions on how. Before you make this change,
+ though, you should think about whether there are ways to fundamentally
+ simplify your scanner - those are certainly preferable!
+
+ Vern
+
+ To increase the 32K limit (on a machine with 32 bit integers), you increase
+ the magnitude of the following in flexdef.h:
+
+ #define JAMSTATE -32766 /* marks a reference to the state that always jams */
+ #define MAXIMUM_MNS 31999
+ #define BAD_SUBSCRIPT -32767
+ #define MAX_SHORT 32700
+
+ Adding a 0 or two after each should do the trick.
+
+
+File: flex.info, Node: Can I fake multi-byte character support?, Next: deleteme01, Prev: Is backing up a big deal?, Up: FAQ
+
+Can I fake multi-byte character support?
+========================================
+
+
+ To: Heeman_Lee@hp.com
+ Subject: Re: flex - multi-byte support?
+ In-reply-to: Your message of Thu, 03 Oct 1996 17:24:04 PDT.
+ Date: Fri, 04 Oct 1996 11:42:18 PDT
+ From: Vern Paxson <vern>
+
+ > I assume as long as my *.l file defines the
+ > range of expected character code values (in octal format), flex will
+ > scan the file and read multi-byte characters correctly. But I have no
+ > confidence in this assumption.
+
+ Your lack of confidence is justified - this won't work.
+
+ Flex has in it a widespread assumption that the input is processed
+ one byte at a time. Fixing this is on the to-do list, but is involved,
+ so it won't happen any time soon. In the interim, the best I can suggest
+ (unless you want to try fixing it yourself) is to write your rules in
+ terms of pairs of bytes, using definitions in the first section:
+
+ X \xfe\xc2
+ ...
+ %%
+ foo{X}bar found_foo_fe_c2_bar();
+
+ etc. Definitely a pain - sorry about that.
+
+ By the way, the email address you used for me is ancient, indicating you
+ have a very old version of flex. You can get the most recent, 2.5.4, from
+ ftp.ee.lbl.gov.
+
+ Vern
+
+
+File: flex.info, Node: deleteme01, Next: Can you discuss some flex internals?, Prev: Can I fake multi-byte character support?, Up: FAQ
+
+deleteme01
+==========
+
+
+ To: moleary@primus.com
+ Subject: Re: Flex / Unicode compatibility question
+ In-reply-to: Your message of Tue, 22 Oct 1996 10:15:42 PDT.
+ Date: Tue, 22 Oct 1996 11:06:13 PDT
+ From: Vern Paxson <vern>
+
+ Unfortunately flex at the moment has a widespread assumption within it
+ that characters are processed 8 bits at a time. I don't see any easy
+ fix for this (other than writing your rules in terms of double characters -
+ a pain). I also don't know of a wider lex, though you might try surfing
+ the Plan 9 stuff because I know it's a Unicode system, and also the PCCT
+ toolkit (try searching say Alta Vista for "Purdue Compiler Construction
+ Toolkit").
+
+ Fixing flex to handle wider characters is on the long-term to-do list.
+ But since flex is a strictly spare-time project these days, this probably
+ won't happen for quite a while, unless someone else does it first.
+
+ Vern
+
+
+File: flex.info, Node: Can you discuss some flex internals?, Next: unput() messes up yy_at_bol, Prev: deleteme01, Up: FAQ
+
+Can you discuss some flex internals?
+====================================
+
+
+ To: Johan Linde <jl@theophys.kth.se>
+ Subject: Re: translation of flex
+ In-reply-to: Your message of Sun, 10 Nov 1996 09:16:36 PST.
+ Date: Mon, 11 Nov 1996 10:33:50 PST
+ From: Vern Paxson <vern>
+
+ > I'm working for the Swedish team translating GNU program, and I'm currently
+ > working with flex. I have a few questions about some of the messages which
+ > I hope you can answer.
+
+ All of the things you're wondering about, by the way, concerning flex
+ internals - probably the only person who understands what they mean in
+ English is me! So I wouldn't worry too much about getting them right.
+ That said ...
+
+ > #: main.c:545
+ > msgid " %d protos created\n"
+ >
+ > Does proto mean prototype?
+
+ Yes - prototypes of state compression tables.
+
+ > #: main.c:539
+ > msgid " %d/%d (peak %d) template nxt-chk entries created\n"
+ >
+ > Here I'm mainly puzzled by 'nxt-chk'. I guess it means 'next-check'. (?)
+ > However, 'template next-check entries' doesn't make much sense to me. To be
+ > able to find a good translation I need to know a little bit more about it.
+
+ There is a scheme in the Aho/Sethi/Ullman compiler book for compressing
+ scanner tables. It involves creating two pairs of tables. The first has
+ "base" and "default" entries, the second has "next" and "check" entries.
+ The "base" entry is indexed by the current state and yields an index into
+ the next/check table. The "default" entry gives what to do if the state
+ transition isn't found in next/check. The "next" entry gives the next
+ state to enter, but only if the "check" entry verifies that this entry is
+ correct for the current state. Flex creates templates of series of
+ next/check entries and then encodes differences from these templates as a
+ way to compress the tables.
+
+ > #: main.c:533
+ > msgid " %d/%d base-def entries created\n"
+ >
+ > The same problem here for 'base-def'.
+
+ See above.
+
+ Vern
+
+
+File: flex.info, Node: unput() messes up yy_at_bol, Next: The | operator is not doing what I want, Prev: Can you discuss some flex internals?, Up: FAQ
+
+unput() messes up yy_at_bol
+===========================
+
+
+ To: Xinying Li <xli@npac.syr.edu>
+ Subject: Re: FLEX ?
+ In-reply-to: Your message of Wed, 13 Nov 1996 17:28:38 PST.
+ Date: Wed, 13 Nov 1996 19:51:54 PST
+ From: Vern Paxson <vern>
+
+ > "unput()" them to input flow, question occurs. If I do this after I scan
+ > a carriage, the variable "YY_CURRENT_BUFFER->yy_at_bol" is changed. That
+ > means the carriage flag has gone.
+
+ You can control this by calling yy_set_bol(). It's described in the manual.
+
+ > And if in pre-reading it goes to the end of file, is anything done
+ > to control the end of curren buffer and end of file?
+
+ No, there's no way to put back an end-of-file.
+
+ > By the way I am using flex 2.5.2 and using the "-l".
+
+ The latest release is 2.5.4, by the way. It fixes some bugs in 2.5.2 and
+ 2.5.3. You can get it from ftp.ee.lbl.gov.
+
+ Vern
+
+
+File: flex.info, Node: The | operator is not doing what I want, Next: Why can't flex understand this variable trailing context pattern?, Prev: unput() messes up yy_at_bol, Up: FAQ
+
+The | operator is not doing what I want
+=======================================
+
+
+ To: Alain.ISSARD@st.com
+ Subject: Re: Start condition with FLEX
+ In-reply-to: Your message of Mon, 18 Nov 1996 09:45:02 PST.
+ Date: Mon, 18 Nov 1996 10:41:34 PST
+ From: Vern Paxson <vern>
+
+ > I am not able to use the start condition scope and to use the | (OR) with
+ > rules having start conditions.
+
+ The problem is that if you use '|' as a regular expression operator, for
+ example "a|b" meaning "match either 'a' or 'b'", then it must *not* have
+ any blanks around it. If you instead want the special '|' *action* (which
+ from your scanner appears to be the case), which is a way of giving two
+ different rules the same action:
+
+ foo |
+ bar matched_foo_or_bar();
+
+ then '|' *must* be separated from the first rule by whitespace and *must*
+ be followed by a new line. You *cannot* write it as:
+
+ foo | bar matched_foo_or_bar();
+
+ even though you might think you could because yacc supports this syntax.
+ The reason for this unfortunately incompatibility is historical, but it's
+ unlikely to be changed.
+
+ Your problems with start condition scope are simply due to syntax errors
+ from your use of '|' later confusing flex.
+
+ Let me know if you still have problems.
+
+ Vern
+
+
+File: flex.info, Node: Why can't flex understand this variable trailing context pattern?, Next: The ^ operator isn't working, Prev: The | operator is not doing what I want, Up: FAQ
+
+Why can't flex understand this variable trailing context pattern?
+=================================================================
+
+
+ To: Gregory Margo <gmargo@newton.vip.best.com>
+ Subject: Re: flex-2.5.3 bug report
+ In-reply-to: Your message of Sat, 23 Nov 1996 16:50:09 PST.
+ Date: Sat, 23 Nov 1996 17:07:32 PST
+ From: Vern Paxson <vern>
+
+ > Enclosed is a lex file that "real" lex will process, but I cannot get
+ > flex to process it. Could you try it and maybe point me in the right direction?
+
+ Your problem is that some of the definitions in the scanner use the '/'
+ trailing context operator, and have it enclosed in ()'s. Flex does not
+ allow this operator to be enclosed in ()'s because doing so allows undefined
+ regular expressions such as "(a/b)+". So the solution is to remove the
+ parentheses. Note that you must also be building the scanner with the -l
+ option for AT&T lex compatibility. Without this option, flex automatically
+ encloses the definitions in parentheses.
+
+ Vern
+
+
+File: flex.info, Node: The ^ operator isn't working, Next: Trailing context is getting confused with trailing optional patterns, Prev: Why can't flex understand this variable trailing context pattern?, Up: FAQ
+
+The ^ operator isn't working
+============================
+
+
+ To: Thomas Hadig <hadig@toots.physik.rwth-aachen.de>
+ Subject: Re: Flex Bug ?
+ In-reply-to: Your message of Tue, 26 Nov 1996 14:35:01 PST.
+ Date: Tue, 26 Nov 1996 11:15:05 PST
+ From: Vern Paxson <vern>
+
+ > In my lexer code, i have the line :
+ > ^\*.* { }
+ >
+ > Thus all lines starting with an astrix (*) are comment lines.
+ > This does not work !
+
+ I can't get this problem to reproduce - it works fine for me. Note
+ though that if what you have is slightly different:
+
+ COMMENT ^\*.*
+ %%
+ {COMMENT} { }
+
+ then it won't work, because flex pushes back macro definitions enclosed
+ in ()'s, so the rule becomes
+
+ (^\*.*) { }
+
+ and now that the '^' operator is not at the immediate beginning of the
+ line, it's interpreted as just a regular character. You can avoid this
+ behavior by using the "-l" lex-compatibility flag, or "%option lex-compat".
+
+ Vern
+
+
+File: flex.info, Node: Trailing context is getting confused with trailing optional patterns, Next: Is flex GNU or not?, Prev: The ^ operator isn't working, Up: FAQ
+
+Trailing context is getting confused with trailing optional patterns
+====================================================================
+
+
+ To: Adoram Rogel <adoram@hybridge.com>
+ Subject: Re: Flex 2.5.4 BOF ???
+ In-reply-to: Your message of Tue, 26 Nov 1996 16:10:41 PST.
+ Date: Wed, 27 Nov 1996 10:56:25 PST
+ From: Vern Paxson <vern>
+
+ > Organization(s)?/[a-z]
+ >
+ > This matched "Organizations" (looking in debug mode, the trailing s
+ > was matched with trailing context instead of the optional (s) in the
+ > end of the word.
+
+ That should only happen with lex. Flex can properly match this pattern.
+ (That might be what you're saying, I'm just not sure.)
+
+ > Is there a way to avoid this dangerous trailing context problem ?
+
+ Unfortunately, there's no easy way. On the other hand, I don't see why
+ it should be a problem. Lex's matching is clearly wrong, and I'd hope
+ that usually the intent remains the same as expressed with the pattern,
+ so flex's matching will be correct.
+
+ Vern
+
+
+File: flex.info, Node: Is flex GNU or not?, Next: ERASEME53, Prev: Trailing context is getting confused with trailing optional patterns, Up: FAQ
+
+Is flex GNU or not?
+===================
+
+
+ To: Cameron MacKinnon <mackin@interlog.com>
+ Subject: Re: Flex documentation bug
+ In-reply-to: Your message of Mon, 02 Dec 1996 00:07:08 PST.
+ Date: Sun, 01 Dec 1996 22:29:39 PST
+ From: Vern Paxson <vern>
+
+ > I'm not sure how or where to submit bug reports (documentation or
+ > otherwise) for the GNU project stuff ...
+
+ Well, strictly speaking flex isn't part of the GNU project. They just
+ distribute it because no one's written a decent GPL'd lex replacement.
+ So you should send bugs directly to me. Those sent to the GNU folks
+ sometimes find there way to me, but some may drop between the cracks.
+
+ > In GNU Info, under the section 'Start Conditions', and also in the man
+ > page (mine's dated April '95) is a nice little snippet showing how to
+ > parse C quoted strings into a buffer, defined to be MAX_STR_CONST in
+ > size. Unfortunately, no overflow checking is ever done ...
+
+ This is already mentioned in the manual:
+
+ Finally, here's an example of how to match C-style quoted
+ strings using exclusive start conditions, including expanded
+ escape sequences (but not including checking for a string
+ that's too long):
+
+ The reason for not doing the overflow checking is that it will needlessly
+ clutter up an example whose main purpose is just to demonstrate how to
+ use flex.
+
+ The latest release is 2.5.4, by the way, available from ftp.ee.lbl.gov.
+
+ Vern
+
+
+File: flex.info, Node: ERASEME53, Next: I need to scan if-then-else blocks and while loops, Prev: Is flex GNU or not?, Up: FAQ
+
+ERASEME53
+=========
+
+
+ To: tsv@cs.UManitoba.CA
+ Subject: Re: Flex (reg)..
+ In-reply-to: Your message of Thu, 06 Mar 1997 23:50:16 PST.
+ Date: Thu, 06 Mar 1997 15:54:19 PST
+ From: Vern Paxson <vern>
+
+ > [:alpha:] ([:alnum:] | \\_)*
+
+ If your rule really has embedded blanks as shown above, then it won't
+ work, as the first blank delimits the rule from the action. (It wouldn't
+ even compile ...) You need instead:
+
+ [:alpha:]([:alnum:]|\\_)*
+
+ and that should work fine - there's no restriction on what can go inside
+ of ()'s except for the trailing context operator, '/'.
+
+ Vern
+
+
+File: flex.info, Node: I need to scan if-then-else blocks and while loops, Next: ERASEME55, Prev: ERASEME53, Up: FAQ
+
+I need to scan if-then-else blocks and while loops
+==================================================
+
+
+ To: "Mike Stolnicki" <mstolnic@ford.com>
+ Subject: Re: FLEX help
+ In-reply-to: Your message of Fri, 30 May 1997 13:33:27 PDT.
+ Date: Fri, 30 May 1997 10:46:35 PDT
+ From: Vern Paxson <vern>
+
+ > We'd like to add "if-then-else", "while", and "for" statements to our
+ > language ...
+ > We've investigated many possible solutions. The one solution that seems
+ > the most reasonable involves knowing the position of a TOKEN in yyin.
+
+ I strongly advise you to instead build a parse tree (abstract syntax tree)
+ and loop over that instead. You'll find this has major benefits in keeping
+ your interpreter simple and extensible.
+
+ That said, the functionality you mention for get_position and set_position
+ have been on the to-do list for a while. As flex is a purely spare-time
+ project for me, no guarantees when this will be added (in particular, it
+ for sure won't be for many months to come).
+
+ Vern
+
+
+File: flex.info, Node: ERASEME55, Next: ERASEME56, Prev: I need to scan if-then-else blocks and while loops, Up: FAQ
+
+ERASEME55
+=========
+
+
+ To: Colin Paul Adams <colin@colina.demon.co.uk>
+ Subject: Re: Flex C++ classes and Bison
+ In-reply-to: Your message of 09 Aug 1997 17:11:41 PDT.
+ Date: Fri, 15 Aug 1997 10:48:19 PDT
+ From: Vern Paxson <vern>
+
+ > #define YY_DECL int yylex (YYSTYPE *lvalp, struct parser_control
+ > *parm)
+ >
+ > I have been trying to get this to work as a C++ scanner, but it does
+ > not appear to be possible (warning that it matches no declarations in
+ > yyFlexLexer, or something like that).
+ >
+ > Is this supposed to be possible, or is it being worked on (I DID
+ > notice the comment that scanner classes are still experimental, so I'm
+ > not too hopeful)?
+
+ What you need to do is derive a subclass from yyFlexLexer that provides
+ the above yylex() method, squirrels away lvalp and parm into member
+ variables, and then invokes yyFlexLexer::yylex() to do the regular scanning.
+
+ Vern
+
+
+File: flex.info, Node: ERASEME56, Next: ERASEME57, Prev: ERASEME55, Up: FAQ
+
+ERASEME56
+=========
+
+
+ To: Mikael.Latvala@lmf.ericsson.se
+ Subject: Re: Possible mistake in Flex v2.5 document
+ In-reply-to: Your message of Fri, 05 Sep 1997 16:07:24 PDT.
+ Date: Fri, 05 Sep 1997 10:01:54 PDT
+ From: Vern Paxson <vern>
+
+ > In that example you show how to count comment lines when using
+ > C style /* ... */ comments. My question is, shouldn't you take into
+ > account a scenario where end of a comment marker occurs inside
+ > character or string literals?
+
+ The scanner certainly needs to also scan character and string literals.
+ However it does that (there's an example in the man page for strings), the
+ lexer will recognize the beginning of the literal before it runs across the
+ embedded "/*". Consequently, it will finish scanning the literal before it
+ even considers the possibility of matching "/*".
+
+ Example:
+
+ '([^']*|{ESCAPE_SEQUENCE})'
+
+ will match all the text between the ''s (inclusive). So the lexer
+ considers this as a token beginning at the first ', and doesn't even
+ attempt to match other tokens inside it.
+
+ I thinnk this subtlety is not worth putting in the manual, as I suspect
+ it would confuse more people than it would enlighten.
+
+ Vern
+
+
+File: flex.info, Node: ERASEME57, Next: Is there a repository for flex scanners?, Prev: ERASEME56, Up: FAQ
+
+ERASEME57
+=========
+
+
+ To: "Marty Leisner" <leisner@sdsp.mc.xerox.com>
+ Subject: Re: flex limitations
+ In-reply-to: Your message of Sat, 06 Sep 1997 11:27:21 PDT.
+ Date: Mon, 08 Sep 1997 11:38:08 PDT
+ From: Vern Paxson <vern>
+
+ > %%
+ > [a-zA-Z]+ /* skip a line */
+ > { printf("got %s\n", yytext); }
+ > %%
+
+ What version of flex are you using? If I feed this to 2.5.4, it complains:
+
+ "bug.l", line 5: EOF encountered inside an action
+ "bug.l", line 5: unrecognized rule
+ "bug.l", line 5: fatal parse error
+
+ Not the world's greatest error message, but it manages to flag the problem.
+
+ (With the introduction of start condition scopes, flex can't accommodate
+ an action on a separate line, since it's ambiguous with an indented rule.)
+
+ You can get 2.5.4 from ftp.ee.lbl.gov.
+
+ Vern
+
+
+File: flex.info, Node: Is there a repository for flex scanners?, Next: How can I conditionally compile or preprocess my flex input file?, Prev: ERASEME57, Up: FAQ
+
+Is there a repository for flex scanners?
+========================================
+
+Not that we know of. You might try asking on comp.compilers.
+
+
+File: flex.info, Node: How can I conditionally compile or preprocess my flex input file?, Next: Where can I find grammars for lex and yacc?, Prev: Is there a repository for flex scanners?, Up: FAQ
+
+How can I conditionally compile or preprocess my flex input file?
+=================================================================
+
+Flex doesn't have a preprocessor like C does. You might try using m4,
+or the C preprocessor plus a sed script to clean up the result.
+
+
+File: flex.info, Node: Where can I find grammars for lex and yacc?, Next: I get an end-of-buffer message for each character scanned., Prev: How can I conditionally compile or preprocess my flex input file?, Up: FAQ
+
+Where can I find grammars for lex and yacc?
+===========================================
+
+In the sources for flex and bison.
+
+
+File: flex.info, Node: I get an end-of-buffer message for each character scanned., Next: unnamed-faq-62, Prev: Where can I find grammars for lex and yacc?, Up: FAQ
+
+I get an end-of-buffer message for each character scanned.
+==========================================================
+
+This will happen if your LexerInput() function returns only one
+character at a time, which can happen either if you're scanner is
+"interactive", or if the streams library on your platform always
+returns 1 for yyin->gcount().
+
+ Solution: override LexerInput() with a version that returns whole
+buffers.
+
+
+File: flex.info, Node: unnamed-faq-62, Next: unnamed-faq-63, Prev: I get an end-of-buffer message for each character scanned., Up: FAQ
+
+unnamed-faq-62
+==============
+
+
+ To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
+ Subject: Re: Flex maximums
+ In-reply-to: Your message of Mon, 17 Nov 1997 17:16:06 PST.
+ Date: Mon, 17 Nov 1997 17:16:15 PST
+ From: Vern Paxson <vern>
+
+ > I took a quick look into the flex-sources and altered some #defines in
+ > flexdefs.h:
+ >
+ > #define INITIAL_MNS 64000
+ > #define MNS_INCREMENT 1024000
+ > #define MAXIMUM_MNS 64000
+
+ The things to fix are to add a couple of zeroes to:
+
+ #define JAMSTATE -32766 /* marks a reference to the state that always jams */
+ #define MAXIMUM_MNS 31999
+ #define BAD_SUBSCRIPT -32767
+ #define MAX_SHORT 32700
+
+ and, if you get complaints about too many rules, make the following change too:
+
+ #define YY_TRAILING_MASK 0x200000
+ #define YY_TRAILING_HEAD_MASK 0x400000
+
+ - Vern
+
+
+File: flex.info, Node: unnamed-faq-63, Next: unnamed-faq-64, Prev: unnamed-faq-62, Up: FAQ
+
+unnamed-faq-63
+==============
+
+
+ To: jimmey@lexis-nexis.com (Jimmey Todd)
+ Subject: Re: FLEX question regarding istream vs ifstream
+ In-reply-to: Your message of Mon, 08 Dec 1997 15:54:15 PST.
+ Date: Mon, 15 Dec 1997 13:21:35 PST
+ From: Vern Paxson <vern>
+
+ > stdin_handle = YY_CURRENT_BUFFER;
+ > ifstream fin( "aFile" );
+ > yy_switch_to_buffer( yy_create_buffer( fin, YY_BUF_SIZE ) );
+ >
+ > What I'm wanting to do, is pass the contents of a file thru one set
+ > of rules and then pass stdin thru another set... It works great if, I
+ > don't use the C++ classes. But since everything else that I'm doing is
+ > in C++, I thought I'd be consistent.
+ >
+ > The problem is that 'yy_create_buffer' is expecting an istream* as it's
+ > first argument (as stated in the man page). However, fin is a ifstream
+ > object. Any ideas on what I might be doing wrong? Any help would be
+ > appreciated. Thanks!!
+
+ You need to pass &fin, to turn it into an ifstream* instead of an ifstream.
+ Then its type will be compatible with the expected istream*, because ifstream
+ is derived from istream.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-64, Next: unnamed-faq-65, Prev: unnamed-faq-63, Up: FAQ
+
+unnamed-faq-64
+==============
+
+
+ To: Enda Fadian <fadiane@piercom.ie>
+ Subject: Re: Question related to Flex man page?
+ In-reply-to: Your message of Tue, 16 Dec 1997 15:17:34 PST.
+ Date: Tue, 16 Dec 1997 14:17:09 PST
+ From: Vern Paxson <vern>
+
+ > Can you explain to me what is ment by a long-jump in relation to flex?
+
+ Using the longjmp() function while inside yylex() or a routine called by it.
+
+ > what is the flex activation frame.
+
+ Just yylex()'s stack frame.
+
+ > As far as I can see yyrestart will bring me back to the sart of the input
+ > file and using flex++ isnot really an option!
+
+ No, yyrestart() doesn't imply a rewind, even though its name might sound
+ like it does. It tells the scanner to flush its internal buffers and
+ start reading from the given file at its present location.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-65, Next: unnamed-faq-66, Prev: unnamed-faq-64, Up: FAQ
+
+unnamed-faq-65
+==============
+
+
+ To: hassan@larc.info.uqam.ca (Hassan Alaoui)
+ Subject: Re: Need urgent Help
+ In-reply-to: Your message of Sat, 20 Dec 1997 19:38:19 PST.
+ Date: Sun, 21 Dec 1997 21:30:46 PST
+ From: Vern Paxson <vern>
+
+ > /usr/lib/yaccpar: In function `int yyparse()':
+ > /usr/lib/yaccpar:184: warning: implicit declaration of function `int yylex(...)'
+ >
+ > ld: Undefined symbol
+ > _yylex
+ > _yyparse
+ > _yyin
+
+ This is a known problem with Solaris C++ (and/or Solaris yacc). I believe
+ the fix is to explicitly insert some 'extern "C"' statements for the
+ corresponding routines/symbols.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-66, Next: unnamed-faq-67, Prev: unnamed-faq-65, Up: FAQ
+
+unnamed-faq-66
+==============
+
+
+ To: mc0307@mclink.it
+ Cc: gnu@prep.ai.mit.edu
+ Subject: Re: [mc0307@mclink.it: Help request]
+ In-reply-to: Your message of Fri, 12 Dec 1997 17:57:29 PST.
+ Date: Sun, 21 Dec 1997 22:33:37 PST
+ From: Vern Paxson <vern>
+
+ > This is my definition for float and integer types:
+ > . . .
+ > NZD [1-9]
+ > ...
+ > I've tested my program on other lex version (on UNIX Sun Solaris an HP
+ > UNIX) and it work well, so I think that my definitions are correct.
+ > There are any differences between Lex and Flex?
+
+ There are indeed differences, as discussed in the man page. The one
+ you are probably running into is that when flex expands a name definition,
+ it puts parentheses around the expansion, while lex does not. There's
+ an example in the man page of how this can lead to different matching.
+ Flex's behavior complies with the POSIX standard (or at least with the
+ last POSIX draft I saw).
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-67, Next: unnamed-faq-68, Prev: unnamed-faq-66, Up: FAQ
+
+unnamed-faq-67
+==============
+
+
+ To: hassan@larc.info.uqam.ca (Hassan Alaoui)
+ Subject: Re: Thanks
+ In-reply-to: Your message of Mon, 22 Dec 1997 16:06:35 PST.
+ Date: Mon, 22 Dec 1997 14:35:05 PST
+ From: Vern Paxson <vern>
+
+ > Thank you very much for your help. I compile and link well with C++ while
+ > declaring 'yylex ...' extern, But a little problem remains. I get a
+ > segmentation default when executing ( I linked with lfl library) while it
+ > works well when using LEX instead of flex. Do you have some ideas about the
+ > reason for this ?
+
+ The one possible reason for this that comes to mind is if you've defined
+ yytext as "extern char yytext[]" (which is what lex uses) instead of
+ "extern char *yytext" (which is what flex uses). If it's not that, then
+ I'm afraid I don't know what the problem might be.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-68, Next: unnamed-faq-69, Prev: unnamed-faq-67, Up: FAQ
+
+unnamed-faq-68
+==============
+
+
+ To: "Bart Niswonger" <NISWONGR@almaden.ibm.com>
+ Subject: Re: flex 2.5: c++ scanners & start conditions
+ In-reply-to: Your message of Tue, 06 Jan 1998 10:34:21 PST.
+ Date: Tue, 06 Jan 1998 19:19:30 PST
+ From: Vern Paxson <vern>
+
+ > The problem is that when I do this (using %option c++) start
+ > conditions seem to not apply.
+
+ The BEGIN macro modifies the yy_start variable. For C scanners, this
+ is a static with scope visible through the whole file. For C++ scanners,
+ it's a member variable, so it only has visible scope within a member
+ function. Your lexbegin() routine is not a member function when you
+ build a C++ scanner, so it's not modifying the correct yy_start. The
+ diagnostic that indicates this is that you found you needed to add
+ a declaration of yy_start in order to get your scanner to compile when
+ using C++; instead, the correct fix is to make lexbegin() a member
+ function (by deriving from yyFlexLexer).
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-69, Next: unnamed-faq-70, Prev: unnamed-faq-68, Up: FAQ
+
+unnamed-faq-69
+==============
+
+
+ To: "Boris Zinin" <boris@ippe.rssi.ru>
+ Subject: Re: current position in flex buffer
+ In-reply-to: Your message of Mon, 12 Jan 1998 18:58:23 PST.
+ Date: Mon, 12 Jan 1998 12:03:15 PST
+ From: Vern Paxson <vern>
+
+ > The problem is how to determine the current position in flex active
+ > buffer when a rule is matched....
+
+ You will need to keep track of this explicitly, such as by redefining
+ YY_USER_ACTION to count the number of characters matched.
+
+ The latest flex release, by the way, is 2.5.4, available from ftp.ee.lbl.gov.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-70, Next: unnamed-faq-71, Prev: unnamed-faq-69, Up: FAQ
+
+unnamed-faq-70
+==============
+
+
+ To: Bik.Dhaliwal@bis.org
+ Subject: Re: Flex question
+ In-reply-to: Your message of Mon, 26 Jan 1998 13:05:35 PST.
+ Date: Tue, 27 Jan 1998 22:41:52 PST
+ From: Vern Paxson <vern>
+
+ > That requirement involves knowing
+ > the character position at which a particular token was matched
+ > in the lexer.
+
+ The way you have to do this is by explicitly keeping track of where
+ you are in the file, by counting the number of characters scanned
+ for each token (available in yyleng). It may prove convenient to
+ do this by redefining YY_USER_ACTION, as described in the manual.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-71, Next: unnamed-faq-72, Prev: unnamed-faq-70, Up: FAQ
+
+unnamed-faq-71
+==============
+
+
+ To: Vladimir Alexiev <vladimir@cs.ualberta.ca>
+ Subject: Re: flex: how to control start condition from parser?
+ In-reply-to: Your message of Mon, 26 Jan 1998 05:50:16 PST.
+ Date: Tue, 27 Jan 1998 22:45:37 PST
+ From: Vern Paxson <vern>
+
+ > It seems useful for the parser to be able to tell the lexer about such
+ > context dependencies, because then they don't have to be limited to
+ > local or sequential context.
+
+ One way to do this is to have the parser call a stub routine that's
+ included in the scanner's .l file, and consequently that has access ot
+ BEGIN. The only ugliness is that the parser can't pass in the state
+ it wants, because those aren't visible - but if you don't have many
+ such states, then using a different set of names doesn't seem like
+ to much of a burden.
+
+ While generating a .h file like you suggests is certainly cleaner,
+ flex development has come to a virtual stand-still :-(, so a workaround
+ like the above is much more pragmatic than waiting for a new feature.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-72, Next: unnamed-faq-73, Prev: unnamed-faq-71, Up: FAQ
+
+unnamed-faq-72
+==============
+
+
+ To: Barbara Denny <denny@3com.com>
+ Subject: Re: freebsd flex bug?
+ In-reply-to: Your message of Fri, 30 Jan 1998 12:00:43 PST.
+ Date: Fri, 30 Jan 1998 12:42:32 PST
+ From: Vern Paxson <vern>
+
+ > lex.yy.c:1996: parse error before `='
+
+ This is the key, identifying this error. (It may help to pinpoint
+ it by using flex -L, so it doesn't generate #line directives in its
+ output.) I will bet you heavy money that you have a start condition
+ name that is also a variable name, or something like that; flex spits
+ out #define's for each start condition name, mapping them to a number,
+ so you can wind up with:
+
+ %x foo
+ %%
+ ...
+ %%
+ void bar()
+ {
+ int foo = 3;
+ }
+
+ and the penultimate will turn into "int 1 = 3" after C preprocessing,
+ since flex will put "#define foo 1" in the generated scanner.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-73, Next: unnamed-faq-74, Prev: unnamed-faq-72, Up: FAQ
+
+unnamed-faq-73
+==============
+
+
+ To: Maurice Petrie <mpetrie@infoscigroup.com>
+ Subject: Re: Lost flex .l file
+ In-reply-to: Your message of Mon, 02 Feb 1998 14:10:01 PST.
+ Date: Mon, 02 Feb 1998 11:15:12 PST
+ From: Vern Paxson <vern>
+
+ > I am curious as to
+ > whether there is a simple way to backtrack from the generated source to
+ > reproduce the lost list of tokens we are searching on.
+
+ In theory, it's straight-forward to go from the DFA representation
+ back to a regular-expression representation - the two are isomorphic.
+ In practice, a huge headache, because you have to unpack all the tables
+ back into a single DFA representation, and then write a program to munch
+ on that and translate it into an RE.
+
+ Sorry for the less-than-happy news ...
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-74, Next: unnamed-faq-75, Prev: unnamed-faq-73, Up: FAQ
+
+unnamed-faq-74
+==============
+
+
+ To: jimmey@lexis-nexis.com (Jimmey Todd)
+ Subject: Re: Flex performance question
+ In-reply-to: Your message of Thu, 19 Feb 1998 11:01:17 PST.
+ Date: Thu, 19 Feb 1998 08:48:51 PST
+ From: Vern Paxson <vern>
+
+ > What I have found, is that the smaller the data chunk, the faster the
+ > program executes. This is the opposite of what I expected. Should this be
+ > happening this way?
+
+ This is exactly what will happen if your input file has embedded NULs.
+ From the man page:
+
+ A final note: flex is slow when matching NUL's, particularly
+ when a token contains multiple NUL's. It's best to write
+ rules which match short amounts of text if it's anticipated
+ that the text will often include NUL's.
+
+ So that's the first thing to look for.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-75, Next: unnamed-faq-76, Prev: unnamed-faq-74, Up: FAQ
+
+unnamed-faq-75
+==============
+
+
+ To: jimmey@lexis-nexis.com (Jimmey Todd)
+ Subject: Re: Flex performance question
+ In-reply-to: Your message of Thu, 19 Feb 1998 11:01:17 PST.
+ Date: Thu, 19 Feb 1998 15:42:25 PST
+ From: Vern Paxson <vern>
+
+ So there are several problems.
+
+ First, to go fast, you want to match as much text as possible, which
+ your scanners don't in the case that what they're scanning is *not*
+ a <RN> tag. So you want a rule like:
+
+ [^<]+
+
+ Second, C++ scanners are particularly slow if they're interactive,
+ which they are by default. Using -B speeds it up by a factor of 3-4
+ on my workstation.
+
+ Third, C++ scanners that use the istream interface are slow, because
+ of how poorly implemented istream's are. I built two versions of
+ the following scanner:
+
+ %%
+ .*\n
+ .*
+ %%
+
+ and the C version inhales a 2.5MB file on my workstation in 0.8 seconds.
+ The C++ istream version, using -B, takes 3.8 seconds.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-76, Next: unnamed-faq-77, Prev: unnamed-faq-75, Up: FAQ
+
+unnamed-faq-76
+==============
+
+
+ To: "Frescatore, David (CRD, TAD)" <frescatore@exc01crdge.crd.ge.com>
+ Subject: Re: FLEX 2.5 & THE YEAR 2000
+ In-reply-to: Your message of Wed, 03 Jun 1998 11:26:22 PDT.
+ Date: Wed, 03 Jun 1998 10:22:26 PDT
+ From: Vern Paxson <vern>
+
+ > I am researching the Y2K problem with General Electric R&D
+ > and need to know if there are any known issues concerning
+ > the above mentioned software and Y2K regardless of version.
+
+ There shouldn't be, all it ever does with the date is ask the system
+ for it and then print it out.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-77, Next: unnamed-faq-78, Prev: unnamed-faq-76, Up: FAQ
+
+unnamed-faq-77
+==============
+
+
+ To: "Hans Dermot Doran" <htd@ibhdoran.com>
+ Subject: Re: flex problem
+ In-reply-to: Your message of Wed, 15 Jul 1998 21:30:13 PDT.
+ Date: Tue, 21 Jul 1998 14:23:34 PDT
+ From: Vern Paxson <vern>
+
+ > To overcome this, I gets() the stdin into a string and lex the string. The
+ > string is lexed OK except that the end of string isn't lexed properly
+ > (yy_scan_string()), that is the lexer dosn't recognise the end of string.
+
+ Flex doesn't contain mechanisms for recognizing buffer endpoints. But if
+ you use fgets instead (which you should anyway, to protect against buffer
+ overflows), then the final \n will be preserved in the string, and you can
+ scan that in order to find the end of the string.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-78, Next: unnamed-faq-79, Prev: unnamed-faq-77, Up: FAQ
+
+unnamed-faq-78
+==============
+
+
+ To: soumen@almaden.ibm.com
+ Subject: Re: Flex++ 2.5.3 instance member vs. static member
+ In-reply-to: Your message of Mon, 27 Jul 1998 02:10:04 PDT.
+ Date: Tue, 28 Jul 1998 01:10:34 PDT
+ From: Vern Paxson <vern>
+
+ > %{
+ > int mylineno = 0;
+ > %}
+ > ws [ \t]+
+ > alpha [A-Za-z]
+ > dig [0-9]
+ > %%
+ >
+ > Now you'd expect mylineno to be a member of each instance of class
+ > yyFlexLexer, but is this the case? A look at the lex.yy.cc file seems to
+ > indicate otherwise; unless I am missing something the declaration of
+ > mylineno seems to be outside any class scope.
+ >
+ > How will this work if I want to run a multi-threaded application with each
+ > thread creating a FlexLexer instance?
+
+ Derive your own subclass and make mylineno a member variable of it.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-79, Next: unnamed-faq-80, Prev: unnamed-faq-78, Up: FAQ
+
+unnamed-faq-79
+==============
+
+
+ To: Adoram Rogel <adoram@hybridge.com>
+ Subject: Re: More than 32K states change hangs
+ In-reply-to: Your message of Tue, 04 Aug 1998 16:55:39 PDT.
+ Date: Tue, 04 Aug 1998 22:28:45 PDT
+ From: Vern Paxson <vern>
+
+ > Vern Paxson,
+ >
+ > I followed your advice, posted on Usenet bu you, and emailed to me
+ > personally by you, on how to overcome the 32K states limit. I'm running
+ > on Linux machines.
+ > I took the full source of version 2.5.4 and did the following changes in
+ > flexdef.h:
+ > #define JAMSTATE -327660
+ > #define MAXIMUM_MNS 319990
+ > #define BAD_SUBSCRIPT -327670
+ > #define MAX_SHORT 327000
+ >
+ > and compiled.
+ > All looked fine, including check and bigcheck, so I installed.
+
+ Hmmm, you shouldn't increase MAX_SHORT, though looking through my email
+ archives I see that I did indeed recommend doing so. Try setting it back
+ to 32700; that should suffice that you no longer need -Ca. If it still
+ hangs, then the interesting question is - where?
+
+ > Compiling the same hanged program with a out-of-the-box (RedHat 4.2
+ > distribution of Linux)
+ > flex 2.5.4 binary works.
+
+ Since Linux comes with source code, you should diff it against what
+ you have to see what problems they missed.
+
+ > Should I always compile with the -Ca option now ? even short and simple
+ > filters ?
+
+ No, definitely not. It's meant to be for those situations where you
+ absolutely must squeeze every last cycle out of your scanner.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-80, Next: unnamed-faq-81, Prev: unnamed-faq-79, Up: FAQ
+
+unnamed-faq-80
+==============
+
+
+ To: "Schmackpfeffer, Craig" <Craig.Schmackpfeffer@usa.xerox.com>
+ Subject: Re: flex output for static code portion
+ In-reply-to: Your message of Tue, 11 Aug 1998 11:55:30 PDT.
+ Date: Mon, 17 Aug 1998 23:57:42 PDT
+ From: Vern Paxson <vern>
+
+ > I would like to use flex under the hood to generate a binary file
+ > containing the data structures that control the parse.
+
+ This has been on the wish-list for a long time. In principle it's
+ straight-forward - you redirect mkdata() et al's I/O to another file,
+ and modify the skeleton to have a start-up function that slurps these
+ into dynamic arrays. The concerns are (1) the scanner generation code
+ is hairy and full of corner cases, so it's easy to get surprised when
+ going down this path :-( ; and (2) being careful about buffering so
+ that when the tables change you make sure the scanner starts in the
+ correct state and reading at the right point in the input file.
+
+ > I was wondering if you know of anyone who has used flex in this way.
+
+ I don't - but it seems like a reasonable project to undertake (unlike
+ numerous other flex tweaks :-).
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-81, Next: unnamed-faq-82, Prev: unnamed-faq-80, Up: FAQ
+
+unnamed-faq-81
+==============
+
+
+ Received: from 131.173.17.11 (131.173.17.11 [131.173.17.11])
+ by ee.lbl.gov (8.9.1/8.9.1) with ESMTP id AAA03838
+ for <vern@ee.lbl.gov>; Thu, 20 Aug 1998 00:47:57 -0700 (PDT)
+ Received: from hal.cl-ki.uni-osnabrueck.de (hal.cl-ki.Uni-Osnabrueck.DE [131.173.141.2])
+ by deimos.rz.uni-osnabrueck.de (8.8.7/8.8.8) with ESMTP id JAA34694
+ for <vern@ee.lbl.gov>; Thu, 20 Aug 1998 09:47:55 +0200
+ Received: (from georg@localhost) by hal.cl-ki.uni-osnabrueck.de (8.6.12/8.6.12) id JAA34834 for vern@ee.lbl.gov; Thu, 20 Aug 1998 09:47:54 +0200
+ From: Georg Rehm <georg@hal.cl-ki.uni-osnabrueck.de>
+ Message-Id: <199808200747.JAA34834@hal.cl-ki.uni-osnabrueck.de>
+ Subject: "flex scanner push-back overflow"
+ To: vern@ee.lbl.gov
+ Date: Thu, 20 Aug 1998 09:47:54 +0200 (MEST)
+ Reply-To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
+ X-NoJunk: Do NOT send commercial mail, spam or ads to this address!
+ X-URL: http://www.cl-ki.uni-osnabrueck.de/~georg/
+ X-Mailer: ELM [version 2.4ME+ PL28 (25)]
+ MIME-Version: 1.0
+ Content-Type: text/plain; charset=US-ASCII
+ Content-Transfer-Encoding: 7bit
+
+ Hi Vern,
+
+ Yesterday, I encountered a strange problem: I use the macro processor m4
+ to include some lengthy lists into a .l file. Following is a flex macro
+ definition that causes some serious pain in my neck:
+
+ AUTHOR ("A. Boucard / L. Boucard"|"A. Dastarac / M. Levent"|"A.Boucaud / L.Boucaud"|"Abderrahim Lamchichi"|"Achmat Dangor"|"Adeline Toullier"|"Adewale Maja-Pearce"|"Ahmed Ziri"|"Akram Ellyas"|"Alain Bihr"|"Alain Gresh"|"Alain Guillemoles"|"Alain Joxe"|"Alain Morice"|"Alain Renon"|"Alain Zecchini"|"Albert Memmi"|"Alberto Manguel"|"Alex De Waal"|"Alfonso Artico"| [...])
+
+ The complete list contains about 10kB. When I try to "flex" this file
+ (on a Solaris 2.6 machine, using a modified flex 2.5.4 (I only increased
+ some of the predefined values in flexdefs.h) I get the error:
+
+ myflex/flex -8 sentag.tmp.l
+ flex scanner push-back overflow
+
+ When I remove the slashes in the macro definition everything works fine.
+ As I understand it, the double quotes escape the slash-character so it
+ really means "/" and not "trailing context". Furthermore, I tried to
+ escape the slashes with backslashes, but with no use, the same error message
+ appeared when flexing the code.
+
+ Do you have an idea what's going on here?
+
+ Greetings from Germany,
+ Georg
+ --
+ Georg Rehm georg@cl-ki.uni-osnabrueck.de
+ Institute for Semantic Information Processing, University of Osnabrueck, FRG
+
+
+File: flex.info, Node: unnamed-faq-82, Next: unnamed-faq-83, Prev: unnamed-faq-81, Up: FAQ
+
+unnamed-faq-82
+==============
+
+
+ To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
+ Subject: Re: "flex scanner push-back overflow"
+ In-reply-to: Your message of Thu, 20 Aug 1998 09:47:54 PDT.
+ Date: Thu, 20 Aug 1998 07:05:35 PDT
+ From: Vern Paxson <vern>
+
+ > myflex/flex -8 sentag.tmp.l
+ > flex scanner push-back overflow
+
+ Flex itself uses a flex scanner. That scanner is running out of buffer
+ space when it tries to unput() the humongous macro you've defined. When
+ you remove the '/'s, you make it small enough so that it fits in the buffer;
+ removing spaces would do the same thing.
+
+ The fix is to either rethink how come you're using such a big macro and
+ perhaps there's another/better way to do it; or to rebuild flex's own
+ scan.c with a larger value for
+
+ #define YY_BUF_SIZE 16384
+
+ - Vern
+
+
+File: flex.info, Node: unnamed-faq-83, Next: unnamed-faq-84, Prev: unnamed-faq-82, Up: FAQ
+
+unnamed-faq-83
+==============
+
+
+ To: Jan Kort <jan@research.techforce.nl>
+ Subject: Re: Flex
+ In-reply-to: Your message of Fri, 04 Sep 1998 12:18:43 +0200.
+ Date: Sat, 05 Sep 1998 00:59:49 PDT
+ From: Vern Paxson <vern>
+
+ > %%
+ >
+ > "TEST1\n" { fprintf(stderr, "TEST1\n"); yyless(5); }
+ > ^\n { fprintf(stderr, "empty line\n"); }
+ > . { }
+ > \n { fprintf(stderr, "new line\n"); }
+ >
+ > %%
+ > -- input ---------------------------------------
+ > TEST1
+ > -- output --------------------------------------
+ > TEST1
+ > empty line
+ > ------------------------------------------------
+
+ IMHO, it's not clear whether or not this is in fact a bug. It depends
+ on whether you view yyless() as backing up in the input stream, or as
+ pushing new characters onto the beginning of the input stream. Flex
+ interprets it as the latter (for implementation convenience, I'll admit),
+ and so considers the newline as in fact matching at the beginning of a
+ line, as after all the last token scanned an entire line and so the
+ scanner is now at the beginning of a new line.
+
+ I agree that this is counter-intuitive for yyless(), given its
+ functional description (it's less so for unput(), depending on whether
+ you're unput()'ing new text or scanned text). But I don't plan to
+ change it any time soon, as it's a pain to do so. Consequently,
+ you do indeed need to use yy_set_bol() and YY_AT_BOL() to tweak
+ your scanner into the behavior you desire.
+
+ Sorry for the less-than-completely-satisfactory answer.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-84, Next: unnamed-faq-85, Prev: unnamed-faq-83, Up: FAQ
+
+unnamed-faq-84
+==============
+
+
+ To: Patrick Krusenotto <krusenot@mac-info-link.de>
+ Subject: Re: Problems with restarting flex-2.5.2-generated scanner
+ In-reply-to: Your message of Thu, 24 Sep 1998 10:14:07 PDT.
+ Date: Thu, 24 Sep 1998 23:28:43 PDT
+ From: Vern Paxson <vern>
+
+ > I am using flex-2.5.2 and bison 1.25 for Solaris and I am desperately
+ > trying to make my scanner restart with a new file after my parser stops
+ > with a parse error. When my compiler restarts, the parser always
+ > receives the token after the token (in the old file!) that caused the
+ > parser error.
+
+ I suspect the problem is that your parser has read ahead in order
+ to attempt to resolve an ambiguity, and when it's restarted it picks
+ up with that token rather than reading a fresh one. If you're using
+ yacc, then the special "error" production can sometimes be used to
+ consume tokens in an attempt to get the parser into a consistent state.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-85, Next: unnamed-faq-86, Prev: unnamed-faq-84, Up: FAQ
+
+unnamed-faq-85
+==============
+
+
+ To: Henric Jungheim <junghelh@pe-nelson.com>
+ Subject: Re: flex 2.5.4a
+ In-reply-to: Your message of Tue, 27 Oct 1998 16:41:42 PST.
+ Date: Tue, 27 Oct 1998 16:50:14 PST
+ From: Vern Paxson <vern>
+
+ > This brings up a feature request: How about a command line
+ > option to specify the filename when reading from stdin? That way one
+ > doesn't need to create a temporary file in order to get the "#line"
+ > directives to make sense.
+
+ Use -o combined with -t (per the man page description of -o).
+
+ > P.S., Is there any simple way to use non-blocking IO to parse multiple
+ > streams?
+
+ Simple, no.
+
+ One approach might be to return a magic character on EWOULDBLOCK and
+ have a rule
+
+ .*<magic-character> // put back .*, eat magic character
+
+ This is off the top of my head, not sure it'll work.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-86, Next: unnamed-faq-87, Prev: unnamed-faq-85, Up: FAQ
+
+unnamed-faq-86
+==============
+
+
+ To: "Repko, Billy D" <billy.d.repko@intel.com>
+ Subject: Re: Compiling scanners
+ In-reply-to: Your message of Wed, 13 Jan 1999 10:52:47 PST.
+ Date: Thu, 14 Jan 1999 00:25:30 PST
+ From: Vern Paxson <vern>
+
+ > It appears that maybe it cannot find the lfl library.
+
+ The Makefile in the distribution builds it, so you should have it.
+ It's exceedingly trivial, just a main() that calls yylex() and
+ a yyrap() that always returns 1.
+
+ > %%
+ > \n ++num_lines; ++num_chars;
+ > . ++num_chars;
+
+ You can't indent your rules like this - that's where the errors are coming
+ from. Flex copies indented text to the output file, it's how you do things
+ like
+
+ int num_lines_seen = 0;
+
+ to declare local variables.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-87, Next: unnamed-faq-88, Prev: unnamed-faq-86, Up: FAQ
+
+unnamed-faq-87
+==============
+
+
+ To: Erick Branderhorst <Erick.Branderhorst@asml.nl>
+ Subject: Re: flex input buffer
+ In-reply-to: Your message of Tue, 09 Feb 1999 13:53:46 PST.
+ Date: Tue, 09 Feb 1999 21:03:37 PST
+ From: Vern Paxson <vern>
+
+ > In the flex.skl file the size of the default input buffers is set. Can you
+ > explain why this size is set and why it is such a high number.
+
+ It's large to optimize performance when scanning large files. You can
+ safely make it a lot lower if needed.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-88, Next: unnamed-faq-90, Prev: unnamed-faq-87, Up: FAQ
+
+unnamed-faq-88
+==============
+
+
+ To: "Guido Minnen" <guidomi@cogs.susx.ac.uk>
+ Subject: Re: Flex error message
+ In-reply-to: Your message of Wed, 24 Feb 1999 15:31:46 PST.
+ Date: Thu, 25 Feb 1999 00:11:31 PST
+ From: Vern Paxson <vern>
+
+ > I'm extending a larger scanner written in Flex and I keep running into
+ > problems. More specifically, I get the error message:
+ > "flex: input rules are too complicated (>= 32000 NFA states)"
+
+ Increase the definitions in flexdef.h for:
+
+ #define JAMSTATE -32766 /* marks a reference to the state that always j
+ ams */
+ #define MAXIMUM_MNS 31999
+ #define BAD_SUBSCRIPT -32767
+
+ recompile everything, and it should all work.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-90, Next: unnamed-faq-91, Prev: unnamed-faq-88, Up: FAQ
+
+unnamed-faq-90
+==============
+
+
+ To: "Dmitriy Goldobin" <gold@ems.chel.su>
+ Subject: Re: FLEX trouble
+ In-reply-to: Your message of Mon, 31 May 1999 18:44:49 PDT.
+ Date: Tue, 01 Jun 1999 00:15:07 PDT
+ From: Vern Paxson <vern>
+
+ > I have a trouble with FLEX. Why rule "/*".*"*/" work properly,=20
+ > but rule "/*"(.|\n)*"*/" don't work ?
+
+ The second of these will have to scan the entire input stream (because
+ "(.|\n)*" matches an arbitrary amount of any text) in order to see if
+ it ends with "*/", terminating the comment. That potentially will overflow
+ the input buffer.
+
+ > More complex rule "/*"([^*]|(\*/[^/]))*"*/ give an error
+ > 'unrecognized rule'.
+
+ You can't use the '/' operator inside parentheses. It's not clear
+ what "(a/b)*" actually means.
+
+ > I now use workaround with state <comment>, but single-rule is
+ > better, i think.
+
+ Single-rule is nice but will always have the problem of either setting
+ restrictions on comments (like not allowing multi-line comments) and/or
+ running the risk of consuming the entire input stream, as noted above.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-91, Next: unnamed-faq-92, Prev: unnamed-faq-90, Up: FAQ
+
+unnamed-faq-91
+==============
+
+
+ Received: from mc-qout4.whowhere.com (mc-qout4.whowhere.com [209.185.123.18])
+ by ee.lbl.gov (8.9.3/8.9.3) with SMTP id IAA05100
+ for <vern@ee.lbl.gov>; Tue, 15 Jun 1999 08:56:06 -0700 (PDT)
+ Received: from Unknown/Local ([?.?.?.?]) by my-deja.com; Tue Jun 15 08:55:43 1999
+ To: vern@ee.lbl.gov
+ Date: Tue, 15 Jun 1999 08:55:43 -0700
+ From: "Aki Niimura" <neko@my-deja.com>
+ Message-ID: <KNONDOHDOBGAEAAA@my-deja.com>
+ Mime-Version: 1.0
+ Cc:
+ X-Sent-Mail: on
+ Reply-To:
+ X-Mailer: MailCity Service
+ Subject: A question on flex C++ scanner
+ X-Sender-Ip: 12.72.207.61
+ Organization: My Deja Email (http://www.my-deja.com:80)
+ Content-Type: text/plain; charset=us-ascii
+ Content-Transfer-Encoding: 7bit
+
+ Dear Dr. Paxon,
+
+ I have been using flex for years.
+ It works very well on many projects.
+ Most case, I used it to generate a scanner on C language.
+ However, one project I needed to generate a scanner
+ on C++ lanuage. Thanks to your enhancement, flex did
+ the job.
+
+ Currently, I'm working on enhancing my previous project.
+ I need to deal with multiple input streams (recursive
+ inclusion) in this scanner (C++).
+ I did similar thing for another scanner (C) as you
+ explained in your documentation.
+
+ The generated scanner (C++) has necessary methods:
+ - switch_to_buffer(struct yy_buffer_state *b)
+ - yy_create_buffer(istream *is, int sz)
+ - yy_delete_buffer(struct yy_buffer_state *b)
+
+ However, I couldn't figure out how to access current
+ buffer (yy_current_buffer).
+
+ yy_current_buffer is a protected member of yyFlexLexer.
+ I can't access it directly.
+ Then, I thought yy_create_buffer() with is = 0 might
+ return current stream buffer. But it seems not as far
+ as I checked the source. (flex 2.5.4)
+
+ I went through the Web in addition to Flex documentation.
+ However, it hasn't been successful, so far.
+
+ It is not my intention to bother you, but, can you
+ comment about how to obtain the current stream buffer?
+
+ Your response would be highly appreciated.
+
+ Best regards,
+ Aki Niimura
+
+ --== Sent via Deja.com http://www.deja.com/ ==--
+ Share what you know. Learn what you don't.
+
+
+File: flex.info, Node: unnamed-faq-92, Next: unnamed-faq-93, Prev: unnamed-faq-91, Up: FAQ
+
+unnamed-faq-92
+==============
+
+
+ To: neko@my-deja.com
+ Subject: Re: A question on flex C++ scanner
+ In-reply-to: Your message of Tue, 15 Jun 1999 08:55:43 PDT.
+ Date: Tue, 15 Jun 1999 09:04:24 PDT
+ From: Vern Paxson <vern>
+
+ > However, I couldn't figure out how to access current
+ > buffer (yy_current_buffer).
+
+ Derive your own subclass from yyFlexLexer.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-93, Next: unnamed-faq-94, Prev: unnamed-faq-92, Up: FAQ
+
+unnamed-faq-93
+==============
+
+
+ To: "Stones, Darren" <Darren.Stones@nectech.co.uk>
+ Subject: Re: You're the man to see?
+ In-reply-to: Your message of Wed, 23 Jun 1999 11:10:29 PDT.
+ Date: Wed, 23 Jun 1999 09:01:40 PDT
+ From: Vern Paxson <vern>
+
+ > I hope you can help me. I am using Flex and Bison to produce an interpreted
+ > language. However all goes well until I try to implement an IF statement or
+ > a WHILE. I cannot get this to work as the parser parses all the conditions
+ > eg. the TRUE and FALSE conditons to check for a rule match. So I cannot
+ > make a decision!!
+
+ You need to use the parser to build a parse tree (= abstract syntax trwee),
+ and when that's all done you recursively evaluate the tree, binding variables
+ to values at that time.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-94, Next: unnamed-faq-95, Prev: unnamed-faq-93, Up: FAQ
+
+unnamed-faq-94
+==============
+
+
+ To: Petr Danecek <petr@ics.cas.cz>
+ Subject: Re: flex - question
+ In-reply-to: Your message of Mon, 28 Jun 1999 19:21:41 PDT.
+ Date: Fri, 02 Jul 1999 16:52:13 PDT
+ From: Vern Paxson <vern>
+
+ > file, it takes an enormous amount of time. It is funny, because the
+ > source code has only 12 rules!!! I think it looks like an exponencial
+ > growth.
+
+ Right, that's the problem - some patterns (those with a lot of
+ ambiguity, where yours has because at any given time the scanner can
+ be in the middle of all sorts of combinations of the different
+ rules) blow up exponentially.
+
+ For your rules, there is an easy fix. Change the ".*" that comes fater
+ the directory name to "[^ ]*". With that in place, the rules are no
+ longer nearly so ambiguous, because then once one of the directories
+ has been matched, no other can be matched (since they all require a
+ leading blank).
+
+ If that's not an acceptable solution, then you can enter a start state
+ to pick up the .*\n after each directory is matched.
+
+ Also note that for speed, you'll want to add a ".*" rule at the end,
+ otherwise rules that don't match any of the patterns will be matched
+ very slowly, a character at a time.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-95, Next: unnamed-faq-96, Prev: unnamed-faq-94, Up: FAQ
+
+unnamed-faq-95
+==============
+
+
+ To: Tielman Koekemoer <tielman@spi.co.za>
+ Subject: Re: Please help.
+ In-reply-to: Your message of Thu, 08 Jul 1999 13:20:37 PDT.
+ Date: Thu, 08 Jul 1999 08:20:39 PDT
+ From: Vern Paxson <vern>
+
+ > I was hoping you could help me with my problem.
+ >
+ > I tried compiling (gnu)flex on a Solaris 2.4 machine
+ > but when I ran make (after configure) I got an error.
+ >
+ > --------------------------------------------------------------
+ > gcc -c -I. -I. -g -O parse.c
+ > ./flex -t -p ./scan.l >scan.c
+ > sh: ./flex: not found
+ > *** Error code 1
+ > make: Fatal error: Command failed for target `scan.c'
+ > -------------------------------------------------------------
+ >
+ > What's strange to me is that I'm only
+ > trying to install flex now. I then edited the Makefile to
+ > and changed where it says "FLEX = flex" to "FLEX = lex"
+ > ( lex: the native Solaris one ) but then it complains about
+ > the "-p" option. Is there any way I can compile flex without
+ > using flex or lex?
+ >
+ > Thanks so much for your time.
+
+ You managed to step on the bootstrap sequence, which first copies
+ initscan.c to scan.c in order to build flex. Try fetching a fresh
+ distribution from ftp.ee.lbl.gov. (Or you can first try removing
+ ".bootstrap" and doing a make again.)
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-96, Next: unnamed-faq-97, Prev: unnamed-faq-95, Up: FAQ
+
+unnamed-faq-96
+==============
+
+
+ To: Tielman Koekemoer <tielman@spi.co.za>
+ Subject: Re: Please help.
+ In-reply-to: Your message of Fri, 09 Jul 1999 09:16:14 PDT.
+ Date: Fri, 09 Jul 1999 00:27:20 PDT
+ From: Vern Paxson <vern>
+
+ > First I removed .bootstrap (and ran make) - no luck. I downloaded the
+ > software but I still have the same problem. Is there anything else I
+ > could try.
+
+ Try:
+
+ cp initscan.c scan.c
+ touch scan.c
+ make scan.o
+
+ If this last tries to first build scan.c from scan.l using ./flex, then
+ your "make" is broken, in which case compile scan.c to scan.o by hand.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-97, Next: unnamed-faq-98, Prev: unnamed-faq-96, Up: FAQ
+
+unnamed-faq-97
+==============
+
+
+ To: Sumanth Kamenani <skamenan@crl.nmsu.edu>
+ Subject: Re: Error
+ In-reply-to: Your message of Mon, 19 Jul 1999 23:08:41 PDT.
+ Date: Tue, 20 Jul 1999 00:18:26 PDT
+ From: Vern Paxson <vern>
+
+ > I am getting a compilation error. The error is given as "unknown symbol- yylex".
+
+ The parser relies on calling yylex(), but you're instead using the C++ scanning
+ class, so you need to supply a yylex() "glue" function that calls an instance
+ scanner of the scanner (e.g., "scanner->yylex()").
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-98, Next: unnamed-faq-99, Prev: unnamed-faq-97, Up: FAQ
+
+unnamed-faq-98
+==============
+
+
+ To: daniel@synchrods.synchrods.COM (Daniel Senderowicz)
+ Subject: Re: lex
+ In-reply-to: Your message of Mon, 22 Nov 1999 11:19:04 PST.
+ Date: Tue, 23 Nov 1999 15:54:30 PST
+ From: Vern Paxson <vern>
+
+ Well, your problem is the
+
+ switch (yybgin-yysvec-1) { /* witchcraft */
+
+ at the beginning of lex rules. "witchcraft" == "non-portable". It's
+ assuming knowledge of the AT&T lex's internal variables.
+
+ For flex, you can probably do the equivalent using a switch on YYSTATE.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-99, Next: unnamed-faq-100, Prev: unnamed-faq-98, Up: FAQ
+
+unnamed-faq-99
+==============
+
+
+ To: archow@hss.hns.com
+ Subject: Re: Regarding distribution of flex and yacc based grammars
+ In-reply-to: Your message of Sun, 19 Dec 1999 17:50:24 +0530.
+ Date: Wed, 22 Dec 1999 01:56:24 PST
+ From: Vern Paxson <vern>
+
+ > When we provide the customer with an object code distribution, is it
+ > necessary for us to provide source
+ > for the generated C files from flex and bison since they are generated by
+ > flex and bison ?
+
+ For flex, no. I don't know what the current state of this is for bison.
+
+ > Also, is there any requrirement for us to neccessarily provide source for
+ > the grammar files which are fed into flex and bison ?
+
+ Again, for flex, no.
+
+ See the file "COPYING" in the flex distribution for the legalese.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-100, Next: unnamed-faq-101, Prev: unnamed-faq-99, Up: FAQ
+
+unnamed-faq-100
+===============
+
+
+ To: Martin Gallwey <gallweym@hyperion.moe.ul.ie>
+ Subject: Re: Flex, and self referencing rules
+ In-reply-to: Your message of Sun, 20 Feb 2000 01:01:21 PST.
+ Date: Sat, 19 Feb 2000 18:33:16 PST
+ From: Vern Paxson <vern>
+
+ > However, I do not use unput anywhere. I do use self-referencing
+ > rules like this:
+ >
+ > UnaryExpr ({UnionExpr})|("-"{UnaryExpr})
+
+ You can't do this - flex is *not* a parser like yacc (which does indeed
+ allow recursion), it is a scanner that's confined to regular expressions.
+
+ Vern
+
+
+File: flex.info, Node: unnamed-faq-101, Next: What is the difference between YYLEX_PARAM and YY_DECL?, Prev: unnamed-faq-100, Up: FAQ
+
+unnamed-faq-101
+===============
+
+
+ To: slg3@lehigh.edu (SAMUEL L. GULDEN)
+ Subject: Re: Flex problem
+ In-reply-to: Your message of Thu, 02 Mar 2000 12:29:04 PST.
+ Date: Thu, 02 Mar 2000 23:00:46 PST
+ From: Vern Paxson <vern>
+
+ If this is exactly your program:
+
+ > digit [0-9]
+ > digits {digit}+
+ > whitespace [ \t\n]+
+ >
+ > %%
+ > "[" { printf("open_brac\n");}
+ > "]" { printf("close_brac\n");}
+ > "+" { printf("addop\n");}
+ > "*" { printf("multop\n");}
+ > {digits} { printf("NUMBER = %s\n", yytext);}
+ > whitespace ;
+
+ then the problem is that the last rule needs to be "{whitespace}" !
+
+ Vern
+
+
+File: flex.info, Node: What is the difference between YYLEX_PARAM and YY_DECL?, Next: Why do I get "conflicting types for yylex" error?, Prev: unnamed-faq-101, Up: FAQ
+
+What is the difference between YYLEX_PARAM and YY_DECL?
+=======================================================
+
+YYLEX_PARAM is not a flex symbol. It is for Bison. It tells Bison to
+pass extra params when it calls yylex() from the parser.
+
+ YY_DECL is the Flex declaration of yylex. The default is similar to
+this:
+
+
+ #define int yy_lex ()
+
+
+File: flex.info, Node: Why do I get "conflicting types for yylex" error?, Next: How do I access the values set in a Flex action from within a Bison action?, Prev: What is the difference between YYLEX_PARAM and YY_DECL?, Up: FAQ
+
+Why do I get "conflicting types for yylex" error?
+=================================================
+
+This is a compiler error regarding a generated Bison parser, not a Flex
+scanner. It means you need a prototype of yylex() in the top of the
+Bison file. Be sure the prototype matches YY_DECL.
+
+
+File: flex.info, Node: How do I access the values set in a Flex action from within a Bison action?, Prev: Why do I get "conflicting types for yylex" error?, Up: FAQ
+
+How do I access the values set in a Flex action from within a Bison action?
+===========================================================================
+
+With $1, $2, $3, etc. These are called "Semantic Values" in the Bison
+manual. See *Note Top: (bison)Top.
+
+
+File: flex.info, Node: Appendices, Next: Indices, Prev: FAQ, Up: Top
+
+Appendix A Appendices
+*********************
+
+* Menu:
+
+* Makefiles and Flex::
+* Bison Bridge::
+* M4 Dependency::
+* Common Patterns::
+
+
+File: flex.info, Node: Makefiles and Flex, Next: Bison Bridge, Prev: Appendices, Up: Appendices
+
+A.1 Makefiles and Flex
+======================
+
+In this appendix, we provide tips for writing Makefiles to build your
+scanners.
+
+ In a traditional build environment, we say that the `.c' files are
+the sources, and the `.o' files are the intermediate files. When using
+`flex', however, the `.l' files are the sources, and the generated `.c'
+files (along with the `.o' files) are the intermediate files. This
+requires you to carefully plan your Makefile.
+
+ Modern `make' programs understand that `foo.l' is intended to
+generate `lex.yy.c' or `foo.c', and will behave accordingly(1)(2). The
+following Makefile does not explicitly instruct `make' how to build
+`foo.c' from `foo.l'. Instead, it relies on the implicit rules of the
+`make' program to build the intermediate file, `scan.c':
+
+
+ # Basic Makefile -- relies on implicit rules
+ # Creates "myprogram" from "scan.l" and "myprogram.c"
+ #
+ LEX=flex
+ myprogram: scan.o myprogram.o
+ scan.o: scan.l
+
+ For simple cases, the above may be sufficient. For other cases, you
+may have to explicitly instruct `make' how to build your scanner. The
+following is an example of a Makefile containing explicit rules:
+
+
+ # Basic Makefile -- provides explicit rules
+ # Creates "myprogram" from "scan.l" and "myprogram.c"
+ #
+ LEX=flex
+ myprogram: scan.o myprogram.o
+ $(CC) -o $@ $(LDFLAGS) $^
+
+ myprogram.o: myprogram.c
+ $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
+
+ scan.o: scan.c
+ $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
+
+ scan.c: scan.l
+ $(LEX) $(LFLAGS) -o $@ $^
+
+ clean:
+ $(RM) *.o scan.c
+
+ Notice in the above example that `scan.c' is in the `clean' target.
+This is because we consider the file `scan.c' to be an intermediate
+file.
+
+ Finally, we provide a realistic example of a `flex' scanner used
+with a `bison' parser(3). There is a tricky problem we have to deal
+with. Since a `flex' scanner will typically include a header file
+(e.g., `y.tab.h') generated by the parser, we need to be sure that the
+header file is generated BEFORE the scanner is compiled. We handle this
+case in the following example:
+
+
+ # Makefile example -- scanner and parser.
+ # Creates "myprogram" from "scan.l", "parse.y", and "myprogram.c"
+ #
+ LEX = flex
+ YACC = bison -y
+ YFLAGS = -d
+ objects = scan.o parse.o myprogram.o
+
+ myprogram: $(objects)
+ scan.o: scan.l parse.c
+ parse.o: parse.y
+ myprogram.o: myprogram.c
+
+ In the above example, notice the line,
+
+
+ scan.o: scan.l parse.c
+
+ , which lists the file `parse.c' (the generated parser) as a
+dependency of `scan.o'. We want to ensure that the parser is created
+before the scanner is compiled, and the above line seems to do the
+trick. Feel free to experiment with your specific implementation of
+`make'.
+
+ For more details on writing Makefiles, see *Note Top: (make)Top.
+
+ ---------- Footnotes ----------
+
+ (1) GNU `make' and GNU `automake' are two such programs that provide
+implicit rules for flex-generated scanners.
+
+ (2) GNU `automake' may generate code to execute flex in
+lex-compatible mode, or to stdout. If this is not what you want, then
+you should provide an explicit rule in your Makefile.am
+
+ (3) This example also applies to yacc parsers.
+
+
+File: flex.info, Node: Bison Bridge, Next: M4 Dependency, Prev: Makefiles and Flex, Up: Appendices
+
+A.2 C Scanners with Bison Parsers
+=================================
+
+This section describes the `flex' features useful when integrating
+`flex' with `GNU bison'(1). Skip this section if you are not using
+`bison' with your scanner. Here we discuss only the `flex' half of the
+`flex' and `bison' pair. We do not discuss `bison' in any detail. For
+more information about generating `bison' parsers, see *Note Top:
+(bison)Top.
+
+ A compatible `bison' scanner is generated by declaring `%option
+bison-bridge' or by supplying `--bison-bridge' when invoking `flex'
+from the command line. This instructs `flex' that the macro `yylval'
+may be used. The data type for `yylval', `YYSTYPE', is typically
+defined in a header file, included in section 1 of the `flex' input
+file. For a list of functions and macros available, *Note
+bison-functions::.
+
+ The declaration of yylex becomes,
+
+
+ int yylex ( YYSTYPE * lvalp, yyscan_t scanner );
+
+ If `%option bison-locations' is specified, then the declaration
+becomes,
+
+
+ int yylex ( YYSTYPE * lvalp, YYLTYPE * llocp, yyscan_t scanner );
+
+ Note that the macros `yylval' and `yylloc' evaluate to pointers.
+Support for `yylloc' is optional in `bison', so it is optional in
+`flex' as well. The following is an example of a `flex' scanner that is
+compatible with `bison'.
+
+
+ /* Scanner for "C" assignment statements... sort of. */
+ %{
+ #include "y.tab.h" /* Generated by bison. */
+ %}
+
+ %option bison-bridge bison-locations
+ %
+
+ [[:digit:]]+ { yylval->num = atoi(yytext); return NUMBER;}
+ [[:alnum:]]+ { yylval->str = strdup(yytext); return STRING;}
+ "="|";" { return yytext[0];}
+ . {}
+ %
+
+ As you can see, there really is no magic here. We just use `yylval'
+as we would any other variable. The data type of `yylval' is generated
+by `bison', and included in the file `y.tab.h'. Here is the
+corresponding `bison' parser:
+
+
+ /* Parser to convert "C" assignments to lisp. */
+ %{
+ /* Pass the argument to yyparse through to yylex. */
+ #define YYPARSE_PARAM scanner
+ #define YYLEX_PARAM scanner
+ %}
+ %locations
+ %pure_parser
+ %union {
+ int num;
+ char* str;
+ }
+ %token <str> STRING
+ %token <num> NUMBER
+ %%
+ assignment:
+ STRING '=' NUMBER ';' {
+ printf( "(setf %s %d)", $1, $3 );
+ }
+ ;
+
+ ---------- Footnotes ----------
+
+ (1) The features described here are purely optional, and are by no
+means the only way to use flex with bison. We merely provide some glue
+to ease development of your parser-scanner pair.
+
+
+File: flex.info, Node: M4 Dependency, Next: Common Patterns, Prev: Bison Bridge, Up: Appendices
+
+A.3 M4 Dependency
+=================
+
+The macro processor `m4'(1) must be installed wherever flex is
+installed. `flex' invokes `m4', found by searching the directories in
+the `PATH' environment variable. Any code you place in section 1 or in
+the actions will be sent through m4. Please follow these rules to
+protect your code from unwanted `m4' processing.
+
+ * Do not use symbols that begin with, `m4_', such as, `m4_define',
+ or `m4_include', since those are reserved for `m4' macro names. If
+ for some reason you need m4_ as a prefix, use a preprocessor
+ #define to get your symbol past m4 unmangled.
+
+ * Do not use the strings `[[' or `]]' anywhere in your code. The
+ former is not valid in C, except within comments and strings, but
+ the latter is valid in code such as `x[y[z]]'. The solution is
+ simple. To get the literal string `"]]"', use `"]""]"'. To get the
+ array notation `x[y[z]]', use `x[y[z] ]'. Flex will attempt to
+ detect these sequences in user code, and escape them. However,
+ it's best to avoid this complexity where possible, by removing
+ such sequences from your code.
+
+
+ `m4' is only required at the time you run `flex'. The generated
+scanner is ordinary C or C++, and does _not_ require `m4'.
+
+ ---------- Footnotes ----------
+
+ (1) The use of m4 is subject to change in future revisions of flex.
+It is not part of the public API of flex. Do not depend on it.
+
+
+File: flex.info, Node: Common Patterns, Prev: M4 Dependency, Up: Appendices
+
+A.4 Common Patterns
+===================
+
+This appendix provides examples of common regular expressions you might
+use in your scanner.
+
+* Menu:
+
+* Numbers::
+* Identifiers::
+* Quoted Constructs::
+* Addresses::
+
+
+File: flex.info, Node: Numbers, Next: Identifiers, Up: Common Patterns
+
+A.4.1 Numbers
+-------------
+
+C99 decimal constant
+ `([[:digit:]]{-}[0])[[:digit:]]*'
+
+C99 hexadecimal constant
+ `0[xX][[:xdigit:]]+'
+
+C99 octal constant
+ `0[0123456]*'
+
+C99 floating point constant
+
+ {dseq} ([[:digit:]]+)
+ {dseq_opt} ([[:digit:]]*)
+ {frac} (({dseq_opt}"."{dseq})|{dseq}".")
+ {exp} ([eE][+-]?{dseq})
+ {exp_opt} ({exp}?)
+ {fsuff} [flFL]
+ {fsuff_opt} ({fsuff}?)
+ {hpref} (0[xX])
+ {hdseq} ([[:xdigit:]]+)
+ {hdseq_opt} ([[:xdigit:]]*)
+ {hfrac} (({hdseq_opt}"."{hdseq})|({hdseq}"."))
+ {bexp} ([pP][+-]?{dseq})
+ {dfc} (({frac}{exp_opt}{fsuff_opt})|({dseq}{exp}{fsuff_opt}))
+ {hfc} (({hpref}{hfrac}{bexp}{fsuff_opt})|({hpref}{hdseq}{bexp}{fsuff_opt}))
+
+ {c99_floating_point_constant} ({dfc}|{hfc})
+
+ See C99 section 6.4.4.2 for the gory details.
+
+
+
+File: flex.info, Node: Identifiers, Next: Quoted Constructs, Prev: Numbers, Up: Common Patterns
+
+A.4.2 Identifiers
+-----------------
+
+C99 Identifier
+
+ ucn ((\\u([[:xdigit:]]{4}))|(\\U([[:xdigit:]]{8})))
+ nondigit [_[:alpha:]]
+ c99_id ([_[:alpha:]]|{ucn})([_[:alnum:]]|{ucn})*
+
+ Technically, the above pattern does not encompass all possible C99
+ identifiers, since C99 allows for "implementation-defined"
+ characters. In practice, C compilers follow the above pattern,
+ with the addition of the `$' character.
+
+UTF-8 Encoded Unicode Code Point
+
+ [\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF]([\x80-\xBF]{2})|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF]([\x80-\xBF]{2})|[\xF1-\xF3]([\x80-\xBF]{3})|\xF4[\x80-\x8F]([\x80-\xBF]{2})
+
+
+
+File: flex.info, Node: Quoted Constructs, Next: Addresses, Prev: Identifiers, Up: Common Patterns
+
+A.4.3 Quoted Constructs
+-----------------------
+
+C99 String Literal
+ `L?\"([^\"\\\n]|(\\['\"?\\abfnrtv])|(\\([0123456]{1,3}))|(\\x[[:xdigit:]]+)|(\\u([[:xdigit:]]{4}))|(\\U([[:xdigit:]]{8})))*\"'
+
+C99 Comment
+ `("/*"([^*]|"*"[^/])*"*/")|("/"(\\\n)*"/"[^\n]*)'
+
+ Note that in C99, a `//'-style comment may be split across lines,
+ and, contrary to popular belief, does not include the trailing
+ `\n' character.
+
+ A better way to scan `/* */' comments is by line, rather than
+ matching possibly huge comments all at once. This will allow you
+ to scan comments of unlimited length, as long as line breaks
+ appear at sane intervals. This is also more efficient when used
+ with automatic line number processing. *Note option-yylineno::.
+
+
+ <INITIAL>{
+ "/*" BEGIN(COMMENT);
+ }
+ <COMMENT>{
+ "*/" BEGIN(0);
+ [^*\n]+ ;
+ "*"[^/] ;
+ \n ;
+ }
+
+
+
+File: flex.info, Node: Addresses, Prev: Quoted Constructs, Up: Common Patterns
+
+A.4.4 Addresses
+---------------
+
+IPv4 Address
+ `(([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3}))'
+
+IPv6 Address
+
+ hex4 ([[:xdigit:]]{1,4})
+ hexseq ({hex4}(:{hex4}*))
+ hexpart ({hexseq}|({hexseq}::({hexseq}?))|::{hexseq})
+ IPv6address ({hexpart}(":"{IPv4address})?)
+
+ See RFC2373 for details.
+
+URI
+ `(([^:/?#]+):)?("//"([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?'
+
+ This pattern is nearly useless, since it allows just about any
+ character to appear in a URI, including spaces and control
+ characters. See RFC2396 for details.
+
+
+
+File: flex.info, Node: Indices, Prev: Appendices, Up: Top
+
+Indices
+*******
+
+* Menu:
+
+* Concept Index::
+* Index of Functions and Macros::
+* Index of Variables::
+* Index of Data Types::
+* Index of Hooks::
+* Index of Scanner Options::
+
diff --git a/doc/flex.info-2 b/doc/flex.info-2
index b2ca705..27cffbd 100644
--- a/doc/flex.info-2
+++ b/doc/flex.info-2
Binary files differ
diff --git a/doc/flex.info-3 b/doc/flex.info-3
deleted file mode 100644
index 7884ba1..0000000
--- a/doc/flex.info-3
+++ /dev/null
@@ -1,1371 +0,0 @@
-This is flex.info, produced by makeinfo version 4.5 from flex.texi.
-
-INFO-DIR-SECTION Programming
-START-INFO-DIR-ENTRY
-* flex: (flex). Fast lexical analyzer generator (lex replacement).
-END-INFO-DIR-ENTRY
-
-
- The flex manual is placed under the same licensing conditions as the
-rest of flex:
-
- Copyright (C) 1990, 1997 The Regents of the University of California.
-All rights reserved.
-
- This code is derived from software contributed to Berkeley by Vern
-Paxson.
-
- The United States Government has rights in this work pursuant to
-contract no. DE-AC03-76SF00098 between the United States Department of
-Energy and the University of California.
-
- Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the
- distribution.
- Neither the name of the University nor the names of its contributors
-may be used to endorse or promote products derived from this software
-without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-
-File: flex.info, Node: Debugging Options, Next: Miscellaneous Options, Prev: Options for Scanner Speed and Size, Up: Scanner Options
-
-Debugging Options
-=================
-
-`-b, --backup, `%option backup''
- Generate backing-up information to `lex.backup'. This is a list of
- scanner states which require backing up and the input characters on
- which they do so. By adding rules one can remove backing-up
- states. If _all_ backing-up states are eliminated and `-Cf' or
- `-CF' is used, the generated scanner will run faster (see the
- `--perf-report' flag). Only users who wish to squeeze every last
- cycle out of their scanners need worry about this option. (*note
- Performance::).
-
-`-d, --debug, `%option debug''
- makes the generated scanner run in "debug" mode. Whenever a
- pattern is recognized and the global variable `yy_flex_debug' is
- non-zero (which is the default), the scanner will write to
- `stderr' a line of the form:
-
-
- -accepting rule at line 53 ("the matched text")
-
- The line number refers to the location of the rule in the file
- defining the scanner (i.e., the file that was fed to flex).
- Messages are also generated when the scanner backs up, accepts the
- default rule, reaches the end of its input buffer (or encounters a
- NUL; at this point, the two look the same as far as the scanner's
- concerned), or reaches an end-of-file.
-
-`-p, --perf-report, `%option perf-report''
- generates a performance report to `stderr'. The report consists of
- comments regarding features of the `flex' input file which will
- cause a serious loss of performance in the resulting scanner. If
- you give the flag twice, you will also get comments regarding
- features that lead to minor performance losses.
-
- Note that the use of `REJECT', and variable trailing context
- (*note Limitations::) entails a substantial performance penalty;
- use of `yymore()', the `^' operator, and the `--interactive' flag
- entail minor performance penalties.
-
-`-s, --nodefault, `%option nodefault''
- causes the _default rule_ (that unmatched scanner input is echoed
- to `stdout)' to be suppressed. If the scanner encounters input
- that does not match any of its rules, it aborts with an error.
- This option is useful for finding holes in a scanner's rule set.
-
-`-T, --trace, `%option trace''
- makes `flex' run in "trace" mode. It will generate a lot of
- messages to `stderr' concerning the form of the input and the
- resultant non-deterministic and deterministic finite automata.
- This option is mostly for use in maintaining `flex'.
-
-`-w, --nowarn, `%option nowarn''
- suppresses warning messages.
-
-`-v, --verbose, `%option verbose''
- specifies that `flex' should write to `stderr' a summary of
- statistics regarding the scanner it generates. Most of the
- statistics are meaningless to the casual `flex' user, but the
- first line identifies the version of `flex' (same as reported by
- `--version'), and the next line the flags used when generating the
- scanner, including those that are on by default.
-
-`--warn, `%option warn''
- warn about certain things. In particular, if the default rule can
- be matched but no defualt rule has been given, the flex will warn
- you. We recommend using this option always.
-
-
-
-File: flex.info, Node: Miscellaneous Options, Prev: Debugging Options, Up: Scanner Options
-
-Miscellaneous Options
-=====================
-
-`-c'
- is a do-nothing option included for POSIX compliance.
-
- generates
-
-`-h, -?, --help'
- generates a "help" summary of `flex''s options to `stdout' and
- then exits.
-
-`-n'
- is another do-nothing option included only for POSIX compliance.
-
-`-V, --version'
- prints the version number to `stdout' and exits.
-
-
-
-File: flex.info, Node: Performance, Next: Cxx, Prev: Scanner Options, Up: Top
-
-Performance Considerations
-**************************
-
- The main design goal of `flex' is that it generate high-performance
-scanners. It has been optimized for dealing well with large sets of
-rules. Aside from the effects on scanner speed of the table compression
-`-C' options outlined above, there are a number of options/actions
-which degrade performance. These are, from most expensive to least:
-
-
- REJECT
- arbitrary trailing context
-
- pattern sets that require backing up
- %option yylineno
- %array
-
- %option interactive
- %option always-interactive
-
- @samp{^} beginning-of-line operator
- yymore()
-
- with the first two all being quite expensive and the last two being
-quite cheap. Note also that `unput()' is implemented as a routine call
-that potentially does quite a bit of work, while `yyless()' is a
-quite-cheap macro. So if you are just putting back some excess text you
-scanned, use `ss()'.
-
- `REJECT' should be avoided at all costs when performance is
-important. It is a particularly expensive option.
-
- There is one case when `%option yylineno' can be expensive. That is
-when your patterns match long tokens that could _possibly_ contain a
-newline character. There is no performance penalty for rules that can
-not possibly match newlines, since flex does not need to check them for
-newlines. In general, you should avoid rules such as `[^f]+', which
-match very long tokens, including newlines, and may possibly match your
-entire file! A better approach is to separate `[^f]+' into two rules:
-
-
- %option yylineno
- %%
- [^f\n]+
- \n+
-
- The above scanner does not incur a performance penalty.
-
- Getting rid of backing up is messy and often may be an enormous
-amount of work for a complicated scanner. In principal, one begins by
-using the `-b' flag to generate a `lex.backup' file. For example, on
-the input:
-
-
- %%
- foo return TOK_KEYWORD;
- foobar return TOK_KEYWORD;
-
- the file looks like:
-
-
- State #6 is non-accepting -
- associated rule line numbers:
- 2 3
- out-transitions: [ o ]
- jam-transitions: EOF [ \001-n p-\177 ]
-
- State #8 is non-accepting -
- associated rule line numbers:
- 3
- out-transitions: [ a ]
- jam-transitions: EOF [ \001-` b-\177 ]
-
- State #9 is non-accepting -
- associated rule line numbers:
- 3
- out-transitions: [ r ]
- jam-transitions: EOF [ \001-q s-\177 ]
-
- Compressed tables always back up.
-
- The first few lines tell us that there's a scanner state in which it
-can make a transition on an 'o' but not on any other character, and
-that in that state the currently scanned text does not match any rule.
-The state occurs when trying to match the rules found at lines 2 and 3
-in the input file. If the scanner is in that state and then reads
-something other than an 'o', it will have to back up to find a rule
-which is matched. With a bit of headscratching one can see that this
-must be the state it's in when it has seen `fo'. When this has
-happened, if anything other than another `o' is seen, the scanner will
-have to back up to simply match the `f' (by the default rule).
-
- The comment regarding State #8 indicates there's a problem when
-`foob' has been scanned. Indeed, on any character other than an `a',
-the scanner will have to back up to accept "foo". Similarly, the
-comment for State #9 concerns when `fooba' has been scanned and an `r'
-does not follow.
-
- The final comment reminds us that there's no point going to all the
-trouble of removing backing up from the rules unless we're using `-Cf'
-or `-CF', since there's no performance gain doing so with compressed
-scanners.
-
- The way to remove the backing up is to add "error" rules:
-
-
- %%
- foo return TOK_KEYWORD;
- foobar return TOK_KEYWORD;
-
- fooba |
- foob |
- fo {
- /* false alarm, not really a keyword */
- return TOK_ID;
- }
-
- Eliminating backing up among a list of keywords can also be done
-using a "catch-all" rule:
-
-
- %%
- foo return TOK_KEYWORD;
- foobar return TOK_KEYWORD;
-
- [a-z]+ return TOK_ID;
-
- This is usually the best solution when appropriate.
-
- Backing up messages tend to cascade. With a complicated set of rules
-it's not uncommon to get hundreds of messages. If one can decipher
-them, though, it often only takes a dozen or so rules to eliminate the
-backing up (though it's easy to make a mistake and have an error rule
-accidentally match a valid token. A possible future `flex' feature
-will be to automatically add rules to eliminate backing up).
-
- It's important to keep in mind that you gain the benefits of
-eliminating backing up only if you eliminate _every_ instance of
-backing up. Leaving just one means you gain nothing.
-
- _Variable_ trailing context (where both the leading and trailing
-parts do not have a fixed length) entails almost the same performance
-loss as `REJECT' (i.e., substantial). So when possible a rule like:
-
-
- %%
- mouse|rat/(cat|dog) run();
-
- is better written:
-
-
- %%
- mouse/cat|dog run();
- rat/cat|dog run();
-
- or as
-
-
- %%
- mouse|rat/cat run();
- mouse|rat/dog run();
-
- Note that here the special '|' action does _not_ provide any
-savings, and can even make things worse (*note Limitations::).
-
- Another area where the user can increase a scanner's performance (and
-one that's easier to implement) arises from the fact that the longer the
-tokens matched, the faster the scanner will run. This is because with
-long tokens the processing of most input characters takes place in the
-(short) inner scanning loop, and does not often have to go through the
-additional work of setting up the scanning environment (e.g., `yytext')
-for the action. Recall the scanner for C comments:
-
-
- %x comment
- %%
- int line_num = 1;
-
- "/*" BEGIN(comment);
-
- <comment>[^*\n]*
- <comment>"*"+[^*/\n]*
- <comment>\n ++line_num;
- <comment>"*"+"/" BEGIN(INITIAL);
-
- This could be sped up by writing it as:
-
-
- %x comment
- %%
- int line_num = 1;
-
- "/*" BEGIN(comment);
-
- <comment>[^*\n]*
- <comment>[^*\n]*\n ++line_num;
- <comment>"*"+[^*/\n]*
- <comment>"*"+[^*/\n]*\n ++line_num;
- <comment>"*"+"/" BEGIN(INITIAL);
-
- Now instead of each newline requiring the processing of another
-action, recognizing the newlines is distributed over the other rules to
-keep the matched text as long as possible. Note that _adding_ rules
-does _not_ slow down the scanner! The speed of the scanner is
-independent of the number of rules or (modulo the considerations given
-at the beginning of this section) how complicated the rules are with
-regard to operators such as `*' and `|'.
-
- A final example in speeding up a scanner: suppose you want to scan
-through a file containing identifiers and keywords, one per line and
-with no other extraneous characters, and recognize all the keywords. A
-natural first approach is:
-
-
- %%
- asm |
- auto |
- break |
- ... etc ...
- volatile |
- while /* it's a keyword */
-
- .|\n /* it's not a keyword */
-
- To eliminate the back-tracking, introduce a catch-all rule:
-
-
- %%
- asm |
- auto |
- break |
- ... etc ...
- volatile |
- while /* it's a keyword */
-
- [a-z]+ |
- .|\n /* it's not a keyword */
-
- Now, if it's guaranteed that there's exactly one word per line, then
-we can reduce the total number of matches by a half by merging in the
-recognition of newlines with that of the other tokens:
-
-
- %%
- asm\n |
- auto\n |
- break\n |
- ... etc ...
- volatile\n |
- while\n /* it's a keyword */
-
- [a-z]+\n |
- .|\n /* it's not a keyword */
-
- One has to be careful here, as we have now reintroduced backing up
-into the scanner. In particular, while _we_ know that there will never
-be any characters in the input stream other than letters or newlines,
-`flex' can't figure this out, and it will plan for possibly needing to
-back up when it has scanned a token like `auto' and then the next
-character is something other than a newline or a letter. Previously it
-would then just match the `auto' rule and be done, but now it has no
-`auto' rule, only a `auto\n' rule. To eliminate the possibility of
-backing up, we could either duplicate all rules but without final
-newlines, or, since we never expect to encounter such an input and
-therefore don't how it's classified, we can introduce one more
-catch-all rule, this one which doesn't include a newline:
-
-
- %%
- asm\n |
- auto\n |
- break\n |
- ... etc ...
- volatile\n |
- while\n /* it's a keyword */
-
- [a-z]+\n |
- [a-z]+ |
- .|\n /* it's not a keyword */
-
- Compiled with `-Cf', this is about as fast as one can get a `flex'
-scanner to go for this particular problem.
-
- A final note: `flex' is slow when matching `NUL's, particularly when
-a token contains multiple `NUL's. It's best to write rules which match
-_short_ amounts of text if it's anticipated that the text will often
-include `NUL's.
-
- Another final note regarding performance: as mentioned in *Note
-Matching::, dynamically resizing `yytext' to accommodate huge tokens is
-a slow process because it presently requires that the (huge) token be
-rescanned from the beginning. Thus if performance is vital, you should
-attempt to match "large" quantities of text but not "huge" quantities,
-where the cutoff between the two is at about 8K characters per token.
-
-
-File: flex.info, Node: Cxx, Next: Reentrant, Prev: Performance, Up: Top
-
-Generating C++ Scanners
-***********************
-
- *IMPORTANT*: the present form of the scanning class is _experimental_
-and may change considerably between major releases.
-
- `flex' provides two different ways to generate scanners for use with
-C++. The first way is to simply compile a scanner generated by `flex'
-using a C++ compiler instead of a C compiler. You should not encounter
-any compilation errors (*note Reporting Bugs::). You can then use C++
-code in your rule actions instead of C code. Note that the default
-input source for your scanner remains `yyin', and default echoing is
-still done to `yyout'. Both of these remain `FILE *' variables and not
-C++ _streams_.
-
- You can also use `flex' to generate a C++ scanner class, using the
-`-+' option (or, equivalently, `%option c++)', which is automatically
-specified if the name of the `flex' executable ends in a '+', such as
-`flex++'. When using this option, `flex' defaults to generating the
-scanner to the file `lex.yy.cc' instead of `lex.yy.c'. The generated
-scanner includes the header file `FlexLexer.h', which defines the
-interface to two C++ classes.
-
- The first class, `FlexLexer', provides an abstract base class
-defining the general scanner class interface. It provides the
-following member functions:
-
-`const char* YYText()'
- returns the text of the most recently matched token, the
- equivalent of `yytext'.
-
-`int YYLeng()'
- returns the length of the most recently matched token, the
- equivalent of `yyleng'.
-
-`int lineno() const'
- returns the current input line number (see `%option yylineno)', or
- `1' if `%option yylineno' was not used.
-
-`void set_debug( int flag )'
- sets the debugging flag for the scanner, equivalent to assigning to
- `yy_flex_debug' (*note Scanner Options::). Note that you must
- build the scannerusing `%option debug' to include debugging
- information in it.
-
-`int debug() const'
- returns the current setting of the debugging flag.
-
- Also provided are member functions equivalent to
-`yy_switch_to_buffer()', `yy_create_buffer()' (though the first
-argument is an `istream*' object pointer and not a `FILE*)',
-`yy_flush_buffer()', `yy_delete_buffer()', and `yyrestart()' (again,
-the first argument is a `istream*' object pointer).
-
- The second class defined in `FlexLexer.h' is `yyFlexLexer', which is
-derived from `FlexLexer'. It defines the following additional member
-functions:
-
-`yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )'
- constructs a `yyFlexLexer' object using the given streams for input
- and output. If not specified, the streams default to `cin' and
- `cout', respectively.
-
-`virtual int yylex()'
- performs the same role is `yylex()' does for ordinary `flex'
- scanners: it scans the input stream, consuming tokens, until a
- rule's action returns a value. If you derive a subclass `S' from
- `yyFlexLexer' and want to access the member functions and variables
- of `S' inside `yylex()', then you need to use `%option
- yyclass="S"' to inform `flex' that you will be using that subclass
- instead of `yyFlexLexer'. In this case, rather than generating
- `yyFlexLexer::yylex()', `flex' generates `S::yylex()' (and also
- generates a dummy `yyFlexLexer::yylex()' that calls
- `yyFlexLexer::LexerError()' if called).
-
-`virtual void switch_streams(istream* new_in = 0, ostream* new_out = 0)'
- reassigns `yyin' to `new_in' (if non-null) and `yyout' to
- `new_out' (if non-null), deleting the previous input buffer if
- `yyin' is reassigned.
-
-`int yylex( istream* new_in, ostream* new_out = 0 )'
- first switches the input streams via `switch_streams( new_in,
- new_out )' and then returns the value of `yylex()'.
-
- In addition, `yyFlexLexer' defines the following protected virtual
-functions which you can redefine in derived classes to tailor the
-scanner:
-
-`virtual int LexerInput( char* buf, int max_size )'
- reads up to `max_size' characters into `buf' and returns the
- number of characters read. To indicate end-of-input, return 0
- characters. Note that `interactive' scanners (see the `-B' and
- `-I' flags in *Note Scanner Options::) define the macro
- `YY_INTERACTIVE'. If you redefine `LexerInput()' and need to take
- different actions depending on whether or not the scanner might be
- scanning an interactive input source, you can test for the
- presence of this name via `#ifdef' statements.
-
-`virtual void LexerOutput( const char* buf, int size )'
- writes out `size' characters from the buffer `buf', which, while
- `NUL'-terminated, may also contain internal `NUL's if the
- scanner's rules can match text with `NUL's in them.
-
-`virtual void LexerError( const char* msg )'
- reports a fatal error message. The default version of this
- function writes the message to the stream `cerr' and exits.
-
- Note that a `yyFlexLexer' object contains its _entire_ scanning
-state. Thus you can use such objects to create reentrant scanners, but
-see also *Note Reentrant::. You can instantiate multiple instances of
-the same `yyFlexLexer' class, and you can also combine multiple C++
-scanner classes together in the same program using the `-P' option
-discussed above.
-
- Finally, note that the `%array' feature is not available to C++
-scanner classes; you must use `%pointer' (the default).
-
- Here is an example of a simple C++ scanner:
-
-
- // An example of using the flex C++ scanner class.
-
- %{
- int mylineno = 0;
- %}
-
- string \"[^\n"]+\"
-
- ws [ \t]+
-
- alpha [A-Za-z]
- dig [0-9]
- name ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$])*
- num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)?
- num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
- number {num1}|{num2}
-
- %%
-
- {ws} /* skip blanks and tabs */
-
- "/*" {
- int c;
-
- while((c = yyinput()) != 0)
- {
- if(c == '\n')
- ++mylineno;
-
- else if(c == @samp{*})
- {
- if((c = yyinput()) == '/')
- break;
- else
- unput(c);
- }
- }
- }
-
- {number} cout "number " YYText() '\n';
-
- \n mylineno++;
-
- {name} cout "name " YYText() '\n';
-
- {string} cout "string " YYText() '\n';
-
- %%
-
- int main( int /* argc */, char** /* argv */ )
- {
- @code{flex}Lexer* lexer = new yyFlexLexer;
- while(lexer->yylex() != 0)
- ;
- return 0;
- }
-
- If you want to create multiple (different) lexer classes, you use the
-`-P' flag (or the `prefix=' option) to rename each `yyFlexLexer' to
-some other `xxFlexLexer'. You then can include `<FlexLexer.h>' in your
-other sources once per lexer class, first renaming `yyFlexLexer' as
-follows:
-
-
- #undef yyFlexLexer
- #define yyFlexLexer xxFlexLexer
- #include <FlexLexer.h>
-
- #undef yyFlexLexer
- #define yyFlexLexer zzFlexLexer
- #include <FlexLexer.h>
-
- if, for example, you used `%option prefix="xx"' for one of your
-scanners and `%option prefix="zz"' for the other.
-
-
-File: flex.info, Node: Reentrant, Next: Lex and Posix, Prev: Cxx, Up: Top
-
-Reentrant C Scanners
-********************
-
- `flex' has the ability to generate a reentrant C scanner. This is
-accomplished by specifying `%option reentrant' (`-R') The generated
-scanner is both portable, and safe to use in one or more separate
-threads of control. The most common use for reentrant scanners is from
-within multi-threaded applications. Any thread may create and execute
-a reentrant `flex' scanner without the need for synchronization with
-other threads.
-
-* Menu:
-
-* Reentrant Uses::
-* Reentrant Overview::
-* Reentrant Example::
-* Reentrant Detail::
-* Reentrant Functions::
-
-
-File: flex.info, Node: Reentrant Uses, Next: Reentrant Overview, Prev: Reentrant, Up: Reentrant
-
-Uses for Reentrant Scanners
-===========================
-
- However, there are other uses for a reentrant scanner. For example,
-you could scan two or more files simultaneously to implement a `diff' at
-the token level (i.e., instead of at the character level):
-
-
- /* Example of maintaining more than one active scanner. */
-
- do {
- int tok1, tok2;
-
- tok1 = yylex( scanner_1 );
- tok2 = yylex( scanner_2 );
-
- if( tok1 != tok2 )
- printf("Files are different.");
-
- } while ( tok1 && tok2 );
-
- Another use for a reentrant scanner is recursion. (Note that a
-recursive scanner can also be created using a non-reentrant scanner and
-buffer states. *Note Multiple Input Buffers::.)
-
- The following crude scanner supports the `eval' command by invoking
-another instance of itself.
-
-
- /* Example of recursive invocation. */
-
- %option reentrant
-
- %%
- "eval(".+")" {
- yyscan_t scanner;
- YY_BUFFER_STATE buf;
-
- yylex_init( &scanner );
- yytext[yyleng-1] = ' ';
-
- buf = yy_scan_string( yytext + 5, scanner );
- yylex( scanner );
-
- yy_delete_buffer(buf,scanner);
- yylex_destroy( scanner );
- }
- ...
- %%
-
-
-File: flex.info, Node: Reentrant Overview, Next: Reentrant Example, Prev: Reentrant Uses, Up: Reentrant
-
-An Overview of the Reentrant API
-================================
-
- The API for reentrant scanners is different than for non-reentrant
-scanners. Here is a quick overview of the API:
-
- `%option reentrant' must be specified.
-
- * All functions take one additional argument: `yyscanner'
-
- * All global variables are replaced by their macro equivalents. (We
- tell you this because it may be important to you during debugging.)
-
- * `yylex_init' and `yylex_destroy' must be called before and after
- `yylex', respectively.
-
- * Accessor methods (get/set functions) provide access to common
- `flex' variables.
-
- * User-specific data can be stored in `yyextra'.
-
-
-File: flex.info, Node: Reentrant Example, Next: Reentrant Detail, Prev: Reentrant Overview, Up: Reentrant
-
-Reentrant Example
-=================
-
- First, an example of a reentrant scanner:
-
- /* This scanner prints "//" comments. */
- %option reentrant stack
- %x COMMENT
- %%
- "//" yy_push_state( COMMENT, yyscanner);
- .|\n
- <COMMENT>\n yy_pop_state( yyscanner );
- <COMMENT>[^\n]+ fprintf( yyout, "%s\n", yytext);
- %%
- int main ( int argc, char * argv[] )
- {
- yyscan_t scanner;
-
- yylex_init ( &scanner );
- yylex ( scanner );
- yylex_destroy ( scanner );
- return 0;
- }
-
-
-File: flex.info, Node: Reentrant Detail, Next: Reentrant Functions, Prev: Reentrant Example, Up: Reentrant
-
-The Reentrant API in Detail
-===========================
-
- Here are the things you need to do or know to use the reentrant C
-API of `flex'.
-
-* Menu:
-
-* Specify Reentrant::
-* Extra Reentrant Argument::
-* Global Replacement::
-* Init and Destroy Functions::
-* Accessor Methods::
-* Extra Data::
-* About yyscan_t::
-
-
-File: flex.info, Node: Specify Reentrant, Next: Extra Reentrant Argument, Prev: Reentrant Detail, Up: Reentrant Detail
-
-Declaring a Scanner As Reentrant
---------------------------------
-
- %option reentrant (-reentrant) must be specified.
-
- Notice that `%option reentrant' is specified in the above example
-(*note Reentrant Example::. Had this option not been specified, `flex'
-would have happily generated a non-reentrant scanner without
-complaining. You may explicitly specify `%option noreentrant', if you
-do _not_ want a reentrant scanner, although it is not necessary. The
-default is to generate a non-reentrant scanner.
-
-
-File: flex.info, Node: Extra Reentrant Argument, Next: Global Replacement, Prev: Specify Reentrant, Up: Reentrant Detail
-
-The Extra Argument
-------------------
-
- All functions take one additional argument: `yyscanner'.
-
- Notice that the calls to `yy_push_state' and `yy_pop_state' both
-have an argument, `yyscanner' , that is not present in a non-reentrant
-scanner. Here are the declarations of `yy_push_state' and
-`yy_pop_state' in the generated scanner:
-
-
- static void yy_push_state ( int new_state , yyscan_t yyscanner ) ;
- static void yy_pop_state ( yyscan_t yyscanner ) ;
-
- Notice that the argument `yyscanner' appears in the declaration of
-both functions. In fact, all `flex' functions in a reentrant scanner
-have this additional argument. It is always the last argument in the
-argument list, it is always of type `yyscan_t' (which is typedef'd to
-`void *') and it is always named `yyscanner'. As you may have guessed,
-`yyscanner' is a pointer to an opaque data structure encapsulating the
-current state of the scanner. For a list of function declarations, see
-*Note Reentrant Functions::. Note that preprocessor macros, such as
-`BEGIN', `ECHO', and `REJECT', do not take this additional argument.
-
-
-File: flex.info, Node: Global Replacement, Next: Init and Destroy Functions, Prev: Extra Reentrant Argument, Up: Reentrant Detail
-
-Global Variables Replaced By Macros
------------------------------------
-
- All global variables in traditional flex have been replaced by macro
-equivalents.
-
- Note that in the above example, `yyout' and `yytext' are not plain
-variables. These are macros that will expand to their equivalent lvalue.
-All of the familiar `flex' globals have been replaced by their macro
-equivalents. In particular, `yytext', `yyleng', `yylineno', `yyin',
-`yyout', `yyextra', `yylval', and `yylloc' are macros. You may safely
-use these macros in actions as if they were plain variables. We only
-tell you this so you don't expect to link to these variables
-externally. Currently, each macro expands to a member of an internal
-struct, e.g.,
-
-
- #define yytext (((struct yyguts_t*)yyscanner)->yytext_r)
-
- One important thing to remember about `yytext' and friends is that
-`yytext' is not a global variable in a reentrant scanner, you can not
-access it directly from outside an action or from other functions. You
-must use an accessor method, e.g., `yyget_text', to accomplish this.
-(See below).
-
-
-File: flex.info, Node: Init and Destroy Functions, Next: Accessor Methods, Prev: Global Replacement, Up: Reentrant Detail
-
-Init and Destroy Functions
---------------------------
-
- `yylex_init' and `yylex_destroy' must be called before and after
-`yylex', respectively.
-
-
- int yylex_init ( yyscan_t * ptr_yy_globals ) ;
- int yylex ( yyscan_t yyscanner ) ;
- int yylex_destroy ( yyscan_t yyscanner ) ;
-
- The function `yylex_init' must be called before calling any other
-function. The argument to `yylex_init' is the address of an
-uninitialized pointer to be filled in by `flex'. The contents of
-`ptr_yy_globals' need not be initialized, since `flex' will overwrite
-it anyway. The value stored in `ptr_yy_globals' should thereafter be
-passed to `yylex()' and yylex_destroy(). Flex does not save the
-argument passed to `yylex_init', so it is safe to pass the address of a
-local pointer to `yylex_init'. The function `yylex' should be familiar
-to you by now. The reentrant version takes one argument, which is the
-value returned (via an argument) by `yylex_init'. Otherwise, it
-behaves the same as the non-reentrant version of `yylex'.
-
- `yylex_init' returns 0 (zero) on success, or non-zero on failure, in
-which case, errno is set to one of the following values:
-
- * ENOMEM Memory allocation error. *Note memory-management::.
-
- * EINVAL Invalid argument.
-
- The function `yylex_destroy' should be called to free resources used
-by the scanner. After `yylex_destroy' is called, the contents of
-`yyscanner' should not be used. Of course, there is no need to destroy
-a scanner if you plan to reuse it. A `flex' scanner (both reentrant
-and non-reentrant) may be restarted by calling `yyrestart'.
-
- Below is an example of a program that creates a scanner, uses it,
-then destroys it when done:
-
-
- int main ()
- {
- yyscan_t scanner;
- int tok;
-
- yylex_init(&scanner);
-
- while ((tok=yylex()) > 0)
- printf("tok=%d yytext=%s\n", tok, yyget_text(scanner));
-
- yylex_destroy(scanner);
- return 0;
- }
-
-
-File: flex.info, Node: Accessor Methods, Next: Extra Data, Prev: Init and Destroy Functions, Up: Reentrant Detail
-
-Accessing Variables with Reentrant Scanners
--------------------------------------------
-
- Accessor methods (get/set functions) provide access to common `flex'
-variables.
-
- Many scanners that you build will be part of a larger project.
-Portions of your project will need access to `flex' values, such as
-`yytext'. In a non-reentrant scanner, these values are global, so
-there is no problem accessing them. However, in a reentrant scanner,
-there are no global `flex' values. You can not access them directly.
-Instead, you must access `flex' values using accessor methods (get/set
-functions). Each accessor method is named `yyget_NAME' or `yyset_NAME',
-where `NAME' is the name of the `flex' variable you want. For example:
-
-
- /* Set the last character of yytext to NULL. */
- void chop ( yyscan_t scanner )
- {
- int len = yyget_leng( scanner );
- yyget_text( scanner )[len - 1] = '\0';
- }
-
- The above code may be called from within an action like this:
-
-
- %%
- .+\n { chop( yyscanner );}
-
- You may find that `%option header-file' is particularly useful for
-generating prototypes of all the accessor functions. *Note
-option-header::.
-
-
-File: flex.info, Node: Extra Data, Next: About yyscan_t, Prev: Accessor Methods, Up: Reentrant Detail
-
-Extra Data
-----------
-
- User-specific data can be stored in `yyextra'.
-
- In a reentrant scanner, it is unwise to use global variables to
-communicate with or maintain state between different pieces of your
-program. However, you may need access to external data or invoke
-external functions from within the scanner actions. Likewise, you may
-need to pass information to your scanner (e.g., open file descriptors,
-or database connections). In a non-reentrant scanner, the only way to
-do this would be through the use of global variables. `Flex' allows
-you to store arbitrary, "extra" data in a scanner. This data is
-accessible through the accessor methods `yyget_extra' and `yyset_extra'
-from outside the scanner, and through the shortcut macro `yyextra' from
-within the scanner itself. They are defined as follows:
-
-
- #define YY_EXTRA_TYPE void*
- YY_EXTRA_TYPE yyget_extra ( yyscan_t scanner );
- void yyset_extra ( YY_EXTRA_TYPE arbitrary_data , yyscan_t scanner);
-
- By default, `YY_EXTRA_TYPE' is defined as type `void *'. You will
-have to cast `yyextra' and the return value from `yyget_extra' to the
-appropriate value each time you access the extra data. To avoid
-casting, you may override the default type by defining `YY_EXTRA_TYPE'
-in section 1 of your scanner:
-
-
- /* An example of overriding YY_EXTRA_TYPE. */
- %{
- #include <sys/stat.h>
- #include <unistd.h>
- #define YY_EXTRA_TYPE struct stat*
- %}
- %option reentrant
- %%
-
- __filesize__ printf( "%ld", yyextra->st_size );
- __lastmod__ printf( "%ld", yyextra->st_mtime );
- %%
- void scan_file( char* filename )
- {
- yyscan_t scanner;
- struct stat buf;
-
- yylex_init ( &scanner );
- yyset_in( fopen(filename,"r"), scanner );
-
- stat( filename, &buf);
- yyset_extra( &buf, scanner );
- yylex ( scanner );
- yylex_destroy( scanner );
- }
-
-
-File: flex.info, Node: About yyscan_t, Prev: Extra Data, Up: Reentrant Detail
-
-About yyscan_t
---------------
-
- `yyscan_t' is defined as:
-
-
- typedef void* yyscan_t;
-
- It is initialized by `yylex_init()' to point to an internal
-structure. You should never access this value directly. In particular,
-you should never attempt to free it (use `yylex_destroy()' instead.)
-
-
-File: flex.info, Node: Reentrant Functions, Prev: Reentrant Detail, Up: Reentrant
-
-Functions and Macros Available in Reentrant C Scanners
-======================================================
-
- The following Functions are available in a reentrant scanner:
-
-
- char *yyget_text ( yyscan_t scanner );
- int yyget_leng ( yyscan_t scanner );
- FILE *yyget_in ( yyscan_t scanner );
- FILE *yyget_out ( yyscan_t scanner );
- int yyget_lineno ( yyscan_t scanner );
- YY_EXTRA_TYPE yyget_extra ( yyscan_t scanner );
- int yyget_debug ( yyscan_t scanner );
-
- void yyset_debug ( int flag, yyscan_t scanner );
- void yyset_in ( FILE * in_str , yyscan_t scanner );
- void yyset_out ( FILE * out_str , yyscan_t scanner );
- void yyset_lineno ( int line_number , yyscan_t scanner );
- void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t scanner );
-
- There are no "set" functions for yytext and yyleng. This is
-intentional.
-
- The following Macro shortcuts are available in actions in a reentrant
-scanner:
-
-
- yytext
- yyleng
- yyin
- yyout
- yylineno
- yyextra
- yy_flex_debug
-
- In a reentrant C scanner, support for yylineno is always present
-(i.e., you may access yylineno), but the value is never modified by
-`flex' unless `%option yylineno' is enabled. This is to allow the user
-to maintain the line count independently of `flex'.
-
- The following functions and macros are made available when `%option
-bison-bridge' (`--bison-bridge') is specified:
-
-
- YYSTYPE * yyget_lval ( yyscan_t scanner );
- void yyset_lval ( YYSTYPE * yylvalp , yyscan_t scanner );
- yylval
-
- The following functions and macros are made available when `%option
-bison-locations' (`--bison-locations') is specified:
-
-
- YYLTYPE *yyget_lloc ( yyscan_t scanner );
- void yyset_lloc ( YYLTYPE * yyllocp , yyscan_t scanner );
- yylloc
-
- Support for yylval assumes that `YYSTYPE' is a valid type. Support
-for yylloc assumes that `YYSLYPE' is a valid type. Typically, these
-types are generated by `bison', and are included in section 1 of the
-`flex' input.
-
-
-File: flex.info, Node: Lex and Posix, Next: Memory Management, Prev: Reentrant, Up: Top
-
-Incompatibilities with Lex and Posix
-************************************
-
- `flex' is a rewrite of the AT&T Unix _lex_ tool (the two
-implementations do not share any code, though), with some extensions and
-incompatibilities, both of which are of concern to those who wish to
-write scanners acceptable to both implementations. `flex' is fully
-compliant with the POSIX `lex' specification, except that when using
-`%pointer' (the default), a call to `unput()' destroys the contents of
-`yytext', which is counter to the POSIX specification. In this section
-we discuss all of the known areas of incompatibility between `flex',
-AT&T `lex', and the POSIX specification. `flex''s `-l' option turns on
-maximum compatibility with the original AT&T `lex' implementation, at
-the cost of a major loss in the generated scanner's performance. We
-note below which incompatibilities can be overcome using the `-l'
-option. `flex' is fully compatible with `lex' with the following
-exceptions:
-
- * The undocumented `lex' scanner internal variable `yylineno' is not
- supported unless `-l' or `%option yylineno' is used.
-
- * `yylineno' should be maintained on a per-buffer basis, rather than
- a per-scanner (single global variable) basis.
-
- * `yylineno' is not part of the POSIX specification.
-
- * The `input()' routine is not redefinable, though it may be called
- to read characters following whatever has been matched by a rule.
- If `input()' encounters an end-of-file the normal `yywrap()'
- processing is done. A "real" end-of-file is returned by `input()'
- as `EOF'.
-
- * Input is instead controlled by defining the `YY_INPUT()' macro.
-
- * The `flex' restriction that `input()' cannot be redefined is in
- accordance with the POSIX specification, which simply does not
- specify any way of controlling the scanner's input other than by
- making an initial assignment to `yyin'.
-
- * The `unput()' routine is not redefinable. This restriction is in
- accordance with POSIX.
-
- * `flex' scanners are not as reentrant as `lex' scanners. In
- particular, if you have an interactive scanner and an interrupt
- handler which long-jumps out of the scanner, and the scanner is
- subsequently called again, you may get the following message:
-
-
- fatal @code{flex} scanner internal error--end of buffer missed
-
- To reenter the scanner, first use:
-
-
- yyrestart( yyin );
-
- Note that this call will throw away any buffered input; usually
- this isn't a problem with an interactive scanner. *Note
- Reentrant::, for `flex''s reentrant API.
-
- * Also note that `flex' C++ scanner classes _are_ reentrant, so if
- using C++ is an option for you, you should use them instead.
- *Note Cxx::, and *Note Reentrant:: for details.
-
- * `output()' is not supported. Output from the ECHO macro is done
- to the file-pointer `yyout' (default `stdout)'.
-
- * `output()' is not part of the POSIX specification.
-
- * `lex' does not support exclusive start conditions (%x), though they
- are in the POSIX specification.
-
- * When definitions are expanded, `flex' encloses them in parentheses.
- With `lex', the following:
-
-
- NAME [A-Z][A-Z0-9]*
- %%
- foo{NAME}? printf( "Found it\n" );
- %%
-
- will not match the string `foo' because when the macro is expanded
- the rule is equivalent to `foo[A-Z][A-Z0-9]*?' and the precedence
- is such that the `?' is associated with `[A-Z0-9]*'. With `flex',
- the rule will be expanded to `foo([A-Z][A-Z0-9]*)?' and so the
- string `foo' will match.
-
- * Note that if the definition begins with `^' or ends with `$' then
- it is _not_ expanded with parentheses, to allow these operators to
- appear in definitions without losing their special meanings. But
- the `<s>', `/', and `<<EOF>>' operators cannot be used in a `flex'
- definition.
-
- * Using `-l' results in the `lex' behavior of no parentheses around
- the definition.
-
- * The POSIX specification is that the definition be enclosed in
- parentheses.
-
- * Some implementations of `lex' allow a rule's action to begin on a
- separate line, if the rule's pattern has trailing whitespace:
-
-
- %%
- foo|bar<space here>
- { foobar_action();}
-
- `flex' does not support this feature.
-
- * The `lex' `%r' (generate a Ratfor scanner) option is not
- supported. It is not part of the POSIX specification.
-
- * After a call to `unput()', _yytext_ is undefined until the next
- token is matched, unless the scanner was built using `%array'.
- This is not the case with `lex' or the POSIX specification. The
- `-l' option does away with this incompatibility.
-
- * The precedence of the `{,}' (numeric range) operator is different.
- The AT&T and POSIX specifications of `lex' interpret `abc{1,3}'
- as match one, two, or three occurrences of `abc'", whereas `flex'
- interprets it as "match `ab' followed by one, two, or three
- occurrences of `c'". The `-l' and `--posix' options do away with
- this incompatibility.
-
- * The precedence of the `^' operator is different. `lex' interprets
- `^foo|bar' as "match either 'foo' at the beginning of a line, or
- 'bar' anywhere", whereas `flex' interprets it as "match either
- `foo' or `bar' if they come at the beginning of a line". The
- latter is in agreement with the POSIX specification.
-
- * The special table-size declarations such as `%a' supported by
- `lex' are not required by `flex' scanners.. `flex' ignores them.
-
- * The name `FLEX_SCANNER' is `#define''d so scanners may be written
- for use with either `flex' or `lex'. Scanners also include
- `YY_FLEX_MAJOR_VERSION', `YY_FLEX_MINOR_VERSION' and
- `YY_FLEX_SUBMINOR_VERSION' indicating which version of `flex'
- generated the scanner. For example, for the 2.5.22 release, these
- defines would be 2, 5 and 22 respectively. If the version of
- `flex' being used is a beta version, then the symbol `FLEX_BETA'
- is defined.
-
- * The symbols `[[' and `]]' in the code sections of the input may
- conflict with the m4 delimiters. *Note M4 Dependency::.
-
-
- The following `flex' features are not included in `lex' or the POSIX
-specification:
-
- * C++ scanners
-
- * %option
-
- * start condition scopes
-
- * start condition stacks
-
- * interactive/non-interactive scanners
-
- * yy_scan_string() and friends
-
- * yyterminate()
-
- * yy_set_interactive()
-
- * yy_set_bol()
-
- * YY_AT_BOL() <<EOF>>
-
- * <*>
-
- * YY_DECL
-
- * YY_START
-
- * YY_USER_ACTION
-
- * YY_USER_INIT
-
- * #line directives
-
- * %{}'s around actions
-
- * reentrant C API
-
- * multiple actions on a line
-
- * almost all of the `flex' command-line options
-
- The feature "multiple actions on a line" refers to the fact that
-with `flex' you can put multiple actions on the same line, separated
-with semi-colons, while with `lex', the following:
-
-
- foo handle_foo(); ++num_foos_seen;
-
- is (rather surprisingly) truncated to
-
-
- foo handle_foo();
-
- `flex' does not truncate the action. Actions that are not enclosed
-in braces are simply terminated at the end of the line.
-
-
-File: flex.info, Node: Memory Management, Next: Serialized Tables, Prev: Lex and Posix, Up: Top
-
-Memory Management
-*****************
-
- This chapter describes how flex handles dynamic memory, and how you
-can override the default behavior.
-
-* Menu:
-
-* The Default Memory Management::
-* Overriding The Default Memory Management::
-* A Note About yytext And Memory::
-
-
-File: flex.info, Node: The Default Memory Management, Next: Overriding The Default Memory Management, Prev: Memory Management, Up: Memory Management
-
-The Default Memory Management
-=============================
-
- Flex allocates dynamic memory during initialization, and once in a
-while from within a call to yylex(). Initialization takes place during
-the first call to yylex(). Thereafter, flex may reallocate more memory
-if it needs to enlarge a buffer. As of version 2.5.9 Flex will clean up
-all memory when you call `yylex_destroy' *Note faq-memory-leak::.
-
- Flex allocates dynamic memory for four purposes, listed below (1)
-
-16kB for the input buffer.
- Flex allocates memory for the character buffer used to perform
- pattern matching. Flex must read ahead from the input stream and
- store it in a large character buffer. This buffer is typically
- the largest chunk of dynamic memory flex consumes. This buffer
- will grow if necessary, doubling the size each time. Flex frees
- this memory when you call yylex_destroy(). The default size of
- this buffer (16384 bytes) is almost always too large. The ideal
- size for this buffer is the length of the longest token expected,
- in bytes, plus a little more. Flex will allocate a few extra
- bytes for housekeeping. Currently, to override the size of the
- input buffer you must `#define YY_BUF_SIZE' to whatever number of
- bytes you want. We don't plan to change this in the near future,
- but we reserve the right to do so if we ever add a more robust
- memory management API.
-
-64kb for the REJECT state. This will only be allocated if you use REJECT.
- The size is the large enough to hold the same number of states as
- characters in the input buffer. If you override the size of the
- input buffer (via `YY_BUF_SIZE'), then you automatically override
- the size of this buffer as well.
-
-100 bytes for the start condition stack.
- Flex allocates memory for the start condition stack. This is the
- stack used for pushing start states, i.e., with yy_push_state().
- It will grow if necessary. Since the states are simply integers,
- this stack doesn't consume much memory. This stack is not present
- if `%option stack' is not specified. You will rarely need to tune
- this buffer. The ideal size for this stack is the maximum depth
- expected. The memory for this stack is automatically destroyed
- when you call yylex_destroy(). *Note option-stack::.
-
-40 bytes for each YY_BUFFER_STATE.
- Flex allocates memory for each YY_BUFFER_STATE. The buffer state
- itself is about 40 bytes, plus an additional large character
- buffer (described above.) The initial buffer state is created
- during initialization, and with each call to yy_create_buffer().
- You can't tune the size of this, but you can tune the character
- buffer as described above. Any buffer state that you explicitly
- create by calling yy_create_buffer() is _NOT_ destroyed
- automatically. You must call yy_delete_buffer() to free the
- memory. The exception to this rule is that flex will delete the
- current buffer automatically when you call yylex_destroy(). If you
- delete the current buffer, be sure to set it to NULL. That way,
- flex will not try to delete the buffer a second time (possibly
- crashing your program!) At the time of this writing, flex does not
- provide a growable stack for the buffer states. You have to
- manage that yourself. *Note Multiple Input Buffers::.
-
-84 bytes for the reentrant scanner guts
- Flex allocates about 84 bytes for the reentrant scanner structure
- when you call yylex_init(). It is destroyed when the user calls
- yylex_destroy().
-
-
- ---------- Footnotes ----------
-
- (1) The quantities given here are approximate, and may vary due to
-host architecture, compiler configuration, or due to future
-enhancements to flex.
-
diff --git a/doc/flex.info-4 b/doc/flex.info-4
deleted file mode 100644
index 2304293..0000000
--- a/doc/flex.info-4
+++ /dev/null
@@ -1,1255 +0,0 @@
-This is flex.info, produced by makeinfo version 4.5 from flex.texi.
-
-INFO-DIR-SECTION Programming
-START-INFO-DIR-ENTRY
-* flex: (flex). Fast lexical analyzer generator (lex replacement).
-END-INFO-DIR-ENTRY
-
-
- The flex manual is placed under the same licensing conditions as the
-rest of flex:
-
- Copyright (C) 1990, 1997 The Regents of the University of California.
-All rights reserved.
-
- This code is derived from software contributed to Berkeley by Vern
-Paxson.
-
- The United States Government has rights in this work pursuant to
-contract no. DE-AC03-76SF00098 between the United States Department of
-Energy and the University of California.
-
- Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the
- distribution.
- Neither the name of the University nor the names of its contributors
-may be used to endorse or promote products derived from this software
-without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-
-File: flex.info, Node: Overriding The Default Memory Management, Next: A Note About yytext And Memory, Prev: The Default Memory Management, Up: Memory Management
-
-Overriding The Default Memory Management
-========================================
-
- Flex calls the functions `yyalloc', `yyrealloc', and `yyfree' when
-it needs to allocate or free memory. By default, these functions are
-wrappers around the standard C functions, `malloc', `realloc', and
-`free', respectively. You can override the default implementations by
-telling flex that you will provide your own implementations.
-
- To override the default implementations, you must do two things:
-
- 1. Suppress the default implementations by specifying one or more of
- the following options:
-
- * `%option noyyalloc'
-
- * `%option noyyrealloc'
-
- * `%option noyyfree'.
-
- 2. Provide your own implementation of the following functions: (1)
-
-
- // For a non-reentrant scanner
- void * yyalloc (size_t bytes);
- void * yyrealloc (void * ptr, size_t bytes);
- void yyfree (void * ptr);
-
- // For a reentrant scanner
- void * yyalloc (size_t bytes, void * yyscanner);
- void * yyrealloc (void * ptr, size_t bytes, void * yyscanner);
- void yyfree (void * ptr, void * yyscanner);
-
-
- In the following example, we will override all three memory
-routines. We assume that there is a custom allocator with garbage
-collection. In order to make this example interesting, we will use a
-reentrant scanner, passing a pointer to the custom allocator through
-`yyextra'.
-
-
- %{
- #include "some_allocator.h"
- %}
-
- /* Suppress the default implementations. */
- %option noyyalloc noyyrealloc noyyfree
- %option reentrant
-
- /* Initialize the allocator. */
- #define YY_EXTRA_TYPE struct allocator*
- #define YY_USER_INIT yyextra = allocator_create();
-
- %%
- .|\n ;
- %%
-
- /* Provide our own implementations. */
- void * yyalloc (size_t bytes, void* yyscanner) {
- return allocator_alloc (yyextra, bytes);
- }
-
- void * yyrealloc (void * ptr, size_t bytes, void* yyscanner) {
- return allocator_realloc (yyextra, bytes);
- }
-
- void yyfree (void * ptr, void * yyscanner) {
- /* Do nothing -- we leave it to the garbage collector. */
- }
-
- ---------- Footnotes ----------
-
- (1) It is not necessary to override all (or any) of the memory
-management routines. You may, for example, override `yyrealloc', but
-not `yyfree' or `yyalloc'.
-
-
-File: flex.info, Node: A Note About yytext And Memory, Prev: Overriding The Default Memory Management, Up: Memory Management
-
-A Note About yytext And Memory
-==============================
-
- When flex finds a match, `yytext' points to the first character of
-the match in the input buffer. The string itself is part of the input
-buffer, and is _NOT_ allocated separately. The value of yytext will be
-overwritten the next time yylex() is called. In short, the value of
-yytext is only valid from within the matched rule's action.
-
- Often, you want the value of yytext to persist for later processing,
-i.e., by a parser with non-zero lookahead. In order to preserve yytext,
-you will have to copy it with strdup() or a similar function. But this
-introduces some headache because your parser is now responsible for
-freeing the copy of yytext. If you use a yacc or bison parser,
-(commonly used with flex), you will discover that the error recovery
-mechanisms can cause memory to be leaked.
-
- To prevent memory leaks from strdup'd yytext, you will have to track
-the memory somehow. Our experience has shown that a garbage collection
-mechanism or a pooled memory mechanism will save you a lot of grief
-when writing parsers.
-
-
-File: flex.info, Node: Serialized Tables, Next: Diagnostics, Prev: Memory Management, Up: Top
-
-Serialized Tables
-*****************
-
- A `flex' scanner has the ability to save the DFA tables to a file,
-and load them at runtime when needed. The motivation for this feature
-is to reduce the runtime memory footprint. Traditionally, these tables
-have been compiled into the scanner as C arrays, and are sometimes
-quite large. Since the tables are compiled into the scanner, the
-memory used by the tables can never be freed. This is a waste of
-memory, especially if an application uses several scanners, but none of
-them at the same time.
-
- The serialization feature allows the tables to be loaded at runtime,
-before scanning begins. The tables may be discarded when scanning is
-finished.
-
-* Menu:
-
-* Creating Serialized Tables::
-* Loading and Unloading Serialized Tables::
-* Tables File Format::
-
-
-File: flex.info, Node: Creating Serialized Tables, Next: Loading and Unloading Serialized Tables, Prev: Serialized Tables, Up: Serialized Tables
-
-Creating Serialized Tables
-==========================
-
- You may create a scanner with serialized tables by specifying:
-
-
- %option tables-file=FILE
- or
- --tables-file=FILE
-
- These options instruct flex to save the DFA tables to the file FILE.
-The tables will _not_ be embedded in the generated scanner. The scanner
-will not function on its own. The scanner will be dependent upon the
-serialized tables. You must load the tables from this file at runtime
-before you can scan anything.
-
- If you do not specify a filename to `--tables-file', the tables will
-be saved to `lex.yy.tables', where `yy' is the appropriate prefix.
-
- If your project uses several different scanners, you can concatenate
-the serialized tables into one file, and flex will find the correct set
-of tables, using the scanner prefix as part of the lookup key. An
-example follows:
-
-
- $ flex --tables-file --prefix=cpp cpp.l
- $ flex --tables-file --prefix=c c.l
- $ cat lex.cpp.tables lex.c.tables > all.tables
-
- The above example created two scanners, `cpp', and `c'. Since we did
-not specify a filename, the tables were serialized to `lex.c.tables' and
-`lex.cpp.tables', respectively. Then, we concatenated the two files
-together into `all.tables', which we will distribute with our project.
-At runtime, we will open the file and tell flex to load the tables from
-it. Flex will find the correct tables automatically. (See next
-section).
-
-
-File: flex.info, Node: Loading and Unloading Serialized Tables, Next: Tables File Format, Prev: Creating Serialized Tables, Up: Serialized Tables
-
-Loading and Unloading Serialized Tables
-=======================================
-
- If you've built your scanner with `%option tables-file', then you
-must load the scanner tables at runtime. This can be accomplished with
-the following function:
-
- - Function: int yytables_fload (FILE* FP [, yyscan_t SCANNER])
- Locates scanner tables in the stream pointed to by FP and loads
- them. Memory for the tables is allocated via `yyalloc'. You must
- call this function before the first call to `yylex'. The argument
- SCANNER only appears in the reentrant scanner. This function
- returns `0' (zero) on success, or non-zero on error.
-
- The loaded tables are *not* automatically destroyed (unloaded) when
-you call `yylex_destroy'. The reason is that you may create several
-scanners of the same type (in a reentrant scanner), each of which needs
-access to these tables. To avoid a nasty memory leak, you must call
-the following function:
-
- - Function: int yytables_destroy ([yyscan_t SCANNER])
- Unloads the scanner tables. The tables must be loaded again before
- you can scan any more data. The argument SCANNER only appears in
- the reentrant scanner. This function returns `0' (zero) on
- success, or non-zero on error.
-
- *The functions `yytables_fload' and `yytables_destroy' are not
-thread-safe.* You must ensure that these functions are called exactly
-once (for each scanner type) in a threaded program, before any thread
-calls `yylex'. After the tables are loaded, they are never written to,
-and no thread protection is required thereafter - until you destroy
-them.
-
-
-File: flex.info, Node: Tables File Format, Prev: Loading and Unloading Serialized Tables, Up: Serialized Tables
-
-Tables File Format
-==================
-
- This section defines the file format of serialized `flex' tables.
-
- The tables format allows for one or more sets of tables to be
-specified, where each set corresponds to a given scanner. Scanners are
-indexed by name, as described below. The file format is as follows:
-
-
- TABLE SET 1
- +-------------------------------+
- Header | uint32 th_magic; |
- | uint32 th_hsize; |
- | uint32 th_ssize; |
- | uint16 th_flags; |
- | char th_version[]; |
- | char th_name[]; |
- | uint8 th_pad64[]; |
- +-------------------------------+
- Table 1 | uint16 td_id; |
- | uint16 td_flags; |
- | uint32 td_lolen; |
- | uint32 td_hilen; |
- | void td_data[]; |
- | uint8 td_pad64[]; |
- +-------------------------------+
- Table 2 | |
- . . .
- . . .
- . . .
- . . .
- Table n | |
- +-------------------------------+
- TABLE SET 2
- .
- .
- .
- TABLE SET N
-
- The above diagram shows that a complete set of tables consists of a
-header followed by multiple individual tables. Furthermore, multiple
-complete sets may be present in the same file, each set with its own
-header and tables. The sets are contiguous in the file. The only way to
-know if another set follows is to check the next four bytes for the
-magic number (or check for EOF). The header and tables sections are
-padded to 64-bit boundaries. Below we describe each field in detail.
-This format does not specify how the scanner will expand the given
-data, i.e., data may be serialized as int8, but expanded to an int32
-array at runtime. This is to reduce the size of the serialized data
-where possible. Remember, _all integer values are in network byte
-order_.
-
-Fields of a table header:
-
-`th_magic'
- Magic number, always 0xF13C57B1.
-
-`th_hsize'
- Size of this entire header, in bytes, including all fields plus
- any padding.
-
-`th_ssize'
- Size of this entire set, in bytes, including the header, all
- tables, plus any padding.
-
-`th_flags'
- Bit flags for this table set. Currently unused.
-
-`th_version[]'
- Flex version in NULL-termninated string format. e.g., `2.5.13a'.
- This is the version of flex that was used to create the serialized
- tables.
-
-`th_name[]'
- Contains the name of this table set. The default is `yytables',
- and is prefixed accordingly, e.g., `footables'. Must be
- NULL-terminated.
-
-`th_pad64[]'
- Zero or more NULL bytes, padding the entire header to the next
- 64-bit boundary as calculated from the beginning of the header.
-
-Fields of a table:
-
-`td_id'
- Specifies the table identifier. Possible values are:
- `YYTD_ID_ACCEPT (0x01)'
- `yy_accept'
-
- `YYTD_ID_BASE (0x02)'
- `yy_base'
-
- `YYTD_ID_CHK (0x03)'
- `yy_chk'
-
- `YYTD_ID_DEF (0x04)'
- `yy_def'
-
- `YYTD_ID_EC (0x05)'
- `yy_ec '
-
- `YYTD_ID_META (0x06)'
- `yy_meta'
-
- `YYTD_ID_NUL_TRANS (0x07)'
- `yy_NUL_trans'
-
- `YYTD_ID_NXT (0x08)'
- `yy_nxt'. This array may be two dimensional. See the
- `td_hilen' field below.
-
- `YYTD_ID_RULE_CAN_MATCH_EOL (0x09)'
- `yy_rule_can_match_eol'
-
- `YYTD_ID_START_STATE_LIST (0x0A)'
- `yy_start_state_list'. This array is handled specially
- because it is an array of pointers to structs. See the
- `td_flags' field below.
-
- `YYTD_ID_TRANSITION (0x0B)'
- `yy_transition'. This array is handled specially because it
- is an array of structs. See the `td_lolen' field below.
-
- `YYTD_ID_ACCLIST (0x0C)'
- `yy_acclist'
-
-`td_flags'
- Bit flags describing how to interpret the data in `td_data'. The
- data arrays are one-dimensional by default, but may be two
- dimensional as specified in the `td_hilen' field.
-
- `YYTD_DATA8 (0x01)'
- The data is serialized as an array of type int8.
-
- `YYTD_DATA16 (0x02)'
- The data is serialized as an array of type int16.
-
- `YYTD_DATA32 (0x04)'
- The data is serialized as an array of type int32.
-
- `YYTD_PTRANS (0x08)'
- The data is a list of indexes of entries in the expanded
- `yy_transition' array. Each index should be expanded to a
- pointer to the corresponding entry in the `yy_transition'
- array. We count on the fact that the `yy_transition' array
- has already been seen.
-
- `YYTD_STRUCT (0x10)'
- The data is a list of yy_trans_info structs, each of which
- consists of two integers. There is no padding between struct
- elements or between structs. The type of each member is
- determined by the `YYTD_DATA*' bits.
-
-`td_lolen'
- Specifies the number of elements in the lowest dimension array. If
- this is a one-dimensional array, then it is simply the number of
- elements in this array. The element size is determined by the
- `td_flags' field.
-
-`td_hilen'
- If `td_hilen' is non-zero, then the data is a two-dimensional
- array. Otherwise, the data is a one-dimensional array. `td_hilen'
- contains the number of elements in the higher dimensional array,
- and `td_lolen' contains the number of elements in the lowest
- dimension.
-
- Conceptually, `td_data' is either `sometype td_data[td_lolen]', or
- `sometype td_data[td_hilen][td_lolen]', where `sometype' is
- specified by the `td_flags' field. It is possible for both
- `td_lolen' and `td_hilen' to be zero, in which case `td_data' is a
- zero length array, and no data is loaded, i.e., this table is
- simply skipped. Flex does not currently generate tables of zero
- length.
-
-`td_data[]'
- The table data. This array may be a one- or two-dimensional array,
- of type `int8', `int16', `int32', `struct yy_trans_info', or
- `struct yy_trans_info*', depending upon the values in the
- `td_flags', `td_lolen', and `td_hilen' fields.
-
-`td_pad64[]'
- Zero or more NULL bytes, padding the entire table to the next
- 64-bit boundary as calculated from the beginning of this table.
-
-
-File: flex.info, Node: Diagnostics, Next: Limitations, Prev: Serialized Tables, Up: Top
-
-Diagnostics
-***********
-
- The following is a list of `flex' diagnostic messages:
-
- * `warning, rule cannot be matched' indicates that the given rule
- cannot be matched because it follows other rules that will always
- match the same text as it. For example, in the following `foo'
- cannot be matched because it comes after an identifier "catch-all"
- rule:
-
-
- [a-z]+ got_identifier();
- foo got_foo();
-
- Using `REJECT' in a scanner suppresses this warning.
-
- * `warning, -s option given but default rule can be matched' means
- that it is possible (perhaps only in a particular start condition)
- that the default rule (match any single character) is the only one
- that will match a particular input. Since `-s' was given,
- presumably this is not intended.
-
- * `reject_used_but_not_detected undefined' or
- `yymore_used_but_not_detected undefined'. These errors can occur
- at compile time. They indicate that the scanner uses `REJECT' or
- `yymore()' but that `flex' failed to notice the fact, meaning that
- `flex' scanned the first two sections looking for occurrences of
- these actions and failed to find any, but somehow you snuck some in
- (via a #include file, for example). Use `%option reject' or
- `%option yymore' to indicate to `flex' that you really do use
- these features.
-
- * `flex scanner jammed'. a scanner compiled with `-s' has
- encountered an input string which wasn't matched by any of its
- rules. This error can also occur due to internal problems.
-
- * `token too large, exceeds YYLMAX'. your scanner uses `%array' and
- one of its rules matched a string longer than the `YYLMAX'
- constant (8K bytes by default). You can increase the value by
- #define'ing `YYLMAX' in the definitions section of your `flex'
- input.
-
- * `scanner requires -8 flag to use the character 'x''. Your scanner
- specification includes recognizing the 8-bit character `'x'' and
- you did not specify the -8 flag, and your scanner defaulted to
- 7-bit because you used the `-Cf' or `-CF' table compression
- options. See the discussion of the `-7' flag, *Note Scanner
- Options::, for details.
-
- * `flex scanner push-back overflow'. you used `unput()' to push back
- so much text that the scanner's buffer could not hold both the
- pushed-back text and the current token in `yytext'. Ideally the
- scanner should dynamically resize the buffer in this case, but at
- present it does not.
-
- * `input buffer overflow, can't enlarge buffer because scanner uses
- REJECT'. the scanner was working on matching an extremely large
- token and needed to expand the input buffer. This doesn't work
- with scanners that use `REJECT'.
-
- * `fatal flex scanner internal error--end of buffer missed'. This can
- occur in a scanner which is reentered after a long-jump has jumped
- out (or over) the scanner's activation frame. Before reentering
- the scanner, use:
-
- yyrestart( yyin );
- or, as noted above, switch to using the C++ scanner class.
-
- * `too many start conditions in <> construct!' you listed more start
- conditions in a <> construct than exist (so you must have listed at
- least one of them twice).
-
-
-File: flex.info, Node: Limitations, Next: Bibliography, Prev: Diagnostics, Up: Top
-
-Limitations
-***********
-
- Some trailing context patterns cannot be properly matched and
-generate warning messages (`dangerous trailing context'). These are
-patterns where the ending of the first part of the rule matches the
-beginning of the second part, such as `zx*/xy*', where the 'x*' matches
-the 'x' at the beginning of the trailing context. (Note that the POSIX
-draft states that the text matched by such patterns is undefined.) For
-some trailing context rules, parts which are actually fixed-length are
-not recognized as such, leading to the abovementioned performance loss.
-In particular, parts using `|' or `{n}' (such as `foo{3}') are always
-considered variable-length. Combining trailing context with the
-special `|' action can result in _fixed_ trailing context being turned
-into the more expensive _variable_ trailing context. For example, in
-the following:
-
-
- %%
- abc |
- xyz/def
-
- Use of `unput()' invalidates yytext and yyleng, unless the `%array'
-directive or the `-l' option has been used. Pattern-matching of `NUL's
-is substantially slower than matching other characters. Dynamic
-resizing of the input buffer is slow, as it entails rescanning all the
-text matched so far by the current (generally huge) token. Due to both
-buffering of input and read-ahead, you cannot intermix calls to
-`<stdio.h>' routines, such as, getchar(), with `flex' rules and expect
-it to work. Call `input()' instead. The total table entries listed by
-the `-v' flag excludes the number of table entries needed to determine
-what rule has been matched. The number of entries is equal to the
-number of DFA states if the scanner does not use `REJECT', and somewhat
-greater than the number of states if it does. `REJECT' cannot be used
-with the `-f' or `-F' options.
-
- The `flex' internal algorithms need documentation.
-
-
-File: flex.info, Node: Bibliography, Next: FAQ, Prev: Limitations, Up: Top
-
-Additional Reading
-******************
-
- You may wish to read more about the following programs:
- * lex
-
- * yacc
-
- * sed
-
- * awk
-
- The following books may contain material of interest:
-
- John Levine, Tony Mason, and Doug Brown, _Lex & Yacc_, O'Reilly and
-Associates. Be sure to get the 2nd edition.
-
- M. E. Lesk and E. Schmidt, _LEX - Lexical Analyzer Generator_
-
- Alfred Aho, Ravi Sethi and Jeffrey Ullman, _Compilers: Principles,
-Techniques and Tools_, Addison-Wesley (1986). Describes the
-pattern-matching techniques used by `flex' (deterministic finite
-automata).
-
-
-File: flex.info, Node: FAQ, Next: Appendices, Prev: Bibliography, Up: Top
-
-FAQ
-***
-
- From time to time, the `flex' maintainer receives certain questions.
-Rather than repeat answers to well-understood problems, we publish them
-here.
-
-* Menu:
-
-* When was flex born?::
-* How do I expand \ escape sequences in C-style quoted strings?::
-* Why do flex scanners call fileno if it is not ANSI compatible?::
-* Does flex support recursive pattern definitions?::
-* How do I skip huge chunks of input (tens of megabytes) while using flex?::
-* Flex is not matching my patterns in the same order that I defined them.::
-* My actions are executing out of order or sometimes not at all.::
-* How can I have multiple input sources feed into the same scanner at the same time?::
-* Can I build nested parsers that work with the same input file?::
-* How can I match text only at the end of a file?::
-* How can I make REJECT cascade across start condition boundaries?::
-* Why cant I use fast or full tables with interactive mode?::
-* How much faster is -F or -f than -C?::
-* If I have a simple grammar cant I just parse it with flex?::
-* Why doesnt yyrestart() set the start state back to INITIAL?::
-* How can I match C-style comments?::
-* The period isnt working the way I expected.::
-* Can I get the flex manual in another format?::
-* Does there exist a "faster" NDFA->DFA algorithm?::
-* How does flex compile the DFA so quickly?::
-* How can I use more than 8192 rules?::
-* How do I abandon a file in the middle of a scan and switch to a new file?::
-* How do I execute code only during initialization (only before the first scan)?::
-* How do I execute code at termination?::
-* Where else can I find help?::
-* Can I include comments in the "rules" section of the file?::
-* I get an error about undefined yywrap().::
-* How can I change the matching pattern at run time?::
-* How can I expand macros in the input?::
-* How can I build a two-pass scanner?::
-* How do I match any string not matched in the preceding rules?::
-* I am trying to port code from AT&T lex that uses yysptr and yysbuf.::
-* Is there a way to make flex treat NULL like a regular character?::
-* Whenever flex can not match the input it says "flex scanner jammed".::
-* Why doesnt flex have non-greedy operators like perl does?::
-* Memory leak - 16386 bytes allocated by malloc.::
-* How do I track the byte offset for lseek()?::
-* How do I use my own I/O classes in a C++ scanner?::
-* How do I skip as many chars as possible?::
-* deleteme00::
-* Are certain equivalent patterns faster than others?::
-* Is backing up a big deal?::
-* Can I fake multi-byte character support?::
-* deleteme01::
-* Can you discuss some flex internals?::
-* unput() messes up yy_at_bol::
-* The | operator is not doing what I want::
-* Why can't flex understand this variable trailing context pattern?::
-* The ^ operator isn't working::
-* Trailing context is getting confused with trailing optional patterns::
-* Is flex GNU or not?::
-* ERASEME53::
-* I need to scan if-then-else blocks and while loops::
-* ERASEME55::
-* ERASEME56::
-* ERASEME57::
-* Is there a repository for flex scanners?::
-* How can I conditionally compile or preprocess my flex input file?::
-* Where can I find grammars for lex and yacc?::
-* I get an end-of-buffer message for each character scanned.::
-* unnamed-faq-62::
-* unnamed-faq-63::
-* unnamed-faq-64::
-* unnamed-faq-65::
-* unnamed-faq-66::
-* unnamed-faq-67::
-* unnamed-faq-68::
-* unnamed-faq-69::
-* unnamed-faq-70::
-* unnamed-faq-71::
-* unnamed-faq-72::
-* unnamed-faq-73::
-* unnamed-faq-74::
-* unnamed-faq-75::
-* unnamed-faq-76::
-* unnamed-faq-77::
-* unnamed-faq-78::
-* unnamed-faq-79::
-* unnamed-faq-80::
-* unnamed-faq-81::
-* unnamed-faq-82::
-* unnamed-faq-83::
-* unnamed-faq-84::
-* unnamed-faq-85::
-* unnamed-faq-86::
-* unnamed-faq-87::
-* unnamed-faq-88::
-* unnamed-faq-90::
-* unnamed-faq-91::
-* unnamed-faq-92::
-* unnamed-faq-93::
-* unnamed-faq-94::
-* unnamed-faq-95::
-* unnamed-faq-96::
-* unnamed-faq-97::
-* unnamed-faq-98::
-* unnamed-faq-99::
-* unnamed-faq-100::
-* unnamed-faq-101::
-* What is the difference between YYLEX_PARAM and YY_DECL?::
-* Why do I get "conflicting types for yylex" error?::
-* How do I access the values set in a Flex action from within a Bison action?::
-
-
-File: flex.info, Node: When was flex born?, Next: How do I expand \ escape sequences in C-style quoted strings?, Up: FAQ
-
-When was flex born?
-===================
-
- Vern Paxson took over the `Software Tools' lex project from Jef
-Poskanzer in 1982. At that point it was written in Ratfor. Around
-1987 or so, Paxson translated it into C, and a legend was born :-).
-
-
-File: flex.info, Node: How do I expand \ escape sequences in C-style quoted strings?, Next: Why do flex scanners call fileno if it is not ANSI compatible?, Prev: When was flex born?, Up: FAQ
-
-How do I expand \ escape sequences in C-style quoted strings?
-=============================================================
-
- A key point when scanning quoted strings is that you cannot (easily)
-write a single rule that will precisely match the string if you allow
-things like embedded escape sequences and newlines. If you try to
-match strings with a single rule then you'll wind up having to rescan
-the string anyway to find any escape sequences.
-
- Instead you can use exclusive start conditions and a set of rules,
-one for matching non-escaped text, one for matching a single escape,
-one for matching an embedded newline, and one for recognizing the end
-of the string. Each of these rules is then faced with the question of
-where to put its intermediary results. The best solution is for the
-rules to append their local value of `yytext' to the end of a "string
-literal" buffer. A rule like the escape-matcher will append to the
-buffer the meaning of the escape sequence rather than the literal text
-in `yytext'. In this way, `yytext' does not need to be modified at all.
-
-
-File: flex.info, Node: Why do flex scanners call fileno if it is not ANSI compatible?, Next: Does flex support recursive pattern definitions?, Prev: How do I expand \ escape sequences in C-style quoted strings?, Up: FAQ
-
-Why do flex scanners call fileno if it is not ANSI compatible?
-==============================================================
-
- Flex scanners call `fileno()' in order to get the file descriptor
-corresponding to `yyin'. The file descriptor may be passed to
-`isatty()' or `read()', depending upon which `%options' you specified.
-If your system does not have `fileno()' support, to get rid of the
-`read()' call, do not specify `%option read'. To get rid of the
-`isatty()' call, you must specify one of `%option always-interactive' or
-`%option never-interactive'.
-
-
-File: flex.info, Node: Does flex support recursive pattern definitions?, Next: How do I skip huge chunks of input (tens of megabytes) while using flex?, Prev: Why do flex scanners call fileno if it is not ANSI compatible?, Up: FAQ
-
-Does flex support recursive pattern definitions?
-================================================
-
- e.g.,
-
-
- %%
- block "{"({block}|{statement})*"}"
-
- No. You cannot have recursive definitions. The pattern-matching
-power of regular expressions in general (and therefore flex scanners,
-too) is limited. In particular, regular expressions cannot "balance"
-parentheses to an arbitrary degree. For example, it's impossible to
-write a regular expression that matches all strings containing the same
-number of '{'s as '}'s. For more powerful pattern matching, you need a
-parser, such as `GNU bison'.
-
-
-File: flex.info, Node: How do I skip huge chunks of input (tens of megabytes) while using flex?, Next: Flex is not matching my patterns in the same order that I defined them., Prev: Does flex support recursive pattern definitions?, Up: FAQ
-
-How do I skip huge chunks of input (tens of megabytes) while using flex?
-========================================================================
-
- Use `fseek()' (or `lseek()') to position yyin, then call
-`yyrestart()'.
-
-
-File: flex.info, Node: Flex is not matching my patterns in the same order that I defined them., Next: My actions are executing out of order or sometimes not at all., Prev: How do I skip huge chunks of input (tens of megabytes) while using flex?, Up: FAQ
-
-Flex is not matching my patterns in the same order that I defined them.
-=======================================================================
-
- `flex' picks the rule that matches the most text (i.e., the longest
-possible input string). This is because `flex' uses an entirely
-different matching technique ("deterministic finite automata") that
-actually does all of the matching simultaneously, in parallel. (Seems
-impossible, but it's actually a fairly simple technique once you
-understand the principles.)
-
- A side-effect of this parallel matching is that when the input
-matches more than one rule, `flex' scanners pick the rule that matched
-the _most_ text. This is explained further in the manual, in the
-section *Note Matching::.
-
- If you want `flex' to choose a shorter match, then you can work
-around this behavior by expanding your short rule to match more text,
-then put back the extra:
-
-
- data_.* yyless( 5 ); BEGIN BLOCKIDSTATE;
-
- Another fix would be to make the second rule active only during the
-`<BLOCKIDSTATE>' start condition, and make that start condition
-exclusive by declaring it with `%x' instead of `%s'.
-
- A final fix is to change the input language so that the ambiguity for
-`data_' is removed, by adding characters to it that don't match the
-identifier rule, or by removing characters (such as `_') from the
-identifier rule so it no longer matches `data_'. (Of course, you might
-also not have the option of changing the input language.)
-
-
-File: flex.info, Node: My actions are executing out of order or sometimes not at all., Next: How can I have multiple input sources feed into the same scanner at the same time?, Prev: Flex is not matching my patterns in the same order that I defined them., Up: FAQ
-
-My actions are executing out of order or sometimes not at all.
-==============================================================
-
- Most likely, you have (in error) placed the opening `{' of the action
-block on a different line than the rule, e.g.,
-
-
- ^(foo|bar)
- { <<<--- WRONG!
-
- }
-
- `flex' requires that the opening `{' of an action associated with a
-rule begin on the same line as does the rule. You need instead to
-write your rules as follows:
-
-
- ^(foo|bar) { // CORRECT!
-
- }
-
-
-File: flex.info, Node: How can I have multiple input sources feed into the same scanner at the same time?, Next: Can I build nested parsers that work with the same input file?, Prev: My actions are executing out of order or sometimes not at all., Up: FAQ
-
-How can I have multiple input sources feed into the same scanner at the same time?
-==================================================================================
-
- If ...
- * your scanner is free of backtracking (verified using `flex''s `-b'
- flag),
-
- * AND you run your scanner interactively (`-I' option; default
- unless using special table compression options),
-
- * AND you feed it one character at a time by redefining `YY_INPUT'
- to do so,
-
- then every time it matches a token, it will have exhausted its input
-buffer (because the scanner is free of backtracking). This means you
-can safely use `select()' at the point and only call `yylex()' for
-another token if `select()' indicates there's data available.
-
- That is, move the `select()' out from the input function to a point
-where it determines whether `yylex()' gets called for the next token.
-
- With this approach, you will still have problems if your input can
-arrive piecemeal; `select()' could inform you that the beginning of a
-token is available, you call `yylex()' to get it, but it winds up
-blocking waiting for the later characters in the token.
-
- Here's another way: Move your input multiplexing inside of
-`YY_INPUT'. That is, whenever `YY_INPUT' is called, it `select()''s to
-see where input is available. If input is available for the scanner,
-it reads and returns the next byte. If input is available from another
-source, it calls whatever function is responsible for reading from that
-source. (If no input is available, it blocks until some input is
-available.) I've used this technique in an interpreter I wrote that
-both reads keyboard input using a `flex' scanner and IPC traffic from
-sockets, and it works fine.
-
-
-File: flex.info, Node: Can I build nested parsers that work with the same input file?, Next: How can I match text only at the end of a file?, Prev: How can I have multiple input sources feed into the same scanner at the same time?, Up: FAQ
-
-Can I build nested parsers that work with the same input file?
-==============================================================
-
- This is not going to work without some additional effort. The
-reason is that `flex' block-buffers the input it reads from `yyin'.
-This means that the "outermost" `yylex()', when called, will
-automatically slurp up the first 8K of input available on yyin, and
-subsequent calls to other `yylex()''s won't see that input. You might
-be tempted to work around this problem by redefining `YY_INPUT' to only
-return a small amount of text, but it turns out that that approach is
-quite difficult. Instead, the best solution is to combine all of your
-scanners into one large scanner, using a different exclusive start
-condition for each.
-
-
-File: flex.info, Node: How can I match text only at the end of a file?, Next: How can I make REJECT cascade across start condition boundaries?, Prev: Can I build nested parsers that work with the same input file?, Up: FAQ
-
-How can I match text only at the end of a file?
-===============================================
-
- There is no way to write a rule which is "match this text, but only
-if it comes at the end of the file". You can fake it, though, if you
-happen to have a character lying around that you don't allow in your
-input. Then you redefine `YY_INPUT' to call your own routine which, if
-it sees an `EOF', returns the magic character first (and remembers to
-return a real `EOF' next time it's called). Then you could write:
-
-
- <COMMENT>(.|\n)*{EOF_CHAR} /* saw comment at EOF */
-
-
-File: flex.info, Node: How can I make REJECT cascade across start condition boundaries?, Next: Why cant I use fast or full tables with interactive mode?, Prev: How can I match text only at the end of a file?, Up: FAQ
-
-How can I make REJECT cascade across start condition boundaries?
-================================================================
-
- You can do this as follows. Suppose you have a start condition `A',
-and after exhausting all of the possible matches in `<A>', you want to
-try matches in `<INITIAL>'. Then you could use the following:
-
-
- %x A
- %%
- <A>rule_that_is_long ...; REJECT;
- <A>rule ...; REJECT; /* shorter rule */
- <A>etc.
- ...
- <A>.|\n {
- /* Shortest and last rule in <A>, so
- * cascaded REJECT's will eventually
- * wind up matching this rule. We want
- * to now switch to the initial state
- * and try matching from there instead.
- */
- yyless(0); /* put back matched text */
- BEGIN(INITIAL);
- }
-
-
-File: flex.info, Node: Why cant I use fast or full tables with interactive mode?, Next: How much faster is -F or -f than -C?, Prev: How can I make REJECT cascade across start condition boundaries?, Up: FAQ
-
-Why can't I use fast or full tables with interactive mode?
-==========================================================
-
- One of the assumptions flex makes is that interactive applications
-are inherently slow (they're waiting on a human after all). It has to
-do with how the scanner detects that it must be finished scanning a
-token. For interactive scanners, after scanning each character the
-current state is looked up in a table (essentially) to see whether
-there's a chance of another input character possibly extending the
-length of the match. If not, the scanner halts. For non-interactive
-scanners, the end-of-token test is much simpler, basically a compare
-with 0, so no memory bus cycles. Since the test occurs in the
-innermost scanning loop, one would like to make it go as fast as
-possible.
-
- Still, it seems reasonable to allow the user to choose to trade off
-a bit of performance in this area to gain the corresponding
-flexibility. There might be another reason, though, why fast scanners
-don't support the interactive option.
-
-
-File: flex.info, Node: How much faster is -F or -f than -C?, Next: If I have a simple grammar cant I just parse it with flex?, Prev: Why cant I use fast or full tables with interactive mode?, Up: FAQ
-
-How much faster is -F or -f than -C?
-====================================
-
- Much faster (factor of 2-3).
-
-
-File: flex.info, Node: If I have a simple grammar cant I just parse it with flex?, Next: Why doesnt yyrestart() set the start state back to INITIAL?, Prev: How much faster is -F or -f than -C?, Up: FAQ
-
-If I have a simple grammar can't I just parse it with flex?
-===========================================================
-
- Is your grammar recursive? That's almost always a sign that you're
-better off using a parser/scanner rather than just trying to use a
-scanner alone.
-
-
-File: flex.info, Node: Why doesnt yyrestart() set the start state back to INITIAL?, Next: How can I match C-style comments?, Prev: If I have a simple grammar cant I just parse it with flex?, Up: FAQ
-
-Why doesn't yyrestart() set the start state back to INITIAL?
-============================================================
-
- There are two reasons. The first is that there might be programs
-that rely on the start state not changing across file changes. The
-second is that beginning with `flex' version 2.4, use of `yyrestart()'
-is no longer required, so fixing the problem there doesn't solve the
-more general problem.
-
-
-File: flex.info, Node: How can I match C-style comments?, Next: The period isnt working the way I expected., Prev: Why doesnt yyrestart() set the start state back to INITIAL?, Up: FAQ
-
-How can I match C-style comments?
-=================================
-
- You might be tempted to try something like this:
-
-
- "/*".*"*/" // WRONG!
-
- or, worse, this:
-
-
- "/*"(.|\n)"*/" // WRONG!
-
- The above rules will eat too much input, and blow up on things like:
-
-
- /* a comment */ do_my_thing( "oops */" );
-
- Here is one way which allows you to track line information:
-
-
- <INITIAL>{
- "/*" BEGIN(IN_COMMENT);
- }
- <IN_COMMENT>{
- "*/" BEGIN(INITIAL);
- [^*\n]+ // eat comment in chunks
- "*" // eat the lone star
- \n yylineno++;
- }
-
-
-File: flex.info, Node: The period isnt working the way I expected., Next: Can I get the flex manual in another format?, Prev: How can I match C-style comments?, Up: FAQ
-
-The '.' isn't working the way I expected.
-=========================================
-
- Here are some tips for using `.':
-
- * A common mistake is to place the grouping parenthesis AFTER an
- operator, when you really meant to place the parenthesis BEFORE
- the operator, e.g., you probably want this `(foo|bar)+' and NOT
- this `(foo|bar+)'.
-
- The first pattern matches the words `foo' or `bar' any number of
- times, e.g., it matches the text `barfoofoobarfoo'. The second
- pattern matches a single instance of `foo' or a single instance of
- `bar' followed by one or more `r's, e.g., it matches the text
- `barrrr' .
-
- * A `.' inside `[]''s just means a literal`.' (period), and NOT "any
- character except newline".
-
- * Remember that `.' matches any character EXCEPT `\n' (and `EOF').
- If you really want to match ANY character, including newlines,
- then use `(.|\n)' Beware that the regex `(.|\n)+' will match your
- entire input!
-
- * Finally, if you want to match a literal `.' (a period), then use
- `[.]' or `"."'
-
-
-File: flex.info, Node: Can I get the flex manual in another format?, Next: Does there exist a "faster" NDFA->DFA algorithm?, Prev: The period isnt working the way I expected., Up: FAQ
-
-Can I get the flex manual in another format?
-============================================
-
- The `flex' source distribution includes a texinfo manual. You are
-free to convert that texinfo into whatever format you desire. The
-`texinfo' package includes tools for conversion to a number of formats.
-
-
-File: flex.info, Node: Does there exist a "faster" NDFA->DFA algorithm?, Next: How does flex compile the DFA so quickly?, Prev: Can I get the flex manual in another format?, Up: FAQ
-
-Does there exist a "faster" NDFA->DFA algorithm?
-================================================
-
- There's no way around the potential exponential running time - it
-can take you exponential time just to enumerate all of the DFA states.
-In practice, though, the running time is closer to linear, or sometimes
-quadratic.
-
-
-File: flex.info, Node: How does flex compile the DFA so quickly?, Next: How can I use more than 8192 rules?, Prev: Does there exist a "faster" NDFA->DFA algorithm?, Up: FAQ
-
-How does flex compile the DFA so quickly?
-=========================================
-
- There are two big speed wins that `flex' uses:
-
- 1. It analyzes the input rules to construct equivalence classes for
- those characters that always make the same transitions. It then
- rewrites the NFA using equivalence classes for transitions instead
- of characters. This cuts down the NFA->DFA computation time
- dramatically, to the point where, for uncompressed DFA tables, the
- DFA generation is often I/O bound in writing out the tables.
-
- 2. It maintains hash values for previously computed DFA states, so
- testing whether a newly constructed DFA state is equivalent to a
- previously constructed state can be done very quickly, by first
- comparing hash values.
-
-
-File: flex.info, Node: How can I use more than 8192 rules?, Next: How do I abandon a file in the middle of a scan and switch to a new file?, Prev: How does flex compile the DFA so quickly?, Up: FAQ
-
-How can I use more than 8192 rules?
-===================================
-
- `Flex' is compiled with an upper limit of 8192 rules per scanner.
-If you need more than 8192 rules in your scanner, you'll have to
-recompile `flex' with the following changes in `flexdef.h':
-
-
- < #define YY_TRAILING_MASK 0x2000
- < #define YY_TRAILING_HEAD_MASK 0x4000
- --
- > #define YY_TRAILING_MASK 0x20000000
- > #define YY_TRAILING_HEAD_MASK 0x40000000
-
- This should work okay as long as your C compiler uses 32 bit
-integers. But you might want to think about whether using such a huge
-number of rules is the best way to solve your problem.
-
- The following may also be relevant:
-
- With luck, you should be able to increase the definitions in
-flexdef.h for:
-
-
- #define JAMSTATE -32766 /* marks a reference to the state that always jams */
- #define MAXIMUM_MNS 31999
- #define BAD_SUBSCRIPT -32767
-
- recompile everything, and it'll all work. Flex only has these
-16-bit-like values built into it because a long time ago it was
-developed on a machine with 16-bit ints. I've given this advice to
-others in the past but haven't heard back from them whether it worked
-okay or not...
-
-
-File: flex.info, Node: How do I abandon a file in the middle of a scan and switch to a new file?, Next: How do I execute code only during initialization (only before the first scan)?, Prev: How can I use more than 8192 rules?, Up: FAQ
-
-How do I abandon a file in the middle of a scan and switch to a new file?
-=========================================================================
-
- Just call `yyrestart(newfile)'. Be sure to reset the start state if
-you want a "fresh start, since `yyrestart' does NOT reset the start
-state back to `INITIAL'.
-
-
-File: flex.info, Node: How do I execute code only during initialization (only before the first scan)?, Next: How do I execute code at termination?, Prev: How do I abandon a file in the middle of a scan and switch to a new file?, Up: FAQ
-
-How do I execute code only during initialization (only before the first scan)?
-==============================================================================
-
- You can specify an initial action by defining the macro
-`YY_USER_INIT' (though note that `yyout' may not be available at the
-time this macro is executed). Or you can add to the beginning of your
-rules section:
-
-
- %%
- /* Must be indented! */
- static int did_init = 0;
-
- if ( ! did_init ){
- do_my_init();
- did_init = 1;
- }
-
-
-File: flex.info, Node: How do I execute code at termination?, Next: Where else can I find help?, Prev: How do I execute code only during initialization (only before the first scan)?, Up: FAQ
-
-How do I execute code at termination?
-=====================================
-
- You can specify an action for the `<<EOF>>' rule.
-
-
-File: flex.info, Node: Where else can I find help?, Next: Can I include comments in the "rules" section of the file?, Prev: How do I execute code at termination?, Up: FAQ
-
-Where else can I find help?
-===========================
-
- You can find the flex homepage on the web at
-`http://flex.sourceforge.net/'. See that page for details about flex
-mailing lists as well.
-
-
-File: flex.info, Node: Can I include comments in the "rules" section of the file?, Next: I get an error about undefined yywrap()., Prev: Where else can I find help?, Up: FAQ
-
-Can I include comments in the "rules" section of the file?
-==========================================================
-
- Yes, just about anywhere you want to. See the manual for the
-specific syntax.
-
-
-File: flex.info, Node: I get an error about undefined yywrap()., Next: How can I change the matching pattern at run time?, Prev: Can I include comments in the "rules" section of the file?, Up: FAQ
-
-I get an error about undefined yywrap().
-========================================
-
- You must supply a `yywrap()' function of your own, or link to
-`libfl.a' (which provides one), or use
-
-
- %option noyywrap
-
- in your source to say you don't want a `yywrap()' function.
-
-
-File: flex.info, Node: How can I change the matching pattern at run time?, Next: How can I expand macros in the input?, Prev: I get an error about undefined yywrap()., Up: FAQ
-
-How can I change the matching pattern at run time?
-==================================================
-
- You can't, it's compiled into a static table when flex builds the
-scanner.
-
-
-File: flex.info, Node: How can I expand macros in the input?, Next: How can I build a two-pass scanner?, Prev: How can I change the matching pattern at run time?, Up: FAQ
-
-How can I expand macros in the input?
-=====================================
-
- The best way to approach this problem is at a higher level, e.g., in
-the parser.
-
- However, you can do this using multiple input buffers.
-
-
- %%
- macro/[a-z]+ {
- /* Saw the macro "macro" followed by extra stuff. */
- main_buffer = YY_CURRENT_BUFFER;
- expansion_buffer = yy_scan_string(expand(yytext));
- yy_switch_to_buffer(expansion_buffer);
- }
-
- <<EOF>> {
- if ( expansion_buffer )
- {
- // We were doing an expansion, return to where
- // we were.
- yy_switch_to_buffer(main_buffer);
- yy_delete_buffer(expansion_buffer);
- expansion_buffer = 0;
- }
- else
- yyterminate();
- }
-
- You probably will want a stack of expansion buffers to allow nested
-macros. From the above though hopefully the idea is clear.
-
-
-File: flex.info, Node: How can I build a two-pass scanner?, Next: How do I match any string not matched in the preceding rules?, Prev: How can I expand macros in the input?, Up: FAQ
-
-How can I build a two-pass scanner?
-===================================
-
- One way to do it is to filter the first pass to a temporary file,
-then process the temporary file on the second pass. You will probably
-see a performance hit, do to all the disk I/O.
-
- When you need to look ahead far forward like this, it almost always
-means that the right solution is to build a parse tree of the entire
-input, then walk it after the parse in order to generate the output.
-In a sense, this is a two-pass approach, once through the text and once
-through the parse tree, but the performance hit for the latter is
-usually an order of magnitude smaller, since everything is already
-classified, in binary format, and residing in memory.
-
diff --git a/doc/flex.info-5 b/doc/flex.info-5
deleted file mode 100644
index 8935ccf..0000000
--- a/doc/flex.info-5
+++ /dev/null
@@ -1,1330 +0,0 @@
-This is flex.info, produced by makeinfo version 4.5 from flex.texi.
-
-INFO-DIR-SECTION Programming
-START-INFO-DIR-ENTRY
-* flex: (flex). Fast lexical analyzer generator (lex replacement).
-END-INFO-DIR-ENTRY
-
-
- The flex manual is placed under the same licensing conditions as the
-rest of flex:
-
- Copyright (C) 1990, 1997 The Regents of the University of California.
-All rights reserved.
-
- This code is derived from software contributed to Berkeley by Vern
-Paxson.
-
- The United States Government has rights in this work pursuant to
-contract no. DE-AC03-76SF00098 between the United States Department of
-Energy and the University of California.
-
- Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the
- distribution.
- Neither the name of the University nor the names of its contributors
-may be used to endorse or promote products derived from this software
-without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-
-File: flex.info, Node: How do I match any string not matched in the preceding rules?, Next: I am trying to port code from AT&T lex that uses yysptr and yysbuf., Prev: How can I build a two-pass scanner?, Up: FAQ
-
-How do I match any string not matched in the preceding rules?
-=============================================================
-
- One way to assign precedence, is to place the more specific rules
-first. If two rules would match the same input (same sequence of
-characters) then the first rule listed in the `flex' input wins. e.g.,
-
-
- %%
- foo[a-zA-Z_]+ return FOO_ID;
- bar[a-zA-Z_]+ return BAR_ID;
- [a-zA-Z_]+ return GENERIC_ID;
-
- Note that the rule `[a-zA-Z_]+' must come *after* the others. It
-will match the same amount of text as the more specific rules, and in
-that case the `flex' scanner will pick the first rule listed in your
-scanner as the one to match.
-
-
-File: flex.info, Node: I am trying to port code from AT&T lex that uses yysptr and yysbuf., Next: Is there a way to make flex treat NULL like a regular character?, Prev: How do I match any string not matched in the preceding rules?, Up: FAQ
-
-I am trying to port code from AT&T lex that uses yysptr and yysbuf.
-===================================================================
-
- Those are internal variables pointing into the AT&T scanner's input
-buffer. I imagine they're being manipulated in user versions of the
-`input()' and `unput()' functions. If so, what you need to do is
-analyze those functions to figure out what they're doing, and then
-replace `input()' with an appropriate definition of `YY_INPUT'. You
-shouldn't need to (and must not) replace `flex''s `unput()' function.
-
-
-File: flex.info, Node: Is there a way to make flex treat NULL like a regular character?, Next: Whenever flex can not match the input it says "flex scanner jammed"., Prev: I am trying to port code from AT&T lex that uses yysptr and yysbuf., Up: FAQ
-
-Is there a way to make flex treat NULL like a regular character?
-================================================================
-
- Yes, `\0' and `\x00' should both do the trick. Perhaps you have an
-ancient version of `flex'. The latest release is version 2.5.33.
-
-
-File: flex.info, Node: Whenever flex can not match the input it says "flex scanner jammed"., Next: Why doesnt flex have non-greedy operators like perl does?, Prev: Is there a way to make flex treat NULL like a regular character?, Up: FAQ
-
-Whenever flex can not match the input it says "flex scanner jammed".
-====================================================================
-
- You need to add a rule that matches the otherwise-unmatched text.
-e.g.,
-
-
- %option yylineno
- %%
- [[a bunch of rules here]]
-
- . printf("bad input character '%s' at line %d\n", yytext, yylineno);
-
- See `%option default' for more information.
-
-
-File: flex.info, Node: Why doesnt flex have non-greedy operators like perl does?, Next: Memory leak - 16386 bytes allocated by malloc., Prev: Whenever flex can not match the input it says "flex scanner jammed"., Up: FAQ
-
-Why doesn't flex have non-greedy operators like perl does?
-==========================================================
-
- A DFA can do a non-greedy match by stopping the first time it enters
-an accepting state, instead of consuming input until it determines that
-no further matching is possible (a "jam" state). This is actually
-easier to implement than longest leftmost match (which flex does).
-
- But it's also much less useful than longest leftmost match. In
-general, when you find yourself wishing for non-greedy matching, that's
-usually a sign that you're trying to make the scanner do some parsing.
-That's generally the wrong approach, since it lacks the power to do a
-decent job. Better is to either introduce a separate parser, or to
-split the scanner into multiple scanners using (exclusive) start
-conditions.
-
- You might have a separate start state once you've seen the `BEGIN'.
-In that state, you might then have a regex that will match `END' (to
-kick you out of the state), and perhaps `(.|\n)' to get a single
-character within the chunk ...
-
- This approach also has much better error-reporting properties.
-
-
-File: flex.info, Node: Memory leak - 16386 bytes allocated by malloc., Next: How do I track the byte offset for lseek()?, Prev: Why doesnt flex have non-greedy operators like perl does?, Up: FAQ
-
-Memory leak - 16386 bytes allocated by malloc.
-==============================================
-
- UPDATED 2002-07-10: As of `flex' version 2.5.9, this leak means that
-you did not call `yylex_destroy()'. If you are using an earlier version
-of `flex', then read on.
-
- The leak is about 16426 bytes. That is, (8192 * 2 + 2) for the
-read-buffer, and about 40 for `struct yy_buffer_state' (depending upon
-alignment). The leak is in the non-reentrant C scanner only (NOT in the
-reentrant scanner, NOT in the C++ scanner). Since `flex' doesn't know
-when you are done, the buffer is never freed.
-
- However, the leak won't multiply since the buffer is reused no
-matter how many times you call `yylex()'.
-
- If you want to reclaim the memory when you are completely done
-scanning, then you might try this:
-
-
- /* For non-reentrant C scanner only. */
- yy_delete_buffer(YY_CURRENT_BUFFER);
- yy_init = 1;
-
- Note: `yy_init' is an "internal variable", and hasn't been tested in
-this situation. It is possible that some other globals may need
-resetting as well.
-
-
-File: flex.info, Node: How do I track the byte offset for lseek()?, Next: How do I use my own I/O classes in a C++ scanner?, Prev: Memory leak - 16386 bytes allocated by malloc., Up: FAQ
-
-How do I track the byte offset for lseek()?
-===========================================
-
-
- > We thought that it would be possible to have this number through the
- > evaluation of the following expression:
- >
- > seek_position = (no_buffers)*YY_READ_BUF_SIZE + yy_c_buf_p - YY_CURRENT_BUFFER->yy_ch_buf
-
- While this is the right idea, it has two problems. The first is that
-it's possible that `flex' will request less than `YY_READ_BUF_SIZE'
-during an invocation of `YY_INPUT' (or that your input source will
-return less even though `YY_READ_BUF_SIZE' bytes were requested). The
-second problem is that when refilling its internal buffer, `flex' keeps
-some characters from the previous buffer (because usually it's in the
-middle of a match, and needs those characters to construct `yytext' for
-the match once it's done). Because of this, `yy_c_buf_p -
-YY_CURRENT_BUFFER->yy_ch_buf' won't be exactly the number of characters
-already read from the current buffer.
-
- An alternative solution is to count the number of characters you've
-matched since starting to scan. This can be done by using
-`YY_USER_ACTION'. For example,
-
-
- #define YY_USER_ACTION num_chars += yyleng;
-
- (You need to be careful to update your bookkeeping if you use
-`yymore('), `yyless()', `unput()', or `input()'.)
-
-
-File: flex.info, Node: How do I use my own I/O classes in a C++ scanner?, Next: How do I skip as many chars as possible?, Prev: How do I track the byte offset for lseek()?, Up: FAQ
-
-How do I use my own I/O classes in a C++ scanner?
-=================================================
-
- When the flex C++ scanning class rewrite finally happens, then this
-sort of thing should become much easier.
-
- You can do this by passing the various functions (such as
-`LexerInput()' and `LexerOutput()') NULL `iostream*''s, and then
-dealing with your own I/O classes surreptitiously (i.e., stashing them
-in special member variables). This works because the only assumption
-about the lexer regarding what's done with the iostream's is that
-they're ultimately passed to `LexerInput()' and `LexerOutput', which
-then do whatever is necessary with them.
-
-
-File: flex.info, Node: How do I skip as many chars as possible?, Next: deleteme00, Prev: How do I use my own I/O classes in a C++ scanner?, Up: FAQ
-
-How do I skip as many chars as possible?
-========================================
-
- How do I skip as many chars as possible - without interfering with
-the other patterns?
-
- In the example below, we want to skip over characters until we see
-the phrase "endskip". The following will _NOT_ work correctly (do you
-see why not?)
-
-
- /* INCORRECT SCANNER */
- %x SKIP
- %%
- <INITIAL>startskip BEGIN(SKIP);
- ...
- <SKIP>"endskip" BEGIN(INITIAL);
- <SKIP>.* ;
-
- The problem is that the pattern .* will eat up the word "endskip."
-The simplest (but slow) fix is:
-
-
- <SKIP>"endskip" BEGIN(INITIAL);
- <SKIP>. ;
-
- The fix involves making the second rule match more, without making
-it match "endskip" plus something else. So for example:
-
-
- <SKIP>"endskip" BEGIN(INITIAL);
- <SKIP>[^e]+ ;
- <SKIP>. ;/* so you eat up e's, too */
-
-
-File: flex.info, Node: deleteme00, Next: Are certain equivalent patterns faster than others?, Prev: How do I skip as many chars as possible?, Up: FAQ
-
-deleteme00
-==========
-
-
- QUESTION:
- When was flex born?
-
- Vern Paxson took over
- the Software Tools lex project from Jef Poskanzer in 1982. At that point it
- was written in Ratfor. Around 1987 or so, Paxson translated it into C, and
- a legend was born :-).
-
-
-File: flex.info, Node: Are certain equivalent patterns faster than others?, Next: Is backing up a big deal?, Prev: deleteme00, Up: FAQ
-
-Are certain equivalent patterns faster than others?
-===================================================
-
-
- To: Adoram Rogel <adoram@orna.hybridge.com>
- Subject: Re: Flex 2.5.2 performance questions
- In-reply-to: Your message of Wed, 18 Sep 96 11:12:17 EDT.
- Date: Wed, 18 Sep 96 10:51:02 PDT
- From: Vern Paxson <vern>
-
- [Note, the most recent flex release is 2.5.4, which you can get from
- ftp.ee.lbl.gov. It has bug fixes over 2.5.2 and 2.5.3.]
-
- > 1. Using the pattern
- > ([Ff](oot)?)?[Nn](ote)?(\.)?
- > instead of
- > (((F|f)oot(N|n)ote)|((N|n)ote)|((N|n)\.)|((F|f)(N|n)(\.)))
- > (in a very complicated flex program) caused the program to slow from
- > 300K+/min to 100K/min (no other changes were done).
-
- These two are not equivalent. For example, the first can match "footnote."
- but the second can only match "footnote". This is almost certainly the
- cause in the discrepancy - the slower scanner run is matching more tokens,
- and/or having to do more backing up.
-
- > 2. Which of these two are better: [Ff]oot or (F|f)oot ?
-
- From a performance point of view, they're equivalent (modulo presumably
- minor effects such as memory cache hit rates; and the presence of trailing
- context, see below). From a space point of view, the first is slightly
- preferable.
-
- > 3. I have a pattern that look like this:
- > pats {p1}|{p2}|{p3}|...|{p50} (50 patterns ORd)
- >
- > running yet another complicated program that includes the following rule:
- > <snext>{and}/{no4}{bb}{pats}
- >
- > gets me to "too complicated - over 32,000 states"...
-
- I can't tell from this example whether the trailing context is variable-length
- or fixed-length (it could be the latter if {and} is fixed-length). If it's
- variable length, which flex -p will tell you, then this reflects a basic
- performance problem, and if you can eliminate it by restructuring your
- scanner, you will see significant improvement.
-
- > so I divided {pats} to {pats1}, {pats2},..., {pats5} each consists of about
- > 10 patterns and changed the rule to be 5 rules.
- > This did compile, but what is the rule of thumb here ?
-
- The rule is to avoid trailing context other than fixed-length, in which for
- a/b, either the 'a' pattern or the 'b' pattern have a fixed length. Use
- of the '|' operator automatically makes the pattern variable length, so in
- this case '[Ff]oot' is preferred to '(F|f)oot'.
-
- > 4. I changed a rule that looked like this:
- > <snext8>{and}{bb}/{ROMAN}[^A-Za-z] { BEGIN...
- >
- > to the next 2 rules:
- > <snext8>{and}{bb}/{ROMAN}[A-Za-z] { ECHO;}
- > <snext8>{and}{bb}/{ROMAN} { BEGIN...
- >
- > Again, I understand the using [^...] will cause a great performance loss
-
- Actually, it doesn't cause any sort of performance loss. It's a surprising
- fact about regular expressions that they always match in linear time
- regardless of how complex they are.
-
- > but are there any specific rules about it ?
-
- See the "Performance Considerations" section of the man page, and also
- the example in MISC/fastwc/.
-
- Vern
-
-
-File: flex.info, Node: Is backing up a big deal?, Next: Can I fake multi-byte character support?, Prev: Are certain equivalent patterns faster than others?, Up: FAQ
-
-Is backing up a big deal?
-=========================
-
-
- To: Adoram Rogel <adoram@hybridge.com>
- Subject: Re: Flex 2.5.2 performance questions
- In-reply-to: Your message of Thu, 19 Sep 96 10:16:04 EDT.
- Date: Thu, 19 Sep 96 09:58:00 PDT
- From: Vern Paxson <vern>
-
- > a lot about the backing up problem.
- > I believe that there lies my biggest problem, and I'll try to improve
- > it.
-
- Since you have variable trailing context, this is a bigger performance
- problem. Fixing it is usually easier than fixing backing up, which in a
- complicated scanner (yours seems to fit the bill) can be extremely
- difficult to do correctly.
-
- You also don't mention what flags you are using for your scanner.
- -f makes a large speed difference, and -Cfe buys you nearly as much
- speed but the resulting scanner is considerably smaller.
-
- > I have an | operator in {and} and in {pats} so both of them are variable
- > length.
-
- -p should have reported this.
-
- > Is changing one of them to fixed-length is enough ?
-
- Yes.
-
- > Is it possible to change the 32,000 states limit ?
-
- Yes. I've appended instructions on how. Before you make this change,
- though, you should think about whether there are ways to fundamentally
- simplify your scanner - those are certainly preferable!
-
- Vern
-
- To increase the 32K limit (on a machine with 32 bit integers), you increase
- the magnitude of the following in flexdef.h:
-
- #define JAMSTATE -32766 /* marks a reference to the state that always jams */
- #define MAXIMUM_MNS 31999
- #define BAD_SUBSCRIPT -32767
- #define MAX_SHORT 32700
-
- Adding a 0 or two after each should do the trick.
-
-
-File: flex.info, Node: Can I fake multi-byte character support?, Next: deleteme01, Prev: Is backing up a big deal?, Up: FAQ
-
-Can I fake multi-byte character support?
-========================================
-
-
- To: Heeman_Lee@hp.com
- Subject: Re: flex - multi-byte support?
- In-reply-to: Your message of Thu, 03 Oct 1996 17:24:04 PDT.
- Date: Fri, 04 Oct 1996 11:42:18 PDT
- From: Vern Paxson <vern>
-
- > I assume as long as my *.l file defines the
- > range of expected character code values (in octal format), flex will
- > scan the file and read multi-byte characters correctly. But I have no
- > confidence in this assumption.
-
- Your lack of confidence is justified - this won't work.
-
- Flex has in it a widespread assumption that the input is processed
- one byte at a time. Fixing this is on the to-do list, but is involved,
- so it won't happen any time soon. In the interim, the best I can suggest
- (unless you want to try fixing it yourself) is to write your rules in
- terms of pairs of bytes, using definitions in the first section:
-
- X \xfe\xc2
- ...
- %%
- foo{X}bar found_foo_fe_c2_bar();
-
- etc. Definitely a pain - sorry about that.
-
- By the way, the email address you used for me is ancient, indicating you
- have a very old version of flex. You can get the most recent, 2.5.4, from
- ftp.ee.lbl.gov.
-
- Vern
-
-
-File: flex.info, Node: deleteme01, Next: Can you discuss some flex internals?, Prev: Can I fake multi-byte character support?, Up: FAQ
-
-deleteme01
-==========
-
-
- To: moleary@primus.com
- Subject: Re: Flex / Unicode compatibility question
- In-reply-to: Your message of Tue, 22 Oct 1996 10:15:42 PDT.
- Date: Tue, 22 Oct 1996 11:06:13 PDT
- From: Vern Paxson <vern>
-
- Unfortunately flex at the moment has a widespread assumption within it
- that characters are processed 8 bits at a time. I don't see any easy
- fix for this (other than writing your rules in terms of double characters -
- a pain). I also don't know of a wider lex, though you might try surfing
- the Plan 9 stuff because I know it's a Unicode system, and also the PCCT
- toolkit (try searching say Alta Vista for "Purdue Compiler Construction
- Toolkit").
-
- Fixing flex to handle wider characters is on the long-term to-do list.
- But since flex is a strictly spare-time project these days, this probably
- won't happen for quite a while, unless someone else does it first.
-
- Vern
-
-
-File: flex.info, Node: Can you discuss some flex internals?, Next: unput() messes up yy_at_bol, Prev: deleteme01, Up: FAQ
-
-Can you discuss some flex internals?
-====================================
-
-
- To: Johan Linde <jl@theophys.kth.se>
- Subject: Re: translation of flex
- In-reply-to: Your message of Sun, 10 Nov 1996 09:16:36 PST.
- Date: Mon, 11 Nov 1996 10:33:50 PST
- From: Vern Paxson <vern>
-
- > I'm working for the Swedish team translating GNU program, and I'm currently
- > working with flex. I have a few questions about some of the messages which
- > I hope you can answer.
-
- All of the things you're wondering about, by the way, concerning flex
- internals - probably the only person who understands what they mean in
- English is me! So I wouldn't worry too much about getting them right.
- That said ...
-
- > #: main.c:545
- > msgid " %d protos created\n"
- >
- > Does proto mean prototype?
-
- Yes - prototypes of state compression tables.
-
- > #: main.c:539
- > msgid " %d/%d (peak %d) template nxt-chk entries created\n"
- >
- > Here I'm mainly puzzled by 'nxt-chk'. I guess it means 'next-check'. (?)
- > However, 'template next-check entries' doesn't make much sense to me. To be
- > able to find a good translation I need to know a little bit more about it.
-
- There is a scheme in the Aho/Sethi/Ullman compiler book for compressing
- scanner tables. It involves creating two pairs of tables. The first has
- "base" and "default" entries, the second has "next" and "check" entries.
- The "base" entry is indexed by the current state and yields an index into
- the next/check table. The "default" entry gives what to do if the state
- transition isn't found in next/check. The "next" entry gives the next
- state to enter, but only if the "check" entry verifies that this entry is
- correct for the current state. Flex creates templates of series of
- next/check entries and then encodes differences from these templates as a
- way to compress the tables.
-
- > #: main.c:533
- > msgid " %d/%d base-def entries created\n"
- >
- > The same problem here for 'base-def'.
-
- See above.
-
- Vern
-
-
-File: flex.info, Node: unput() messes up yy_at_bol, Next: The | operator is not doing what I want, Prev: Can you discuss some flex internals?, Up: FAQ
-
-unput() messes up yy_at_bol
-===========================
-
-
- To: Xinying Li <xli@npac.syr.edu>
- Subject: Re: FLEX ?
- In-reply-to: Your message of Wed, 13 Nov 1996 17:28:38 PST.
- Date: Wed, 13 Nov 1996 19:51:54 PST
- From: Vern Paxson <vern>
-
- > "unput()" them to input flow, question occurs. If I do this after I scan
- > a carriage, the variable "YY_CURRENT_BUFFER->yy_at_bol" is changed. That
- > means the carriage flag has gone.
-
- You can control this by calling yy_set_bol(). It's described in the manual.
-
- > And if in pre-reading it goes to the end of file, is anything done
- > to control the end of curren buffer and end of file?
-
- No, there's no way to put back an end-of-file.
-
- > By the way I am using flex 2.5.2 and using the "-l".
-
- The latest release is 2.5.4, by the way. It fixes some bugs in 2.5.2 and
- 2.5.3. You can get it from ftp.ee.lbl.gov.
-
- Vern
-
-
-File: flex.info, Node: The | operator is not doing what I want, Next: Why can't flex understand this variable trailing context pattern?, Prev: unput() messes up yy_at_bol, Up: FAQ
-
-The | operator is not doing what I want
-=======================================
-
-
- To: Alain.ISSARD@st.com
- Subject: Re: Start condition with FLEX
- In-reply-to: Your message of Mon, 18 Nov 1996 09:45:02 PST.
- Date: Mon, 18 Nov 1996 10:41:34 PST
- From: Vern Paxson <vern>
-
- > I am not able to use the start condition scope and to use the | (OR) with
- > rules having start conditions.
-
- The problem is that if you use '|' as a regular expression operator, for
- example "a|b" meaning "match either 'a' or 'b'", then it must *not* have
- any blanks around it. If you instead want the special '|' *action* (which
- from your scanner appears to be the case), which is a way of giving two
- different rules the same action:
-
- foo |
- bar matched_foo_or_bar();
-
- then '|' *must* be separated from the first rule by whitespace and *must*
- be followed by a new line. You *cannot* write it as:
-
- foo | bar matched_foo_or_bar();
-
- even though you might think you could because yacc supports this syntax.
- The reason for this unfortunately incompatibility is historical, but it's
- unlikely to be changed.
-
- Your problems with start condition scope are simply due to syntax errors
- from your use of '|' later confusing flex.
-
- Let me know if you still have problems.
-
- Vern
-
-
-File: flex.info, Node: Why can't flex understand this variable trailing context pattern?, Next: The ^ operator isn't working, Prev: The | operator is not doing what I want, Up: FAQ
-
-Why can't flex understand this variable trailing context pattern?
-=================================================================
-
-
- To: Gregory Margo <gmargo@newton.vip.best.com>
- Subject: Re: flex-2.5.3 bug report
- In-reply-to: Your message of Sat, 23 Nov 1996 16:50:09 PST.
- Date: Sat, 23 Nov 1996 17:07:32 PST
- From: Vern Paxson <vern>
-
- > Enclosed is a lex file that "real" lex will process, but I cannot get
- > flex to process it. Could you try it and maybe point me in the right direction?
-
- Your problem is that some of the definitions in the scanner use the '/'
- trailing context operator, and have it enclosed in ()'s. Flex does not
- allow this operator to be enclosed in ()'s because doing so allows undefined
- regular expressions such as "(a/b)+". So the solution is to remove the
- parentheses. Note that you must also be building the scanner with the -l
- option for AT&T lex compatibility. Without this option, flex automatically
- encloses the definitions in parentheses.
-
- Vern
-
-
-File: flex.info, Node: The ^ operator isn't working, Next: Trailing context is getting confused with trailing optional patterns, Prev: Why can't flex understand this variable trailing context pattern?, Up: FAQ
-
-The ^ operator isn't working
-============================
-
-
- To: Thomas Hadig <hadig@toots.physik.rwth-aachen.de>
- Subject: Re: Flex Bug ?
- In-reply-to: Your message of Tue, 26 Nov 1996 14:35:01 PST.
- Date: Tue, 26 Nov 1996 11:15:05 PST
- From: Vern Paxson <vern>
-
- > In my lexer code, i have the line :
- > ^\*.* { }
- >
- > Thus all lines starting with an astrix (*) are comment lines.
- > This does not work !
-
- I can't get this problem to reproduce - it works fine for me. Note
- though that if what you have is slightly different:
-
- COMMENT ^\*.*
- %%
- {COMMENT} { }
-
- then it won't work, because flex pushes back macro definitions enclosed
- in ()'s, so the rule becomes
-
- (^\*.*) { }
-
- and now that the '^' operator is not at the immediate beginning of the
- line, it's interpreted as just a regular character. You can avoid this
- behavior by using the "-l" lex-compatibility flag, or "%option lex-compat".
-
- Vern
-
-
-File: flex.info, Node: Trailing context is getting confused with trailing optional patterns, Next: Is flex GNU or not?, Prev: The ^ operator isn't working, Up: FAQ
-
-Trailing context is getting confused with trailing optional patterns
-====================================================================
-
-
- To: Adoram Rogel <adoram@hybridge.com>
- Subject: Re: Flex 2.5.4 BOF ???
- In-reply-to: Your message of Tue, 26 Nov 1996 16:10:41 PST.
- Date: Wed, 27 Nov 1996 10:56:25 PST
- From: Vern Paxson <vern>
-
- > Organization(s)?/[a-z]
- >
- > This matched "Organizations" (looking in debug mode, the trailing s
- > was matched with trailing context instead of the optional (s) in the
- > end of the word.
-
- That should only happen with lex. Flex can properly match this pattern.
- (That might be what you're saying, I'm just not sure.)
-
- > Is there a way to avoid this dangerous trailing context problem ?
-
- Unfortunately, there's no easy way. On the other hand, I don't see why
- it should be a problem. Lex's matching is clearly wrong, and I'd hope
- that usually the intent remains the same as expressed with the pattern,
- so flex's matching will be correct.
-
- Vern
-
-
-File: flex.info, Node: Is flex GNU or not?, Next: ERASEME53, Prev: Trailing context is getting confused with trailing optional patterns, Up: FAQ
-
-Is flex GNU or not?
-===================
-
-
- To: Cameron MacKinnon <mackin@interlog.com>
- Subject: Re: Flex documentation bug
- In-reply-to: Your message of Mon, 02 Dec 1996 00:07:08 PST.
- Date: Sun, 01 Dec 1996 22:29:39 PST
- From: Vern Paxson <vern>
-
- > I'm not sure how or where to submit bug reports (documentation or
- > otherwise) for the GNU project stuff ...
-
- Well, strictly speaking flex isn't part of the GNU project. They just
- distribute it because no one's written a decent GPL'd lex replacement.
- So you should send bugs directly to me. Those sent to the GNU folks
- sometimes find there way to me, but some may drop between the cracks.
-
- > In GNU Info, under the section 'Start Conditions', and also in the man
- > page (mine's dated April '95) is a nice little snippet showing how to
- > parse C quoted strings into a buffer, defined to be MAX_STR_CONST in
- > size. Unfortunately, no overflow checking is ever done ...
-
- This is already mentioned in the manual:
-
- Finally, here's an example of how to match C-style quoted
- strings using exclusive start conditions, including expanded
- escape sequences (but not including checking for a string
- that's too long):
-
- The reason for not doing the overflow checking is that it will needlessly
- clutter up an example whose main purpose is just to demonstrate how to
- use flex.
-
- The latest release is 2.5.4, by the way, available from ftp.ee.lbl.gov.
-
- Vern
-
-
-File: flex.info, Node: ERASEME53, Next: I need to scan if-then-else blocks and while loops, Prev: Is flex GNU or not?, Up: FAQ
-
-ERASEME53
-=========
-
-
- To: tsv@cs.UManitoba.CA
- Subject: Re: Flex (reg)..
- In-reply-to: Your message of Thu, 06 Mar 1997 23:50:16 PST.
- Date: Thu, 06 Mar 1997 15:54:19 PST
- From: Vern Paxson <vern>
-
- > [:alpha:] ([:alnum:] | \\_)*
-
- If your rule really has embedded blanks as shown above, then it won't
- work, as the first blank delimits the rule from the action. (It wouldn't
- even compile ...) You need instead:
-
- [:alpha:]([:alnum:]|\\_)*
-
- and that should work fine - there's no restriction on what can go inside
- of ()'s except for the trailing context operator, '/'.
-
- Vern
-
-
-File: flex.info, Node: I need to scan if-then-else blocks and while loops, Next: ERASEME55, Prev: ERASEME53, Up: FAQ
-
-I need to scan if-then-else blocks and while loops
-==================================================
-
-
- To: "Mike Stolnicki" <mstolnic@ford.com>
- Subject: Re: FLEX help
- In-reply-to: Your message of Fri, 30 May 1997 13:33:27 PDT.
- Date: Fri, 30 May 1997 10:46:35 PDT
- From: Vern Paxson <vern>
-
- > We'd like to add "if-then-else", "while", and "for" statements to our
- > language ...
- > We've investigated many possible solutions. The one solution that seems
- > the most reasonable involves knowing the position of a TOKEN in yyin.
-
- I strongly advise you to instead build a parse tree (abstract syntax tree)
- and loop over that instead. You'll find this has major benefits in keeping
- your interpreter simple and extensible.
-
- That said, the functionality you mention for get_position and set_position
- have been on the to-do list for a while. As flex is a purely spare-time
- project for me, no guarantees when this will be added (in particular, it
- for sure won't be for many months to come).
-
- Vern
-
-
-File: flex.info, Node: ERASEME55, Next: ERASEME56, Prev: I need to scan if-then-else blocks and while loops, Up: FAQ
-
-ERASEME55
-=========
-
-
- To: Colin Paul Adams <colin@colina.demon.co.uk>
- Subject: Re: Flex C++ classes and Bison
- In-reply-to: Your message of 09 Aug 1997 17:11:41 PDT.
- Date: Fri, 15 Aug 1997 10:48:19 PDT
- From: Vern Paxson <vern>
-
- > #define YY_DECL int yylex (YYSTYPE *lvalp, struct parser_control
- > *parm)
- >
- > I have been trying to get this to work as a C++ scanner, but it does
- > not appear to be possible (warning that it matches no declarations in
- > yyFlexLexer, or something like that).
- >
- > Is this supposed to be possible, or is it being worked on (I DID
- > notice the comment that scanner classes are still experimental, so I'm
- > not too hopeful)?
-
- What you need to do is derive a subclass from yyFlexLexer that provides
- the above yylex() method, squirrels away lvalp and parm into member
- variables, and then invokes yyFlexLexer::yylex() to do the regular scanning.
-
- Vern
-
-
-File: flex.info, Node: ERASEME56, Next: ERASEME57, Prev: ERASEME55, Up: FAQ
-
-ERASEME56
-=========
-
-
- To: Mikael.Latvala@lmf.ericsson.se
- Subject: Re: Possible mistake in Flex v2.5 document
- In-reply-to: Your message of Fri, 05 Sep 1997 16:07:24 PDT.
- Date: Fri, 05 Sep 1997 10:01:54 PDT
- From: Vern Paxson <vern>
-
- > In that example you show how to count comment lines when using
- > C style /* ... */ comments. My question is, shouldn't you take into
- > account a scenario where end of a comment marker occurs inside
- > character or string literals?
-
- The scanner certainly needs to also scan character and string literals.
- However it does that (there's an example in the man page for strings), the
- lexer will recognize the beginning of the literal before it runs across the
- embedded "/*". Consequently, it will finish scanning the literal before it
- even considers the possibility of matching "/*".
-
- Example:
-
- '([^']*|{ESCAPE_SEQUENCE})'
-
- will match all the text between the ''s (inclusive). So the lexer
- considers this as a token beginning at the first ', and doesn't even
- attempt to match other tokens inside it.
-
- I thinnk this subtlety is not worth putting in the manual, as I suspect
- it would confuse more people than it would enlighten.
-
- Vern
-
-
-File: flex.info, Node: ERASEME57, Next: Is there a repository for flex scanners?, Prev: ERASEME56, Up: FAQ
-
-ERASEME57
-=========
-
-
- To: "Marty Leisner" <leisner@sdsp.mc.xerox.com>
- Subject: Re: flex limitations
- In-reply-to: Your message of Sat, 06 Sep 1997 11:27:21 PDT.
- Date: Mon, 08 Sep 1997 11:38:08 PDT
- From: Vern Paxson <vern>
-
- > %%
- > [a-zA-Z]+ /* skip a line */
- > { printf("got %s\n", yytext); }
- > %%
-
- What version of flex are you using? If I feed this to 2.5.4, it complains:
-
- "bug.l", line 5: EOF encountered inside an action
- "bug.l", line 5: unrecognized rule
- "bug.l", line 5: fatal parse error
-
- Not the world's greatest error message, but it manages to flag the problem.
-
- (With the introduction of start condition scopes, flex can't accommodate
- an action on a separate line, since it's ambiguous with an indented rule.)
-
- You can get 2.5.4 from ftp.ee.lbl.gov.
-
- Vern
-
-
-File: flex.info, Node: Is there a repository for flex scanners?, Next: How can I conditionally compile or preprocess my flex input file?, Prev: ERASEME57, Up: FAQ
-
-Is there a repository for flex scanners?
-========================================
-
- Not that we know of. You might try asking on comp.compilers.
-
-
-File: flex.info, Node: How can I conditionally compile or preprocess my flex input file?, Next: Where can I find grammars for lex and yacc?, Prev: Is there a repository for flex scanners?, Up: FAQ
-
-How can I conditionally compile or preprocess my flex input file?
-=================================================================
-
- Flex doesn't have a preprocessor like C does. You might try using
-m4, or the C preprocessor plus a sed script to clean up the result.
-
-
-File: flex.info, Node: Where can I find grammars for lex and yacc?, Next: I get an end-of-buffer message for each character scanned., Prev: How can I conditionally compile or preprocess my flex input file?, Up: FAQ
-
-Where can I find grammars for lex and yacc?
-===========================================
-
- In the sources for flex and bison.
-
-
-File: flex.info, Node: I get an end-of-buffer message for each character scanned., Next: unnamed-faq-62, Prev: Where can I find grammars for lex and yacc?, Up: FAQ
-
-I get an end-of-buffer message for each character scanned.
-==========================================================
-
- This will happen if your LexerInput() function returns only one
-character at a time, which can happen either if you're scanner is
-"interactive", or if the streams library on your platform always
-returns 1 for yyin->gcount().
-
- Solution: override LexerInput() with a version that returns whole
-buffers.
-
-
-File: flex.info, Node: unnamed-faq-62, Next: unnamed-faq-63, Prev: I get an end-of-buffer message for each character scanned., Up: FAQ
-
-unnamed-faq-62
-==============
-
-
- To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
- Subject: Re: Flex maximums
- In-reply-to: Your message of Mon, 17 Nov 1997 17:16:06 PST.
- Date: Mon, 17 Nov 1997 17:16:15 PST
- From: Vern Paxson <vern>
-
- > I took a quick look into the flex-sources and altered some #defines in
- > flexdefs.h:
- >
- > #define INITIAL_MNS 64000
- > #define MNS_INCREMENT 1024000
- > #define MAXIMUM_MNS 64000
-
- The things to fix are to add a couple of zeroes to:
-
- #define JAMSTATE -32766 /* marks a reference to the state that always jams */
- #define MAXIMUM_MNS 31999
- #define BAD_SUBSCRIPT -32767
- #define MAX_SHORT 32700
-
- and, if you get complaints about too many rules, make the following change too:
-
- #define YY_TRAILING_MASK 0x200000
- #define YY_TRAILING_HEAD_MASK 0x400000
-
- - Vern
-
-
-File: flex.info, Node: unnamed-faq-63, Next: unnamed-faq-64, Prev: unnamed-faq-62, Up: FAQ
-
-unnamed-faq-63
-==============
-
-
- To: jimmey@lexis-nexis.com (Jimmey Todd)
- Subject: Re: FLEX question regarding istream vs ifstream
- In-reply-to: Your message of Mon, 08 Dec 1997 15:54:15 PST.
- Date: Mon, 15 Dec 1997 13:21:35 PST
- From: Vern Paxson <vern>
-
- > stdin_handle = YY_CURRENT_BUFFER;
- > ifstream fin( "aFile" );
- > yy_switch_to_buffer( yy_create_buffer( fin, YY_BUF_SIZE ) );
- >
- > What I'm wanting to do, is pass the contents of a file thru one set
- > of rules and then pass stdin thru another set... It works great if, I
- > don't use the C++ classes. But since everything else that I'm doing is
- > in C++, I thought I'd be consistent.
- >
- > The problem is that 'yy_create_buffer' is expecting an istream* as it's
- > first argument (as stated in the man page). However, fin is a ifstream
- > object. Any ideas on what I might be doing wrong? Any help would be
- > appreciated. Thanks!!
-
- You need to pass &fin, to turn it into an ifstream* instead of an ifstream.
- Then its type will be compatible with the expected istream*, because ifstream
- is derived from istream.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-64, Next: unnamed-faq-65, Prev: unnamed-faq-63, Up: FAQ
-
-unnamed-faq-64
-==============
-
-
- To: Enda Fadian <fadiane@piercom.ie>
- Subject: Re: Question related to Flex man page?
- In-reply-to: Your message of Tue, 16 Dec 1997 15:17:34 PST.
- Date: Tue, 16 Dec 1997 14:17:09 PST
- From: Vern Paxson <vern>
-
- > Can you explain to me what is ment by a long-jump in relation to flex?
-
- Using the longjmp() function while inside yylex() or a routine called by it.
-
- > what is the flex activation frame.
-
- Just yylex()'s stack frame.
-
- > As far as I can see yyrestart will bring me back to the sart of the input
- > file and using flex++ isnot really an option!
-
- No, yyrestart() doesn't imply a rewind, even though its name might sound
- like it does. It tells the scanner to flush its internal buffers and
- start reading from the given file at its present location.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-65, Next: unnamed-faq-66, Prev: unnamed-faq-64, Up: FAQ
-
-unnamed-faq-65
-==============
-
-
- To: hassan@larc.info.uqam.ca (Hassan Alaoui)
- Subject: Re: Need urgent Help
- In-reply-to: Your message of Sat, 20 Dec 1997 19:38:19 PST.
- Date: Sun, 21 Dec 1997 21:30:46 PST
- From: Vern Paxson <vern>
-
- > /usr/lib/yaccpar: In function `int yyparse()':
- > /usr/lib/yaccpar:184: warning: implicit declaration of function `int yylex(...)'
- >
- > ld: Undefined symbol
- > _yylex
- > _yyparse
- > _yyin
-
- This is a known problem with Solaris C++ (and/or Solaris yacc). I believe
- the fix is to explicitly insert some 'extern "C"' statements for the
- corresponding routines/symbols.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-66, Next: unnamed-faq-67, Prev: unnamed-faq-65, Up: FAQ
-
-unnamed-faq-66
-==============
-
-
- To: mc0307@mclink.it
- Cc: gnu@prep.ai.mit.edu
- Subject: Re: [mc0307@mclink.it: Help request]
- In-reply-to: Your message of Fri, 12 Dec 1997 17:57:29 PST.
- Date: Sun, 21 Dec 1997 22:33:37 PST
- From: Vern Paxson <vern>
-
- > This is my definition for float and integer types:
- > . . .
- > NZD [1-9]
- > ...
- > I've tested my program on other lex version (on UNIX Sun Solaris an HP
- > UNIX) and it work well, so I think that my definitions are correct.
- > There are any differences between Lex and Flex?
-
- There are indeed differences, as discussed in the man page. The one
- you are probably running into is that when flex expands a name definition,
- it puts parentheses around the expansion, while lex does not. There's
- an example in the man page of how this can lead to different matching.
- Flex's behavior complies with the POSIX standard (or at least with the
- last POSIX draft I saw).
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-67, Next: unnamed-faq-68, Prev: unnamed-faq-66, Up: FAQ
-
-unnamed-faq-67
-==============
-
-
- To: hassan@larc.info.uqam.ca (Hassan Alaoui)
- Subject: Re: Thanks
- In-reply-to: Your message of Mon, 22 Dec 1997 16:06:35 PST.
- Date: Mon, 22 Dec 1997 14:35:05 PST
- From: Vern Paxson <vern>
-
- > Thank you very much for your help. I compile and link well with C++ while
- > declaring 'yylex ...' extern, But a little problem remains. I get a
- > segmentation default when executing ( I linked with lfl library) while it
- > works well when using LEX instead of flex. Do you have some ideas about the
- > reason for this ?
-
- The one possible reason for this that comes to mind is if you've defined
- yytext as "extern char yytext[]" (which is what lex uses) instead of
- "extern char *yytext" (which is what flex uses). If it's not that, then
- I'm afraid I don't know what the problem might be.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-68, Next: unnamed-faq-69, Prev: unnamed-faq-67, Up: FAQ
-
-unnamed-faq-68
-==============
-
-
- To: "Bart Niswonger" <NISWONGR@almaden.ibm.com>
- Subject: Re: flex 2.5: c++ scanners & start conditions
- In-reply-to: Your message of Tue, 06 Jan 1998 10:34:21 PST.
- Date: Tue, 06 Jan 1998 19:19:30 PST
- From: Vern Paxson <vern>
-
- > The problem is that when I do this (using %option c++) start
- > conditions seem to not apply.
-
- The BEGIN macro modifies the yy_start variable. For C scanners, this
- is a static with scope visible through the whole file. For C++ scanners,
- it's a member variable, so it only has visible scope within a member
- function. Your lexbegin() routine is not a member function when you
- build a C++ scanner, so it's not modifying the correct yy_start. The
- diagnostic that indicates this is that you found you needed to add
- a declaration of yy_start in order to get your scanner to compile when
- using C++; instead, the correct fix is to make lexbegin() a member
- function (by deriving from yyFlexLexer).
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-69, Next: unnamed-faq-70, Prev: unnamed-faq-68, Up: FAQ
-
-unnamed-faq-69
-==============
-
-
- To: "Boris Zinin" <boris@ippe.rssi.ru>
- Subject: Re: current position in flex buffer
- In-reply-to: Your message of Mon, 12 Jan 1998 18:58:23 PST.
- Date: Mon, 12 Jan 1998 12:03:15 PST
- From: Vern Paxson <vern>
-
- > The problem is how to determine the current position in flex active
- > buffer when a rule is matched....
-
- You will need to keep track of this explicitly, such as by redefining
- YY_USER_ACTION to count the number of characters matched.
-
- The latest flex release, by the way, is 2.5.4, available from ftp.ee.lbl.gov.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-70, Next: unnamed-faq-71, Prev: unnamed-faq-69, Up: FAQ
-
-unnamed-faq-70
-==============
-
-
- To: Bik.Dhaliwal@bis.org
- Subject: Re: Flex question
- In-reply-to: Your message of Mon, 26 Jan 1998 13:05:35 PST.
- Date: Tue, 27 Jan 1998 22:41:52 PST
- From: Vern Paxson <vern>
-
- > That requirement involves knowing
- > the character position at which a particular token was matched
- > in the lexer.
-
- The way you have to do this is by explicitly keeping track of where
- you are in the file, by counting the number of characters scanned
- for each token (available in yyleng). It may prove convenient to
- do this by redefining YY_USER_ACTION, as described in the manual.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-71, Next: unnamed-faq-72, Prev: unnamed-faq-70, Up: FAQ
-
-unnamed-faq-71
-==============
-
-
- To: Vladimir Alexiev <vladimir@cs.ualberta.ca>
- Subject: Re: flex: how to control start condition from parser?
- In-reply-to: Your message of Mon, 26 Jan 1998 05:50:16 PST.
- Date: Tue, 27 Jan 1998 22:45:37 PST
- From: Vern Paxson <vern>
-
- > It seems useful for the parser to be able to tell the lexer about such
- > context dependencies, because then they don't have to be limited to
- > local or sequential context.
-
- One way to do this is to have the parser call a stub routine that's
- included in the scanner's .l file, and consequently that has access ot
- BEGIN. The only ugliness is that the parser can't pass in the state
- it wants, because those aren't visible - but if you don't have many
- such states, then using a different set of names doesn't seem like
- to much of a burden.
-
- While generating a .h file like you suggests is certainly cleaner,
- flex development has come to a virtual stand-still :-(, so a workaround
- like the above is much more pragmatic than waiting for a new feature.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-72, Next: unnamed-faq-73, Prev: unnamed-faq-71, Up: FAQ
-
-unnamed-faq-72
-==============
-
-
- To: Barbara Denny <denny@3com.com>
- Subject: Re: freebsd flex bug?
- In-reply-to: Your message of Fri, 30 Jan 1998 12:00:43 PST.
- Date: Fri, 30 Jan 1998 12:42:32 PST
- From: Vern Paxson <vern>
-
- > lex.yy.c:1996: parse error before `='
-
- This is the key, identifying this error. (It may help to pinpoint
- it by using flex -L, so it doesn't generate #line directives in its
- output.) I will bet you heavy money that you have a start condition
- name that is also a variable name, or something like that; flex spits
- out #define's for each start condition name, mapping them to a number,
- so you can wind up with:
-
- %x foo
- %%
- ...
- %%
- void bar()
- {
- int foo = 3;
- }
-
- and the penultimate will turn into "int 1 = 3" after C preprocessing,
- since flex will put "#define foo 1" in the generated scanner.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-73, Next: unnamed-faq-74, Prev: unnamed-faq-72, Up: FAQ
-
-unnamed-faq-73
-==============
-
-
- To: Maurice Petrie <mpetrie@infoscigroup.com>
- Subject: Re: Lost flex .l file
- In-reply-to: Your message of Mon, 02 Feb 1998 14:10:01 PST.
- Date: Mon, 02 Feb 1998 11:15:12 PST
- From: Vern Paxson <vern>
-
- > I am curious as to
- > whether there is a simple way to backtrack from the generated source to
- > reproduce the lost list of tokens we are searching on.
-
- In theory, it's straight-forward to go from the DFA representation
- back to a regular-expression representation - the two are isomorphic.
- In practice, a huge headache, because you have to unpack all the tables
- back into a single DFA representation, and then write a program to munch
- on that and translate it into an RE.
-
- Sorry for the less-than-happy news ...
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-74, Next: unnamed-faq-75, Prev: unnamed-faq-73, Up: FAQ
-
-unnamed-faq-74
-==============
-
-
- To: jimmey@lexis-nexis.com (Jimmey Todd)
- Subject: Re: Flex performance question
- In-reply-to: Your message of Thu, 19 Feb 1998 11:01:17 PST.
- Date: Thu, 19 Feb 1998 08:48:51 PST
- From: Vern Paxson <vern>
-
- > What I have found, is that the smaller the data chunk, the faster the
- > program executes. This is the opposite of what I expected. Should this be
- > happening this way?
-
- This is exactly what will happen if your input file has embedded NULs.
- From the man page:
-
- A final note: flex is slow when matching NUL's, particularly
- when a token contains multiple NUL's. It's best to write
- rules which match short amounts of text if it's anticipated
- that the text will often include NUL's.
-
- So that's the first thing to look for.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-75, Next: unnamed-faq-76, Prev: unnamed-faq-74, Up: FAQ
-
-unnamed-faq-75
-==============
-
-
- To: jimmey@lexis-nexis.com (Jimmey Todd)
- Subject: Re: Flex performance question
- In-reply-to: Your message of Thu, 19 Feb 1998 11:01:17 PST.
- Date: Thu, 19 Feb 1998 15:42:25 PST
- From: Vern Paxson <vern>
-
- So there are several problems.
-
- First, to go fast, you want to match as much text as possible, which
- your scanners don't in the case that what they're scanning is *not*
- a <RN> tag. So you want a rule like:
-
- [^<]+
-
- Second, C++ scanners are particularly slow if they're interactive,
- which they are by default. Using -B speeds it up by a factor of 3-4
- on my workstation.
-
- Third, C++ scanners that use the istream interface are slow, because
- of how poorly implemented istream's are. I built two versions of
- the following scanner:
-
- %%
- .*\n
- .*
- %%
-
- and the C version inhales a 2.5MB file on my workstation in 0.8 seconds.
- The C++ istream version, using -B, takes 3.8 seconds.
-
- Vern
-
diff --git a/doc/flex.info-6 b/doc/flex.info-6
deleted file mode 100644
index 04f95d8..0000000
--- a/doc/flex.info-6
+++ /dev/null
@@ -1,1134 +0,0 @@
-This is flex.info, produced by makeinfo version 4.5 from flex.texi.
-
-INFO-DIR-SECTION Programming
-START-INFO-DIR-ENTRY
-* flex: (flex). Fast lexical analyzer generator (lex replacement).
-END-INFO-DIR-ENTRY
-
-
- The flex manual is placed under the same licensing conditions as the
-rest of flex:
-
- Copyright (C) 1990, 1997 The Regents of the University of California.
-All rights reserved.
-
- This code is derived from software contributed to Berkeley by Vern
-Paxson.
-
- The United States Government has rights in this work pursuant to
-contract no. DE-AC03-76SF00098 between the United States Department of
-Energy and the University of California.
-
- Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the
- distribution.
- Neither the name of the University nor the names of its contributors
-may be used to endorse or promote products derived from this software
-without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-
-File: flex.info, Node: unnamed-faq-76, Next: unnamed-faq-77, Prev: unnamed-faq-75, Up: FAQ
-
-unnamed-faq-76
-==============
-
-
- To: "Frescatore, David (CRD, TAD)" <frescatore@exc01crdge.crd.ge.com>
- Subject: Re: FLEX 2.5 & THE YEAR 2000
- In-reply-to: Your message of Wed, 03 Jun 1998 11:26:22 PDT.
- Date: Wed, 03 Jun 1998 10:22:26 PDT
- From: Vern Paxson <vern>
-
- > I am researching the Y2K problem with General Electric R&D
- > and need to know if there are any known issues concerning
- > the above mentioned software and Y2K regardless of version.
-
- There shouldn't be, all it ever does with the date is ask the system
- for it and then print it out.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-77, Next: unnamed-faq-78, Prev: unnamed-faq-76, Up: FAQ
-
-unnamed-faq-77
-==============
-
-
- To: "Hans Dermot Doran" <htd@ibhdoran.com>
- Subject: Re: flex problem
- In-reply-to: Your message of Wed, 15 Jul 1998 21:30:13 PDT.
- Date: Tue, 21 Jul 1998 14:23:34 PDT
- From: Vern Paxson <vern>
-
- > To overcome this, I gets() the stdin into a string and lex the string. The
- > string is lexed OK except that the end of string isn't lexed properly
- > (yy_scan_string()), that is the lexer dosn't recognise the end of string.
-
- Flex doesn't contain mechanisms for recognizing buffer endpoints. But if
- you use fgets instead (which you should anyway, to protect against buffer
- overflows), then the final \n will be preserved in the string, and you can
- scan that in order to find the end of the string.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-78, Next: unnamed-faq-79, Prev: unnamed-faq-77, Up: FAQ
-
-unnamed-faq-78
-==============
-
-
- To: soumen@almaden.ibm.com
- Subject: Re: Flex++ 2.5.3 instance member vs. static member
- In-reply-to: Your message of Mon, 27 Jul 1998 02:10:04 PDT.
- Date: Tue, 28 Jul 1998 01:10:34 PDT
- From: Vern Paxson <vern>
-
- > %{
- > int mylineno = 0;
- > %}
- > ws [ \t]+
- > alpha [A-Za-z]
- > dig [0-9]
- > %%
- >
- > Now you'd expect mylineno to be a member of each instance of class
- > yyFlexLexer, but is this the case? A look at the lex.yy.cc file seems to
- > indicate otherwise; unless I am missing something the declaration of
- > mylineno seems to be outside any class scope.
- >
- > How will this work if I want to run a multi-threaded application with each
- > thread creating a FlexLexer instance?
-
- Derive your own subclass and make mylineno a member variable of it.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-79, Next: unnamed-faq-80, Prev: unnamed-faq-78, Up: FAQ
-
-unnamed-faq-79
-==============
-
-
- To: Adoram Rogel <adoram@hybridge.com>
- Subject: Re: More than 32K states change hangs
- In-reply-to: Your message of Tue, 04 Aug 1998 16:55:39 PDT.
- Date: Tue, 04 Aug 1998 22:28:45 PDT
- From: Vern Paxson <vern>
-
- > Vern Paxson,
- >
- > I followed your advice, posted on Usenet bu you, and emailed to me
- > personally by you, on how to overcome the 32K states limit. I'm running
- > on Linux machines.
- > I took the full source of version 2.5.4 and did the following changes in
- > flexdef.h:
- > #define JAMSTATE -327660
- > #define MAXIMUM_MNS 319990
- > #define BAD_SUBSCRIPT -327670
- > #define MAX_SHORT 327000
- >
- > and compiled.
- > All looked fine, including check and bigcheck, so I installed.
-
- Hmmm, you shouldn't increase MAX_SHORT, though looking through my email
- archives I see that I did indeed recommend doing so. Try setting it back
- to 32700; that should suffice that you no longer need -Ca. If it still
- hangs, then the interesting question is - where?
-
- > Compiling the same hanged program with a out-of-the-box (RedHat 4.2
- > distribution of Linux)
- > flex 2.5.4 binary works.
-
- Since Linux comes with source code, you should diff it against what
- you have to see what problems they missed.
-
- > Should I always compile with the -Ca option now ? even short and simple
- > filters ?
-
- No, definitely not. It's meant to be for those situations where you
- absolutely must squeeze every last cycle out of your scanner.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-80, Next: unnamed-faq-81, Prev: unnamed-faq-79, Up: FAQ
-
-unnamed-faq-80
-==============
-
-
- To: "Schmackpfeffer, Craig" <Craig.Schmackpfeffer@usa.xerox.com>
- Subject: Re: flex output for static code portion
- In-reply-to: Your message of Tue, 11 Aug 1998 11:55:30 PDT.
- Date: Mon, 17 Aug 1998 23:57:42 PDT
- From: Vern Paxson <vern>
-
- > I would like to use flex under the hood to generate a binary file
- > containing the data structures that control the parse.
-
- This has been on the wish-list for a long time. In principle it's
- straight-forward - you redirect mkdata() et al's I/O to another file,
- and modify the skeleton to have a start-up function that slurps these
- into dynamic arrays. The concerns are (1) the scanner generation code
- is hairy and full of corner cases, so it's easy to get surprised when
- going down this path :-( ; and (2) being careful about buffering so
- that when the tables change you make sure the scanner starts in the
- correct state and reading at the right point in the input file.
-
- > I was wondering if you know of anyone who has used flex in this way.
-
- I don't - but it seems like a reasonable project to undertake (unlike
- numerous other flex tweaks :-).
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-81, Next: unnamed-faq-82, Prev: unnamed-faq-80, Up: FAQ
-
-unnamed-faq-81
-==============
-
-
- Received: from 131.173.17.11 (131.173.17.11 [131.173.17.11])
- by ee.lbl.gov (8.9.1/8.9.1) with ESMTP id AAA03838
- for <vern@ee.lbl.gov>; Thu, 20 Aug 1998 00:47:57 -0700 (PDT)
- Received: from hal.cl-ki.uni-osnabrueck.de (hal.cl-ki.Uni-Osnabrueck.DE [131.173.141.2])
- by deimos.rz.uni-osnabrueck.de (8.8.7/8.8.8) with ESMTP id JAA34694
- for <vern@ee.lbl.gov>; Thu, 20 Aug 1998 09:47:55 +0200
- Received: (from georg@localhost) by hal.cl-ki.uni-osnabrueck.de (8.6.12/8.6.12) id JAA34834 for vern@ee.lbl.gov; Thu, 20 Aug 1998 09:47:54 +0200
- From: Georg Rehm <georg@hal.cl-ki.uni-osnabrueck.de>
- Message-Id: <199808200747.JAA34834@hal.cl-ki.uni-osnabrueck.de>
- Subject: "flex scanner push-back overflow"
- To: vern@ee.lbl.gov
- Date: Thu, 20 Aug 1998 09:47:54 +0200 (MEST)
- Reply-To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
- X-NoJunk: Do NOT send commercial mail, spam or ads to this address!
- X-URL: http://www.cl-ki.uni-osnabrueck.de/~georg/
- X-Mailer: ELM [version 2.4ME+ PL28 (25)]
- MIME-Version: 1.0
- Content-Type: text/plain; charset=US-ASCII
- Content-Transfer-Encoding: 7bit
-
- Hi Vern,
-
- Yesterday, I encountered a strange problem: I use the macro processor m4
- to include some lengthy lists into a .l file. Following is a flex macro
- definition that causes some serious pain in my neck:
-
- AUTHOR ("A. Boucard / L. Boucard"|"A. Dastarac / M. Levent"|"A.Boucaud / L.Boucaud"|"Abderrahim Lamchichi"|"Achmat Dangor"|"Adeline Toullier"|"Adewale Maja-Pearce"|"Ahmed Ziri"|"Akram Ellyas"|"Alain Bihr"|"Alain Gresh"|"Alain Guillemoles"|"Alain Joxe"|"Alain Morice"|"Alain Renon"|"Alain Zecchini"|"Albert Memmi"|"Alberto Manguel"|"Alex De Waal"|"Alfonso Artico"| [...])
-
- The complete list contains about 10kB. When I try to "flex" this file
- (on a Solaris 2.6 machine, using a modified flex 2.5.4 (I only increased
- some of the predefined values in flexdefs.h) I get the error:
-
- myflex/flex -8 sentag.tmp.l
- flex scanner push-back overflow
-
- When I remove the slashes in the macro definition everything works fine.
- As I understand it, the double quotes escape the slash-character so it
- really means "/" and not "trailing context". Furthermore, I tried to
- escape the slashes with backslashes, but with no use, the same error message
- appeared when flexing the code.
-
- Do you have an idea what's going on here?
-
- Greetings from Germany,
- Georg
- --
- Georg Rehm georg@cl-ki.uni-osnabrueck.de
- Institute for Semantic Information Processing, University of Osnabrueck, FRG
-
-
-File: flex.info, Node: unnamed-faq-82, Next: unnamed-faq-83, Prev: unnamed-faq-81, Up: FAQ
-
-unnamed-faq-82
-==============
-
-
- To: Georg.Rehm@CL-KI.Uni-Osnabrueck.DE
- Subject: Re: "flex scanner push-back overflow"
- In-reply-to: Your message of Thu, 20 Aug 1998 09:47:54 PDT.
- Date: Thu, 20 Aug 1998 07:05:35 PDT
- From: Vern Paxson <vern>
-
- > myflex/flex -8 sentag.tmp.l
- > flex scanner push-back overflow
-
- Flex itself uses a flex scanner. That scanner is running out of buffer
- space when it tries to unput() the humongous macro you've defined. When
- you remove the '/'s, you make it small enough so that it fits in the buffer;
- removing spaces would do the same thing.
-
- The fix is to either rethink how come you're using such a big macro and
- perhaps there's another/better way to do it; or to rebuild flex's own
- scan.c with a larger value for
-
- #define YY_BUF_SIZE 16384
-
- - Vern
-
-
-File: flex.info, Node: unnamed-faq-83, Next: unnamed-faq-84, Prev: unnamed-faq-82, Up: FAQ
-
-unnamed-faq-83
-==============
-
-
- To: Jan Kort <jan@research.techforce.nl>
- Subject: Re: Flex
- In-reply-to: Your message of Fri, 04 Sep 1998 12:18:43 +0200.
- Date: Sat, 05 Sep 1998 00:59:49 PDT
- From: Vern Paxson <vern>
-
- > %%
- >
- > "TEST1\n" { fprintf(stderr, "TEST1\n"); yyless(5); }
- > ^\n { fprintf(stderr, "empty line\n"); }
- > . { }
- > \n { fprintf(stderr, "new line\n"); }
- >
- > %%
- > -- input ---------------------------------------
- > TEST1
- > -- output --------------------------------------
- > TEST1
- > empty line
- > ------------------------------------------------
-
- IMHO, it's not clear whether or not this is in fact a bug. It depends
- on whether you view yyless() as backing up in the input stream, or as
- pushing new characters onto the beginning of the input stream. Flex
- interprets it as the latter (for implementation convenience, I'll admit),
- and so considers the newline as in fact matching at the beginning of a
- line, as after all the last token scanned an entire line and so the
- scanner is now at the beginning of a new line.
-
- I agree that this is counter-intuitive for yyless(), given its
- functional description (it's less so for unput(), depending on whether
- you're unput()'ing new text or scanned text). But I don't plan to
- change it any time soon, as it's a pain to do so. Consequently,
- you do indeed need to use yy_set_bol() and YY_AT_BOL() to tweak
- your scanner into the behavior you desire.
-
- Sorry for the less-than-completely-satisfactory answer.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-84, Next: unnamed-faq-85, Prev: unnamed-faq-83, Up: FAQ
-
-unnamed-faq-84
-==============
-
-
- To: Patrick Krusenotto <krusenot@mac-info-link.de>
- Subject: Re: Problems with restarting flex-2.5.2-generated scanner
- In-reply-to: Your message of Thu, 24 Sep 1998 10:14:07 PDT.
- Date: Thu, 24 Sep 1998 23:28:43 PDT
- From: Vern Paxson <vern>
-
- > I am using flex-2.5.2 and bison 1.25 for Solaris and I am desperately
- > trying to make my scanner restart with a new file after my parser stops
- > with a parse error. When my compiler restarts, the parser always
- > receives the token after the token (in the old file!) that caused the
- > parser error.
-
- I suspect the problem is that your parser has read ahead in order
- to attempt to resolve an ambiguity, and when it's restarted it picks
- up with that token rather than reading a fresh one. If you're using
- yacc, then the special "error" production can sometimes be used to
- consume tokens in an attempt to get the parser into a consistent state.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-85, Next: unnamed-faq-86, Prev: unnamed-faq-84, Up: FAQ
-
-unnamed-faq-85
-==============
-
-
- To: Henric Jungheim <junghelh@pe-nelson.com>
- Subject: Re: flex 2.5.4a
- In-reply-to: Your message of Tue, 27 Oct 1998 16:41:42 PST.
- Date: Tue, 27 Oct 1998 16:50:14 PST
- From: Vern Paxson <vern>
-
- > This brings up a feature request: How about a command line
- > option to specify the filename when reading from stdin? That way one
- > doesn't need to create a temporary file in order to get the "#line"
- > directives to make sense.
-
- Use -o combined with -t (per the man page description of -o).
-
- > P.S., Is there any simple way to use non-blocking IO to parse multiple
- > streams?
-
- Simple, no.
-
- One approach might be to return a magic character on EWOULDBLOCK and
- have a rule
-
- .*<magic-character> // put back .*, eat magic character
-
- This is off the top of my head, not sure it'll work.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-86, Next: unnamed-faq-87, Prev: unnamed-faq-85, Up: FAQ
-
-unnamed-faq-86
-==============
-
-
- To: "Repko, Billy D" <billy.d.repko@intel.com>
- Subject: Re: Compiling scanners
- In-reply-to: Your message of Wed, 13 Jan 1999 10:52:47 PST.
- Date: Thu, 14 Jan 1999 00:25:30 PST
- From: Vern Paxson <vern>
-
- > It appears that maybe it cannot find the lfl library.
-
- The Makefile in the distribution builds it, so you should have it.
- It's exceedingly trivial, just a main() that calls yylex() and
- a yyrap() that always returns 1.
-
- > %%
- > \n ++num_lines; ++num_chars;
- > . ++num_chars;
-
- You can't indent your rules like this - that's where the errors are coming
- from. Flex copies indented text to the output file, it's how you do things
- like
-
- int num_lines_seen = 0;
-
- to declare local variables.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-87, Next: unnamed-faq-88, Prev: unnamed-faq-86, Up: FAQ
-
-unnamed-faq-87
-==============
-
-
- To: Erick Branderhorst <Erick.Branderhorst@asml.nl>
- Subject: Re: flex input buffer
- In-reply-to: Your message of Tue, 09 Feb 1999 13:53:46 PST.
- Date: Tue, 09 Feb 1999 21:03:37 PST
- From: Vern Paxson <vern>
-
- > In the flex.skl file the size of the default input buffers is set. Can you
- > explain why this size is set and why it is such a high number.
-
- It's large to optimize performance when scanning large files. You can
- safely make it a lot lower if needed.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-88, Next: unnamed-faq-90, Prev: unnamed-faq-87, Up: FAQ
-
-unnamed-faq-88
-==============
-
-
- To: "Guido Minnen" <guidomi@cogs.susx.ac.uk>
- Subject: Re: Flex error message
- In-reply-to: Your message of Wed, 24 Feb 1999 15:31:46 PST.
- Date: Thu, 25 Feb 1999 00:11:31 PST
- From: Vern Paxson <vern>
-
- > I'm extending a larger scanner written in Flex and I keep running into
- > problems. More specifically, I get the error message:
- > "flex: input rules are too complicated (>= 32000 NFA states)"
-
- Increase the definitions in flexdef.h for:
-
- #define JAMSTATE -32766 /* marks a reference to the state that always j
- ams */
- #define MAXIMUM_MNS 31999
- #define BAD_SUBSCRIPT -32767
-
- recompile everything, and it should all work.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-90, Next: unnamed-faq-91, Prev: unnamed-faq-88, Up: FAQ
-
-unnamed-faq-90
-==============
-
-
- To: "Dmitriy Goldobin" <gold@ems.chel.su>
- Subject: Re: FLEX trouble
- In-reply-to: Your message of Mon, 31 May 1999 18:44:49 PDT.
- Date: Tue, 01 Jun 1999 00:15:07 PDT
- From: Vern Paxson <vern>
-
- > I have a trouble with FLEX. Why rule "/*".*"*/" work properly,=20
- > but rule "/*"(.|\n)*"*/" don't work ?
-
- The second of these will have to scan the entire input stream (because
- "(.|\n)*" matches an arbitrary amount of any text) in order to see if
- it ends with "*/", terminating the comment. That potentially will overflow
- the input buffer.
-
- > More complex rule "/*"([^*]|(\*/[^/]))*"*/ give an error
- > 'unrecognized rule'.
-
- You can't use the '/' operator inside parentheses. It's not clear
- what "(a/b)*" actually means.
-
- > I now use workaround with state <comment>, but single-rule is
- > better, i think.
-
- Single-rule is nice but will always have the problem of either setting
- restrictions on comments (like not allowing multi-line comments) and/or
- running the risk of consuming the entire input stream, as noted above.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-91, Next: unnamed-faq-92, Prev: unnamed-faq-90, Up: FAQ
-
-unnamed-faq-91
-==============
-
-
- Received: from mc-qout4.whowhere.com (mc-qout4.whowhere.com [209.185.123.18])
- by ee.lbl.gov (8.9.3/8.9.3) with SMTP id IAA05100
- for <vern@ee.lbl.gov>; Tue, 15 Jun 1999 08:56:06 -0700 (PDT)
- Received: from Unknown/Local ([?.?.?.?]) by my-deja.com; Tue Jun 15 08:55:43 1999
- To: vern@ee.lbl.gov
- Date: Tue, 15 Jun 1999 08:55:43 -0700
- From: "Aki Niimura" <neko@my-deja.com>
- Message-ID: <KNONDOHDOBGAEAAA@my-deja.com>
- Mime-Version: 1.0
- Cc:
- X-Sent-Mail: on
- Reply-To:
- X-Mailer: MailCity Service
- Subject: A question on flex C++ scanner
- X-Sender-Ip: 12.72.207.61
- Organization: My Deja Email (http://www.my-deja.com:80)
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
-
- Dear Dr. Paxon,
-
- I have been using flex for years.
- It works very well on many projects.
- Most case, I used it to generate a scanner on C language.
- However, one project I needed to generate a scanner
- on C++ lanuage. Thanks to your enhancement, flex did
- the job.
-
- Currently, I'm working on enhancing my previous project.
- I need to deal with multiple input streams (recursive
- inclusion) in this scanner (C++).
- I did similar thing for another scanner (C) as you
- explained in your documentation.
-
- The generated scanner (C++) has necessary methods:
- - switch_to_buffer(struct yy_buffer_state *b)
- - yy_create_buffer(istream *is, int sz)
- - yy_delete_buffer(struct yy_buffer_state *b)
-
- However, I couldn't figure out how to access current
- buffer (yy_current_buffer).
-
- yy_current_buffer is a protected member of yyFlexLexer.
- I can't access it directly.
- Then, I thought yy_create_buffer() with is = 0 might
- return current stream buffer. But it seems not as far
- as I checked the source. (flex 2.5.4)
-
- I went through the Web in addition to Flex documentation.
- However, it hasn't been successful, so far.
-
- It is not my intention to bother you, but, can you
- comment about how to obtain the current stream buffer?
-
- Your response would be highly appreciated.
-
- Best regards,
- Aki Niimura
-
- --== Sent via Deja.com http://www.deja.com/ ==--
- Share what you know. Learn what you don't.
-
-
-File: flex.info, Node: unnamed-faq-92, Next: unnamed-faq-93, Prev: unnamed-faq-91, Up: FAQ
-
-unnamed-faq-92
-==============
-
-
- To: neko@my-deja.com
- Subject: Re: A question on flex C++ scanner
- In-reply-to: Your message of Tue, 15 Jun 1999 08:55:43 PDT.
- Date: Tue, 15 Jun 1999 09:04:24 PDT
- From: Vern Paxson <vern>
-
- > However, I couldn't figure out how to access current
- > buffer (yy_current_buffer).
-
- Derive your own subclass from yyFlexLexer.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-93, Next: unnamed-faq-94, Prev: unnamed-faq-92, Up: FAQ
-
-unnamed-faq-93
-==============
-
-
- To: "Stones, Darren" <Darren.Stones@nectech.co.uk>
- Subject: Re: You're the man to see?
- In-reply-to: Your message of Wed, 23 Jun 1999 11:10:29 PDT.
- Date: Wed, 23 Jun 1999 09:01:40 PDT
- From: Vern Paxson <vern>
-
- > I hope you can help me. I am using Flex and Bison to produce an interpreted
- > language. However all goes well until I try to implement an IF statement or
- > a WHILE. I cannot get this to work as the parser parses all the conditions
- > eg. the TRUE and FALSE conditons to check for a rule match. So I cannot
- > make a decision!!
-
- You need to use the parser to build a parse tree (= abstract syntax trwee),
- and when that's all done you recursively evaluate the tree, binding variables
- to values at that time.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-94, Next: unnamed-faq-95, Prev: unnamed-faq-93, Up: FAQ
-
-unnamed-faq-94
-==============
-
-
- To: Petr Danecek <petr@ics.cas.cz>
- Subject: Re: flex - question
- In-reply-to: Your message of Mon, 28 Jun 1999 19:21:41 PDT.
- Date: Fri, 02 Jul 1999 16:52:13 PDT
- From: Vern Paxson <vern>
-
- > file, it takes an enormous amount of time. It is funny, because the
- > source code has only 12 rules!!! I think it looks like an exponencial
- > growth.
-
- Right, that's the problem - some patterns (those with a lot of
- ambiguity, where yours has because at any given time the scanner can
- be in the middle of all sorts of combinations of the different
- rules) blow up exponentially.
-
- For your rules, there is an easy fix. Change the ".*" that comes fater
- the directory name to "[^ ]*". With that in place, the rules are no
- longer nearly so ambiguous, because then once one of the directories
- has been matched, no other can be matched (since they all require a
- leading blank).
-
- If that's not an acceptable solution, then you can enter a start state
- to pick up the .*\n after each directory is matched.
-
- Also note that for speed, you'll want to add a ".*" rule at the end,
- otherwise rules that don't match any of the patterns will be matched
- very slowly, a character at a time.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-95, Next: unnamed-faq-96, Prev: unnamed-faq-94, Up: FAQ
-
-unnamed-faq-95
-==============
-
-
- To: Tielman Koekemoer <tielman@spi.co.za>
- Subject: Re: Please help.
- In-reply-to: Your message of Thu, 08 Jul 1999 13:20:37 PDT.
- Date: Thu, 08 Jul 1999 08:20:39 PDT
- From: Vern Paxson <vern>
-
- > I was hoping you could help me with my problem.
- >
- > I tried compiling (gnu)flex on a Solaris 2.4 machine
- > but when I ran make (after configure) I got an error.
- >
- > --------------------------------------------------------------
- > gcc -c -I. -I. -g -O parse.c
- > ./flex -t -p ./scan.l >scan.c
- > sh: ./flex: not found
- > *** Error code 1
- > make: Fatal error: Command failed for target `scan.c'
- > -------------------------------------------------------------
- >
- > What's strange to me is that I'm only
- > trying to install flex now. I then edited the Makefile to
- > and changed where it says "FLEX = flex" to "FLEX = lex"
- > ( lex: the native Solaris one ) but then it complains about
- > the "-p" option. Is there any way I can compile flex without
- > using flex or lex?
- >
- > Thanks so much for your time.
-
- You managed to step on the bootstrap sequence, which first copies
- initscan.c to scan.c in order to build flex. Try fetching a fresh
- distribution from ftp.ee.lbl.gov. (Or you can first try removing
- ".bootstrap" and doing a make again.)
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-96, Next: unnamed-faq-97, Prev: unnamed-faq-95, Up: FAQ
-
-unnamed-faq-96
-==============
-
-
- To: Tielman Koekemoer <tielman@spi.co.za>
- Subject: Re: Please help.
- In-reply-to: Your message of Fri, 09 Jul 1999 09:16:14 PDT.
- Date: Fri, 09 Jul 1999 00:27:20 PDT
- From: Vern Paxson <vern>
-
- > First I removed .bootstrap (and ran make) - no luck. I downloaded the
- > software but I still have the same problem. Is there anything else I
- > could try.
-
- Try:
-
- cp initscan.c scan.c
- touch scan.c
- make scan.o
-
- If this last tries to first build scan.c from scan.l using ./flex, then
- your "make" is broken, in which case compile scan.c to scan.o by hand.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-97, Next: unnamed-faq-98, Prev: unnamed-faq-96, Up: FAQ
-
-unnamed-faq-97
-==============
-
-
- To: Sumanth Kamenani <skamenan@crl.nmsu.edu>
- Subject: Re: Error
- In-reply-to: Your message of Mon, 19 Jul 1999 23:08:41 PDT.
- Date: Tue, 20 Jul 1999 00:18:26 PDT
- From: Vern Paxson <vern>
-
- > I am getting a compilation error. The error is given as "unknown symbol- yylex".
-
- The parser relies on calling yylex(), but you're instead using the C++ scanning
- class, so you need to supply a yylex() "glue" function that calls an instance
- scanner of the scanner (e.g., "scanner->yylex()").
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-98, Next: unnamed-faq-99, Prev: unnamed-faq-97, Up: FAQ
-
-unnamed-faq-98
-==============
-
-
- To: daniel@synchrods.synchrods.COM (Daniel Senderowicz)
- Subject: Re: lex
- In-reply-to: Your message of Mon, 22 Nov 1999 11:19:04 PST.
- Date: Tue, 23 Nov 1999 15:54:30 PST
- From: Vern Paxson <vern>
-
- Well, your problem is the
-
- switch (yybgin-yysvec-1) { /* witchcraft */
-
- at the beginning of lex rules. "witchcraft" == "non-portable". It's
- assuming knowledge of the AT&T lex's internal variables.
-
- For flex, you can probably do the equivalent using a switch on YYSTATE.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-99, Next: unnamed-faq-100, Prev: unnamed-faq-98, Up: FAQ
-
-unnamed-faq-99
-==============
-
-
- To: archow@hss.hns.com
- Subject: Re: Regarding distribution of flex and yacc based grammars
- In-reply-to: Your message of Sun, 19 Dec 1999 17:50:24 +0530.
- Date: Wed, 22 Dec 1999 01:56:24 PST
- From: Vern Paxson <vern>
-
- > When we provide the customer with an object code distribution, is it
- > necessary for us to provide source
- > for the generated C files from flex and bison since they are generated by
- > flex and bison ?
-
- For flex, no. I don't know what the current state of this is for bison.
-
- > Also, is there any requrirement for us to neccessarily provide source for
- > the grammar files which are fed into flex and bison ?
-
- Again, for flex, no.
-
- See the file "COPYING" in the flex distribution for the legalese.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-100, Next: unnamed-faq-101, Prev: unnamed-faq-99, Up: FAQ
-
-unnamed-faq-100
-===============
-
-
- To: Martin Gallwey <gallweym@hyperion.moe.ul.ie>
- Subject: Re: Flex, and self referencing rules
- In-reply-to: Your message of Sun, 20 Feb 2000 01:01:21 PST.
- Date: Sat, 19 Feb 2000 18:33:16 PST
- From: Vern Paxson <vern>
-
- > However, I do not use unput anywhere. I do use self-referencing
- > rules like this:
- >
- > UnaryExpr ({UnionExpr})|("-"{UnaryExpr})
-
- You can't do this - flex is *not* a parser like yacc (which does indeed
- allow recursion), it is a scanner that's confined to regular expressions.
-
- Vern
-
-
-File: flex.info, Node: unnamed-faq-101, Next: What is the difference between YYLEX_PARAM and YY_DECL?, Prev: unnamed-faq-100, Up: FAQ
-
-unnamed-faq-101
-===============
-
-
- To: slg3@lehigh.edu (SAMUEL L. GULDEN)
- Subject: Re: Flex problem
- In-reply-to: Your message of Thu, 02 Mar 2000 12:29:04 PST.
- Date: Thu, 02 Mar 2000 23:00:46 PST
- From: Vern Paxson <vern>
-
- If this is exactly your program:
-
- > digit [0-9]
- > digits {digit}+
- > whitespace [ \t\n]+
- >
- > %%
- > "[" { printf("open_brac\n");}
- > "]" { printf("close_brac\n");}
- > "+" { printf("addop\n");}
- > "*" { printf("multop\n");}
- > {digits} { printf("NUMBER = %s\n", yytext);}
- > whitespace ;
-
- then the problem is that the last rule needs to be "{whitespace}" !
-
- Vern
-
-
-File: flex.info, Node: What is the difference between YYLEX_PARAM and YY_DECL?, Next: Why do I get "conflicting types for yylex" error?, Prev: unnamed-faq-101, Up: FAQ
-
-What is the difference between YYLEX_PARAM and YY_DECL?
-=======================================================
-
- YYLEX_PARAM is not a flex symbol. It is for Bison. It tells Bison to
-pass extra params when it calls yylex() from the parser.
-
- YY_DECL is the Flex declaration of yylex. The default is similar to
-this:
-
-
- #define int yy_lex ()
-
-
-File: flex.info, Node: Why do I get "conflicting types for yylex" error?, Next: How do I access the values set in a Flex action from within a Bison action?, Prev: What is the difference between YYLEX_PARAM and YY_DECL?, Up: FAQ
-
-Why do I get "conflicting types for yylex" error?
-=================================================
-
- This is a compiler error regarding a generated Bison parser, not a
-Flex scanner. It means you need a prototype of yylex() in the top of
-the Bison file. Be sure the prototype matches YY_DECL.
-
-
-File: flex.info, Node: How do I access the values set in a Flex action from within a Bison action?, Prev: Why do I get "conflicting types for yylex" error?, Up: FAQ
-
-How do I access the values set in a Flex action from within a Bison action?
-===========================================================================
-
- With $1, $2, $3, etc. These are called "Semantic Values" in the
-Bison manual. See *Note Top: (bison)Top.
-
-
-File: flex.info, Node: Appendices, Next: Indices, Prev: FAQ, Up: Top
-
-Appendices
-**********
-
-* Menu:
-
-* Makefiles and Flex::
-* Bison Bridge::
-* M4 Dependency::
-
-
-File: flex.info, Node: Makefiles and Flex, Next: Bison Bridge, Prev: Appendices, Up: Appendices
-
-Makefiles and Flex
-==================
-
- In this appendix, we provide tips for writing Makefiles to build
-your scanners.
-
- In a traditional build environment, we say that the `.c' files are
-the sources, and the `.o' files are the intermediate files. When using
-`flex', however, the `.l' files are the sources, and the generated `.c'
-files (along with the `.o' files) are the intermediate files. This
-requires you to carefully plan your Makefile.
-
- Modern `make' programs understand that `foo.l' is intended to
-generate `lex.yy.c' or `foo.c', and will behave accordingly(1). The
-following Makefile does not explicitly instruct `make' how to build
-`foo.c' from `foo.l'. Instead, it relies on the implicit rules of the
-`make' program to build the intermediate file, `scan.c':
-
-
- # Basic Makefile -- relies on implicit rules
- # Creates "myprogram" from "scan.l" and "myprogram.c"
- #
- LEX=flex
- myprogram: scan.o myprogram.o
- scan.o: scan.l
-
- For simple cases, the above may be sufficient. For other cases, you
-may have to explicitly instruct `make' how to build your scanner. The
-following is an example of a Makefile containing explicit rules:
-
-
- # Basic Makefile -- provides explicit rules
- # Creates "myprogram" from "scan.l" and "myprogram.c"
- #
- LEX=flex
- myprogram: scan.o myprogram.o
- $(CC) -o $@ $(LDFLAGS) $^
-
- myprogram.o: myprogram.c
- $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
-
- scan.o: scan.c
- $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
-
- scan.c: scan.l
- $(LEX) $(LFLAGS) -o $@ $^
-
- clean:
- $(RM) *.o scan.c
-
- Notice in the above example that `scan.c' is in the `clean' target.
-This is because we consider the file `scan.c' to be an intermediate
-file.
-
- Finally, we provide a realistic example of a `flex' scanner used
-with a `bison' parser(2). There is a tricky problem we have to deal
-with. Since a `flex' scanner will typically include a header file
-(e.g., `y.tab.h') generated by the parser, we need to be sure that the
-header file is generated BEFORE the scanner is compiled. We handle this
-case in the following example:
-
-
- # Makefile example -- scanner and parser.
- # Creates "myprogram" from "scan.l", "parse.y", and "myprogram.c"
- #
- LEX = flex
- YACC = bison -y
- YFLAGS = -d
- objects = scan.o parse.o myprogram.o
-
- myprogram: $(objects)
- scan.o: scan.l parse.c
- parse.o: parse.y
- myprogram.o: myprogram.c
-
- In the above example, notice the line,
-
-
- scan.o: scan.l parse.c
-
- , which lists the file `parse.c' (the generated parser) as a
-dependency of `scan.o'. We want to ensure that the parser is created
-before the scanner is compiled, and the above line seems to do the
-trick. Feel free to experiment with your specific implementation of
-`make'.
-
- For more details on writing Makefiles, see *Note Top: (make)Top.
-
- ---------- Footnotes ----------
-
- (1) GNU `make' and GNU `automake' are two such programs that provide
-implicit rules for flex-generated scanners.
-
- (2) This example also applies to yacc parsers.
-
-
-File: flex.info, Node: Bison Bridge, Next: M4 Dependency, Prev: Makefiles and Flex, Up: Appendices
-
-C Scanners with Bison Parsers
-=============================
-
- This section describes the `flex' features useful when integrating
-`flex' with `GNU bison'(1). Skip this section if you are not using
-`bison' with your scanner. Here we discuss only the `flex' half of the
-`flex' and `bison' pair. We do not discuss `bison' in any detail. For
-more information about generating `bison' parsers, see *Note Top:
-(bison)Top.
-
- A compatible `bison' scanner is generated by declaring `%option
-bison-bridge' or by supplying `--bison-bridge' when invoking `flex'
-from the command line. This instructs `flex' that the macro `yylval'
-may be used. The data type for `yylval', `YYSTYPE', is typically
-defined in a header file, included in section 1 of the `flex' input
-file. For a list of functions and macros available, *Note
-bison-functions::.
-
- The declaration of yylex becomes,
-
-
- int yylex ( YYSTYPE * lvalp, yyscan_t scanner );
-
- If `%option bison-locations' is specified, then the declaration
-becomes,
-
-
- int yylex ( YYSTYPE * lvalp, YYLTYPE * llocp, yyscan_t scanner );
-
- Note that the macros `yylval' and `yylloc' evaluate to pointers.
-Support for `yylloc' is optional in `bison', so it is optional in
-`flex' as well. The following is an example of a `flex' scanner that is
-compatible with `bison'.
-
-
- /* Scanner for "C" assignment statements... sort of. */
- %{
- #include "y.tab.h" /* Generated by bison. */
- %}
-
- %option bison-bridge bison-locations
- %
-
- [[:digit:]]+ { yylval->num = atoi(yytext); return NUMBER;}
- [[:alnum:]]+ { yylval->str = strdup(yytext); return STRING;}
- "="|";" { return yytext[0];}
- . {}
- %
-
- As you can see, there really is no magic here. We just use `yylval'
-as we would any other variable. The data type of `yylval' is generated
-by `bison', and included in the file `y.tab.h'. Here is the
-corresponding `bison' parser:
-
-
- /* Parser to convert "C" assignments to lisp. */
- %{
- /* Pass the argument to yyparse through to yylex. */
- #define YYPARSE_PARAM scanner
- #define YYLEX_PARAM scanner
- %}
- %locations
- %pure_parser
- %union {
- int num;
- char* str;
- }
- %token <str> STRING
- %token <num> NUMBER
- %%
- assignment:
- STRING '=' NUMBER ';' {
- printf( "(setf %s %d)", $1, $3 );
- }
- ;
-
- ---------- Footnotes ----------
-
- (1) The features described here are purely optional, and are by no
-means the only way to use flex with bison. We merely provide some glue
-to ease development of your parser-scanner pair.
-
-
-File: flex.info, Node: M4 Dependency, Prev: Bison Bridge, Up: Appendices
-
-M4 Dependency
-=============
-
- The macro processor `m4'(1) must be installed wherever flex is
-installed. `flex' invokes `m4', found by searching the directories in
-the `PATH' environment variable. Any code you place in section 1 or in
-the actions will be sent through m4. Please follow these rules to
-protect your code from unwanted `m4' processing.
-
- * Do not use symbols that begin with, `m4_', such as, `m4_define',
- or `m4_include', since those are reserved for `m4' macro names. If
- for some reason you need m4_ as a prefix, use a preprocessor
- #define to get your symbol past m4 unmangled.
-
- * Do not use the strings `[[' or `]]' anywhere in your code. The
- former is not valid in C, except within comments and strings, but
- the latter is valid in code such as `x[y[z]]'. The solution is
- simple. To get the literal string `"]]"', use `"]""]"'. To get the
- array notation `x[y[z]]', use `x[y[z] ]'.
-
-
- `m4' is only required at the time you run `flex'. The generated
-scanner is ordinary C or C++, and does _not_ require `m4'.
-
- ---------- Footnotes ----------
-
- (1) The use of m4 is subject to change in future revisions of flex.
-It is not part of the public API of flex. Do not depend on it.
-
-
-File: flex.info, Node: Indices, Prev: Appendices, Up: Top
-
-Indices
-*******
-
-* Menu:
-
-* Concept Index::
-* Index of Functions and Macros::
-* Index of Variables::
-* Index of Data Types::
-* Index of Hooks::
-* Index of Scanner Options::
-
diff --git a/doc/flex.info-7 b/doc/flex.info-7
deleted file mode 100644
index 8ccc35c..0000000
--- a/doc/flex.info-7
+++ /dev/null
@@ -1,601 +0,0 @@
-This is flex.info, produced by makeinfo version 4.5 from flex.texi.
-
-INFO-DIR-SECTION Programming
-START-INFO-DIR-ENTRY
-* flex: (flex). Fast lexical analyzer generator (lex replacement).
-END-INFO-DIR-ENTRY
-
-
- The flex manual is placed under the same licensing conditions as the
-rest of flex:
-
- Copyright (C) 1990, 1997 The Regents of the University of California.
-All rights reserved.
-
- This code is derived from software contributed to Berkeley by Vern
-Paxson.
-
- The United States Government has rights in this work pursuant to
-contract no. DE-AC03-76SF00098 between the United States Department of
-Energy and the University of California.
-
- Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the
- distribution.
- Neither the name of the University nor the names of its contributors
-may be used to endorse or promote products derived from this software
-without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-
-File: flex.info, Node: Concept Index, Next: Index of Functions and Macros, Prev: Indices, Up: Indices
-
-Concept Index
-=============
-
-* Menu:
-
-* $ as normal character in patterns: Patterns.
-* %array, advantages of: Matching.
-* %array, use of: Matching.
-* %array, with C++: Matching.
-* %option nowrap: Generated Scanner.
-* %pointer, and unput(): Actions.
-* %pointer, use of: Matching.
-* %top: Definitions Section.
-* %{ and %}, in Definitions Section: Definitions Section.
-* %{ and %}, in Rules Section: Actions.
-* <<EOF>>, use of: EOF.
-* [] in patterns: Patterns.
-* ^ as non-special character in patterns: Patterns.
-* accessor functions, use of: Accessor Methods.
-* actions: Actions.
-* actions, embedded C strings: Actions.
-* actions, redefining YY_BREAK: Misc Macros.
-* actions, use of { and }: Actions.
-* aliases, how to define: Definitions Section.
-* arguments, command-line: Scanner Options.
-* array, default size for yytext: User Values.
-* backing up, eliminating: Performance.
-* backing up, eliminating by adding error rules: Performance.
-* backing up, eliminating with catch-all rule: Performance.
-* backing up, example of eliminating: Performance.
-* BEGIN: Actions.
-* BEGIN, explanation: Start Conditions.
-* beginning of line, in patterns: Patterns.
-* bison, bridging with flex: Bison Bridge.
-* bison, parser: Bison Bridge.
-* bison, scanner to be called from bison: Bison Bridge.
-* BOL, checking the BOL flag: Misc Macros.
-* BOL, in patterns: Patterns.
-* BOL, setting it: Misc Macros.
-* braces in patterns: Patterns.
-* bugs, reporting: Reporting Bugs.
-* C code in flex input: Definitions Section.
-* C++: Cxx.
-* C++ and %array: User Values.
-* C++ I/O, customizing: How do I use my own I/O classes in a C++ scanner?.
-* C++ scanners, including multiple scanners: Cxx.
-* C++ scanners, use of: Cxx.
-* c++, experimental form of scanner class: Cxx.
-* C++, multiple different scanners: Cxx.
-* C-strings, in actions: Actions.
-* case-insensitive, effect on character classes: Patterns.
-* character classes in patterns: Patterns.
-* character classes in patterns, syntax of: Patterns.
-* character classes, equivalence of: Patterns.
-* clearing an input buffer: Multiple Input Buffers.
-* command-line options: Scanner Options.
-* comments in flex input: Definitions Section.
-* comments in the input: Comments in the Input.
-* comments, discarding: Actions.
-* comments, example of scanning C comments: Start Conditions.
-* comments, in actions: Actions.
-* comments, in rules section: Comments in the Input.
-* comments, syntax of: Comments in the Input.
-* comments, valid uses of: Comments in the Input.
-* compressing whitespace: Actions.
-* concatenation, in patterns: Patterns.
-* copyright of flex: Copyright.
-* counting characters and lines: Simple Examples.
-* customizing I/O in C++ scanners: How do I use my own I/O classes in a C++ scanner?.
-* default rule <1>: Matching.
-* default rule: Simple Examples.
-* defining pattern aliases: Definitions Section.
-* Definitions, in flex input: Definitions Section.
-* deleting lines from input: Actions.
-* discarding C comments: Actions.
-* distributing flex: Copyright.
-* ECHO: Actions.
-* ECHO, and yyout: Generated Scanner.
-* embedding C code in flex input: Definitions Section.
-* end of file, in patterns: Patterns.
-* end of line, in negated character classes: Patterns.
-* end of line, in patterns: Patterns.
-* end-of-file, and yyrestart(): Generated Scanner.
-* EOF and yyrestart(): Generated Scanner.
-* EOF in patterns, syntax of: Patterns.
-* EOF, example using multiple input buffers: Multiple Input Buffers.
-* EOF, explanation: EOF.
-* EOF, pushing back: Actions.
-* EOL, in negated character classes: Patterns.
-* EOL, in patterns: Patterns.
-* error messages, end of buffer missed: Lex and Posix.
-* error reporting, diagnostic messages: Diagnostics.
-* error reporting, in C++: Cxx.
-* error rules, to eliminate backing up: Performance.
-* escape sequences in patterns, syntax of: Patterns.
-* exiting with yyterminate(): Actions.
-* experimental form of c++ scanner class: Cxx.
-* extended scope of start conditions: Start Conditions.
-* file format: Format.
-* file format, serialized tables: Tables File Format.
-* flushing an input buffer: Multiple Input Buffers.
-* flushing the internal buffer: Actions.
-* format of flex input: Format.
-* format of input file: Format.
-* freeing tables: Loading and Unloading Serialized Tables.
-* getting current start state with YY_START: Start Conditions.
-* halting with yyterminate(): Actions.
-* handling include files with multiple input buffers: Multiple Input Buffers.
-* header files, with C++: Cxx.
-* include files, with C++: Cxx.
-* input file, Definitions section: Definitions Section.
-* input file, Rules Section: Rules Section.
-* input file, user code Section: User Code Section.
-* input(): Actions.
-* input(), and C++: Actions.
-* input, format of: Format.
-* input, matching: Matching.
-* keywords, for performance: Performance.
-* lex (traditional) and POSIX: Lex and Posix.
-* LexerInput, overriding: How do I use my own I/O classes in a C++ scanner?.
-* LexerOutput, overriding: How do I use my own I/O classes in a C++ scanner?.
-* limitations of flex: Limitations.
-* literal text in patterns, syntax of: Patterns.
-* loading tables at runtime: Loading and Unloading Serialized Tables.
-* m4: M4 Dependency.
-* Makefile, example of implicit rules: Makefiles and Flex.
-* Makefile, explicit example: Makefiles and Flex.
-* Makefile, syntax: Makefiles and Flex.
-* matching C-style double-quoted strings: Start Conditions.
-* matching, and trailing context: Matching.
-* matching, length of: Matching.
-* matching, multiple matches: Matching.
-* member functions, C++: Cxx.
-* memory management: Memory Management.
-* memory, allocating input buffers: Multiple Input Buffers.
-* memory, considerations for reentrant scanners: Init and Destroy Functions.
-* memory, deleting input buffers: Multiple Input Buffers.
-* memory, for start condition stacks: Start Conditions.
-* memory, serialized tables <1>: Loading and Unloading Serialized Tables.
-* memory, serialized tables: Serialized Tables.
-* methods, c++: Cxx.
-* minimal scanner: Matching.
-* multiple input streams: Multiple Input Buffers.
-* name definitions, not POSIX: Lex and Posix.
-* negating ranges in patterns: Patterns.
-* newline, matching in patterns: Patterns.
-* non-POSIX features of flex: Lex and Posix.
-* nowrap, %option: Generated Scanner.
-* NULL character in patterns, syntax of: Patterns.
-* octal characters in patterns: Patterns.
-* options, command-line: Scanner Options.
-* overriding LexerInput: How do I use my own I/O classes in a C++ scanner?.
-* overriding LexerOutput: How do I use my own I/O classes in a C++ scanner?.
-* overriding the memory routines: Overriding The Default Memory Management.
-* Pascal-like language: Simple Examples.
-* pattern aliases, defining: Definitions Section.
-* pattern aliases, expansion of: Patterns.
-* pattern aliases, how to define: Definitions Section.
-* pattern aliases, use of: Definitions Section.
-* patterns and actions on different lines: Lex and Posix.
-* patterns, character class equivalence: Patterns.
-* patterns, end of line: Patterns.
-* patterns, grouping and precedence: Patterns.
-* patterns, in rules section: Patterns.
-* patterns, invalid trailing context: Patterns.
-* patterns, matching: Matching.
-* patterns, precedence of operators: Patterns.
-* patterns, repetitions with grouping: Patterns.
-* patterns, special characters treated as non-special: Patterns.
-* patterns, syntax: Patterns.
-* patterns, tuning for performance: Performance.
-* patterns, valid character classes: Patterns.
-* performance optimization, matching longer tokens: Performance.
-* performance optimization, recognizing keywords: Performance.
-* performance, backing up: Performance.
-* performance, considerations: Performance.
-* performance, using keywords: Performance.
-* popping an input buffer: Multiple Input Buffers.
-* POSIX and lex: Lex and Posix.
-* POSIX comp;compliance: Lex and Posix.
-* POSIX, character classes in patterns, syntax of: Patterns.
-* preprocessor macros, for use in actions: Actions.
-* pushing an input buffer: Multiple Input Buffers.
-* pushing back characters with unput: Actions.
-* pushing back characters with unput(): Actions.
-* pushing back characters with yyless: Actions.
-* pushing back EOF: Actions.
-* ranges in patterns: Patterns.
-* ranges in patterns, negating: Patterns.
-* recognizing C comments: Start Conditions.
-* reentrant scanners, multiple interleaved scanners: Reentrant Uses.
-* reentrant scanners, recursive invocation: Reentrant Uses.
-* reentrant, accessing flex variables: Global Replacement.
-* reentrant, accessor functions: Accessor Methods.
-* reentrant, API explanation: Reentrant Overview.
-* reentrant, calling functions: Extra Reentrant Argument.
-* reentrant, example of: Reentrant Example.
-* reentrant, explanation: Reentrant.
-* reentrant, extra data: Extra Data.
-* reentrant, initialization: Init and Destroy Functions.
-* regular expressions, in patterns: Patterns.
-* REJECT: Actions.
-* REJECT, calling multiple times: Actions.
-* REJECT, performance costs: Performance.
-* reporting bugs: Reporting Bugs.
-* restarting the scanner: Lex and Posix.
-* RETURN, within actions: Generated Scanner.
-* rules, default: Simple Examples.
-* rules, in flex input: Rules Section.
-* scanner, definition of: Introduction.
-* sections of flex input: Format.
-* serialization: Serialized Tables.
-* serialization of tables: Creating Serialized Tables.
-* serialized tables, multiple scanners: Creating Serialized Tables.
-* stack, input buffer pop: Multiple Input Buffers.
-* stack, input buffer push: Multiple Input Buffers.
-* stacks, routines for manipulating: Start Conditions.
-* start condition, applying to multiple patterns: Start Conditions.
-* start conditions: Start Conditions.
-* start conditions, behavior of default rule: Start Conditions.
-* start conditions, exclusive: Start Conditions.
-* start conditions, for different interpretations of same input: Start Conditions.
-* start conditions, in patterns: Patterns.
-* start conditions, inclusive: Start Conditions.
-* start conditions, inclusive v.s. exclusive: Start Conditions.
-* start conditions, integer values: Start Conditions.
-* start conditions, multiple: Start Conditions.
-* start conditions, special wildcard condition: Start Conditions.
-* start conditions, use of a stack: Start Conditions.
-* start conditions, use of wildcard condition (<*>): Start Conditions.
-* start conditions, using BEGIN: Start Conditions.
-* stdin, default for yyin: Generated Scanner.
-* stdout, as default for yyout: Generated Scanner.
-* strings, scanning strings instead of files: Multiple Input Buffers.
-* tables, creating serialized: Creating Serialized Tables.
-* tables, file format: Tables File Format.
-* tables, freeing: Loading and Unloading Serialized Tables.
-* tables, loading and unloading: Loading and Unloading Serialized Tables.
-* terminating with yyterminate(): Actions.
-* token: Matching.
-* trailing context, in patterns: Patterns.
-* trailing context, limits of: Patterns.
-* trailing context, matching: Matching.
-* trailing context, performance costs: Performance.
-* trailing context, variable length: Performance.
-* unput(): Actions.
-* unput(), and %pointer: Actions.
-* unput(), pushing back characters: Actions.
-* user code, in flex input: User Code Section.
-* username expansion: Simple Examples.
-* using integer values of start condition names: Start Conditions.
-* verbatim text in patterns, syntax of: Patterns.
-* warning, dangerous trailing context: Limitations.
-* warning, rule cannot be matched: Diagnostics.
-* warnings, diagnostic messages: Diagnostics.
-* whitespace, compressing: Actions.
-* yacc interface: Yacc.
-* yacc, interface: Yacc.
-* YY_CURRENT_BUFFER, and multiple buffers Finally, the macro: Multiple Input Buffers.
-* YY_EXTRA_TYPE, defining your own type: Extra Data.
-* YY_FLUSH_BUFFER(): Actions.
-* YY_INPUT: Generated Scanner.
-* YY_INPUT, overriding: Generated Scanner.
-* YY_START, example: Start Conditions.
-* YY_USER_ACTION to track each time a rule is matched: Misc Macros.
-* yyalloc, overriding: Overriding The Default Memory Management.
-* yyfree, overriding: Overriding The Default Memory Management.
-* yyin: Generated Scanner.
-* yyinput(): Actions.
-* yyleng: Matching.
-* yyleng, modification of: Actions.
-* yyless(): Actions.
-* yyless(), pushing back characters: Actions.
-* yylex(), in generated scanner: Generated Scanner.
-* yylex(), overriding: Generated Scanner.
-* yylex, overriding the prototype of: Generated Scanner.
-* yylineno, in a reentrant scanner: Reentrant Functions.
-* yylineno, performance costs: Performance.
-* yymore(): Actions.
-* yymore() to append token to previous token: Actions.
-* yymore(), mega-kludge: Actions.
-* yymore, and yyleng: Actions.
-* yymore, performance penalty of: Actions.
-* yyout: Generated Scanner.
-* yyrealloc, overriding: Overriding The Default Memory Management.
-* yyrestart(): Generated Scanner.
-* yyterminate(): Actions.
-* yytext: Matching.
-* yytext, default array size: User Values.
-* yytext, memory considerations: A Note About yytext And Memory.
-* yytext, modification of: Actions.
-* yytext, two types of: Matching.
-* yywrap(): Generated Scanner.
-* yywrap, default for: Generated Scanner.
-* |, in actions: Actions.
-* |, use of: Actions.
-
-
-File: flex.info, Node: Index of Functions and Macros, Next: Index of Variables, Prev: Concept Index, Up: Indices
-
-Index of Functions and Macros
-=============================
-
- This is an index of functions and preprocessor macros that look like
-functions. For macros that expand to variables or constants, see *Note
-Index of Variables::.
-
-* Menu:
-
-* BEGIN: Start Conditions.
-* debug (C++ only): Cxx.
-* LexerError (C++ only): Cxx.
-* LexerInput (C++ only): Cxx.
-* LexerOutput (C++ only): Cxx.
-* lineno (C++ only): Cxx.
-* set_debug (C++ only): Cxx.
-* switch_streams (C++ only): Cxx.
-* YY_AT_BOL: Misc Macros.
-* yy_create_buffer: Multiple Input Buffers.
-* yy_delete_buffer: Multiple Input Buffers.
-* yy_flush_buffer: Multiple Input Buffers.
-* yy_new_buffer: Multiple Input Buffers.
-* YY_NEW_FILE (now obsolete): EOF.
-* yy_pop_state: Start Conditions.
-* yy_push_state: Start Conditions.
-* yy_scan_buffer: Multiple Input Buffers.
-* yy_scan_bytes: Multiple Input Buffers.
-* yy_scan_string: Multiple Input Buffers.
-* yy_set_bol: Misc Macros.
-* yy_set_interactive: Misc Macros.
-* yy_switch_to_buffer: Multiple Input Buffers.
-* yy_top_state: Start Conditions.
-* yyFlexLexer constructor (C++ only): Cxx.
-* yyget_debug: Reentrant Functions.
-* yyget_extra <1>: Reentrant Functions.
-* yyget_extra: Extra Data.
-* yyget_in: Reentrant Functions.
-* yyget_leng: Reentrant Functions.
-* yyget_lineno: Reentrant Functions.
-* yyget_out: Reentrant Functions.
-* yyget_text: Reentrant Functions.
-* YYLeng (C++ only): Cxx.
-* yylex (C++ version): Cxx.
-* yylex (reentrant version): Bison Bridge.
-* yylex_destroy: Init and Destroy Functions.
-* yylex_init: Init and Destroy Functions.
-* yypop_buffer_state: Multiple Input Buffers.
-* yypush_buffer_state: Multiple Input Buffers.
-* yyrestart: User Values.
-* yyset_debug: Reentrant Functions.
-* yyset_extra <1>: Reentrant Functions.
-* yyset_extra: Extra Data.
-* yyset_in: Reentrant Functions.
-* yyset_lineno: Reentrant Functions.
-* yyset_out: Reentrant Functions.
-* yytables_destroy: Loading and Unloading Serialized Tables.
-* yytables_fload: Loading and Unloading Serialized Tables.
-* YYText (C++ only): Cxx.
-
-
-File: flex.info, Node: Index of Variables, Next: Index of Data Types, Prev: Index of Functions and Macros, Up: Indices
-
-Index of Variables
-==================
-
- This is an index of variables, constants, and preprocessor macros
-that expand to variables or constants.
-
-* Menu:
-
-* INITIAL: Start Conditions.
-* YY_CURRENT_BUFFER: User Values.
-* YY_END_OF_BUFFER_CHAR: Multiple Input Buffers.
-* YY_NUM_RULES: Misc Macros.
-* YY_START <1>: User Values.
-* YY_START: Start Conditions.
-* yyextra: Extra Data.
-* yyin: User Values.
-* yyleng: User Values.
-* yylloc: Bison Bridge.
-* YYLMAX: User Values.
-* yylval: Bison Bridge.
-* yylval, with yacc: Yacc.
-* yyout: User Values.
-* yyscanner (reentrant only): Extra Reentrant Argument.
-* yytext <1>: User Values.
-* yytext: Matching.
-
-
-File: flex.info, Node: Index of Data Types, Next: Index of Hooks, Prev: Index of Variables, Up: Indices
-
-Index of Data Types
-===================
-
-* Menu:
-
-* FlexLexer (C++ only): Cxx.
-* YY_BUFFER_STATE: Multiple Input Buffers.
-* YY_EXTRA_TYPE (reentrant only): Extra Data.
-* yy_size_t: Multiple Input Buffers.
-* yyFlexLexer (C++ only): Cxx.
-* YYLTYPE: Bison Bridge.
-* yyscan_t (reentrant only): About yyscan_t.
-* YYSTYPE: Bison Bridge.
-
-
-File: flex.info, Node: Index of Hooks, Next: Index of Scanner Options, Prev: Index of Data Types, Up: Indices
-
-Index of Hooks
-==============
-
- This is an index of "hooks" that the user may define. These hooks
-typically correspond to specific locations in the generated scanner,
-and may be used to insert arbitrary code.
-
-* Menu:
-
-* YY_BREAK: Misc Macros.
-* YY_USER_ACTION: Misc Macros.
-* YY_USER_INIT: Misc Macros.
-
-
-File: flex.info, Node: Index of Scanner Options, Prev: Index of Hooks, Up: Indices
-
-Index of Scanner Options
-========================
-
-* Menu:
-
-* -+: Code-Level And API Options.
-* --7bit: Options Affecting Scanner Behavior.
-* --8bit: Options Affecting Scanner Behavior.
-* --align: Options for Scanner Speed and Size.
-* --always-interactive: Options Affecting Scanner Behavior.
-* --array: Code-Level And API Options.
-* --backup: Debugging Options.
-* --batch: Options Affecting Scanner Behavior.
-* --bison-bridge: Code-Level And API Options.
-* --bison-locations: Code-Level And API Options.
-* --c++: Code-Level And API Options.
-* --case-insensitive: Options Affecting Scanner Behavior.
-* --debug: Debugging Options.
-* --default: Options Affecting Scanner Behavior.
-* --ecs: Options for Scanner Speed and Size.
-* --fast: Options for Scanner Speed and Size.
-* --full: Options for Scanner Speed and Size.
-* --header-file: Options for Specifing Filenames.
-* --help: Miscellaneous Options.
-* --interactive: Options Affecting Scanner Behavior.
-* --lex-compat: Options Affecting Scanner Behavior.
-* --main: Code-Level And API Options.
-* --meta-ecs: Options for Scanner Speed and Size.
-* --never-interactive: Options Affecting Scanner Behavior.
-* --nodefault: Debugging Options.
-* --noline: Code-Level And API Options.
-* --nounistd: Code-Level And API Options.
-* --nowarn: Debugging Options.
-* --option-ansi-definitions: Code-Level And API Options.
-* --option-ansi-prototypes: Code-Level And API Options.
-* --outfile: Options for Specifing Filenames.
-* --perf-report: Debugging Options.
-* --pointer: Code-Level And API Options.
-* --posix: Options Affecting Scanner Behavior.
-* --prefix: Code-Level And API Options.
-* --read: Options for Scanner Speed and Size.
-* --reentrant: Code-Level And API Options.
-* --skel: Options for Specifing Filenames.
-* --stack: Options Affecting Scanner Behavior.
-* --stdinit: Options Affecting Scanner Behavior.
-* --stdout: Options for Specifing Filenames.
-* --tables-file: Options for Specifing Filenames.
-* --tables-verify: Options for Specifing Filenames.
-* --trace: Debugging Options.
-* --verbose: Debugging Options.
-* --version: Miscellaneous Options.
-* --warn: Debugging Options.
-* --yyclass: Code-Level And API Options.
-* --yylineno: Options Affecting Scanner Behavior.
-* --yywrap: Options Affecting Scanner Behavior.
-* -7: Options Affecting Scanner Behavior.
-* -8: Options Affecting Scanner Behavior.
-* -b: Debugging Options.
-* -B: Options Affecting Scanner Behavior.
-* -c: Miscellaneous Options.
-* -C: Options for Scanner Speed and Size.
-* -Ca: Options for Scanner Speed and Size.
-* -Ce: Options for Scanner Speed and Size.
-* -CF: Options for Scanner Speed and Size.
-* -Cf: Options for Scanner Speed and Size.
-* -Cm: Options for Scanner Speed and Size.
-* -Cr: Options for Scanner Speed and Size.
-* -d: Debugging Options.
-* -F: Options for Scanner Speed and Size.
-* -f: Options for Scanner Speed and Size.
-* -h: Miscellaneous Options.
-* -I: Options Affecting Scanner Behavior.
-* -i: Options Affecting Scanner Behavior.
-* -L: Code-Level And API Options.
-* -l: Options Affecting Scanner Behavior.
-* -n: Miscellaneous Options.
-* -o: Options for Specifing Filenames.
-* -p: Debugging Options.
-* -P: Code-Level And API Options.
-* -R: Code-Level And API Options.
-* -s: Debugging Options.
-* -T: Debugging Options.
-* -t: Options for Specifing Filenames.
-* -V: Miscellaneous Options.
-* -v: Debugging Options.
-* -w: Debugging Options.
-* -X: Options Affecting Scanner Behavior.
-* 7bit: Options Affecting Scanner Behavior.
-* 8bit: Options Affecting Scanner Behavior.
-* align: Options for Scanner Speed and Size.
-* always-interactive: Options Affecting Scanner Behavior.
-* ansi-definitions: Code-Level And API Options.
-* ansi-prototypes: Code-Level And API Options.
-* array: Code-Level And API Options.
-* backup: Debugging Options.
-* batch: Options Affecting Scanner Behavior.
-* bison-bridge: Code-Level And API Options.
-* bison-locations: Code-Level And API Options.
-* c++: Code-Level And API Options.
-* case-insensitive: Options Affecting Scanner Behavior.
-* debug: Debugging Options.
-* default: Options Affecting Scanner Behavior.
-* ecs: Options for Scanner Speed and Size.
-* fast: Options for Scanner Speed and Size.
-* full: Options for Scanner Speed and Size.
-* header-file: Options for Specifing Filenames.
-* interactive: Options Affecting Scanner Behavior.
-* lex-compat: Options Affecting Scanner Behavior.
-* main: Code-Level And API Options.
-* meta-ecs: Options for Scanner Speed and Size.
-* nodefault: Debugging Options.
-* noline: Code-Level And API Options.
-* nounistd: Code-Level And API Options.
-* nowarn: Debugging Options.
-* noyyalloc: Overriding The Default Memory Management.
-* outfile: Options for Specifing Filenames.
-* perf-report: Debugging Options.
-* pointer: Code-Level And API Options.
-* posix: Options Affecting Scanner Behavior.
-* prefix: Code-Level And API Options.
-* read: Options for Scanner Speed and Size.
-* reentrant: Code-Level And API Options.
-* stack: Options Affecting Scanner Behavior.
-* stdinit: Options Affecting Scanner Behavior.
-* stdout: Options for Specifing Filenames.
-* tables-file: Options for Specifing Filenames.
-* tables-verify: Options for Specifing Filenames.
-* trace: Debugging Options.
-* verbose: Debugging Options.
-* warn: Debugging Options.
-* yyclass: Code-Level And API Options.
-* yylineno: Options Affecting Scanner Behavior.
-* yywrap: Options Affecting Scanner Behavior.
-
-
diff --git a/doc/flex.pdf b/doc/flex.pdf
new file mode 100644
index 0000000..18b5a1e
--- /dev/null
+++ b/doc/flex.pdf
Binary files differ
diff --git a/doc/flex.texi b/doc/flex.texi
index 130cf09..f9a9e9e 100644
--- a/doc/flex.texi
+++ b/doc/flex.texi
@@ -1,8 +1,9 @@
\input texinfo.tex @c -*-texinfo-*-
@c %**start of header
@setfilename flex.info
-@settitle flex: a fast lexical analyzer generator
+@settitle Lexical Analysis With Flex
@include version.texi
+@set authors Vern Paxson, Will Estes and John Millaway
@c "Macro Hooks" index
@defindex hk
@c "Options" index
@@ -18,6 +19,9 @@
The flex manual is placed under the same licensing conditions as the
rest of flex:
+Copyright @copyright{} 2001, 2002, 2003, 2004, 2005, 2006, 2007 The Flex
+Project.
+
Copyright @copyright{} 1990, 1997 The Regents of the University of California.
All rights reserved.
@@ -54,18 +58,15 @@ PURPOSE.
@end copying
@titlepage
-@title Flex, version @value{VERSION}
-@subtitle A fast scanner generator
+@title @value{title}
@subtitle Edition @value{EDITION}, @value{UPDATED}
-@author Vern Paxson
-@author W. L. Estes
-@author John Millaway
+@author @value{authors}
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
-
+@ifnottex
@node Top, Copyright, (dir), (dir)
@top flex
@@ -76,6 +77,8 @@ reference sections.
This edition of @cite{The flex Manual} documents @code{flex} version
@value{VERSION}. It was last updated on @value{UPDATED}.
+This manual was written by @value{authors}.
+
@menu
* Copyright::
* Reporting Bugs::
@@ -118,7 +121,7 @@ Format of the Input File
Scanner Options
-* Options for Specifing Filenames::
+* Options for Specifying Filenames::
* Options Affecting Scanner Behavior::
* Code-Level And API Options::
* Options for Scanner Speed and Size::
@@ -158,7 +161,7 @@ Serialized Tables
FAQ
* When was flex born?::
-* How do I expand \ escape sequences in C-style quoted strings?::
+* How do I expand backslash-escape sequences in C-style quoted strings?::
* Why do flex scanners call fileno if it is not ANSI compatible?::
* Does flex support recursive pattern definitions?::
* How do I skip huge chunks of input (tens of megabytes) while using flex?::
@@ -171,9 +174,9 @@ FAQ
* Why cant I use fast or full tables with interactive mode?::
* How much faster is -F or -f than -C?::
* If I have a simple grammar cant I just parse it with flex?::
-* Why doesnt yyrestart() set the start state back to INITIAL?::
+* Why doesn't yyrestart() set the start state back to INITIAL?::
* How can I match C-style comments?::
-* The period isnt working the way I expected.::
+* The period isn't working the way I expected.::
* Can I get the flex manual in another format?::
* Does there exist a "faster" NDFA->DFA algorithm?::
* How does flex compile the DFA so quickly?::
@@ -191,7 +194,7 @@ FAQ
* I am trying to port code from AT&T lex that uses yysptr and yysbuf.::
* Is there a way to make flex treat NULL like a regular character?::
* Whenever flex can not match the input it says "flex scanner jammed".::
-* Why doesnt flex have non-greedy operators like perl does?::
+* Why doesn't flex have non-greedy operators like perl does?::
* Memory leak - 16386 bytes allocated by malloc.::
* How do I track the byte offset for lseek()?::
* How do I use my own I/O classes in a C++ scanner?::
@@ -265,6 +268,7 @@ Appendices
* Makefiles and Flex::
* Bison Bridge::
* M4 Dependency::
+* Common Patterns::
Indices
@@ -277,7 +281,7 @@ Indices
@end detailmenu
@end menu
-
+@end ifnottex
@node Copyright, Reporting Bugs, Top, Top
@chapter Copyright
@@ -291,9 +295,9 @@ Indices
@cindex bugs, reporting
@cindex reporting bugs
-If you have problems with @code{flex} or think you have found a bug,
-please send mail detailing your problem to
-@email{flex-help@@lists.sourceforge.net}. Patches are always welcome.
+If you find a bug in @code{flex}, please report it using
+the SourceForge Bug Tracking facilities which can be found on
+@url{http://sourceforge.net/projects/flex,flex's SourceForge Page}.
@node Introduction, Simple Examples, Reporting Bugs, Top
@chapter Introduction
@@ -602,7 +606,8 @@ The presence of this section is optional; if it is missing, the second
@section Comments in the Input
@cindex comments, syntax of
-Flex supports C-style comments, that is, anything between /* and */ is
+Flex supports C-style comments, that is, anything between @samp{/*} and
+@samp{*/} is
considered a comment. Whenever flex encounters a comment, it copies the
entire comment verbatim to the generated source code. Comments may
appear just about anywhere, but with the following exceptions:
@@ -693,6 +698,9 @@ character EXCEPT an uppercase letter.
any character EXCEPT an uppercase letter or
a newline
+@item [a-z]@{-@}[aeiou]
+the lowercase consonants
+
@item r*
zero or more r's, where r is any regular expression
@@ -742,6 +750,43 @@ the character with hexadecimal value 2a
@item (r)
match an @samp{r}; parentheses are used to override precedence (see below)
+@item (?r-s:pattern)
+apply option @samp{r} and omit option @samp{s} while interpreting pattern.
+Options may be zero or more of the characters @samp{i}, @samp{s}, or @samp{x}.
+
+@samp{i} means case-insensitive. @samp{-i} means case-sensitive.
+
+@samp{s} alters the meaning of the @samp{.} syntax to match any single byte whatsoever.
+@samp{-s} alters the meaning of @samp{.} to match any byte except @samp{\n}.
+
+@samp{x} ignores comments and whitespace in patterns. Whitespace is ignored unless
+it is backslash-escaped, contained within @samp{""}s, or appears inside a
+character class.
+
+The following are all valid:
+
+@verbatim
+(?:foo) same as (foo)
+(?i:ab7) same as ([aA][bB]7)
+(?-i:ab) same as (ab)
+(?s:.) same as [\x00-\xFF]
+(?-s:.) same as [^\n]
+(?ix-s: a . b) same as ([Aa][^\n][bB])
+(?x:a b) same as ("ab")
+(?x:a\ b) same as ("a b")
+(?x:a" "b) same as ("a b")
+(?x:a[ ]b) same as ("a b")
+(?x:a
+ /* comment */
+ b
+ c) same as (abc)
+@end verbatim
+
+@item (?# comment )
+omit everything within @samp{()}. The first @samp{)}
+character encountered ends the pattern. It is not possible to for the comment
+to contain a @samp{)} character. The comment may span lines.
+
@cindex concatenation, in patterns
@item rs
the regular expression @samp{r} followed by the regular expression @samp{s}; called
@@ -886,7 +931,10 @@ For example, the following character classes are all equivalent:
@end verbatim
@end example
-Some notes on patterns are in order.
+A word of caution. Character classes are expanded immediately when seen in the @code{flex} input.
+This means the character classes are sensitive to the locale in which @code{flex}
+is executed, and the resulting scanner will not be sensitive to the runtime locale.
+This may or may not be desirable.
@itemize
@@ -927,6 +975,40 @@ unfortunately the inconsistency is historically entrenched. Matching
newlines means that a pattern like @samp{[^"]*} can match the entire
input unless there's another quote in the input.
+Flex allows negation of character class expressions by prepending @samp{^} to
+the POSIX character class name.
+
+@example
+@verbatim
+ [:^alnum:] [:^alpha:] [:^blank:]
+ [:^cntrl:] [:^digit:] [:^graph:]
+ [:^lower:] [:^print:] [:^punct:]
+ [:^space:] [:^upper:] [:^xdigit:]
+@end verbatim
+@end example
+
+Flex will issue a warning if the expressions @samp{[:^upper:]} and
+@samp{[:^lower:]} appear in a case-insensitive scanner, since their meaning is
+unclear. The current behavior is to skip them entirely, but this may change
+without notice in future revisions of flex.
+
+@item
+
+The @samp{@{-@}} operator computes the difference of two character classes. For
+example, @samp{[a-c]@{-@}[b-z]} represents all the characters in the class
+@samp{[a-c]} that are not in the class @samp{[b-z]} (which in this case, is
+just the single character @samp{a}). The @samp{@{-@}} operator is left
+associative, so @samp{[abc]@{-@}[b]@{-@}[c]} is the same as @samp{[a]}. Be careful
+not to accidentally create an empty set, which will never match.
+
+@item
+
+The @samp{@{+@}} operator computes the union of two character classes. For
+example, @samp{[a-z]@{+@}[0-9]} is the same as @samp{[a-z0-9]}. This operator
+is useful when preceded by the result of a difference operation, as in,
+@samp{[[:alpha:]]@{-@}[[:lower:]]@{+@}[q]}, which is equivalent to
+@samp{[A-Zq]} in the "C" locale.
+
@cindex trailing context, limits of
@cindex ^ as non-special character in patterns
@cindex $ as normal character in patterns
@@ -1112,7 +1194,7 @@ single blank, and throws away whitespace found at the end of a line:
@cindex actions, embedded C strings
@cindex C-strings, in actions
@cindex comments, in actions
-If the action contains a @samp{@}}, then the action spans till the
+If the action contains a @samp{@{}, then the action spans till the
balancing @samp{@}} is found, and the action may cross multiple lines.
@code{flex} knows about C strings and comments and won't be fooled by
braces found within them, but also allows actions to begin with
@@ -1176,7 +1258,7 @@ whenever @samp{frob} is seen:
@end verbatim
@end example
-Without the @code{REJECT}, any occurences of @samp{frob} in the input
+Without the @code{REJECT}, any occurrences of @samp{frob} in the input
would not be counted as words, since the scanner normally executes only
one action per token. Multiple uses of @code{REJECT} are allowed, each
one finding the next best choice to the currently active rule. For
@@ -1206,7 +1288,7 @@ will slow down @emph{all} of the scanner's matching. Furthermore,
(@pxref{Scanner Options}).
Note also that unlike the other special actions, @code{REJECT} is a
-@emph{branch}. code immediately following it in the action will
+@emph{branch}. Code immediately following it in the action will
@emph{not} be executed.
@item yymore()
@@ -1544,7 +1626,7 @@ condition, and
will be active only when the current start condition is either
@code{INITIAL}, @code{STRING}, or @code{QUOTE}.
-@cindex start conditions, inclusive v.s. exclusive
+@cindex start conditions, inclusive v.s.@: exclusive
Start conditions are declared in the definitions (first) section of the
input using unindented lines beginning with either @samp{%s} or
@samp{%x} followed by a list of names. The former declares
@@ -1594,7 +1676,7 @@ is equivalent to
Without the @code{<INITIAL,example>} qualifier, the @code{bar} pattern in
the second example wouldn't be active (i.e., couldn't match) when in
-start condition @code{example}. If we just used @code{example>} to
+start condition @code{example}. If we just used @code{<example>} to
qualify @code{bar}, though, then it would only be active in
@code{example} and not in @code{INITIAL}, while in the first example
it's active in both, because in the first example the @code{example}
@@ -2295,7 +2377,7 @@ switch statement and separated using @code{YY_BREAK}, which may be
redefined. By default, it is simply a @code{break}, to separate each
rule's action from the following rule's. Redefining @code{YY_BREAK}
allows, for example, C++ users to #define YY_BREAK to do nothing (while
-being very careful that every rule ends with a @code{break}" or a
+being very careful that every rule ends with a @code{break} or a
@code{return}!) to avoid suffering from unreachable statement warnings
where because a rule's action ends with @code{return}, the
@code{YY_BREAK} is inaccessible.
@@ -2408,7 +2490,7 @@ The various @code{flex} options are categorized by function in the following
menu. If you want to lookup a particular option by name, @xref{Index of Scanner Options}.
@menu
-* Options for Specifing Filenames::
+* Options for Specifying Filenames::
* Options Affecting Scanner Behavior::
* Code-Level And API Options::
* Options for Scanner Speed and Size::
@@ -2431,7 +2513,7 @@ specify the following options:
The first line specifies the general type of scanner we want. The second line
specifies that we are being careful. The third line asks flex to track line
numbers. The last line tells flex what to name the files. (The options can be
-specified in any order. We just dividied them.)
+specified in any order. We just divided them.)
@code{flex} also provides a mechanism for controlling options within the
scanner specification itself, rather than from the flex command-line.
@@ -2474,8 +2556,8 @@ corresponding routine not appearing in the generated scanner:
(though @code{yy_push_state()} and friends won't appear anyway unless
you use @code{%option stack)}.
-@node Options for Specifing Filenames, Options Affecting Scanner Behavior, Scanner Options, Scanner Options
-@section Options for Specifing Filenames
+@node Options for Specifying Filenames, Options Affecting Scanner Behavior, Scanner Options, Scanner Options
+@section Options for Specifying Filenames
@table @samp
@@ -2547,7 +2629,7 @@ the serialized tables match the in-code tables, instead of loading them.
@end table
-@node Options Affecting Scanner Behavior, Code-Level And API Options, Options for Specifing Filenames, Scanner Options
+@node Options Affecting Scanner Behavior, Code-Level And API Options, Options for Specifying Filenames, Scanner Options
@section Options Affecting Scanner Behavior
@table @samp
@@ -2975,9 +3057,9 @@ to find them.
@anchor{option-yyclass}
@opindex ---yyclass
@opindex yyclass
-@item --yyclass, @code{%option yyclass="NAME"}
+@item --yyclass=NAME, @code{%option yyclass="NAME"}
only applies when generating a C++ scanner (the @samp{--c++} option). It
-informs @code{flex} that you have derived @code{foo} as a subclass of
+informs @code{flex} that you have derived @code{NAME} as a subclass of
@code{yyFlexLexer}, so @code{flex} will place your actions in the member
function @code{foo::yylex()} instead of @code{yyFlexLexer::yylex()}. It
also generates a @code{yyFlexLexer::yylex()} member function that emits
@@ -3143,7 +3225,7 @@ the @emph{identifier} rule is present and you then use a hash table or some such
to detect the keywords, you're better off using
@samp{--fast}.
-This option is equivalent to @samp{-CFr} (see below). It cannot be used
+This option is equivalent to @samp{-CFr}. It cannot be used
with @samp{--c++}.
@end table
@@ -3263,7 +3345,7 @@ those that are on by default.
@opindex warn
@item --warn, @code{%option warn}
warn about certain things. In particular, if the default rule can be
-matched but no defualt rule has been given, the flex will warn you.
+matched but no default rule has been given, the flex will warn you.
We recommend using this option always.
@end table
@@ -3274,18 +3356,17 @@ We recommend using this option always.
@table @samp
@opindex -c
@item -c
-is a do-nothing option included for POSIX compliance.
+A do-nothing option included for POSIX compliance.
@opindex -h
@opindex ---help
-generates
@item -h, -?, --help
generates a ``help'' summary of @code{flex}'s options to @file{stdout}
and then exits.
@opindex -n
@item -n
-is another do-nothing option included only for
+Another do-nothing option included for
POSIX compliance.
@opindex -V
@@ -3330,7 +3411,7 @@ with the first two all being quite expensive and the last two being
quite cheap. Note also that @code{unput()} is implemented as a routine
call that potentially does quite a bit of work, while @code{yyless()} is
a quite-cheap macro. So if you are just putting back some excess text
-you scanned, use @code{ss()}.
+you scanned, use @code{yyless()}.
@code{REJECT} should be avoided at all costs when performance is
important. It is a particularly expensive option.
@@ -3710,7 +3791,7 @@ returns the current input line number (see @code{%option yylineno)}, or
@item void set_debug( int flag )
sets the debugging flag for the scanner, equivalent to assigning to
@code{yy_flex_debug} (@pxref{Scanner Options}). Note that you must build
-the scannerusing @code{%option debug} to include debugging information
+the scanner using @code{%option debug} to include debugging information
in it.
@findex debug (C++ only)
@@ -4004,14 +4085,20 @@ First, an example of a reentrant scanner:
@example
@verbatim
/* This scanner prints "//" comments. */
- %option reentrant stack
+
+ %option reentrant stack noyywrap
%x COMMENT
+
%%
+
"//" yy_push_state( COMMENT, yyscanner);
.|\n
+
<COMMENT>\n yy_pop_state( yyscanner );
<COMMENT>[^\n]+ fprintf( yyout, "%s\n", yytext);
+
%%
+
int main ( int argc, char * argv[] )
{
yyscan_t scanner;
@@ -4062,7 +4149,7 @@ All functions take one additional argument: @code{yyscanner}.
Notice that the calls to @code{yy_push_state} and @code{yy_pop_state}
both have an argument, @code{yyscanner} , that is not present in a
non-reentrant scanner. Here are the declarations of
-@code{yy_push_state} and @code{yy_pop_state} in the generated scanner:
+@code{yy_push_state} and @code{yy_pop_state} in the reentrant scanner:
@example
@verbatim
@@ -4128,6 +4215,7 @@ after @code{yylex}, respectively.
@example
@verbatim
int yylex_init ( yyscan_t * ptr_yy_globals ) ;
+ int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t * ptr_yy_globals ) ;
int yylex ( yyscan_t yyscanner ) ;
int yylex_destroy ( yyscan_t yyscanner ) ;
@end verbatim
@@ -4135,19 +4223,26 @@ after @code{yylex}, respectively.
The function @code{yylex_init} must be called before calling any other
function. The argument to @code{yylex_init} is the address of an
-uninitialized pointer to be filled in by @code{flex}. The contents of
-@code{ptr_yy_globals} need not be initialized, since @code{flex} will
-overwrite it anyway. The value stored in @code{ptr_yy_globals} should
-thereafter be passed to @code{yylex()} and @b{yylex_destroy()}. Flex
+uninitialized pointer to be filled in by @code{yylex_init}, overwriting
+any previous contents. The function @code{yylex_init_extra} may be used
+instead, taking as its first argument a variable of type @code{YY_EXTRA_TYPE}.
+See the section on yyextra, below, for more details.
+
+The value stored in @code{ptr_yy_globals} should
+thereafter be passed to @code{yylex} and @code{yylex_destroy}. Flex
does not save the argument passed to @code{yylex_init}, so it is safe to
-pass the address of a local pointer to @code{yylex_init}. The function
+pass the address of a local pointer to @code{yylex_init} so long as it remains
+in scope for the duration of all calls to the scanner, up to and including
+the call to @code{yylex_destroy}.
+
+The function
@code{yylex} should be familiar to you by now. The reentrant version
takes one argument, which is the value returned (via an argument) by
@code{yylex_init}. Otherwise, it behaves the same as the non-reentrant
version of @code{yylex}.
-@code{yylex_init} returns 0 (zero) on success, or non-zero on failure,
-in which case, errno is set to one of the following values:
+Both @code{yylex_init} and @code{yylex_init_extra} returns 0 (zero) on success,
+or non-zero on failure, in which case errno is set to one of the following values:
@itemize
@item ENOMEM
@@ -4243,9 +4338,7 @@ In a non-reentrant scanner, the only way to do this would be through the
use of global variables.
@code{Flex} allows you to store arbitrary, ``extra'' data in a scanner.
This data is accessible through the accessor methods
-@code{yyget_extra}
-and
-@code{yyset_extra}
+@code{yyget_extra} and @code{yyset_extra}
from outside the scanner, and through the shortcut macro
@code{yyextra}
from within the scanner itself. They are defined as follows:
@@ -4261,11 +4354,14 @@ from within the scanner itself. They are defined as follows:
@end verbatim
@end example
+In addition, an extra form of @code{yylex_init} is provided,
+@code{yylex_init_extra}. This function is provided so that the yyextra value can
+be accessed from within the very first yyalloc, used to allocate
+the scanner itself.
+
By default, @code{YY_EXTRA_TYPE} is defined as type @code{void *}. You
-will have to cast @code{yyextra} and the return value from
-@code{yyget_extra} to the appropriate value each time you access the
-extra data. To avoid casting, you may override the default type by
-defining @code{YY_EXTRA_TYPE} in section 1 of your scanner:
+may redefine this type using @code{%option extra-type="your_type"} in
+the scanner:
@cindex YY_EXTRA_TYPE, defining your own type
@example
@@ -4274,9 +4370,9 @@ defining @code{YY_EXTRA_TYPE} in section 1 of your scanner:
%{
#include <sys/stat.h>
#include <unistd.h>
- #define YY_EXTRA_TYPE struct stat*
%}
%option reentrant
+ %option extra-type="struct stat *"
%%
__filesize__ printf( "%ld", yyextra->st_size );
@@ -4286,14 +4382,17 @@ defining @code{YY_EXTRA_TYPE} in section 1 of your scanner:
{
yyscan_t scanner;
struct stat buf;
+ FILE *in;
- yylex_init ( &scanner );
- yyset_in( fopen(filename,"r"), scanner );
+ in = fopen( filename, "r" );
+ stat( filename, &buf );
- stat( filename, &buf);
- yyset_extra( &buf, scanner );
- yylex ( scanner );
+ yylex_init_extra( buf, &scanner );
+ yyset_in( in, scanner );
+ yylex( scanner );
yylex_destroy( scanner );
+
+ fclose( in );
}
@end verbatim
@end example
@@ -5033,7 +5132,7 @@ any padding.
Bit flags for this table set. Currently unused.
@item th_version[]
-Flex version in NULL-termninated string format. e.g., @samp{2.5.13a}. This is
+Flex version in NULL-terminated string format. e.g., @samp{2.5.13a}. This is
the version of flex that was used to create the serialized tables.
@item th_name[]
@@ -5306,7 +5405,7 @@ publish them here.
@menu
* When was flex born?::
-* How do I expand \ escape sequences in C-style quoted strings?::
+* How do I expand backslash-escape sequences in C-style quoted strings?::
* Why do flex scanners call fileno if it is not ANSI compatible?::
* Does flex support recursive pattern definitions?::
* How do I skip huge chunks of input (tens of megabytes) while using flex?::
@@ -5319,9 +5418,9 @@ publish them here.
* Why cant I use fast or full tables with interactive mode?::
* How much faster is -F or -f than -C?::
* If I have a simple grammar cant I just parse it with flex?::
-* Why doesnt yyrestart() set the start state back to INITIAL?::
+* Why doesn't yyrestart() set the start state back to INITIAL?::
* How can I match C-style comments?::
-* The period isnt working the way I expected.::
+* The period isn't working the way I expected.::
* Can I get the flex manual in another format?::
* Does there exist a "faster" NDFA->DFA algorithm?::
* How does flex compile the DFA so quickly?::
@@ -5339,7 +5438,7 @@ publish them here.
* I am trying to port code from AT&T lex that uses yysptr and yysbuf.::
* Is there a way to make flex treat NULL like a regular character?::
* Whenever flex can not match the input it says "flex scanner jammed".::
-* Why doesnt flex have non-greedy operators like perl does?::
+* Why doesn't flex have non-greedy operators like perl does?::
* Memory leak - 16386 bytes allocated by malloc.::
* How do I track the byte offset for lseek()?::
* How do I use my own I/O classes in a C++ scanner?::
@@ -5417,8 +5516,8 @@ the @cite{Software Tools} lex project from Jef Poskanzer in 1982. At that point
was written in Ratfor. Around 1987 or so, Paxson translated it into C, and
a legend was born :-).
-@node How do I expand \ escape sequences in C-style quoted strings?
-@unnumberedsec How do I expand \ escape sequences in C-style quoted strings?
+@node How do I expand backslash-escape sequences in C-style quoted strings?
+@unnumberedsec How do I expand backslash-escape sequences in C-style quoted strings?
A key point when scanning quoted strings is that you cannot (easily) write
a single rule that will precisely match the string if you allow things
@@ -5615,7 +5714,7 @@ matches in @samp{<INITIAL>}. Then you could use the following:
...
<A>.|\n {
/* Shortest and last rule in <A>, so
-* cascaded REJECT's will eventually
+* cascaded REJECTs will eventually
* wind up matching this rule. We want
* to now switch to the initial state
* and try matching from there instead.
@@ -5658,7 +5757,7 @@ Is your grammar recursive? That's almost always a sign that you're
better off using a parser/scanner rather than just trying to use a scanner
alone.
-@node Why doesnt yyrestart() set the start state back to INITIAL?
+@node Why doesn't yyrestart() set the start state back to INITIAL?
@unnumberedsec Why doesn't yyrestart() set the start state back to INITIAL?
There are two reasons. The first is that there might
@@ -5709,7 +5808,7 @@ Here is one way which allows you to track line information:
@end verbatim
@end example
-@node The period isnt working the way I expected.
+@node The period isn't working the way I expected.
@unnumberedsec The '.' isn't working the way I expected.
Here are some tips for using @samp{.}:
@@ -5823,13 +5922,13 @@ can add to the beginning of your rules section:
@example
@verbatim
%%
-/* Must be indented! */
-static int did_init = 0;
+ /* Must be indented! */
+ static int did_init = 0;
-if ( ! did_init ){
+ if ( ! did_init ){
do_my_init();
-did_init = 1;
-}
+ did_init = 1;
+ }
@end verbatim
@end example
@@ -5909,7 +6008,7 @@ From the above though hopefully the idea is clear.
One way to do it is to filter the first pass to a temporary file,
then process the temporary file on the second pass. You will probably see a
-performance hit, do to all the disk I/O.
+performance hit, due to all the disk I/O.
When you need to look ahead far forward like this, it almost always means
that the right solution is to build a parse tree of the entire input, then
@@ -5924,7 +6023,7 @@ residing in memory.
One way to assign precedence, is to place the more specific rules first. If
two rules would match the same input (same sequence of characters) then the
-first rule listed in the @code{flex} input wins. e.g.,
+first rule listed in the @code{flex} input wins, e.g.,
@example
@verbatim
@@ -5959,7 +6058,7 @@ version of @code{flex}. The latest release is version @value{VERSION}.
@node Whenever flex can not match the input it says "flex scanner jammed".
@unnumberedsec Whenever flex can not match the input it says "flex scanner jammed".
-You need to add a rule that matches the otherwise-unmatched text.
+You need to add a rule that matches the otherwise-unmatched text,
e.g.,
@example
@@ -5974,7 +6073,7 @@ e.g.,
See @code{%option default} for more information.
-@node Why doesnt flex have non-greedy operators like perl does?
+@node Why doesn't flex have non-greedy operators like perl does?
@unnumberedsec Why doesn't flex have non-greedy operators like perl does?
A DFA can do a non-greedy match by stopping
@@ -8055,6 +8154,7 @@ See @ref{Top, , , bison, the GNU Bison Manual}.
* Makefiles and Flex::
* Bison Bridge::
* M4 Dependency::
+* Common Patterns::
@end menu
@node Makefiles and Flex, Bison Bridge, Appendices, Appendices
@@ -8073,7 +8173,9 @@ This requires you to carefully plan your Makefile.
Modern @command{make} programs understand that @file{foo.l} is intended to
generate @file{lex.yy.c} or @file{foo.c}, and will behave
accordingly@footnote{GNU @command{make} and GNU @command{automake} are two such
-programs that provide implicit rules for flex-generated scanners.}. The
+programs that provide implicit rules for flex-generated scanners.}@footnote{GNU @command{automake}
+may generate code to execute flex in lex-compatible mode, or to stdout. If this is not what you want,
+then you should provide an explicit rule in your Makefile.am}. The
following Makefile does not explicitly instruct @command{make} how to build
@file{foo.c} from @file{foo.l}. Instead, it relies on the implicit rules of the
@command{make} program to build the intermediate file, @file{scan.c}:
@@ -8268,7 +8370,7 @@ As you can see, there really is no magic here. We just use
@end verbatim
@end example
-@node M4 Dependency, , Bison Bridge, Appendices
+@node M4 Dependency, Common Patterns, Bison Bridge, Appendices
@section M4 Dependency
@cindex m4
The macro processor @code{m4}@footnote{The use of m4 is subject to change in
@@ -8290,13 +8392,150 @@ symbol past m4 unmangled.
former is not valid in C, except within comments and strings, but the latter is valid in
code such as @code{x[y[z]]}. The solution is simple. To get the literal string
@code{"]]"}, use @code{"]""]"}. To get the array notation @code{x[y[z]]},
-use @code{x[y[z] ]}.
+use @code{x[y[z] ]}. Flex will attempt to detect these sequences in user code, and
+escape them. However, it's best to avoid this complexity where possible, by
+removing such sequences from your code.
@end itemize
@code{m4} is only required at the time you run @code{flex}. The generated
scanner is ordinary C or C++, and does @emph{not} require @code{m4}.
+@node Common Patterns, ,M4 Dependency, Appendices
+@section Common Patterns
+@cindex patterns, common
+
+This appendix provides examples of common regular expressions you might use
+in your scanner.
+
+@menu
+* Numbers::
+* Identifiers::
+* Quoted Constructs::
+* Addresses::
+@end menu
+
+
+@node Numbers, Identifiers, ,Common Patterns
+@subsection Numbers
+
+@table @asis
+
+@item C99 decimal constant
+@code{([[:digit:]]@{-@}[0])[[:digit:]]*}
+
+@item C99 hexadecimal constant
+@code{0[xX][[:xdigit:]]+}
+
+@item C99 octal constant
+@code{0[0123456]*}
+
+@item C99 floating point constant
+@verbatim
+ {dseq} ([[:digit:]]+)
+ {dseq_opt} ([[:digit:]]*)
+ {frac} (({dseq_opt}"."{dseq})|{dseq}".")
+ {exp} ([eE][+-]?{dseq})
+ {exp_opt} ({exp}?)
+ {fsuff} [flFL]
+ {fsuff_opt} ({fsuff}?)
+ {hpref} (0[xX])
+ {hdseq} ([[:xdigit:]]+)
+ {hdseq_opt} ([[:xdigit:]]*)
+ {hfrac} (({hdseq_opt}"."{hdseq})|({hdseq}"."))
+ {bexp} ([pP][+-]?{dseq})
+ {dfc} (({frac}{exp_opt}{fsuff_opt})|({dseq}{exp}{fsuff_opt}))
+ {hfc} (({hpref}{hfrac}{bexp}{fsuff_opt})|({hpref}{hdseq}{bexp}{fsuff_opt}))
+
+ {c99_floating_point_constant} ({dfc}|{hfc})
+@end verbatim
+
+See C99 section 6.4.4.2 for the gory details.
+
+@end table
+
+@node Identifiers, Quoted Constructs, Numbers, Common Patterns
+@subsection Identifiers
+
+@table @asis
+
+@item C99 Identifier
+@verbatim
+ucn ((\\u([[:xdigit:]]{4}))|(\\U([[:xdigit:]]{8})))
+nondigit [_[:alpha:]]
+c99_id ([_[:alpha:]]|{ucn})([_[:alnum:]]|{ucn})*
+@end verbatim
+
+Technically, the above pattern does not encompass all possible C99 identifiers, since C99 allows for
+"implementation-defined" characters. In practice, C compilers follow the above pattern, with the
+addition of the @samp{$} character.
+
+@item UTF-8 Encoded Unicode Code Point
+@verbatim
+[\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF]([\x80-\xBF]{2})|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF]([\x80-\xBF]{2})|[\xF1-\xF3]([\x80-\xBF]{3})|\xF4[\x80-\x8F]([\x80-\xBF]{2})
+@end verbatim
+
+@end table
+
+@node Quoted Constructs, Addresses, Identifiers, Common Patterns
+@subsection Quoted Constructs
+
+@table @asis
+@item C99 String Literal
+@code{L?\"([^\"\\\n]|(\\['\"?\\abfnrtv])|(\\([0123456]@{1,3@}))|(\\x[[:xdigit:]]+)|(\\u([[:xdigit:]]@{4@}))|(\\U([[:xdigit:]]@{8@})))*\"}
+
+@item C99 Comment
+@code{("/*"([^*]|"*"[^/])*"*/")|("/"(\\\n)*"/"[^\n]*)}
+
+Note that in C99, a @samp{//}-style comment may be split across lines, and, contrary to popular belief,
+does not include the trailing @samp{\n} character.
+
+A better way to scan @samp{/* */} comments is by line, rather than matching
+possibly huge comments all at once. This will allow you to scan comments of
+unlimited length, as long as line breaks appear at sane intervals. This is also
+more efficient when used with automatic line number processing. @xref{option-yylineno}.
+
+@verbatim
+<INITIAL>{
+ "/*" BEGIN(COMMENT);
+}
+<COMMENT>{
+ "*/" BEGIN(0);
+ [^*\n]+ ;
+ "*"[^/] ;
+ \n ;
+}
+@end verbatim
+
+@end table
+
+@node Addresses, ,Quoted Constructs, Common Patterns
+@subsection Addresses
+
+@table @asis
+
+@item IPv4 Address
+@code{(([[:digit:]]@{1,3@}".")@{3@}([[:digit:]]@{1,3@}))}
+
+@item IPv6 Address
+@verbatim
+hex4 ([[:xdigit:]]{1,4})
+hexseq ({hex4}(:{hex4}*))
+hexpart ({hexseq}|({hexseq}::({hexseq}?))|::{hexseq})
+IPv6address ({hexpart}(":"{IPv4address})?)
+@end verbatim
+
+See RFC2373 for details.
+
+@item URI
+@code{(([^:/?#]+):)?("//"([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?}
+
+This pattern is nearly useless, since it allows just about any character to
+appear in a URI, including spaces and control characters. See RFC2396 for
+details.
+
+@end table
+
@node Indices, , Appendices, Top
@unnumbered Indices
diff --git a/doc/mdate-sh b/doc/mdate-sh
index b610b47..cd916c0 100755
--- a/doc/mdate-sh
+++ b/doc/mdate-sh
@@ -1,6 +1,10 @@
#!/bin/sh
# Get modification time of a file or directory and pretty-print it.
-# Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
+
+scriptversion=2005-06-29.22
+
+# Copyright (C) 1995, 1996, 1997, 2003, 2004, 2005 Free Software
+# Foundation, Inc.
# written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
#
# This program is free software; you can redistribute it and/or modify
@@ -15,13 +19,38 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
+# This file is maintained in Automake, please report
+# bugs to <bug-automake@gnu.org> or send patches to
+# <automake-patches@gnu.org>.
+
+case $1 in
+ '')
+ echo "$0: No file. Try \`$0 --help' for more information." 1>&2
+ exit 1;
+ ;;
+ -h | --h*)
+ cat <<\EOF
+Usage: mdate-sh [--help] [--version] FILE
+
+Pretty-print the modification time of FILE.
+
+Report bugs to <bug-automake@gnu.org>.
+EOF
+ exit $?
+ ;;
+ -v | --v*)
+ echo "mdate-sh $scriptversion"
+ exit $?
+ ;;
+esac
+
# Prevent date giving response in another language.
LANG=C
export LANG
@@ -30,7 +59,15 @@ export LC_ALL
LC_TIME=C
export LC_TIME
-save_arg1="$1"
+# GNU ls changes its time format in response to the TIME_STYLE
+# variable. Since we cannot assume `unset' works, revert this
+# variable to its documented default.
+if test "${TIME_STYLE+set}" = set; then
+ TIME_STYLE=posix-long-iso
+ export TIME_STYLE
+fi
+
+save_arg1=$1
# Find out how to get the extended ls output of a file or directory.
if ls -L /dev/null 1>/dev/null 2>&1; then
@@ -52,7 +89,7 @@ fi
# words should be skipped to get the date.
# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
-set - x`$ls_command /`
+set x`ls -l -d /`
# Find which argument is the month.
month=
@@ -79,13 +116,32 @@ do
done
# Get the extended ls output of the file or directory.
-set - x`eval "$ls_command \"\$save_arg1\""`
+set dummy x`eval "$ls_command \"\$save_arg1\""`
# Remove all preceding arguments
eval $command
-# Get the month. Next argument is day, followed by the year or time.
-case $1 in
+# Because of the dummy argument above, month is in $2.
+#
+# On a POSIX system, we should have
+#
+# $# = 5
+# $1 = file size
+# $2 = month
+# $3 = day
+# $4 = year or time
+# $5 = filename
+#
+# On Darwin 7.7.0 and 7.6.0, we have
+#
+# $# = 4
+# $1 = day
+# $2 = month
+# $3 = year or time
+# $4 = filename
+
+# Get the month.
+case $2 in
Jan) month=January; nummonth=1;;
Feb) month=February; nummonth=2;;
Mar) month=March; nummonth=3;;
@@ -100,7 +156,10 @@ case $1 in
Dec) month=December; nummonth=12;;
esac
-day=$2
+case $3 in
+ ???*) day=$1;;
+ *) day=$3; shift;;
+esac
# Here we have to deal with the problem that the ls output gives either
# the time of day or the year.
@@ -131,3 +190,12 @@ esac
# The result.
echo $day $month $year
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:
diff --git a/doc/stamp-vti b/doc/stamp-vti
index 7711f31..d69698f 100644
--- a/doc/stamp-vti
+++ b/doc/stamp-vti
@@ -1,4 +1,4 @@
-@set UPDATED 20 February 2006
-@set UPDATED-MONTH February 2006
-@set EDITION 2.5.33
-@set VERSION 2.5.33
+@set UPDATED 10 September 2007
+@set UPDATED-MONTH September 2007
+@set EDITION 2.5.34
+@set VERSION 2.5.34
diff --git a/doc/texinfo.tex b/doc/texinfo.tex
index 807ce6d..ff2c406 100644
--- a/doc/texinfo.tex
+++ b/doc/texinfo.tex
@@ -3,10 +3,11 @@
% Load plain if necessary, i.e., if running under initex.
\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
%
-\def\texinfoversion{2003-03-22.08}
+\def\texinfoversion{2005-07-05.19}
%
% Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
-% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software
+% Foundation, Inc.
%
% This texinfo.tex file is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
@@ -20,26 +21,21 @@
%
% You should have received a copy of the GNU General Public License
% along with this texinfo.tex file; see the file COPYING. If not, write
-% to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-% Boston, MA 02111-1307, USA.
+% to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+% Boston, MA 02110-1301, USA.
%
-% In other words, you are welcome to use, share and improve this program.
-% You are forbidden to forbid anyone else to use, share and improve
-% what you give them. Help stamp out software-hoarding!
+% As a special exception, when this file is read by TeX when processing
+% a Texinfo source document, you may use the result without
+% restriction. (This has been our intent since Texinfo was invented.)
%
% Please try the latest version of texinfo.tex before submitting bug
% reports; you can get the latest version from:
-% ftp://ftp.gnu.org/gnu/texinfo/texinfo.tex
-% (and all GNU mirrors, see http://www.gnu.org/order/ftp.html)
+% http://www.gnu.org/software/texinfo/ (the Texinfo home page), or
% ftp://tug.org/tex/texinfo.tex
-% (and all CTAN mirrors, see http://www.ctan.org),
-% and /home/gd/gnu/doc/texinfo.tex on the GNU machines.
-%
-% The GNU Texinfo home page is http://www.gnu.org/software/texinfo.
-%
-% The texinfo.tex in any given Texinfo distribution could well be out
+% (and all CTAN mirrors, see http://www.ctan.org).
+% The texinfo.tex in any given distribution could well be out
% of date, so if that's what you're using, please check.
-%
+%
% Send bug reports to bug-texinfo@gnu.org. Please include including a
% complete document in each bug report with which we can reproduce the
% problem. Patches are, of course, greatly appreciated.
@@ -55,10 +51,13 @@
% The extra TeX runs get the cross-reference information correct.
% Sometimes one run after texindex suffices, and sometimes you need more
% than two; texi2dvi does it as many times as necessary.
-%
+%
% It is possible to adapt texinfo.tex for other languages, to some
% extent. You can get the existing language-specific files from the
% full Texinfo distribution.
+%
+% The GNU Texinfo home page is http://www.gnu.org/software/texinfo.
+
\message{Loading texinfo [version \texinfoversion]:}
@@ -85,11 +84,16 @@
\let\ptexend=\end
\let\ptexequiv=\equiv
\let\ptexexclam=\!
+\let\ptexfootnote=\footnote
\let\ptexgtr=>
\let\ptexhat=^
\let\ptexi=\i
+\let\ptexindent=\indent
+\let\ptexinsert=\insert
\let\ptexlbrace=\{
\let\ptexless=<
+\let\ptexnewwrite\newwrite
+\let\ptexnoindent=\noindent
\let\ptexplus=+
\let\ptexrbrace=\}
\let\ptexslash=\/
@@ -100,6 +104,15 @@
% starts a new line in the output.
\newlinechar = `^^J
+% Use TeX 3.0's \inputlineno to get the line number, for better error
+% messages, but if we're using an old version of TeX, don't do anything.
+%
+\ifx\inputlineno\thisisundefined
+ \let\linenumber = \empty % Pre-3.0.
+\else
+ \def\linenumber{l.\the\inputlineno:\space}
+\fi
+
% Set up fixed words for English if not already set.
\ifx\putwordAppendix\undefined \gdef\putwordAppendix{Appendix}\fi
\ifx\putwordChapter\undefined \gdef\putwordChapter{Chapter}\fi
@@ -138,43 +151,89 @@
\ifx\putwordDefspec\undefined \gdef\putwordDefspec{Special Form}\fi
\ifx\putwordDefvar\undefined \gdef\putwordDefvar{Variable}\fi
\ifx\putwordDefopt\undefined \gdef\putwordDefopt{User Option}\fi
-\ifx\putwordDeftypevar\undefined\gdef\putwordDeftypevar{Variable}\fi
\ifx\putwordDeffunc\undefined \gdef\putwordDeffunc{Function}\fi
-\ifx\putwordDeftypefun\undefined\gdef\putwordDeftypefun{Function}\fi
% In some macros, we cannot use the `\? notation---the left quote is
% in some cases the escape char.
+\chardef\backChar = `\\
\chardef\colonChar = `\:
\chardef\commaChar = `\,
\chardef\dotChar = `\.
-\chardef\equalChar = `\=
\chardef\exclamChar= `\!
+\chardef\plusChar = `\+
\chardef\questChar = `\?
\chardef\semiChar = `\;
-\chardef\spaceChar = `\ %
\chardef\underChar = `\_
+\chardef\spaceChar = `\ %
+\chardef\spacecat = 10
+\def\spaceisspace{\catcode\spaceChar=\spacecat}
+
+{% for help with debugging.
+ % example usage: \expandafter\show\activebackslash
+ \catcode`\! = 0 \catcode`\\ = \active
+ !global!def!activebackslash{\}
+}
+
% Ignore a token.
%
\def\gobble#1{}
-% True if #1 is the empty string, i.e., called like `\ifempty{}'.
-%
-\def\ifempty#1{\ifemptyx #1\emptymarkA\emptymarkB}%
-\def\ifemptyx#1#2\emptymarkB{\ifx #1\emptymarkA}%
+% The following is used inside several \edef's.
+\def\makecsname#1{\expandafter\noexpand\csname#1\endcsname}
% Hyphenation fixes.
-\hyphenation{ap-pen-dix}
-\hyphenation{eshell}
-\hyphenation{mini-buf-fer mini-buf-fers}
-\hyphenation{time-stamp}
-\hyphenation{white-space}
+\hyphenation{
+ Flor-i-da Ghost-script Ghost-view Mac-OS Post-Script
+ ap-pen-dix bit-map bit-maps
+ data-base data-bases eshell fall-ing half-way long-est man-u-script
+ man-u-scripts mini-buf-fer mini-buf-fers over-view par-a-digm
+ par-a-digms rath-er rec-tan-gu-lar ro-bot-ics se-vere-ly set-up spa-ces
+ spell-ing spell-ings
+ stand-alone strong-est time-stamp time-stamps which-ever white-space
+ wide-spread wrap-around
+}
% Margin to add to right of even pages, to left of odd pages.
\newdimen\bindingoffset
\newdimen\normaloffset
\newdimen\pagewidth \newdimen\pageheight
+% For a final copy, take out the rectangles
+% that mark overfull boxes (in case you have decided
+% that the text looks ok even though it passes the margin).
+%
+\def\finalout{\overfullrule=0pt}
+
+% @| inserts a changebar to the left of the current line. It should
+% surround any changed text. This approach does *not* work if the
+% change spans more than two lines of output. To handle that, we would
+% have adopt a much more difficult approach (putting marks into the main
+% vertical list for the beginning and end of each change).
+%
+\def\|{%
+ % \vadjust can only be used in horizontal mode.
+ \leavevmode
+ %
+ % Append this vertical mode material after the current line in the output.
+ \vadjust{%
+ % We want to insert a rule with the height and depth of the current
+ % leading; that is exactly what \strutbox is supposed to record.
+ \vskip-\baselineskip
+ %
+ % \vadjust-items are inserted at the left edge of the type. So
+ % the \llap here moves out into the left-hand margin.
+ \llap{%
+ %
+ % For a thicker or thinner bar, change the `1pt'.
+ \vrule height\baselineskip width1pt
+ %
+ % This is the space between the bar and the text.
+ \hskip 12pt
+ }%
+ }%
+}
+
% Sometimes it is convenient to have everything in the transcript file
% and nothing on the terminal. We don't just call \tracingall here,
% since that produces some useless output on the terminal. We also make
@@ -199,12 +258,12 @@
\tracingassigns1
\fi
\tracingcommands3 % 3 gives us more in etex
- \errorcontextlines\maxdimen
+ \errorcontextlines16
}%
% add check for \lastpenalty to plain's definitions. If the last thing
% we did was a \nobreak, we don't want to insert more space.
-%
+%
\def\smallbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\smallskipamount
\removelastskip\penalty-50\smallskip\fi\fi}
\def\medbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\medskipamount
@@ -251,13 +310,10 @@
% take effect in \write's, yet the group defined by the \vbox ends
% before the \shipout runs.
%
- \escapechar = `\\ % use backslash in output files.
\indexdummies % don't expand commands in the output.
- \normalturnoffactive % \ in index entries must not stay \, e.g., if
- % the page break happens to be in the middle of an example.
\shipout\vbox{%
% Do this early so pdf references go to the beginning of the page.
- \ifpdfmakepagedest \pdfmkdest{\the\pageno} \fi
+ \ifpdfmakepagedest \pdfdest name{\the\pageno} xyz\fi
%
\ifcropmarks \vbox to \outervsize\bgroup
\hsize = \outerhsize
@@ -305,7 +361,7 @@
\egroup % \vbox from first cropmarks clause
\fi
}% end of \shipout\vbox
- }% end of group with \normalturnoffactive
+ }% end of group with \indexdummies
\advancepageno
\ifnum\outputpenalty>-20000 \else\dosupereject\fi
}
@@ -338,132 +394,162 @@
% the input line (except we remove a trailing comment). #1 should be a
% macro which expects an ordinary undelimited TeX argument.
%
-\def\parsearg#1{%
- \let\next = #1%
+\def\parsearg{\parseargusing{}}
+\def\parseargusing#1#2{%
+ \def\next{#2}%
\begingroup
\obeylines
- \futurelet\temp\parseargx
-}
-
-% If the next token is an obeyed space (from an @example environment or
-% the like), remove it and recurse. Otherwise, we're done.
-\def\parseargx{%
- % \obeyedspace is defined far below, after the definition of \sepspaces.
- \ifx\obeyedspace\temp
- \expandafter\parseargdiscardspace
- \else
- \expandafter\parseargline
- \fi
+ \spaceisspace
+ #1%
+ \parseargline\empty% Insert the \empty token, see \finishparsearg below.
}
-% Remove a single space (as the delimiter token to the macro call).
-{\obeyspaces %
- \gdef\parseargdiscardspace {\futurelet\temp\parseargx}}
-
{\obeylines %
\gdef\parseargline#1^^M{%
\endgroup % End of the group started in \parsearg.
- %
- % First remove any @c comment, then any @comment.
- % Result of each macro is put in \toks0.
- \argremovec #1\c\relax %
- \expandafter\argremovecomment \the\toks0 \comment\relax %
- %
- % Call the caller's macro, saved as \next in \parsearg.
- \expandafter\next\expandafter{\the\toks0}%
+ \argremovecomment #1\comment\ArgTerm%
}%
}
-% Since all \c{,omment} does is throw away the argument, we can let TeX
-% do that for us. The \relax here is matched by the \relax in the call
-% in \parseargline; it could be more or less anything, its purpose is
-% just to delimit the argument to the \c.
-\def\argremovec#1\c#2\relax{\toks0 = {#1}}
-\def\argremovecomment#1\comment#2\relax{\toks0 = {#1}}
+% First remove any @comment, then any @c comment.
+\def\argremovecomment#1\comment#2\ArgTerm{\argremovec #1\c\ArgTerm}
+\def\argremovec#1\c#2\ArgTerm{\argcheckspaces#1\^^M\ArgTerm}
-% \argremovec{,omment} might leave us with trailing spaces, though; e.g.,
+% Each occurence of `\^^M' or `<space>\^^M' is replaced by a single space.
+%
+% \argremovec might leave us with trailing space, e.g.,
% @end itemize @c foo
-% will have two active spaces as part of the argument with the
-% `itemize'. Here we remove all active spaces from #1, and assign the
-% result to \toks0.
-%
-% This loses if there are any *other* active characters besides spaces
-% in the argument -- _ ^ +, for example -- since they get expanded.
-% Fortunately, Texinfo does not define any such commands. (If it ever
-% does, the catcode of the characters in questionwill have to be changed
-% here.) But this means we cannot call \removeactivespaces as part of
-% \argremovec{,omment}, since @c uses \parsearg, and thus the argument
-% that \parsearg gets might well have any character at all in it.
-%
-\def\removeactivespaces#1{%
- \begingroup
- \ignoreactivespaces
- \edef\temp{#1}%
- \global\toks0 = \expandafter{\temp}%
- \endgroup
+% This space token undergoes the same procedure and is eventually removed
+% by \finishparsearg.
+%
+\def\argcheckspaces#1\^^M{\argcheckspacesX#1\^^M \^^M}
+\def\argcheckspacesX#1 \^^M{\argcheckspacesY#1\^^M}
+\def\argcheckspacesY#1\^^M#2\^^M#3\ArgTerm{%
+ \def\temp{#3}%
+ \ifx\temp\empty
+ % We cannot use \next here, as it holds the macro to run;
+ % thus we reuse \temp.
+ \let\temp\finishparsearg
+ \else
+ \let\temp\argcheckspaces
+ \fi
+ % Put the space token in:
+ \temp#1 #3\ArgTerm
}
-% Change the active space to expand to nothing.
+% If a _delimited_ argument is enclosed in braces, they get stripped; so
+% to get _exactly_ the rest of the line, we had to prevent such situation.
+% We prepended an \empty token at the very beginning and we expand it now,
+% just before passing the control to \next.
+% (Similarily, we have to think about #3 of \argcheckspacesY above: it is
+% either the null string, or it ends with \^^M---thus there is no danger
+% that a pair of braces would be stripped.
%
-\begingroup
+% But first, we have to remove the trailing space token.
+%
+\def\finishparsearg#1 \ArgTerm{\expandafter\next\expandafter{#1}}
+
+% \parseargdef\foo{...}
+% is roughly equivalent to
+% \def\foo{\parsearg\Xfoo}
+% \def\Xfoo#1{...}
+%
+% Actually, I use \csname\string\foo\endcsname, ie. \\foo, as it is my
+% favourite TeX trick. --kasal, 16nov03
+
+\def\parseargdef#1{%
+ \expandafter \doparseargdef \csname\string#1\endcsname #1%
+}
+\def\doparseargdef#1#2{%
+ \def#2{\parsearg#1}%
+ \def#1##1%
+}
+
+% Several utility definitions with active space:
+{
\obeyspaces
- \gdef\ignoreactivespaces{\obeyspaces\let =\empty}
-\endgroup
+ \gdef\obeyedspace{ }
+
+ % Make each space character in the input produce a normal interword
+ % space in the output. Don't allow a line break at this space, as this
+ % is used only in environments like @example, where each line of input
+ % should produce a line of output anyway.
+ %
+ \gdef\sepspaces{\obeyspaces\let =\tie}
+
+ % If an index command is used in an @example environment, any spaces
+ % therein should become regular spaces in the raw index file, not the
+ % expansion of \tie (\leavevmode \penalty \@M \ ).
+ \gdef\unsepspaces{\let =\space}
+}
\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
-%% These are used to keep @begin/@end levels from running away
-%% Call \inENV within environments (after a \begingroup)
-\newif\ifENV \ENVfalse \def\inENV{\ifENV\relax\else\ENVtrue\fi}
-\def\ENVcheck{%
-\ifENV\errmessage{Still within an environment; press RETURN to continue}
-\endgroup\fi} % This is not perfect, but it should reduce lossage
+% Define the framework for environments in texinfo.tex. It's used like this:
+%
+% \envdef\foo{...}
+% \def\Efoo{...}
+%
+% It's the responsibility of \envdef to insert \begingroup before the
+% actual body; @end closes the group after calling \Efoo. \envdef also
+% defines \thisenv, so the current environment is known; @end checks
+% whether the environment name matches. The \checkenv macro can also be
+% used to check whether the current environment is the one expected.
+%
+% Non-false conditionals (@iftex, @ifset) don't fit into this, so they
+% are not treated as enviroments; they don't open a group. (The
+% implementation of @end takes care not to call \endgroup in this
+% special case.)
-% @begin foo is the same as @foo, for now.
-\newhelp\EMsimple{Press RETURN to continue.}
-\outer\def\begin{\parsearg\beginxxx}
+% At runtime, environments start with this:
+\def\startenvironment#1{\begingroup\def\thisenv{#1}}
+% initialize
+\let\thisenv\empty
-\def\beginxxx #1{%
-\expandafter\ifx\csname #1\endcsname\relax
-{\errhelp=\EMsimple \errmessage{Undefined command @begin #1}}\else
-\csname #1\endcsname\fi}
+% ... but they get defined via ``\envdef\foo{...}'':
+\long\def\envdef#1#2{\def#1{\startenvironment#1#2}}
+\def\envparseargdef#1#2{\parseargdef#1{\startenvironment#1#2}}
-% @end foo executes the definition of \Efoo.
-%
-\def\end{\parsearg\endxxx}
-\def\endxxx #1{%
- \removeactivespaces{#1}%
- \edef\endthing{\the\toks0}%
- %
- \expandafter\ifx\csname E\endthing\endcsname\relax
- \expandafter\ifx\csname \endthing\endcsname\relax
- % There's no \foo, i.e., no ``environment'' foo.
- \errhelp = \EMsimple
- \errmessage{Undefined command `@end \endthing'}%
- \else
- \unmatchedenderror\endthing
- \fi
+% Check whether we're in the right environment:
+\def\checkenv#1{%
+ \def\temp{#1}%
+ \ifx\thisenv\temp
\else
- % Everything's ok; the right environment has been started.
- \csname E\endthing\endcsname
+ \badenverr
\fi
}
-% There is an environment #1, but it hasn't been started. Give an error.
-%
-\def\unmatchedenderror#1{%
+% Evironment mismatch, #1 expected:
+\def\badenverr{%
\errhelp = \EMsimple
- \errmessage{This `@end #1' doesn't have a matching `@#1'}%
+ \errmessage{This command can appear only \inenvironment\temp,
+ not \inenvironment\thisenv}%
+}
+\def\inenvironment#1{%
+ \ifx#1\empty
+ out of any environment%
+ \else
+ in environment \expandafter\string#1%
+ \fi
}
-% Define the control sequence \E#1 to give an unmatched @end error.
+% @end foo executes the definition of \Efoo.
+% But first, it executes a specialized version of \checkenv
%
-\def\defineunmatchedend#1{%
- \expandafter\def\csname E#1\endcsname{\unmatchedenderror{#1}}%
+\parseargdef\end{%
+ \if 1\csname iscond.#1\endcsname
+ \else
+ % The general wording of \badenverr may not be ideal, but... --kasal, 06nov03
+ \expandafter\checkenv\csname#1\endcsname
+ \csname E#1\endcsname
+ \endgroup
+ \fi
}
+\newhelp\EMsimple{Press RETURN to continue.}
+
%% Simple single-character @ commands
@@ -485,7 +571,7 @@
\let\}=\myrbrace
\begingroup
% Definitions to produce \{ and \} commands for indices,
- % and @{ and @} for the aux file.
+ % and @{ and @} for the aux/toc files.
\catcode`\{ = \other \catcode`\} = \other
\catcode`\[ = 1 \catcode`\] = 2
\catcode`\! = 0 \catcode`\\ = \other
@@ -495,6 +581,9 @@
!gdef!rbraceatcmd[@}]%
!endgroup
+% @comma{} to avoid , parsing problems.
+\let\comma = ,
+
% Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
% Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H.
\let\, = \c
@@ -504,10 +593,12 @@
\let\ubaraccent = \b
\let\udotaccent = \d
-% Other special characters: @questiondown @exclamdown
+% Other special characters: @questiondown @exclamdown @ordf @ordm
% Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss.
\def\questiondown{?`}
\def\exclamdown{!`}
+\def\ordf{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{a}}}
+\def\ordm{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{o}}}
% Dotless i and dotless j, used for accents.
\def\imacro{i}
@@ -520,6 +611,25 @@
\fi\fi
}
+% The \TeX{} logo, as in plain, but resetting the spacing so that a
+% period following counts as ending a sentence. (Idea found in latex.)
+%
+\edef\TeX{\TeX \spacefactor=1000 }
+
+% @LaTeX{} logo. Not quite the same results as the definition in
+% latex.ltx, since we use a different font for the raised A; it's most
+% convenient for us to use an explicitly smaller font, rather than using
+% the \scriptstyle font (since we don't reset \scriptstyle and
+% \scriptscriptstyle).
+%
+\def\LaTeX{%
+ L\kern-.36em
+ {\setbox0=\hbox{T}%
+ \vbox to \ht0{\hbox{\selectfonts\lllsize A}\vss}}%
+ \kern-.15em
+ \TeX
+}
+
% Be sure we're in horizontal mode when doing a tie, since we make space
% equivalent to this in @example-like environments. Otherwise, a space
% at the beginning of a line will start with \penalty -- and
@@ -542,13 +652,28 @@
\let\/=\allowbreak
% @. is an end-of-sentence period.
-\def\.{.\spacefactor=3000 }
+\def\.{.\spacefactor=\endofsentencespacefactor\space}
% @! is an end-of-sentence bang.
-\def\!{!\spacefactor=3000 }
+\def\!{!\spacefactor=\endofsentencespacefactor\space}
% @? is an end-of-sentence query.
-\def\?{?\spacefactor=3000 }
+\def\?{?\spacefactor=\endofsentencespacefactor\space}
+
+% @frenchspacing on|off says whether to put extra space after punctuation.
+%
+\def\onword{on}
+\def\offword{off}
+%
+\parseargdef\frenchspacing{%
+ \def\temp{#1}%
+ \ifx\temp\onword \plainfrenchspacing
+ \else\ifx\temp\offword \plainnonfrenchspacing
+ \else
+ \errhelp = \EMsimple
+ \errmessage{Unknown @frenchspacing option `\temp', must be on/off}%
+ \fi\fi
+}
% @w prevents a word break. Without the \leavevmode, @w at the
% beginning of a paragraph, when TeX is still in vertical mode, would
@@ -569,63 +694,18 @@
% explicit \vfill so that the extra space is at the bottom. The
% threshold for doing this is if the group is more than \vfilllimit
% percent of a page (\vfilllimit can be changed inside of @tex).
-%
+%
\newbox\groupbox
\def\vfilllimit{0.7}
%
-\def\group{\begingroup
- \ifnum\catcode13=\active \else
+\envdef\group{%
+ \ifnum\catcode`\^^M=\active \else
\errhelp = \groupinvalidhelp
\errmessage{@group invalid in context where filling is enabled}%
\fi
- %
- % The \vtop we start below produces a box with normal height and large
- % depth; thus, TeX puts \baselineskip glue before it, and (when the
- % next line of text is done) \lineskip glue after it. (See p.82 of
- % the TeXbook.) Thus, space below is not quite equal to space
- % above. But it's pretty close.
- \def\Egroup{%
- \egroup % End the \vtop.
- % \dimen0 is the vertical size of the group's box.
- \dimen0 = \ht\groupbox \advance\dimen0 by \dp\groupbox
- % \dimen2 is how much space is left on the page (more or less).
- \dimen2 = \pageheight \advance\dimen2 by -\pagetotal
- % if the group doesn't fit on the current page, and it's a big big
- % group, force a page break.
- \ifdim \dimen0 > \dimen2
- \ifdim \pagetotal < \vfilllimit\pageheight
- \page
- \fi
- \fi
- \copy\groupbox
- \endgroup % End the \group.
- }%
+ \startsavinginserts
%
\setbox\groupbox = \vtop\bgroup
- % We have to put a strut on the last line in case the @group is in
- % the midst of an example, rather than completely enclosing it.
- % Otherwise, the interline space between the last line of the group
- % and the first line afterwards is too small. But we can't put the
- % strut in \Egroup, since there it would be on a line by itself.
- % Hence this just inserts a strut at the beginning of each line.
- \everypar = {\strut}%
- %
- % Since we have a strut on every line, we don't need any of TeX's
- % normal interline spacing.
- \offinterlineskip
- %
- % OK, but now we have to do something about blank
- % lines in the input in @example-like environments, which normally
- % just turn into \lisppar, which will insert no space now that we've
- % turned off the interline space. Simplest is to make them be an
- % empty paragraph.
- \ifx\par\lisppar
- \edef\par{\leavevmode \par}%
- %
- % Reset ^^M's definition to new definition of \par.
- \obeylines
- \fi
- %
% Do @comment since we are called inside an environment such as
% @example, where each end-of-line in the input causes an
% end-of-line in the output. We don't want the end-of-line after
@@ -635,6 +715,32 @@
\comment
}
%
+% The \vtop produces a box with normal height and large depth; thus, TeX puts
+% \baselineskip glue before it, and (when the next line of text is done)
+% \lineskip glue after it. Thus, space below is not quite equal to space
+% above. But it's pretty close.
+\def\Egroup{%
+ % To get correct interline space between the last line of the group
+ % and the first line afterwards, we have to propagate \prevdepth.
+ \endgraf % Not \par, as it may have been set to \lisppar.
+ \global\dimen1 = \prevdepth
+ \egroup % End the \vtop.
+ % \dimen0 is the vertical size of the group's box.
+ \dimen0 = \ht\groupbox \advance\dimen0 by \dp\groupbox
+ % \dimen2 is how much space is left on the page (more or less).
+ \dimen2 = \pageheight \advance\dimen2 by -\pagetotal
+ % if the group doesn't fit on the current page, and it's a big big
+ % group, force a page break.
+ \ifdim \dimen0 > \dimen2
+ \ifdim \pagetotal < \vfilllimit\pageheight
+ \page
+ \fi
+ \fi
+ \box\groupbox
+ \prevdepth = \dimen1
+ \checkinserts
+}
+%
% TeX puts in an \escapechar (i.e., `@') at the beginning of the help
% message, so this ends up printing `@group can only ...'.
%
@@ -647,10 +753,8 @@ where each line of input produces a line of output.}
\newdimen\mil \mil=0.001in
-\def\need{\parsearg\needx}
-
% Old definition--didn't work.
-%\def\needx #1{\par %
+%\parseargdef\need{\par %
%% This method tries to make TeX break the page naturally
%% if the depth of the box does not fit.
%{\baselineskip=0pt%
@@ -658,7 +762,7 @@ where each line of input produces a line of output.}
%\prevdepth=-1000pt
%}}
-\def\needx#1{%
+\parseargdef\need{%
% Ensure vertical mode, so we don't make a big box in the middle of a
% paragraph.
\par
@@ -697,35 +801,10 @@ where each line of input produces a line of output.}
\fi
}
-% @br forces paragraph break
+% @br forces paragraph break (and is undocumented).
\let\br = \par
-% @dots{} output an ellipsis using the current font.
-% We do .5em per period so that it has the same spacing in a typewriter
-% font as three actual period characters.
-%
-\def\dots{%
- \leavevmode
- \hbox to 1.5em{%
- \hskip 0pt plus 0.25fil minus 0.25fil
- .\hss.\hss.%
- \hskip 0pt plus 0.5fil minus 0.5fil
- }%
-}
-
-% @enddots{} is an end-of-sentence ellipsis.
-%
-\def\enddots{%
- \leavevmode
- \hbox to 2em{%
- \hskip 0pt plus 0.25fil minus 0.25fil
- .\hss.\hss.\hss.%
- \hskip 0pt plus 0.5fil minus 0.5fil
- }%
- \spacefactor=3000
-}
-
% @page forces the start of a new page.
%
\def\page{\par\vfill\supereject}
@@ -738,13 +817,11 @@ where each line of input produces a line of output.}
\newskip\exdentamount
% This defn is used inside fill environments such as @defun.
-\def\exdent{\parsearg\exdentyyy}
-\def\exdentyyy #1{{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}}
+\parseargdef\exdent{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}
% This defn is used inside nofill environments such as @example.
-\def\nofillexdent{\parsearg\nofillexdentyyy}
-\def\nofillexdentyyy #1{{\advance \leftskip by -\exdentamount
-\leftline{\hskip\leftskip{\rm#1}}}}
+\parseargdef\nofillexdent{{\advance \leftskip by -\exdentamount
+ \leftline{\hskip\leftskip{\rm#1}}}}
% @inmargin{WHICH}{TEXT} puts TEXT in the WHICH margin next to the current
% paragraph. For more general purposes, use the \margin insertion
@@ -775,10 +852,10 @@ where each line of input produces a line of output.}
% @inmargin{TEXT [, RIGHT-TEXT]}
% (if RIGHT-TEXT is given, use TEXT for left page, RIGHT-TEXT for right;
% else use TEXT for both).
-%
+%
\def\inmargin#1{\parseinmargin #1,,\finish}
\def\parseinmargin#1,#2,#3\finish{% not perfect, but better than nothing.
- \setbox0 = \hbox{\ignorespaces #2}%
+ \setbox0 = \hbox{\ignorespaces #2}%
\ifdim\wd0 > 0pt
\def\lefttext{#1}% have both texts
\def\righttext{#2}%
@@ -796,8 +873,19 @@ where each line of input produces a line of output.}
}
% @include file insert text of that file as input.
-% Allow normal characters that we make active in the argument (a file name).
-\def\include{\begingroup
+%
+\def\include{\parseargusing\filenamecatcodes\includezzz}
+\def\includezzz#1{%
+ \pushthisfilestack
+ \def\thisfile{#1}%
+ {%
+ \makevalueexpandable
+ \def\temp{\input #1 }%
+ \expandafter
+ }\temp
+ \popthisfilestack
+}
+\def\filenamecatcodes{%
\catcode`\\=\other
\catcode`~=\other
\catcode`^=\other
@@ -806,33 +894,50 @@ where each line of input produces a line of output.}
\catcode`<=\other
\catcode`>=\other
\catcode`+=\other
- \parsearg\includezzz}
-% Restore active chars for included file.
-\def\includezzz#1{\endgroup\begingroup
- % Read the included file in a group so nested @include's work.
- \def\thisfile{#1}%
- \let\value=\expandablevalue
- \input\thisfile
-\endgroup}
+ \catcode`-=\other
+}
+
+\def\pushthisfilestack{%
+ \expandafter\pushthisfilestackX\popthisfilestack\StackTerm
+}
+\def\pushthisfilestackX{%
+ \expandafter\pushthisfilestackY\thisfile\StackTerm
+}
+\def\pushthisfilestackY #1\StackTerm #2\StackTerm {%
+ \gdef\popthisfilestack{\gdef\thisfile{#1}\gdef\popthisfilestack{#2}}%
+}
+
+\def\popthisfilestack{\errthisfilestackempty}
+\def\errthisfilestackempty{\errmessage{Internal error:
+ the stack of filenames is empty.}}
\def\thisfile{}
% @center line
% outputs that line, centered.
%
-\def\center{\parsearg\docenter}
-\def\docenter#1{{%
- \ifhmode \hfil\break \fi
- \advance\hsize by -\leftskip
- \advance\hsize by -\rightskip
- \line{\hfil \ignorespaces#1\unskip \hfil}%
- \ifhmode \break \fi
-}}
+\parseargdef\center{%
+ \ifhmode
+ \let\next\centerH
+ \else
+ \let\next\centerV
+ \fi
+ \next{\hfil \ignorespaces#1\unskip \hfil}%
+}
+\def\centerH#1{%
+ {%
+ \hfil\break
+ \advance\hsize by -\leftskip
+ \advance\hsize by -\rightskip
+ \line{#1}%
+ \break
+ }%
+}
+\def\centerV#1{\line{\kern\leftskip #1\kern\rightskip}}
% @sp n outputs n lines of vertical space
-\def\sp{\parsearg\spxxx}
-\def\spxxx #1{\vskip #1\baselineskip}
+\parseargdef\sp{\vskip #1\baselineskip}
% @comment ...line which is ignored...
% @c is the same as @comment
@@ -847,13 +952,13 @@ where each line of input produces a line of output.}
% @paragraphindent NCHARS
% We'll use ems for NCHARS, close enough.
-% We cannot implement @paragraphindent asis, though.
-%
+% NCHARS can also be the word `asis' or `none'.
+% We cannot feasibly implement @paragraphindent asis, though.
+%
\def\asisword{asis} % no translation, these are keywords
\def\noneword{none}
%
-\def\paragraphindent{\parsearg\doparagraphindent}
-\def\doparagraphindent#1{%
+\parseargdef\paragraphindent{%
\def\temp{#1}%
\ifx\temp\asisword
\else
@@ -870,8 +975,7 @@ where each line of input produces a line of output.}
% We'll use ems for NCHARS like @paragraphindent.
% It seems @exampleindent asis isn't necessary, but
% I preserve it to make it similar to @paragraphindent.
-\def\exampleindent{\parsearg\doexampleindent}
-\def\doexampleindent#1{%
+\parseargdef\exampleindent{%
\def\temp{#1}%
\ifx\temp\asisword
\else
@@ -883,48 +987,97 @@ where each line of input produces a line of output.}
\fi
}
+% @firstparagraphindent WORD
+% If WORD is `none', then suppress indentation of the first paragraph
+% after a section heading. If WORD is `insert', then do indent at such
+% paragraphs.
+%
+% The paragraph indentation is suppressed or not by calling
+% \suppressfirstparagraphindent, which the sectioning commands do.
+% We switch the definition of this back and forth according to WORD.
+% By default, we suppress indentation.
+%
+\def\suppressfirstparagraphindent{\dosuppressfirstparagraphindent}
+\def\insertword{insert}
+%
+\parseargdef\firstparagraphindent{%
+ \def\temp{#1}%
+ \ifx\temp\noneword
+ \let\suppressfirstparagraphindent = \dosuppressfirstparagraphindent
+ \else\ifx\temp\insertword
+ \let\suppressfirstparagraphindent = \relax
+ \else
+ \errhelp = \EMsimple
+ \errmessage{Unknown @firstparagraphindent option `\temp'}%
+ \fi\fi
+}
+
+% Here is how we actually suppress indentation. Redefine \everypar to
+% \kern backwards by \parindent, and then reset itself to empty.
+%
+% We also make \indent itself not actually do anything until the next
+% paragraph.
+%
+\gdef\dosuppressfirstparagraphindent{%
+ \gdef\indent{%
+ \restorefirstparagraphindent
+ \indent
+ }%
+ \gdef\noindent{%
+ \restorefirstparagraphindent
+ \noindent
+ }%
+ \global\everypar = {%
+ \kern -\parindent
+ \restorefirstparagraphindent
+ }%
+}
+
+\gdef\restorefirstparagraphindent{%
+ \global \let \indent = \ptexindent
+ \global \let \noindent = \ptexnoindent
+ \global \everypar = {}%
+}
+
+
% @asis just yields its argument. Used with @table, for example.
%
\def\asis#1{#1}
% @math outputs its argument in math mode.
-% We don't use $'s directly in the definition of \math because we need
-% to set catcodes according to plain TeX first, to allow for subscripts,
-% superscripts, special math chars, etc.
-%
-\let\implicitmath = $%$ font-lock fix
%
% One complication: _ usually means subscripts, but it could also mean
% an actual _ character, as in @math{@var{some_variable} + 1}. So make
-% _ within @math be active (mathcode "8000), and distinguish by seeing
-% if the current family is \slfam, which is what @var uses.
-%
-{\catcode\underChar = \active
-\gdef\mathunderscore{%
- \catcode\underChar=\active
- \def_{\ifnum\fam=\slfam \_\else\sb\fi}%
-}}
-%
+% _ active, and distinguish by seeing if the current family is \slfam,
+% which is what @var uses.
+{
+ \catcode\underChar = \active
+ \gdef\mathunderscore{%
+ \catcode\underChar=\active
+ \def_{\ifnum\fam=\slfam \_\else\sb\fi}%
+ }
+}
% Another complication: we want \\ (and @\) to output a \ character.
% FYI, plain.tex uses \\ as a temporary control sequence (why?), but
% this is not advertised and we don't care. Texinfo does not
% otherwise define @\.
-%
+%
% The \mathchar is class=0=ordinary, family=7=ttfam, position=5C=\.
\def\mathbackslash{\ifnum\fam=\ttfam \mathchar"075C \else\backslash \fi}
%
\def\math{%
\tex
- \mathcode`\_="8000 \mathunderscore
+ \mathunderscore
\let\\ = \mathbackslash
\mathactive
- \implicitmath\finishmath}
-\def\finishmath#1{#1\implicitmath\Etex}
+ $\finishmath
+}
+\def\finishmath#1{#1$\endgroup} % Close the group opened by \tex.
% Some active characters (such as <) are spaced differently in math.
-% We have to reset their definitions in case the @math was an
-% argument to a command which set the catcodes (such as @item or @section).
-%
+% We have to reset their definitions in case the @math was an argument
+% to a command which sets the catcodes (such as @item or @section).
+%
{
\catcode`^ = \active
\catcode`< = \active
@@ -939,8 +1092,33 @@ where each line of input produces a line of output.}
}
% @bullet and @minus need the same treatment as @math, just above.
-\def\bullet{\implicitmath\ptexbullet\implicitmath}
-\def\minus{\implicitmath-\implicitmath}
+\def\bullet{$\ptexbullet$}
+\def\minus{$-$}
+
+% @dots{} outputs an ellipsis using the current font.
+% We do .5em per period so that it has the same spacing in a typewriter
+% font as three actual period characters.
+%
+\def\dots{%
+ \leavevmode
+ \hbox to 1.5em{%
+ \hskip 0pt plus 0.25fil
+ .\hfil.\hfil.%
+ \hskip 0pt plus 0.5fil
+ }%
+}
+
+% @enddots{} is an end-of-sentence ellipsis.
+%
+\def\enddots{%
+ \dots
+ \spacefactor=\endofsentencespacefactor
+}
+
+% @comma{} is so commas can be inserted into text without messing up
+% Texinfo's parsing.
+%
+\let\comma = ,
% @refill is a no-op.
\let\refill=\relax
@@ -956,20 +1134,20 @@ where each line of input produces a line of output.}
% So open here the files we need to have open while reading the input.
% This makes it possible to make a .fmt file for texinfo.
\def\setfilename{%
+ \fixbackslash % Turn off hack to swallow `\input texinfo'.
\iflinks
- \readauxfile
+ \tryauxfile
+ % Open the new aux file. TeX will close it automatically at exit.
+ \immediate\openout\auxfile=\jobname.aux
\fi % \openindices needs to do some work in any case.
\openindices
- \fixbackslash % Turn off hack to swallow `\input texinfo'.
- \global\let\setfilename=\comment % Ignore extra @setfilename cmds.
+ \let\setfilename=\comment % Ignore extra @setfilename cmds.
%
% If texinfo.cnf is present on the system, read it.
% Useful for site-wide @afourpaper, etc.
- % Just to be on the safe side, close the input stream before the \input.
\openin 1 texinfo.cnf
- \ifeof1 \let\temp=\relax \else \def\temp{\input texinfo.cnf }\fi
- \closein1
- \temp
+ \ifeof 1 \else \input texinfo.cnf \fi
+ \closein 1
%
\comment % Ignore the actual filename.
}
@@ -1005,17 +1183,78 @@ where each line of input produces a line of output.}
\newif\ifpdf
\newif\ifpdfmakepagedest
+% when pdftex is run in dvi mode, \pdfoutput is defined (so \pdfoutput=1
+% can be set). So we test for \relax and 0 as well as \undefined,
+% borrowed from ifpdf.sty.
\ifx\pdfoutput\undefined
- \pdffalse
- \let\pdfmkdest = \gobble
- \let\pdfurl = \gobble
- \let\endlink = \relax
- \let\linkcolor = \relax
- \let\pdfmakeoutlines = \relax
\else
- \pdftrue
- \pdfoutput = 1
+ \ifx\pdfoutput\relax
+ \else
+ \ifcase\pdfoutput
+ \else
+ \pdftrue
+ \fi
+ \fi
+\fi
+
+% PDF uses PostScript string constants for the names of xref targets, to
+% for display in the outlines, and in other places. Thus, we have to
+% double any backslashes. Otherwise, a name like "\node" will be
+% interpreted as a newline (\n), followed by o, d, e. Not good.
+% http://www.ntg.nl/pipermail/ntg-pdftex/2004-July/000654.html
+% (and related messages, the final outcome is that it is up to the TeX
+% user to double the backslashes and otherwise make the string valid, so
+% that's we do).
+
+% double active backslashes.
+%
+{\catcode`\@=0 \catcode`\\=\active
+ @gdef@activebackslash{@catcode`@\=@active @otherbackslash}
+ @gdef@activebackslashdouble{%
+ @catcode@backChar=@active
+ @let\=@doublebackslash}
+}
+
+% To handle parens, we must adopt a different approach, since parens are
+% not active characters. hyperref.dtx (which has the same problem as
+% us) handles it with this amazing macro to replace tokens. I've
+% tinkered with it a little for texinfo, but it's definitely from there.
+%
+% #1 is the tokens to replace.
+% #2 is the replacement.
+% #3 is the control sequence with the string.
+%
+\def\HyPsdSubst#1#2#3{%
+ \def\HyPsdReplace##1#1##2\END{%
+ ##1%
+ \ifx\\##2\\%
+ \else
+ #2%
+ \HyReturnAfterFi{%
+ \HyPsdReplace##2\END
+ }%
+ \fi
+ }%
+ \xdef#3{\expandafter\HyPsdReplace#3#1\END}%
+}
+\long\def\HyReturnAfterFi#1\fi{\fi#1}
+
+% #1 is a control sequence in which to do the replacements.
+\def\backslashparens#1{%
+ \xdef#1{#1}% redefine it as its expansion; the definition is simply
+ % \lastnode when called from \setref -> \pdfmkdest.
+ \HyPsdSubst{(}{\backslashlparen}{#1}%
+ \HyPsdSubst{)}{\backslashrparen}{#1}%
+}
+
+{\catcode\exclamChar = 0 \catcode\backChar = \other
+ !gdef!backslashlparen{\(}%
+ !gdef!backslashrparen{\)}%
+}
+
+\ifpdf
\input pdfcolor
+ \pdfcatalog{/PageMode /UseOutlines}%
\def\dopdfimage#1#2#3{%
\def\imagewidth{#2}%
\def\imageheight{#3}%
@@ -1036,8 +1275,19 @@ where each line of input produces a line of output.}
\ifnum\pdftexversion < 14 \else
\pdfrefximage \pdflastximage
\fi}
- \def\pdfmkdest#1{{\normalturnoffactive \pdfdest name{#1} xyz}}
- \def\pdfmkpgn#1{#1}
+ \def\pdfmkdest#1{{%
+ % We have to set dummies so commands such as @code, and characters
+ % such as \, aren't expanded when present in a section title.
+ \atdummies
+ \activebackslashdouble
+ \def\pdfdestname{#1}%
+ \backslashparens\pdfdestname
+ \pdfdest name{\pdfdestname} xyz%
+ }}%
+ %
+ % used to mark target names; must be expandable.
+ \def\pdfmkpgn#1{#1}%
+ %
\let\linkcolor = \Blue % was Cyan, but that seems light?
\def\endlink{\Black\pdfendlink}
% Adding outlines to PDF; macros for calculating structure of outlines
@@ -1045,79 +1295,106 @@ where each line of input produces a line of output.}
\def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
\else \csname#1\endcsname \fi}
\def\advancenumber#1{\tempnum=\expnumber{#1}\relax
- \advance\tempnum by1
+ \advance\tempnum by 1
\expandafter\xdef\csname#1\endcsname{\the\tempnum}}
- \def\pdfmakeoutlines{{%
- \openin 1 \jobname.toc
- \ifeof 1\else\begingroup
- \closein 1
- % Thanh's hack / proper braces in bookmarks
+ %
+ % #1 is the section text, which is what will be displayed in the
+ % outline by the pdf viewer. #2 is the pdf expression for the number
+ % of subentries (or empty, for subsubsections). #3 is the node text,
+ % which might be empty if this toc entry had no corresponding node.
+ % #4 is the page number
+ %
+ \def\dopdfoutline#1#2#3#4{%
+ % Generate a link to the node text if that exists; else, use the
+ % page number. We could generate a destination for the section
+ % text in the case where a section has no node, but it doesn't
+ % seem worth the trouble, since most documents are normally structured.
+ \def\pdfoutlinedest{#3}%
+ \ifx\pdfoutlinedest\empty
+ \def\pdfoutlinedest{#4}%
+ \else
+ % Doubled backslashes in the name.
+ {\activebackslashdouble \xdef\pdfoutlinedest{#3}%
+ \backslashparens\pdfoutlinedest}%
+ \fi
+ %
+ % Also double the backslashes in the display string.
+ {\activebackslashdouble \xdef\pdfoutlinetext{#1}%
+ \backslashparens\pdfoutlinetext}%
+ %
+ \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{\pdfoutlinetext}%
+ }
+ %
+ \def\pdfmakeoutlines{%
+ \begingroup
+ % Thanh's hack / proper braces in bookmarks
\edef\mylbrace{\iftrue \string{\else}\fi}\let\{=\mylbrace
\edef\myrbrace{\iffalse{\else\string}\fi}\let\}=\myrbrace
%
- \def\chapentry ##1##2##3{}
- \def\secentry ##1##2##3##4{\advancenumber{chap##2}}
- \def\subsecentry ##1##2##3##4##5{\advancenumber{sec##2.##3}}
- \def\subsubsecentry ##1##2##3##4##5##6{\advancenumber{subsec##2.##3.##4}}
- \let\appendixentry = \chapentry
- \let\unnumbchapentry = \chapentry
- \let\unnumbsecentry = \secentry
- \let\unnumbsubsecentry = \subsecentry
- \let\unnumbsubsubsecentry = \subsubsecentry
- \input \jobname.toc
- \def\chapentry ##1##2##3{%
- \pdfoutline goto name{\pdfmkpgn{##3}}count-\expnumber{chap##2}{##1}}
- \def\secentry ##1##2##3##4{%
- \pdfoutline goto name{\pdfmkpgn{##4}}count-\expnumber{sec##2.##3}{##1}}
- \def\subsecentry ##1##2##3##4##5{%
- \pdfoutline goto name{\pdfmkpgn{##5}}count-\expnumber{subsec##2.##3.##4}{##1}}
- \def\subsubsecentry ##1##2##3##4##5##6{%
- \pdfoutline goto name{\pdfmkpgn{##6}}{##1}}
- \let\appendixentry = \chapentry
- \let\unnumbchapentry = \chapentry
- \let\unnumbsecentry = \secentry
- \let\unnumbsubsecentry = \subsecentry
- \let\unnumbsubsubsecentry = \subsubsecentry
+ % Read toc silently, to get counts of subentries for \pdfoutline.
+ \def\numchapentry##1##2##3##4{%
+ \def\thischapnum{##2}%
+ \def\thissecnum{0}%
+ \def\thissubsecnum{0}%
+ }%
+ \def\numsecentry##1##2##3##4{%
+ \advancenumber{chap\thischapnum}%
+ \def\thissecnum{##2}%
+ \def\thissubsecnum{0}%
+ }%
+ \def\numsubsecentry##1##2##3##4{%
+ \advancenumber{sec\thissecnum}%
+ \def\thissubsecnum{##2}%
+ }%
+ \def\numsubsubsecentry##1##2##3##4{%
+ \advancenumber{subsec\thissubsecnum}%
+ }%
+ \def\thischapnum{0}%
+ \def\thissecnum{0}%
+ \def\thissubsecnum{0}%
+ %
+ % use \def rather than \let here because we redefine \chapentry et
+ % al. a second time, below.
+ \def\appentry{\numchapentry}%
+ \def\appsecentry{\numsecentry}%
+ \def\appsubsecentry{\numsubsecentry}%
+ \def\appsubsubsecentry{\numsubsubsecentry}%
+ \def\unnchapentry{\numchapentry}%
+ \def\unnsecentry{\numsecentry}%
+ \def\unnsubsecentry{\numsubsecentry}%
+ \def\unnsubsubsecentry{\numsubsubsecentry}%
+ \readdatafile{toc}%
%
- % Make special characters normal for writing to the pdf file.
- %
+ % Read toc second time, this time actually producing the outlines.
+ % The `-' means take the \expnumber as the absolute number of
+ % subentries, which we calculated on our first read of the .toc above.
+ %
+ % We use the node names as the destinations.
+ \def\numchapentry##1##2##3##4{%
+ \dopdfoutline{##1}{count-\expnumber{chap##2}}{##3}{##4}}%
+ \def\numsecentry##1##2##3##4{%
+ \dopdfoutline{##1}{count-\expnumber{sec##2}}{##3}{##4}}%
+ \def\numsubsecentry##1##2##3##4{%
+ \dopdfoutline{##1}{count-\expnumber{subsec##2}}{##3}{##4}}%
+ \def\numsubsubsecentry##1##2##3##4{% count is always zero
+ \dopdfoutline{##1}{}{##3}{##4}}%
+ %
+ % PDF outlines are displayed using system fonts, instead of
+ % document fonts. Therefore we cannot use special characters,
+ % since the encoding is unknown. For example, the eogonek from
+ % Latin 2 (0xea) gets translated to a | character. Info from
+ % Staszek Wawrykiewicz, 19 Jan 2004 04:09:24 +0100.
+ %
+ % xx to do this right, we have to translate 8-bit characters to
+ % their "best" equivalent, based on the @documentencoding. Right
+ % now, I guess we'll just let the pdf reader have its way.
\indexnofonts
- \let\tt=\relax
- \turnoffactive
+ \setupdatafile
+ \activebackslash
\input \jobname.toc
- \endgroup\fi
- }}
- \def\makelinks #1,{%
- \def\params{#1}\def\E{END}%
- \ifx\params\E
- \let\nextmakelinks=\relax
- \else
- \let\nextmakelinks=\makelinks
- \ifnum\lnkcount>0,\fi
- \picknum{#1}%
- \startlink attr{/Border [0 0 0]}
- goto name{\pdfmkpgn{\the\pgn}}%
- \linkcolor #1%
- \advance\lnkcount by 1%
- \endlink
- \fi
- \nextmakelinks
- }
- \def\picknum#1{\expandafter\pn#1}
- \def\pn#1{%
- \def\p{#1}%
- \ifx\p\lbrace
- \let\nextpn=\ppn
- \else
- \let\nextpn=\ppnn
- \def\first{#1}
- \fi
- \nextpn
+ \endgroup
}
- \def\ppn#1{\pgn=#1\gobble}
- \def\ppnn{\pgn=\first}
- \def\pdfmklnk#1{\lnkcount=0\makelinks #1,END,}
- \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
+ %
\def\skipspaces#1{\def\PP{#1}\def\D{|}%
\ifx\PP\D\let\nextsp\relax
\else\let\nextsp\skipspaces
@@ -1135,22 +1412,21 @@ where each line of input produces a line of output.}
\def\pdfurl#1{%
\begingroup
\normalturnoffactive\def\@{@}%
- \let\value=\expandablevalue
+ \makevalueexpandable
\leavevmode\Red
\startlink attr{/Border [0 0 0]}%
user{/Subtype /Link /A << /S /URI /URI (#1) >>}%
- % #1
\endgroup}
\def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
\def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
\def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
\def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
\def\maketoks{%
- \expandafter\poptoks\the\toksA|ENDTOKS|
+ \expandafter\poptoks\the\toksA|ENDTOKS|\relax
\ifx\first0\adn0
\else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
\else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
- \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
+ \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
\else
\ifnum0=\countA\else\makelink\fi
\ifx\first.\let\next=\done\else
@@ -1166,20 +1442,44 @@ where each line of input produces a line of output.}
\startlink attr{/Border [0 0 0]} goto name{\pdfmkpgn{#1}}
\linkcolor #1\endlink}
\def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
-\fi % \ifx\pdfoutput
+\else
+ \let\pdfmkdest = \gobble
+ \let\pdfurl = \gobble
+ \let\endlink = \relax
+ \let\linkcolor = \relax
+ \let\pdfmakeoutlines = \relax
+\fi % \ifx\pdfoutput
\message{fonts,}
-% Font-change commands.
+
+% Change the current font style to #1, remembering it in \curfontstyle.
+% For now, we do not accumulate font styles: @b{@i{foo}} prints foo in
+% italics, not bold italics.
+%
+\def\setfontstyle#1{%
+ \def\curfontstyle{#1}% not as a control sequence, because we are \edef'd.
+ \csname ten#1\endcsname % change the current font
+}
+
+% Select #1 fonts with the current style.
+%
+\def\selectfonts#1{\csname #1fonts\endcsname \csname\curfontstyle\endcsname}
+
+\def\rm{\fam=0 \setfontstyle{rm}}
+\def\it{\fam=\itfam \setfontstyle{it}}
+\def\sl{\fam=\slfam \setfontstyle{sl}}
+\def\bf{\fam=\bffam \setfontstyle{bf}}\def\bfstylename{bf}
+\def\tt{\fam=\ttfam \setfontstyle{tt}}
% Texinfo sort of supports the sans serif font style, which plain TeX does not.
-% So we set up a \sf analogous to plain's \rm, etc.
+% So we set up a \sf.
\newfam\sffam
-\def\sf{\fam=\sffam \tensf}
+\def\sf{\fam=\sffam \setfontstyle{sf}}
\let\li = \sf % Sometimes we call it \li, not \sf.
-% We don't need math for this one.
-\def\ttsl{\tenttsl}
+% We don't need math for this font style.
+\def\ttsl{\setfontstyle{ttsl}}
% Default leading.
\newdimen\textleading \textleading = 13.2pt
@@ -1230,21 +1530,11 @@ where each line of input produces a line of output.}
\def\scshape{csc}
\def\scbshape{csc}
-\newcount\mainmagstep
-\ifx\bigger\relax
- % not really supported.
- \mainmagstep=\magstep1
- \setfont\textrm\rmshape{12}{1000}
- \setfont\texttt\ttshape{12}{1000}
-\else
- \mainmagstep=\magstephalf
- \setfont\textrm\rmshape{10}{\mainmagstep}
- \setfont\texttt\ttshape{10}{\mainmagstep}
-\fi
-% Instead of cmb10, you may want to use cmbx10.
-% cmbx10 is a prettier font on its own, but cmb10
-% looks better when embedded in a line with cmr10
-% (in Bob's opinion).
+% Text fonts (11.2pt, magstep1).
+\def\textnominalsize{11pt}
+\edef\mainmagstep{\magstephalf}
+\setfont\textrm\rmshape{10}{\mainmagstep}
+\setfont\texttt\ttshape{10}{\mainmagstep}
\setfont\textbf\bfshape{10}{\mainmagstep}
\setfont\textit\itshape{10}{\mainmagstep}
\setfont\textsl\slshape{10}{\mainmagstep}
@@ -1254,12 +1544,14 @@ where each line of input produces a line of output.}
\font\texti=cmmi10 scaled \mainmagstep
\font\textsy=cmsy10 scaled \mainmagstep
-% A few fonts for @defun, etc.
-\setfont\defbf\bxshape{10}{\magstep1} %was 1314
+% A few fonts for @defun names and args.
+\setfont\defbf\bfshape{10}{\magstep1}
\setfont\deftt\ttshape{10}{\magstep1}
-\def\df{\let\tentt=\deftt \let\tenbf = \defbf \bf}
+\setfont\defttsl\ttslshape{10}{\magstep1}
+\def\df{\let\tentt=\deftt \let\tenbf = \defbf \let\tenttsl=\defttsl \bf}
% Fonts for indices, footnotes, small examples (9pt).
+\def\smallnominalsize{9pt}
\setfont\smallrm\rmshape{9}{1000}
\setfont\smalltt\ttshape{9}{1000}
\setfont\smallbf\bfshape{10}{900}
@@ -1272,6 +1564,7 @@ where each line of input produces a line of output.}
\font\smallsy=cmsy9
% Fonts for small examples (8pt).
+\def\smallernominalsize{8pt}
\setfont\smallerrm\rmshape{8}{1000}
\setfont\smallertt\ttshape{8}{1000}
\setfont\smallerbf\bfshape{10}{800}
@@ -1283,7 +1576,8 @@ where each line of input produces a line of output.}
\font\smalleri=cmmi8
\font\smallersy=cmsy8
-% Fonts for title page:
+% Fonts for title page (20.4pt):
+\def\titlenominalsize{20pt}
\setfont\titlerm\rmbshape{12}{\magstep3}
\setfont\titleit\itbshape{10}{\magstep4}
\setfont\titlesl\slbshape{10}{\magstep4}
@@ -1298,6 +1592,7 @@ where each line of input produces a line of output.}
\def\authortt{\sectt}
% Chapter (and unnumbered) fonts (17.28pt).
+\def\chapnominalsize{17pt}
\setfont\chaprm\rmbshape{12}{\magstep2}
\setfont\chapit\itbshape{10}{\magstep3}
\setfont\chapsl\slbshape{10}{\magstep3}
@@ -1310,6 +1605,7 @@ where each line of input produces a line of output.}
\font\chapsy=cmsy10 scaled \magstep3
% Section fonts (14.4pt).
+\def\secnominalsize{14pt}
\setfont\secrm\rmbshape{12}{\magstep1}
\setfont\secit\itbshape{10}{\magstep2}
\setfont\secsl\slbshape{10}{\magstep2}
@@ -1322,6 +1618,7 @@ where each line of input produces a line of output.}
\font\secsy=cmsy10 scaled \magstep2
% Subsection fonts (13.15pt).
+\def\ssecnominalsize{13pt}
\setfont\ssecrm\rmbshape{12}{\magstephalf}
\setfont\ssecit\itbshape{10}{1315}
\setfont\ssecsl\slbshape{10}{1315}
@@ -1329,11 +1626,22 @@ where each line of input produces a line of output.}
\setfont\ssecttsl\ttslshape{10}{1315}
\setfont\ssecsf\sfbshape{12}{\magstephalf}
\let\ssecbf\ssecrm
-\setfont\ssecsc\scbshape{10}{\magstep1}
+\setfont\ssecsc\scbshape{10}{1315}
\font\sseci=cmmi12 scaled \magstephalf
\font\ssecsy=cmsy10 scaled 1315
-% The smallcaps and symbol fonts should actually be scaled \magstep1.5,
-% but that is not a standard magnification.
+
+% Reduced fonts for @acro in text (10pt).
+\def\reducednominalsize{10pt}
+\setfont\reducedrm\rmshape{10}{1000}
+\setfont\reducedtt\ttshape{10}{1000}
+\setfont\reducedbf\bfshape{10}{1000}
+\setfont\reducedit\itshape{10}{1000}
+\setfont\reducedsl\slshape{10}{1000}
+\setfont\reducedsf\sfshape{10}{1000}
+\setfont\reducedsc\scshape{10}{1000}
+\setfont\reducedttsl\ttslshape{10}{1000}
+\font\reducedi=cmmi10
+\font\reducedsy=cmsy10
% In order for the font changes to affect most math symbols and letters,
% we have to define the \textfont of the standard families. Since
@@ -1348,50 +1656,81 @@ where each line of input produces a line of output.}
}
% The font-changing commands redefine the meanings of \tenSTYLE, instead
-% of just \STYLE. We do this so that font changes will continue to work
-% in math mode, where it is the current \fam that is relevant in most
-% cases, not the current font. Plain TeX does \def\bf{\fam=\bffam
-% \tenbf}, for example. By redefining \tenbf, we obviate the need to
-% redefine \bf itself.
+% of just \STYLE. We do this because \STYLE needs to also set the
+% current \fam for math mode. Our \STYLE (e.g., \rm) commands hardwire
+% \tenSTYLE to set the current font.
+%
+% Each font-changing command also sets the names \lsize (one size lower)
+% and \lllsize (three sizes lower). These relative commands are used in
+% the LaTeX logo and acronyms.
+%
+% This all needs generalizing, badly.
+%
\def\textfonts{%
\let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl
\let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc
- \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy \let\tenttsl=\textttsl
+ \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy
+ \let\tenttsl=\textttsl
+ \def\curfontsize{text}%
+ \def\lsize{reduced}\def\lllsize{smaller}%
\resetmathfonts \setleading{\textleading}}
\def\titlefonts{%
\let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl
\let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc
\let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy
\let\tenttsl=\titlettsl
+ \def\curfontsize{title}%
+ \def\lsize{chap}\def\lllsize{subsec}%
\resetmathfonts \setleading{25pt}}
\def\titlefont#1{{\titlefonts\rm #1}}
\def\chapfonts{%
\let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl
\let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc
- \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy \let\tenttsl=\chapttsl
+ \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy
+ \let\tenttsl=\chapttsl
+ \def\curfontsize{chap}%
+ \def\lsize{sec}\def\lllsize{text}%
\resetmathfonts \setleading{19pt}}
\def\secfonts{%
\let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl
\let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc
- \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy \let\tenttsl=\secttsl
+ \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy
+ \let\tenttsl=\secttsl
+ \def\curfontsize{sec}%
+ \def\lsize{subsec}\def\lllsize{reduced}%
\resetmathfonts \setleading{16pt}}
\def\subsecfonts{%
\let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl
\let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc
- \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy \let\tenttsl=\ssecttsl
+ \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy
+ \let\tenttsl=\ssecttsl
+ \def\curfontsize{ssec}%
+ \def\lsize{text}\def\lllsize{small}%
\resetmathfonts \setleading{15pt}}
-\let\subsubsecfonts = \subsecfonts % Maybe make sssec fonts scaled magstephalf?
+\let\subsubsecfonts = \subsecfonts
+\def\reducedfonts{%
+ \let\tenrm=\reducedrm \let\tenit=\reducedit \let\tensl=\reducedsl
+ \let\tenbf=\reducedbf \let\tentt=\reducedtt \let\reducedcaps=\reducedsc
+ \let\tensf=\reducedsf \let\teni=\reducedi \let\tensy=\reducedsy
+ \let\tenttsl=\reducedttsl
+ \def\curfontsize{reduced}%
+ \def\lsize{small}\def\lllsize{smaller}%
+ \resetmathfonts \setleading{10.5pt}}
\def\smallfonts{%
\let\tenrm=\smallrm \let\tenit=\smallit \let\tensl=\smallsl
\let\tenbf=\smallbf \let\tentt=\smalltt \let\smallcaps=\smallsc
\let\tensf=\smallsf \let\teni=\smalli \let\tensy=\smallsy
\let\tenttsl=\smallttsl
+ \def\curfontsize{small}%
+ \def\lsize{smaller}\def\lllsize{smaller}%
\resetmathfonts \setleading{10.5pt}}
\def\smallerfonts{%
\let\tenrm=\smallerrm \let\tenit=\smallerit \let\tensl=\smallersl
\let\tenbf=\smallerbf \let\tentt=\smallertt \let\smallcaps=\smallersc
\let\tensf=\smallersf \let\teni=\smalleri \let\tensy=\smallersy
\let\tenttsl=\smallerttsl
+ \def\curfontsize{smaller}%
+ \def\lsize{smaller}\def\lllsize{smaller}%
\resetmathfonts \setleading{9.5pt}}
% Set the fonts to use with the @small... environments.
@@ -1400,22 +1739,21 @@ where each line of input produces a line of output.}
% About \smallexamplefonts. If we use \smallfonts (9pt), @smallexample
% can fit this many characters:
% 8.5x11=86 smallbook=72 a4=90 a5=69
-% If we use \smallerfonts (8pt), then we can fit this many characters:
+% If we use \scriptfonts (8pt), then we can fit this many characters:
% 8.5x11=90+ smallbook=80 a4=90+ a5=77
% For me, subjectively, the few extra characters that fit aren't worth
% the additional smallness of 8pt. So I'm making the default 9pt.
-%
+%
% By the way, for comparison, here's what fits with @example (10pt):
% 8.5x11=71 smallbook=60 a4=75 a5=58
-%
-% I wish we used A4 paper on this side of the Atlantic.
-%
+%
+% I wish the USA used A4 paper.
% --karl, 24jan03.
% Set up the default fonts, so we can use them for creating boxes.
%
-\textfonts
+\textfonts \rm
% Define these so they can be easily changed for other fonts.
\def\angleleft{$\langle$}
@@ -1426,7 +1764,7 @@ where each line of input produces a line of output.}
% Fonts for short table of contents.
\setfont\shortcontrm\rmshape{12}{1000}
-\setfont\shortcontbf\bxshape{12}{1000}
+\setfont\shortcontbf\bfshape{10}{\magstep1} % no cmb12
\setfont\shortcontsl\slshape{12}{1000}
\setfont\shortconttt\ttshape{12}{1000}
@@ -1435,19 +1773,32 @@ where each line of input produces a line of output.}
% \smartitalic{ARG} outputs arg in italics, followed by an italic correction
% unless the following character is such as not to need one.
-\def\smartitalicx{\ifx\next,\else\ifx\next-\else\ifx\next.\else\/\fi\fi\fi}
+\def\smartitalicx{\ifx\next,\else\ifx\next-\else\ifx\next.\else
+ \ptexslash\fi\fi\fi}
\def\smartslanted#1{{\ifusingtt\ttsl\sl #1}\futurelet\next\smartitalicx}
\def\smartitalic#1{{\ifusingtt\ttsl\it #1}\futurelet\next\smartitalicx}
+% like \smartslanted except unconditionally uses \ttsl.
+% @var is set to this for defun arguments.
+\def\ttslanted#1{{\ttsl #1}\futurelet\next\smartitalicx}
+
+% like \smartslanted except unconditionally use \sl. We never want
+% ttsl for book titles, do we?
+\def\cite#1{{\sl #1}\futurelet\next\smartitalicx}
+
\let\i=\smartitalic
+\let\slanted=\smartslanted
\let\var=\smartslanted
\let\dfn=\smartslanted
\let\emph=\smartitalic
-\let\cite=\smartslanted
+% @b, explicit bold.
\def\b#1{{\bf #1}}
\let\strong=\b
+% @sansserif, explicit sans.
+\def\sansserif#1{{\sf #1}}
+
% We can't just use \exhyphenpenalty, because that only has effect at
% the end of a paragraph. Restore normal hyphenation at the end of the
% group within which \nohyphenation is presumably called.
@@ -1458,19 +1809,25 @@ where each line of input produces a line of output.}
% Set sfcode to normal for the chars that usually have another value.
% Can't use plain's \frenchspacing because it uses the `\x notation, and
% sometimes \x has an active definition that messes things up.
-%
+%
\catcode`@=11
- \def\frenchspacing{%
+ \def\plainfrenchspacing{%
\sfcode\dotChar =\@m \sfcode\questChar=\@m \sfcode\exclamChar=\@m
\sfcode\colonChar=\@m \sfcode\semiChar =\@m \sfcode\commaChar =\@m
+ \def\endofsentencespacefactor{1000}% for @. and friends
+ }
+ \def\plainnonfrenchspacing{%
+ \sfcode`\.3000\sfcode`\?3000\sfcode`\!3000
+ \sfcode`\:2000\sfcode`\;1500\sfcode`\,1250
+ \def\endofsentencespacefactor{3000}% for @. and friends
}
\catcode`@=\other
+\def\endofsentencespacefactor{3000}% default
\def\t#1{%
- {\tt \rawbackslash \frenchspacing #1}%
+ {\tt \rawbackslash \plainfrenchspacing #1}%
\null
}
-\let\ttfont=\t
\def\samp#1{`\tclose{#1}'\null}
\setfont\keyrm\rmshape{8}{1000}
\font\keysy=cmsy9
@@ -1505,13 +1862,13 @@ where each line of input produces a line of output.}
\nohyphenation
%
\rawbackslash
- \frenchspacing
+ \plainfrenchspacing
#1%
}%
\null
}
-% We *must* turn on hyphenation at `-' and `_' in \code.
+% We *must* turn on hyphenation at `-' and `_' in @code.
% Otherwise, it is too hard to avoid overfull hboxes
% in the Emacs manual, the Library manual, etc.
@@ -1525,14 +1882,16 @@ where each line of input produces a line of output.}
\catcode`\_=\active
%
\global\def\code{\begingroup
- \catcode`\-=\active \let-\codedash
- \catcode`\_=\active \let_\codeunder
+ \catcode`\-=\active \catcode`\_=\active
+ \ifallowcodebreaks
+ \let-\codedash
+ \let_\codeunder
+ \else
+ \let-\realdash
+ \let_\realunder
+ \fi
\codex
}
- %
- % If we end up with any active - characters when handling the index,
- % just treat them as a normal -.
- \global\def\indexbreaks{\catcode`\-=\active \let-\realdash}
}
\def\realdash{-}
@@ -1550,24 +1909,45 @@ where each line of input produces a line of output.}
}
\def\codex #1{\tclose{#1}\endgroup}
+% An additional complication: the above will allow breaks after, e.g.,
+% each of the four underscores in __typeof__. This is undesirable in
+% some manuals, especially if they don't have long identifiers in
+% general. @allowcodebreaks provides a way to control this.
+%
+\newif\ifallowcodebreaks \allowcodebreakstrue
+
+\def\keywordtrue{true}
+\def\keywordfalse{false}
+
+\parseargdef\allowcodebreaks{%
+ \def\txiarg{#1}%
+ \ifx\txiarg\keywordtrue
+ \allowcodebreakstrue
+ \else\ifx\txiarg\keywordfalse
+ \allowcodebreaksfalse
+ \else
+ \errhelp = \EMsimple
+ \errmessage{Unknown @allowcodebreaks option `\txiarg'}%
+ \fi\fi
+}
+
% @kbd is like @code, except that if the argument is just one @key command,
% then @kbd has no effect.
% @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
% `example' (@kbd uses ttsl only inside of @example and friends),
% or `code' (@kbd uses normal tty font always).
-\def\kbdinputstyle{\parsearg\kbdinputstylexxx}
-\def\kbdinputstylexxx#1{%
- \def\arg{#1}%
- \ifx\arg\worddistinct
+\parseargdef\kbdinputstyle{%
+ \def\txiarg{#1}%
+ \ifx\txiarg\worddistinct
\gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
- \else\ifx\arg\wordexample
+ \else\ifx\txiarg\wordexample
\gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}%
- \else\ifx\arg\wordcode
+ \else\ifx\txiarg\wordcode
\gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}%
\else
\errhelp = \EMsimple
- \errmessage{Unknown @kbdinputstyle `\arg'}%
+ \errmessage{Unknown @kbdinputstyle option `\txiarg'}%
\fi\fi\fi
}
\def\worddistinct{distinct}
@@ -1583,8 +1963,8 @@ where each line of input produces a line of output.}
\else{\tclose{\kbdfont\look}}\fi
\else{\tclose{\kbdfont\look}}\fi}
-% For @url, @env, @command quotes seem unnecessary, so use \code.
-\let\url=\code
+% For @indicateurl, @env, @command quotes seem unnecessary, so use \code.
+\let\indicateurl=\code
\let\env=\code
\let\command=\code
@@ -1616,9 +1996,13 @@ where each line of input produces a line of output.}
\endlink
\endgroup}
+% @url synonym for @uref, since that's how everyone uses it.
+%
+\let\url=\uref
+
% rms does not like angle brackets --karl, 17may97.
% So now @email is just like @uref, unless we are pdf.
-%
+%
%\def\email#1{\angleleft{\tt #1}\angleright}
\ifpdf
\def\email#1{\doemail#1,,\finish}
@@ -1657,22 +2041,101 @@ where each line of input produces a line of output.}
\def\sc#1{{\smallcaps#1}} % smallcaps font
\def\ii#1{{\it #1}} % italic font
-% @acronym downcases the argument and prints in smallcaps.
-\def\acronym#1{{\smallcaps \lowercase{#1}}}
+% @acronym for "FBI", "NATO", and the like.
+% We print this one point size smaller, since it's intended for
+% all-uppercase.
+%
+\def\acronym#1{\doacronym #1,,\finish}
+\def\doacronym#1,#2,#3\finish{%
+ {\selectfonts\lsize #1}%
+ \def\temp{#2}%
+ \ifx\temp\empty \else
+ \space ({\unsepspaces \ignorespaces \temp \unskip})%
+ \fi
+}
-% @pounds{} is a sterling sign.
+% @abbr for "Comput. J." and the like.
+% No font change, but don't do end-of-sentence spacing.
+%
+\def\abbr#1{\doabbr #1,,\finish}
+\def\doabbr#1,#2,#3\finish{%
+ {\plainfrenchspacing #1}%
+ \def\temp{#2}%
+ \ifx\temp\empty \else
+ \space ({\unsepspaces \ignorespaces \temp \unskip})%
+ \fi
+}
+
+% @pounds{} is a sterling sign, which Knuth put in the CM italic font.
+%
\def\pounds{{\it\$}}
-% @registeredsymbol - R in a circle. For now, only works in text size;
-% we'd have to redo the font mechanism to change the \scriptstyle and
-% \scriptscriptstyle font sizes to make it look right in headings.
-% Adapted from the plain.tex definition of \copyright.
+% @euro{} comes from a separate font, depending on the current style.
+% We use the free feym* fonts from the eurosym package by Henrik
+% Theiling, which support regular, slanted, bold and bold slanted (and
+% "outlined" (blackboard board, sort of) versions, which we don't need).
+% It is available from http://www.ctan.org/tex-archive/fonts/eurosym.
+%
+% Although only regular is the truly official Euro symbol, we ignore
+% that. The Euro is designed to be slightly taller than the regular
+% font height.
+%
+% feymr - regular
+% feymo - slanted
+% feybr - bold
+% feybo - bold slanted
+%
+% There is no good (free) typewriter version, to my knowledge.
+% A feymr10 euro is ~7.3pt wide, while a normal cmtt10 char is ~5.25pt wide.
+% Hmm.
+%
+% Also doesn't work in math. Do we need to do math with euro symbols?
+% Hope not.
%
+%
+\def\euro{{\eurofont e}}
+\def\eurofont{%
+ % We set the font at each command, rather than predefining it in
+ % \textfonts and the other font-switching commands, so that
+ % installations which never need the symbol don't have to have the
+ % font installed.
+ %
+ % There is only one designed size (nominal 10pt), so we always scale
+ % that to the current nominal size.
+ %
+ % By the way, simply using "at 1em" works for cmr10 and the like, but
+ % does not work for cmbx10 and other extended/shrunken fonts.
+ %
+ \def\eurosize{\csname\curfontsize nominalsize\endcsname}%
+ %
+ \ifx\curfontstyle\bfstylename
+ % bold:
+ \font\thiseurofont = \ifusingit{feybo10}{feybr10} at \eurosize
+ \else
+ % regular:
+ \font\thiseurofont = \ifusingit{feymo10}{feymr10} at \eurosize
+ \fi
+ \thiseurofont
+}
+
+% @registeredsymbol - R in a circle. The font for the R should really
+% be smaller yet, but lllsize is the best we can do for now.
+% Adapted from the plain.tex definition of \copyright.
+%
\def\registeredsymbol{%
- $^{{\ooalign{\hfil\raise.07ex\hbox{$\scriptstyle\rm R$}\hfil\crcr\Orb}}%
+ $^{{\ooalign{\hfil\raise.07ex\hbox{\selectfonts\lllsize R}%
+ \hfil\crcr\Orb}}%
}$%
}
+% Laurent Siebenmann reports \Orb undefined with:
+% Textures 1.7.7 (preloaded format=plain 93.10.14) (68K) 16 APR 2004 02:38
+% so we'll define it if necessary.
+%
+\ifx\Orb\undefined
+\def\Orb{\mathhexbox20D}
+\fi
+
\message{page headings,}
@@ -1691,87 +2154,103 @@ where each line of input produces a line of output.}
\newif\ifsetshortcontentsaftertitlepage
\let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue
-\def\shorttitlepage{\parsearg\shorttitlepagezzz}
-\def\shorttitlepagezzz #1{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
+\parseargdef\shorttitlepage{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
\endgroup\page\hbox{}\page}
-\def\titlepage{\begingroup \parindent=0pt \textfonts
- \let\subtitlerm=\tenrm
- \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}%
- %
- \def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines
- \let\tt=\authortt}%
- %
- % Leave some space at the very top of the page.
- \vglue\titlepagetopglue
- %
- % Now you can print the title using @title.
- \def\title{\parsearg\titlezzz}%
- \def\titlezzz##1{\leftline{\titlefonts\rm ##1}
- % print a rule at the page bottom also.
- \finishedtitlepagefalse
- \vskip4pt \hrule height 4pt width \hsize \vskip4pt}%
- % No rule at page bottom unless we print one at the top with @title.
- \finishedtitlepagetrue
- %
- % Now you can put text using @subtitle.
- \def\subtitle{\parsearg\subtitlezzz}%
- \def\subtitlezzz##1{{\subtitlefont \rightline{##1}}}%
- %
- % @author should come last, but may come many times.
- \def\author{\parsearg\authorzzz}%
- \def\authorzzz##1{\ifseenauthor\else\vskip 0pt plus 1filll\seenauthortrue\fi
- {\authorfont \leftline{##1}}}%
- %
- % Most title ``pages'' are actually two pages long, with space
- % at the top of the second. We don't want the ragged left on the second.
- \let\oldpage = \page
- \def\page{%
+\envdef\titlepage{%
+ % Open one extra group, as we want to close it in the middle of \Etitlepage.
+ \begingroup
+ \parindent=0pt \textfonts
+ % Leave some space at the very top of the page.
+ \vglue\titlepagetopglue
+ % No rule at page bottom unless we print one at the top with @title.
+ \finishedtitlepagetrue
+ %
+ % Most title ``pages'' are actually two pages long, with space
+ % at the top of the second. We don't want the ragged left on the second.
+ \let\oldpage = \page
+ \def\page{%
\iffinishedtitlepage\else
- \finishtitlepage
+ \finishtitlepage
\fi
- \oldpage
\let\page = \oldpage
- \hbox{}}%
-% \def\page{\oldpage \hbox{}}
+ \page
+ \null
+ }%
}
\def\Etitlepage{%
- \iffinishedtitlepage\else
- \finishtitlepage
- \fi
- % It is important to do the page break before ending the group,
- % because the headline and footline are only empty inside the group.
- % If we use the new definition of \page, we always get a blank page
- % after the title page, which we certainly don't want.
- \oldpage
- \endgroup
- %
- % Need this before the \...aftertitlepage checks so that if they are
- % in effect the toc pages will come out with page numbers.
- \HEADINGSon
- %
- % If they want short, they certainly want long too.
- \ifsetshortcontentsaftertitlepage
- \shortcontents
- \contents
- \global\let\shortcontents = \relax
- \global\let\contents = \relax
- \fi
- %
- \ifsetcontentsaftertitlepage
- \contents
- \global\let\contents = \relax
- \global\let\shortcontents = \relax
- \fi
+ \iffinishedtitlepage\else
+ \finishtitlepage
+ \fi
+ % It is important to do the page break before ending the group,
+ % because the headline and footline are only empty inside the group.
+ % If we use the new definition of \page, we always get a blank page
+ % after the title page, which we certainly don't want.
+ \oldpage
+ \endgroup
+ %
+ % Need this before the \...aftertitlepage checks so that if they are
+ % in effect the toc pages will come out with page numbers.
+ \HEADINGSon
+ %
+ % If they want short, they certainly want long too.
+ \ifsetshortcontentsaftertitlepage
+ \shortcontents
+ \contents
+ \global\let\shortcontents = \relax
+ \global\let\contents = \relax
+ \fi
+ %
+ \ifsetcontentsaftertitlepage
+ \contents
+ \global\let\contents = \relax
+ \global\let\shortcontents = \relax
+ \fi
}
\def\finishtitlepage{%
- \vskip4pt \hrule height 2pt width \hsize
- \vskip\titlepagebottomglue
- \finishedtitlepagetrue
+ \vskip4pt \hrule height 2pt width \hsize
+ \vskip\titlepagebottomglue
+ \finishedtitlepagetrue
+}
+
+%%% Macros to be used within @titlepage:
+
+\let\subtitlerm=\tenrm
+\def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}
+
+\def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines
+ \let\tt=\authortt}
+
+\parseargdef\title{%
+ \checkenv\titlepage
+ \leftline{\titlefonts\rm #1}
+ % print a rule at the page bottom also.
+ \finishedtitlepagefalse
+ \vskip4pt \hrule height 4pt width \hsize \vskip4pt
+}
+
+\parseargdef\subtitle{%
+ \checkenv\titlepage
+ {\subtitlefont \rightline{#1}}%
+}
+
+% @author should come last, but may come many times.
+% It can also be used inside @quotation.
+%
+\parseargdef\author{%
+ \def\temp{\quotation}%
+ \ifx\thisenv\temp
+ \def\quotationauthor{#1}% printed in \Equotation.
+ \else
+ \checkenv\titlepage
+ \ifseenauthor\else \vskip 0pt plus 1filll \seenauthortrue \fi
+ {\authorfont \leftline{#1}}%
+ \fi
}
+
%%% Set up page headings and footings.
\let\thispage=\folio
@@ -1781,7 +2260,7 @@ where each line of input produces a line of output.}
\newtoks\evenfootline % footline on even pages
\newtoks\oddfootline % footline on odd pages
-% Now make Tex use those variables
+% Now make TeX use those variables
\headline={{\textfonts\rm \ifodd\pageno \the\oddheadline
\else \the\evenheadline \fi}}
\footline={{\textfonts\rm \ifodd\pageno \the\oddfootline
@@ -1795,32 +2274,27 @@ where each line of input produces a line of output.}
% @evenfooting @thisfile||
% @oddfooting ||@thisfile
-\def\evenheading{\parsearg\evenheadingxxx}
-\def\oddheading{\parsearg\oddheadingxxx}
-\def\everyheading{\parsearg\everyheadingxxx}
-
-\def\evenfooting{\parsearg\evenfootingxxx}
-\def\oddfooting{\parsearg\oddfootingxxx}
-\def\everyfooting{\parsearg\everyfootingxxx}
-
-{\catcode`\@=0 %
-\gdef\evenheadingxxx #1{\evenheadingyyy #1@|@|@|@|\finish}
-\gdef\evenheadingyyy #1@|#2@|#3@|#4\finish{%
+\def\evenheading{\parsearg\evenheadingxxx}
+\def\evenheadingxxx #1{\evenheadingyyy #1\|\|\|\|\finish}
+\def\evenheadingyyy #1\|#2\|#3\|#4\finish{%
\global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
-\gdef\oddheadingxxx #1{\oddheadingyyy #1@|@|@|@|\finish}
-\gdef\oddheadingyyy #1@|#2@|#3@|#4\finish{%
+\def\oddheading{\parsearg\oddheadingxxx}
+\def\oddheadingxxx #1{\oddheadingyyy #1\|\|\|\|\finish}
+\def\oddheadingyyy #1\|#2\|#3\|#4\finish{%
\global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
-\gdef\everyheadingxxx#1{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
+\parseargdef\everyheading{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
-\gdef\evenfootingxxx #1{\evenfootingyyy #1@|@|@|@|\finish}
-\gdef\evenfootingyyy #1@|#2@|#3@|#4\finish{%
+\def\evenfooting{\parsearg\evenfootingxxx}
+\def\evenfootingxxx #1{\evenfootingyyy #1\|\|\|\|\finish}
+\def\evenfootingyyy #1\|#2\|#3\|#4\finish{%
\global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
-\gdef\oddfootingxxx #1{\oddfootingyyy #1@|@|@|@|\finish}
-\gdef\oddfootingyyy #1@|#2@|#3@|#4\finish{%
+\def\oddfooting{\parsearg\oddfootingxxx}
+\def\oddfootingxxx #1{\oddfootingyyy #1\|\|\|\|\finish}
+\def\oddfootingyyy #1\|#2\|#3\|#4\finish{%
\global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}%
%
% Leave some space for the footline. Hopefully ok to assume
@@ -1829,9 +2303,8 @@ where each line of input produces a line of output.}
\global\advance\vsize by -\baselineskip
}
-\gdef\everyfootingxxx#1{\oddfootingxxx{#1}\evenfootingxxx{#1}}
-%
-}% unbind the catcode of @.
+\parseargdef\everyfooting{\oddfootingxxx{#1}\evenfootingxxx{#1}}
+
% @headings double turns headings on for double-sided printing.
% @headings single turns headings on for single-sided printing.
@@ -1845,7 +2318,7 @@ where each line of input produces a line of output.}
\def\headings #1 {\csname HEADINGS#1\endcsname}
-\def\HEADINGSoff{
+\def\HEADINGSoff{%
\global\evenheadline={\hfil} \global\evenfootline={\hfil}
\global\oddheadline={\hfil} \global\oddfootline={\hfil}}
\HEADINGSoff
@@ -1854,7 +2327,7 @@ where each line of input produces a line of output.}
% chapter name on inside top of right hand pages, document
% title on inside top of left hand pages, and page numbers on outside top
% edge of all pages.
-\def\HEADINGSdouble{
+\def\HEADINGSdouble{%
\global\pageno=1
\global\evenfootline={\hfil}
\global\oddfootline={\hfil}
@@ -1866,7 +2339,7 @@ where each line of input produces a line of output.}
% For single-sided printing, chapter title goes across top left of page,
% page number on top right.
-\def\HEADINGSsingle{
+\def\HEADINGSsingle{%
\global\pageno=1
\global\evenfootline={\hfil}
\global\oddfootline={\hfil}
@@ -1913,12 +2386,11 @@ where each line of input produces a line of output.}
% @settitle line... specifies the title of the document, for headings.
% It generates no output of its own.
\def\thistitle{\putwordNoTitle}
-\def\settitle{\parsearg\settitlezzz}
-\def\settitlezzz #1{\gdef\thistitle{#1}}
+\def\settitle{\parsearg{\gdef\thistitle}}
\message{tables,}
-% Tables -- @table, @ftable, @vtable, @item(x), @kitem(x), @xitem(x).
+% Tables -- @table, @ftable, @vtable, @item(x).
% default indentation of table text
\newdimen\tableindent \tableindent=.8in
@@ -1930,7 +2402,7 @@ where each line of input produces a line of output.}
% used internally for \itemindent minus \itemmargin
\newdimen\itemmax
-% Note @table, @vtable, and @vtable define @item, @itemx, etc., with
+% Note @table, @ftable, and @vtable define @item, @itemx, etc., with
% these defs.
% They also define \itemindex
% to index the item name in whatever manner is desired (perhaps none).
@@ -1942,22 +2414,10 @@ where each line of input produces a line of output.}
\def\internalBitem{\smallbreak \parsearg\itemzzz}
\def\internalBitemx{\itemxpar \parsearg\itemzzz}
-\def\internalBxitem "#1"{\def\xitemsubtopix{#1} \smallbreak \parsearg\xitemzzz}
-\def\internalBxitemx "#1"{\def\xitemsubtopix{#1} \itemxpar \parsearg\xitemzzz}
-
-\def\internalBkitem{\smallbreak \parsearg\kitemzzz}
-\def\internalBkitemx{\itemxpar \parsearg\kitemzzz}
-
-\def\kitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \lastfunction}}%
- \itemzzz {#1}}
-
-\def\xitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \xitemsubtopic}}%
- \itemzzz {#1}}
-
\def\itemzzz #1{\begingroup %
\advance\hsize by -\rightskip
\advance\hsize by -\tableindent
- \setbox0=\hbox{\itemfont{#1}}%
+ \setbox0=\hbox{\itemindicate{#1}}%
\itemindex{#1}%
\nobreak % This prevents a break before @itemx.
%
@@ -1981,17 +2441,13 @@ where each line of input produces a line of output.}
% \parskip glue -- logically it's part of the @item we just started.
\nobreak \vskip-\parskip
%
- % Stop a page break at the \parskip glue coming up. (Unfortunately
- % we can't prevent a possible page break at the following
- % \baselineskip glue.) However, if what follows is an environment
- % such as @example, there will be no \parskip glue; then
- % the negative vskip we just would cause the example and the item to
- % crash together. So we use this bizarre value of 10001 as a signal
- % to \aboveenvbreak to insert \parskip glue after all.
- % (Possibly there are other commands that could be followed by
- % @example which need the same treatment, but not section titles; or
- % maybe section titles are the only special case and they should be
- % penalty 10001...)
+ % Stop a page break at the \parskip glue coming up. However, if
+ % what follows is an environment such as @example, there will be no
+ % \parskip glue; then the negative vskip we just inserted would
+ % cause the example and the item to crash together. So we use this
+ % bizarre value of 10001 as a signal to \aboveenvbreak to insert
+ % \parskip glue after all. Section titles are handled this way also.
+ %
\penalty 10001
\endgroup
\itemxneedsnegativevskipfalse
@@ -2011,92 +2467,106 @@ where each line of input produces a line of output.}
\fi
}
-\def\item{\errmessage{@item while not in a table}}
-\def\itemx{\errmessage{@itemx while not in a table}}
-\def\kitem{\errmessage{@kitem while not in a table}}
-\def\kitemx{\errmessage{@kitemx while not in a table}}
-\def\xitem{\errmessage{@xitem while not in a table}}
-\def\xitemx{\errmessage{@xitemx while not in a table}}
-
-% Contains a kludge to get @end[description] to work.
-\def\description{\tablez{\dontindex}{1}{}{}{}{}}
+\def\item{\errmessage{@item while not in a list environment}}
+\def\itemx{\errmessage{@itemx while not in a list environment}}
% @table, @ftable, @vtable.
-\def\table{\begingroup\inENV\obeylines\obeyspaces\tablex}
-{\obeylines\obeyspaces%
-\gdef\tablex #1^^M{%
-\tabley\dontindex#1 \endtabley}}
-
-\def\ftable{\begingroup\inENV\obeylines\obeyspaces\ftablex}
-{\obeylines\obeyspaces%
-\gdef\ftablex #1^^M{%
-\tabley\fnitemindex#1 \endtabley
-\def\Eftable{\endgraf\afterenvbreak\endgroup}%
-\let\Etable=\relax}}
-
-\def\vtable{\begingroup\inENV\obeylines\obeyspaces\vtablex}
-{\obeylines\obeyspaces%
-\gdef\vtablex #1^^M{%
-\tabley\vritemindex#1 \endtabley
-\def\Evtable{\endgraf\afterenvbreak\endgroup}%
-\let\Etable=\relax}}
-
-\def\dontindex #1{}
-\def\fnitemindex #1{\doind {fn}{\code{#1}}}%
-\def\vritemindex #1{\doind {vr}{\code{#1}}}%
-
-{\obeyspaces %
-\gdef\tabley#1#2 #3 #4 #5 #6 #7\endtabley{\endgroup%
-\tablez{#1}{#2}{#3}{#4}{#5}{#6}}}
-
-\def\tablez #1#2#3#4#5#6{%
-\aboveenvbreak %
-\begingroup %
-\def\Edescription{\Etable}% Necessary kludge.
-\let\itemindex=#1%
-\ifnum 0#3>0 \advance \leftskip by #3\mil \fi %
-\ifnum 0#4>0 \tableindent=#4\mil \fi %
-\ifnum 0#5>0 \advance \rightskip by #5\mil \fi %
-\def\itemfont{#2}%
-\itemmax=\tableindent %
-\advance \itemmax by -\itemmargin %
-\advance \leftskip by \tableindent %
-\exdentamount=\tableindent
-\parindent = 0pt
-\parskip = \smallskipamount
-\ifdim \parskip=0pt \parskip=2pt \fi%
-\def\Etable{\endgraf\afterenvbreak\endgroup}%
-\let\item = \internalBitem %
-\let\itemx = \internalBitemx %
-\let\kitem = \internalBkitem %
-\let\kitemx = \internalBkitemx %
-\let\xitem = \internalBxitem %
-\let\xitemx = \internalBxitemx %
+\envdef\table{%
+ \let\itemindex\gobble
+ \tablecheck{table}%
+}
+\envdef\ftable{%
+ \def\itemindex ##1{\doind {fn}{\code{##1}}}%
+ \tablecheck{ftable}%
+}
+\envdef\vtable{%
+ \def\itemindex ##1{\doind {vr}{\code{##1}}}%
+ \tablecheck{vtable}%
+}
+\def\tablecheck#1{%
+ \ifnum \the\catcode`\^^M=\active
+ \endgroup
+ \errmessage{This command won't work in this context; perhaps the problem is
+ that we are \inenvironment\thisenv}%
+ \def\next{\doignore{#1}}%
+ \else
+ \let\next\tablex
+ \fi
+ \next
+}
+\def\tablex#1{%
+ \def\itemindicate{#1}%
+ \parsearg\tabley
+}
+\def\tabley#1{%
+ {%
+ \makevalueexpandable
+ \edef\temp{\noexpand\tablez #1\space\space\space}%
+ \expandafter
+ }\temp \endtablez
+}
+\def\tablez #1 #2 #3 #4\endtablez{%
+ \aboveenvbreak
+ \ifnum 0#1>0 \advance \leftskip by #1\mil \fi
+ \ifnum 0#2>0 \tableindent=#2\mil \fi
+ \ifnum 0#3>0 \advance \rightskip by #3\mil \fi
+ \itemmax=\tableindent
+ \advance \itemmax by -\itemmargin
+ \advance \leftskip by \tableindent
+ \exdentamount=\tableindent
+ \parindent = 0pt
+ \parskip = \smallskipamount
+ \ifdim \parskip=0pt \parskip=2pt \fi
+ \let\item = \internalBitem
+ \let\itemx = \internalBitemx
}
+\def\Etable{\endgraf\afterenvbreak}
+\let\Eftable\Etable
+\let\Evtable\Etable
+\let\Eitemize\Etable
+\let\Eenumerate\Etable
% This is the counter used by @enumerate, which is really @itemize
\newcount \itemno
-\def\itemize{\parsearg\itemizezzz}
+\envdef\itemize{\parsearg\doitemize}
-\def\itemizezzz #1{%
- \begingroup % ended by the @end itemize
- \itemizey {#1}{\Eitemize}
+\def\doitemize#1{%
+ \aboveenvbreak
+ \itemmax=\itemindent
+ \advance\itemmax by -\itemmargin
+ \advance\leftskip by \itemindent
+ \exdentamount=\itemindent
+ \parindent=0pt
+ \parskip=\smallskipamount
+ \ifdim\parskip=0pt \parskip=2pt \fi
+ \def\itemcontents{#1}%
+ % @itemize with no arg is equivalent to @itemize @bullet.
+ \ifx\itemcontents\empty\def\itemcontents{\bullet}\fi
+ \let\item=\itemizeitem
}
-\def\itemizey #1#2{%
-\aboveenvbreak %
-\itemmax=\itemindent %
-\advance \itemmax by -\itemmargin %
-\advance \leftskip by \itemindent %
-\exdentamount=\itemindent
-\parindent = 0pt %
-\parskip = \smallskipamount %
-\ifdim \parskip=0pt \parskip=2pt \fi%
-\def#2{\endgraf\afterenvbreak\endgroup}%
-\def\itemcontents{#1}%
-\let\item=\itemizeitem}
+% Definition of @item while inside @itemize and @enumerate.
+%
+\def\itemizeitem{%
+ \advance\itemno by 1 % for enumerations
+ {\let\par=\endgraf \smallbreak}% reasonable place to break
+ {%
+ % If the document has an @itemize directly after a section title, a
+ % \nobreak will be last on the list, and \sectionheading will have
+ % done a \vskip-\parskip. In that case, we don't want to zero
+ % parskip, or the item text will crash with the heading. On the
+ % other hand, when there is normal text preceding the item (as there
+ % usually is), we do want to zero parskip, or there would be too much
+ % space. In that case, we won't have a \nobreak before. At least
+ % that's the theory.
+ \ifnum\lastpenalty<10000 \parskip=0in \fi
+ \noindent
+ \hbox to 0pt{\hss \itemcontents \kern\itemmargin}%
+ \vadjust{\penalty 1200}}% not good to break after first line of item.
+ \flushcr
+}
% \splitoff TOKENS\endmark defines \first to be the first token in
% TOKENS, and \rest to be the remainder.
@@ -2107,11 +2577,8 @@ where each line of input produces a line of output.}
% or number, to specify the first label in the enumerated list. No
% argument is the same as `1'.
%
-\def\enumerate{\parsearg\enumeratezzz}
-\def\enumeratezzz #1{\enumeratey #1 \endenumeratey}
+\envparseargdef\enumerate{\enumeratey #1 \endenumeratey}
\def\enumeratey #1 #2\endenumeratey{%
- \begingroup % ended by the @end enumerate
- %
% If we were given no argument, pretend we were given `1'.
\def\thearg{#1}%
\ifx\thearg\empty \def\thearg{1}\fi
@@ -2182,13 +2649,13 @@ where each line of input produces a line of output.}
}%
}
-% Call itemizey, adding a period to the first argument and supplying the
+% Call \doitemize, adding a period to the first argument and supplying the
% common last two arguments. Also subtract one from the initial value in
% \itemno, since @item increments \itemno.
%
\def\startenumeration#1{%
\advance\itemno by -1
- \itemizey{#1.}\Eenumerate\flushcr
+ \doitemize{#1.}\flushcr
}
% @alphaenumerate and @capsenumerate are abbreviations for giving an arg
@@ -2199,16 +2666,6 @@ where each line of input produces a line of output.}
\def\Ealphaenumerate{\Eenumerate}
\def\Ecapsenumerate{\Eenumerate}
-% Definition of @item while inside @itemize.
-
-\def\itemizeitem{%
-\advance\itemno by 1
-{\let\par=\endgraf \smallbreak}%
-\ifhmode \errmessage{In hmode at itemizeitem}\fi
-{\parskip=0in \hskip 0pt
-\hbox to 0pt{\hss \itemcontents\hskip \itemmargin}%
-\vadjust{\penalty 1200}}%
-\flushcr}
% @multitable macros
% Amy Hendrickson, 8/18/94, 3/6/96
@@ -2235,24 +2692,14 @@ where each line of input produces a line of output.}
% @multitable {Column 1 template} {Column 2 template} {Column 3 template}
% @item ...
% using the widest term desired in each column.
-%
-% For those who want to use more than one line's worth of words in
-% the preamble, break the line within one argument and it
-% will parse correctly, i.e.,
-%
-% @multitable {Column 1 template} {Column 2 template} {Column 3
-% template}
-% Not:
-% @multitable {Column 1 template} {Column 2 template}
-% {Column 3 template}
% Each new table line starts with @item, each subsequent new column
% starts with @tab. Empty columns may be produced by supplying @tab's
% with nothing between them for as many times as empty columns are needed,
% ie, @tab@tab@tab will produce two empty columns.
-% @item, @tab, @multitable or @end multitable do not need to be on their
-% own lines, but it will not hurt if they are.
+% @item, @tab do not need to be on their own lines, but it will not hurt
+% if they are.
% Sample multitable:
@@ -2296,13 +2743,12 @@ where each line of input produces a line of output.}
\def\xcolumnfractions{\columnfractions}
\newif\ifsetpercent
-% #1 is the part of the @columnfraction before the decimal point, which
-% is presumably either 0 or the empty string (but we don't check, we
-% just throw it away). #2 is the decimal part, which we use as the
-% percent of \hsize for this column.
-\def\pickupwholefraction#1.#2 {%
+% #1 is the @columnfraction, usually a decimal number like .5, but might
+% be just 1. We just use it, whatever it is.
+%
+\def\pickupwholefraction#1 {%
\global\advance\colcount by 1
- \expandafter\xdef\csname col\the\colcount\endcsname{.#2\hsize}%
+ \expandafter\xdef\csname col\the\colcount\endcsname{#1\hsize}%
\setuptable
}
@@ -2335,18 +2781,33 @@ where each line of input produces a line of output.}
\go
}
+% multitable-only commands.
+%
+% @headitem starts a heading row, which we typeset in bold.
+% Assignments have to be global since we are inside the implicit group
+% of an alignment entry. Note that \everycr resets \everytab.
+\def\headitem{\checkenv\multitable \crcr \global\everytab={\bf}\the\everytab}%
+%
+% A \tab used to include \hskip1sp. But then the space in a template
+% line is not enough. That is bad. So let's go back to just `&' until
+% we encounter the problem it was intended to solve again.
+% --karl, nathan@acm.org, 20apr99.
+\def\tab{\checkenv\multitable &\the\everytab}%
+
% @multitable ... @end multitable definitions:
%
-\def\multitable{\parsearg\dotable}
-\def\dotable#1{\bgroup
+\newtoks\everytab % insert after every tab.
+%
+\envdef\multitable{%
\vskip\parskip
- \let\item=\crcrwithfootnotes
- % A \tab used to include \hskip1sp. But then the space in a template
- % line is not enough. That is bad. So let's go back to just & until
- % we encounter the problem it was intended to solve again. --karl,
- % nathan@acm.org, 20apr99.
- \let\tab=&%
- \let\startfootins=\startsavedfootnote
+ \startsavinginserts
+ %
+ % @item within a multitable starts a normal row.
+ % We use \def instead of \let so that if one of the multitable entries
+ % contains an @itemize, we don't choke on the \item (seen as \crcr aka
+ % \endtemplate) expanding \doitemize.
+ \def\item{\crcr}%
+ %
\tolerance=9500
\hbadness=9500
\setmultitablespacing
@@ -2354,85 +2815,93 @@ where each line of input produces a line of output.}
\parindent=\multitableparindent
\overfullrule=0pt
\global\colcount=0
- \def\Emultitable{%
- \global\setpercentfalse
- \crcrwithfootnotes\crcr
- \egroup\egroup
+ %
+ \everycr = {%
+ \noalign{%
+ \global\everytab={}%
+ \global\colcount=0 % Reset the column counter.
+ % Check for saved footnotes, etc.
+ \checkinserts
+ % Keeps underfull box messages off when table breaks over pages.
+ %\filbreak
+ % Maybe so, but it also creates really weird page breaks when the
+ % table breaks over pages. Wouldn't \vfil be better? Wait until the
+ % problem manifests itself, so it can be fixed for real --karl.
+ }%
}%
%
+ \parsearg\domultitable
+}
+\def\domultitable#1{%
% To parse everything between @multitable and @item:
\setuptable#1 \endsetuptable
%
- % \everycr will reset column counter, \colcount, at the end of
- % each line. Every column entry will cause \colcount to advance by one.
- % The table preamble
- % looks at the current \colcount to find the correct column width.
- \everycr{\noalign{%
- %
- % \filbreak%% keeps underfull box messages off when table breaks over pages.
- % Maybe so, but it also creates really weird page breaks when the table
- % breaks over pages. Wouldn't \vfil be better? Wait until the problem
- % manifests itself, so it can be fixed for real --karl.
- \global\colcount=0\relax}}%
- %
% This preamble sets up a generic column definition, which will
% be used as many times as user calls for columns.
% \vtop will set a single line and will also let text wrap and
% continue for many paragraphs if desired.
- \halign\bgroup&\global\advance\colcount by 1\relax
- \multistrut\vtop{\hsize=\expandafter\csname col\the\colcount\endcsname
- %
- % In order to keep entries from bumping into each other
- % we will add a \leftskip of \multitablecolspace to all columns after
- % the first one.
- %
- % If a template has been used, we will add \multitablecolspace
- % to the width of each template entry.
- %
- % If the user has set preamble in terms of percent of \hsize we will
- % use that dimension as the width of the column, and the \leftskip
- % will keep entries from bumping into each other. Table will start at
- % left margin and final column will justify at right margin.
- %
- % Make sure we don't inherit \rightskip from the outer environment.
- \rightskip=0pt
- \ifnum\colcount=1
- % The first column will be indented with the surrounding text.
- \advance\hsize by\leftskip
- \else
- \ifsetpercent \else
- % If user has not set preamble in terms of percent of \hsize
- % we will advance \hsize by \multitablecolspace.
- \advance\hsize by \multitablecolspace
- \fi
- % In either case we will make \leftskip=\multitablecolspace:
- \leftskip=\multitablecolspace
- \fi
- % Ignoring space at the beginning and end avoids an occasional spurious
- % blank line, when TeX decides to break the line at the space before the
- % box from the multistrut, so the strut ends up on a line by itself.
- % For example:
- % @multitable @columnfractions .11 .89
- % @item @code{#}
- % @tab Legal holiday which is valid in major parts of the whole country.
- % Is automatically provided with highlighting sequences respectively marking
- % characters.
- \noindent\ignorespaces##\unskip\multistrut}\cr
-}
-
-\def\setmultitablespacing{% test to see if user has set \multitablelinespace.
-% If so, do nothing. If not, give it an appropriate dimension based on
-% current baselineskip.
+ \halign\bgroup &%
+ \global\advance\colcount by 1
+ \multistrut
+ \vtop{%
+ % Use the current \colcount to find the correct column width:
+ \hsize=\expandafter\csname col\the\colcount\endcsname
+ %
+ % In order to keep entries from bumping into each other
+ % we will add a \leftskip of \multitablecolspace to all columns after
+ % the first one.
+ %
+ % If a template has been used, we will add \multitablecolspace
+ % to the width of each template entry.
+ %
+ % If the user has set preamble in terms of percent of \hsize we will
+ % use that dimension as the width of the column, and the \leftskip
+ % will keep entries from bumping into each other. Table will start at
+ % left margin and final column will justify at right margin.
+ %
+ % Make sure we don't inherit \rightskip from the outer environment.
+ \rightskip=0pt
+ \ifnum\colcount=1
+ % The first column will be indented with the surrounding text.
+ \advance\hsize by\leftskip
+ \else
+ \ifsetpercent \else
+ % If user has not set preamble in terms of percent of \hsize
+ % we will advance \hsize by \multitablecolspace.
+ \advance\hsize by \multitablecolspace
+ \fi
+ % In either case we will make \leftskip=\multitablecolspace:
+ \leftskip=\multitablecolspace
+ \fi
+ % Ignoring space at the beginning and end avoids an occasional spurious
+ % blank line, when TeX decides to break the line at the space before the
+ % box from the multistrut, so the strut ends up on a line by itself.
+ % For example:
+ % @multitable @columnfractions .11 .89
+ % @item @code{#}
+ % @tab Legal holiday which is valid in major parts of the whole country.
+ % Is automatically provided with highlighting sequences respectively
+ % marking characters.
+ \noindent\ignorespaces##\unskip\multistrut
+ }\cr
+}
+\def\Emultitable{%
+ \crcr
+ \egroup % end the \halign
+ \global\setpercentfalse
+}
+
+\def\setmultitablespacing{%
+ \def\multistrut{\strut}% just use the standard line spacing
+ %
+ % Compute \multitablelinespace (if not defined by user) for use in
+ % \multitableparskip calculation. We used define \multistrut based on
+ % this, but (ironically) that caused the spacing to be off.
+ % See bug-texinfo report from Werner Lemberg, 31 Oct 2004 12:52:20 +0100.
\ifdim\multitablelinespace=0pt
\setbox0=\vbox{X}\global\multitablelinespace=\the\baselineskip
\global\advance\multitablelinespace by-\ht0
-%% strut to put in table in case some entry doesn't have descenders,
-%% to keep lines equally spaced
-\let\multistrut = \strut
-\else
-%% FIXME: what is \box0 supposed to be?
-\gdef\multistrut{\vrule height\multitablelinespace depth\dp0
-width0pt\relax} \fi
+\fi
%% Test to see if parskip is larger than space between lines of
%% table. If not, do nothing.
%% If so, set to same dimension as multitablelinespace.
@@ -2447,163 +2916,33 @@ width0pt\relax} \fi
%% than skip between lines in the table.
\fi}
-% In case a @footnote appears inside an alignment, save the footnote
-% text to a box and make the \insert when a row of the table is
-% finished. Otherwise, the insertion is lost, it never migrates to the
-% main vertical list. --kasal, 22jan03.
-%
-\newbox\savedfootnotes
-%
-% \dotable \let's \startfootins to this, so that \dofootnote will call
-% it instead of starting the insertion right away.
-\def\startsavedfootnote{%
- \global\setbox\savedfootnotes = \vbox\bgroup
- \unvbox\savedfootnotes
-}
-\def\crcrwithfootnotes{%
- \crcr
- \ifvoid\savedfootnotes \else
- \noalign{\insert\footins{\box\savedfootnotes}}%
- \fi
-}
\message{conditionals,}
-% Prevent errors for section commands.
-% Used in @ignore and in failing conditionals.
-\def\ignoresections{%
- \let\chapter=\relax
- \let\unnumbered=\relax
- \let\top=\relax
- \let\unnumberedsec=\relax
- \let\unnumberedsection=\relax
- \let\unnumberedsubsec=\relax
- \let\unnumberedsubsection=\relax
- \let\unnumberedsubsubsec=\relax
- \let\unnumberedsubsubsection=\relax
- \let\section=\relax
- \let\subsec=\relax
- \let\subsubsec=\relax
- \let\subsection=\relax
- \let\subsubsection=\relax
- \let\appendix=\relax
- \let\appendixsec=\relax
- \let\appendixsection=\relax
- \let\appendixsubsec=\relax
- \let\appendixsubsection=\relax
- \let\appendixsubsubsec=\relax
- \let\appendixsubsubsection=\relax
- \let\contents=\relax
- \let\smallbook=\relax
- \let\titlepage=\relax
-}
-
-% Used in nested conditionals, where we have to parse the Texinfo source
-% and so want to turn off most commands, in case they are used
-% incorrectly.
-%
-% We use \empty instead of \relax for the @def... commands, so that \end
-% doesn't throw an error. For instance:
-% @ignore
-% @deffn ...
-% @end deffn
-% @end ignore
-%
-% The @end deffn is going to get expanded, because we're trying to allow
-% nested conditionals. But we don't want to expand the actual @deffn,
-% since it might be syntactically correct and intended to be ignored.
-% Since \end checks for \relax, using \empty does not cause an error.
-%
-\def\ignoremorecommands{%
- \let\defcodeindex = \relax
- \let\defcv = \empty
- \let\defcvx = \empty
- \let\Edefcv = \empty
- \let\deffn = \empty
- \let\deffnx = \empty
- \let\Edeffn = \empty
- \let\defindex = \relax
- \let\defivar = \empty
- \let\defivarx = \empty
- \let\Edefivar = \empty
- \let\defmac = \empty
- \let\defmacx = \empty
- \let\Edefmac = \empty
- \let\defmethod = \empty
- \let\defmethodx = \empty
- \let\Edefmethod = \empty
- \let\defop = \empty
- \let\defopx = \empty
- \let\Edefop = \empty
- \let\defopt = \empty
- \let\defoptx = \empty
- \let\Edefopt = \empty
- \let\defspec = \empty
- \let\defspecx = \empty
- \let\Edefspec = \empty
- \let\deftp = \empty
- \let\deftpx = \empty
- \let\Edeftp = \empty
- \let\deftypefn = \empty
- \let\deftypefnx = \empty
- \let\Edeftypefn = \empty
- \let\deftypefun = \empty
- \let\deftypefunx = \empty
- \let\Edeftypefun = \empty
- \let\deftypeivar = \empty
- \let\deftypeivarx = \empty
- \let\Edeftypeivar = \empty
- \let\deftypemethod = \empty
- \let\deftypemethodx = \empty
- \let\Edeftypemethod = \empty
- \let\deftypeop = \empty
- \let\deftypeopx = \empty
- \let\Edeftypeop = \empty
- \let\deftypevar = \empty
- \let\deftypevarx = \empty
- \let\Edeftypevar = \empty
- \let\deftypevr = \empty
- \let\deftypevrx = \empty
- \let\Edeftypevr = \empty
- \let\defun = \empty
- \let\defunx = \empty
- \let\Edefun = \empty
- \let\defvar = \empty
- \let\defvarx = \empty
- \let\Edefvar = \empty
- \let\defvr = \empty
- \let\defvrx = \empty
- \let\Edefvr = \empty
- \let\clear = \relax
- \let\down = \relax
- \let\evenfooting = \relax
- \let\evenheading = \relax
- \let\everyfooting = \relax
- \let\everyheading = \relax
- \let\headings = \relax
- \let\include = \relax
- \let\item = \relax
- \let\lowersections = \relax
- \let\oddfooting = \relax
- \let\oddheading = \relax
- \let\printindex = \relax
- \let\pxref = \relax
- \let\raisesections = \relax
- \let\ref = \relax
- \let\set = \relax
- \let\setchapternewpage = \relax
- \let\setchapterstyle = \relax
- \let\settitle = \relax
- \let\up = \relax
- \let\verbatiminclude = \relax
- \let\xref = \relax
+
+% @iftex, @ifnotdocbook, @ifnothtml, @ifnotinfo, @ifnotplaintext,
+% @ifnotxml always succeed. They currently do nothing; we don't
+% attempt to check whether the conditionals are properly nested. But we
+% have to remember that they are conditionals, so that @end doesn't
+% attempt to close an environment group.
+%
+\def\makecond#1{%
+ \expandafter\let\csname #1\endcsname = \relax
+ \expandafter\let\csname iscond.#1\endcsname = 1
}
+\makecond{iftex}
+\makecond{ifnotdocbook}
+\makecond{ifnothtml}
+\makecond{ifnotinfo}
+\makecond{ifnotplaintext}
+\makecond{ifnotxml}
% Ignore @ignore, @ifhtml, @ifinfo, and the like.
%
\def\direntry{\doignore{direntry}}
-\def\documentdescriptionword{documentdescription}
\def\documentdescription{\doignore{documentdescription}}
+\def\docbook{\doignore{docbook}}
\def\html{\doignore{html}}
+\def\ifdocbook{\doignore{ifdocbook}}
\def\ifhtml{\doignore{ifhtml}}
\def\ifinfo{\doignore{ifinfo}}
\def\ifnottex{\doignore{ifnottex}}
@@ -2613,198 +2952,133 @@ width0pt\relax} \fi
\def\menu{\doignore{menu}}
\def\xml{\doignore{xml}}
-% @dircategory CATEGORY -- specify a category of the dir file
-% which this file should belong to. Ignore this in TeX.
-\let\dircategory = \comment
-
-% Ignore text until a line `@end #1'.
+% Ignore text until a line `@end #1', keeping track of nested conditionals.
%
+% A count to remember the depth of nesting.
+\newcount\doignorecount
+
\def\doignore#1{\begingroup
- % Don't complain about control sequences we have declared \outer.
- \ignoresections
- %
- % Define a command to swallow text until we reach `@end #1'.
- % This @ is a catcode 12 token (that is the normal catcode of @ in
- % this texinfo.tex file). We change the catcode of @ below to match.
- \long\def\doignoretext##1@end #1{\enddoignore}%
+ % Scan in ``verbatim'' mode:
+ \catcode`\@ = \other
+ \catcode`\{ = \other
+ \catcode`\} = \other
%
% Make sure that spaces turn into tokens that match what \doignoretext wants.
- \catcode\spaceChar = 10
- %
- % Ignore braces, too, so mismatched braces don't cause trouble.
- \catcode`\{ = 9
- \catcode`\} = 9
+ \spaceisspace
%
- % We must not have @c interpreted as a control sequence.
- \catcode`\@ = 12
- %
- \def\ignoreword{#1}%
- \ifx\ignoreword\documentdescriptionword
- % The c kludge breaks documentdescription, since
- % `documentdescription' contains a `c'. Means not everything will
- % be ignored inside @documentdescription, but oh well...
- \else
- % Make the letter c a comment character so that the rest of the line
- % will be ignored. This way, the document can have (for example)
- % @c @end ifinfo
- % and the @end ifinfo will be properly ignored.
- % (We've just changed @ to catcode 12.)
- \catcode`\c = 14
- \fi
+ % Count number of #1's that we've seen.
+ \doignorecount = 0
%
- % And now expand the command defined above.
- \doignoretext
-}
-
-% What we do to finish off ignored text.
-%
-\def\enddoignore{\endgroup\ignorespaces}%
-
-\newif\ifwarnedobs\warnedobsfalse
-\def\obstexwarn{%
- \ifwarnedobs\relax\else
- % We need to warn folks that they may have trouble with TeX 3.0.
- % This uses \immediate\write16 rather than \message to get newlines.
- \immediate\write16{}
- \immediate\write16{WARNING: for users of Unix TeX 3.0!}
- \immediate\write16{This manual trips a bug in TeX version 3.0 (tex hangs).}
- \immediate\write16{If you are running another version of TeX, relax.}
- \immediate\write16{If you are running Unix TeX 3.0, kill this TeX process.}
- \immediate\write16{ Then upgrade your TeX installation if you can.}
- \immediate\write16{ (See ftp://ftp.gnu.org/non-gnu/TeX.README.)}
- \immediate\write16{If you are stuck with version 3.0, run the}
- \immediate\write16{ script ``tex3patch'' from the Texinfo distribution}
- \immediate\write16{ to use a workaround.}
- \immediate\write16{}
- \global\warnedobstrue
- \fi
+ % Swallow text until we reach the matching `@end #1'.
+ \dodoignore{#1}%
}
-% **In TeX 3.0, setting text in \nullfont hangs tex. For a
-% workaround (which requires the file ``dummy.tfm'' to be installed),
-% uncomment the following line:
-%%%%%\font\nullfont=dummy\let\obstexwarn=\relax
-
-% Ignore text, except that we keep track of conditional commands for
-% purposes of nesting, up to an `@end #1' command.
-%
-\def\nestedignore#1{%
- \obstexwarn
- % We must actually expand the ignored text to look for the @end
- % command, so that nested ignore constructs work. Thus, we put the
- % text into a \vbox and then do nothing with the result. To minimize
- % the chance of memory overflow, we follow the approach outlined on
- % page 401 of the TeXbook.
+{ \catcode`_=11 % We want to use \_STOP_ which cannot appear in texinfo source.
+ \obeylines %
%
- \setbox0 = \vbox\bgroup
- % Don't complain about control sequences we have declared \outer.
- \ignoresections
- %
- % Define `@end #1' to end the box, which will in turn undefine the
- % @end command again.
- \expandafter\def\csname E#1\endcsname{\egroup\ignorespaces}%
+ \gdef\dodoignore#1{%
+ % #1 contains the command name as a string, e.g., `ifinfo'.
%
- % We are going to be parsing Texinfo commands. Most cause no
- % trouble when they are used incorrectly, but some commands do
- % complicated argument parsing or otherwise get confused, so we
- % undefine them.
+ % Define a command to find the next `@end #1', which must be on a line
+ % by itself.
+ \long\def\doignoretext##1^^M@end #1{\doignoretextyyy##1^^M@#1\_STOP_}%
+ % And this command to find another #1 command, at the beginning of a
+ % line. (Otherwise, we would consider a line `@c @ifset', for
+ % example, to count as an @ifset for nesting.)
+ \long\def\doignoretextyyy##1^^M@#1##2\_STOP_{\doignoreyyy{##2}\_STOP_}%
%
- % We can't do anything about stray @-signs, unfortunately;
- % they'll produce `undefined control sequence' errors.
- \ignoremorecommands
- %
- % Set the current font to be \nullfont, a TeX primitive, and define
- % all the font commands to also use \nullfont. We don't use
- % dummy.tfm, as suggested in the TeXbook, because some sites
- % might not have that installed. Therefore, math mode will still
- % produce output, but that should be an extremely small amount of
- % stuff compared to the main input.
- %
- \nullfont
- \let\tenrm=\nullfont \let\tenit=\nullfont \let\tensl=\nullfont
- \let\tenbf=\nullfont \let\tentt=\nullfont \let\smallcaps=\nullfont
- \let\tensf=\nullfont
- % Similarly for index fonts.
- \let\smallrm=\nullfont \let\smallit=\nullfont \let\smallsl=\nullfont
- \let\smallbf=\nullfont \let\smalltt=\nullfont \let\smallsc=\nullfont
- \let\smallsf=\nullfont
- % Similarly for smallexample fonts.
- \let\smallerrm=\nullfont \let\smallerit=\nullfont \let\smallersl=\nullfont
- \let\smallerbf=\nullfont \let\smallertt=\nullfont \let\smallersc=\nullfont
- \let\smallersf=\nullfont
- %
- % Don't complain when characters are missing from the fonts.
- \tracinglostchars = 0
- %
- % Don't bother to do space factor calculations.
- \frenchspacing
- %
- % Don't report underfull hboxes.
- \hbadness = 10000
- %
- % Do minimal line-breaking.
- \pretolerance = 10000
- %
- % Do not execute instructions in @tex.
- \def\tex{\doignore{tex}}%
- % Do not execute macro definitions.
- % `c' is a comment character, so the word `macro' will get cut off.
- \def\macro{\doignore{ma}}%
+ % And now expand that command.
+ \obeylines %
+ \doignoretext ^^M%
+ }%
+}
+
+\def\doignoreyyy#1{%
+ \def\temp{#1}%
+ \ifx\temp\empty % Nothing found.
+ \let\next\doignoretextzzz
+ \else % Found a nested condition, ...
+ \advance\doignorecount by 1
+ \let\next\doignoretextyyy % ..., look for another.
+ % If we're here, #1 ends with ^^M\ifinfo (for example).
+ \fi
+ \next #1% the token \_STOP_ is present just after this macro.
+}
+
+% We have to swallow the remaining "\_STOP_".
+%
+\def\doignoretextzzz#1{%
+ \ifnum\doignorecount = 0 % We have just found the outermost @end.
+ \let\next\enddoignore
+ \else % Still inside a nested condition.
+ \advance\doignorecount by -1
+ \let\next\doignoretext % Look for the next @end.
+ \fi
+ \next
}
+% Finish off ignored text.
+\def\enddoignore{\endgroup\ignorespaces}
+
+
% @set VAR sets the variable VAR to an empty value.
% @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE.
%
% Since we want to separate VAR from REST-OF-LINE (which might be
% empty), we can't just use \parsearg; we have to insert a space of our
% own to delimit the rest of the line, and then take it out again if we
-% didn't need it. Make sure the catcode of space is correct to avoid
-% losing inside @example, for instance.
+% didn't need it.
+% We rely on the fact that \parsearg sets \catcode`\ =10.
%
-\def\set{\begingroup\catcode` =10
- \catcode`\-=12 \catcode`\_=12 % Allow - and _ in VAR.
- \parsearg\setxxx}
-\def\setxxx#1{\setyyy#1 \endsetyyy}
+\parseargdef\set{\setyyy#1 \endsetyyy}
\def\setyyy#1 #2\endsetyyy{%
- \def\temp{#2}%
- \ifx\temp\empty \global\expandafter\let\csname SET#1\endcsname = \empty
- \else \setzzz{#1}#2\endsetzzz % Remove the trailing space \setxxx inserted.
- \fi
- \endgroup
+ {%
+ \makevalueexpandable
+ \def\temp{#2}%
+ \edef\next{\gdef\makecsname{SET#1}}%
+ \ifx\temp\empty
+ \next{}%
+ \else
+ \setzzz#2\endsetzzz
+ \fi
+ }%
}
-% Can't use \xdef to pre-expand #2 and save some time, since \temp or
-% \next or other control sequences that we've defined might get us into
-% an infinite loop. Consider `@set foo @cite{bar}'.
-\def\setzzz#1#2 \endsetzzz{\expandafter\gdef\csname SET#1\endcsname{#2}}
+% Remove the trailing space \setxxx inserted.
+\def\setzzz#1 \endsetzzz{\next{#1}}
% @clear VAR clears (i.e., unsets) the variable VAR.
%
-\def\clear{\parsearg\clearxxx}
-\def\clearxxx#1{\global\expandafter\let\csname SET#1\endcsname=\relax}
+\parseargdef\clear{%
+ {%
+ \makevalueexpandable
+ \global\expandafter\let\csname SET#1\endcsname=\relax
+ }%
+}
% @value{foo} gets the text saved in variable foo.
+\def\value{\begingroup\makevalueexpandable\valuexxx}
+\def\valuexxx#1{\expandablevalue{#1}\endgroup}
{
- \catcode`\_ = \active
+ \catcode`\- = \active \catcode`\_ = \active
%
- % We might end up with active _ or - characters in the argument if
- % we're called from @code, as @code{@value{foo-bar_}}. So \let any
- % such active characters to their normal equivalents.
- \gdef\value{\begingroup
+ \gdef\makevalueexpandable{%
+ \let\value = \expandablevalue
+ % We don't want these characters active, ...
\catcode`\-=\other \catcode`\_=\other
- \indexbreaks \let_\normalunderscore
- \valuexxx}
+ % ..., but we might end up with active ones in the argument if
+ % we're called from @code, as @code{@value{foo-bar_}}, though.
+ % So \let them to their normal equivalents.
+ \let-\realdash \let_\normalunderscore
+ }
}
-\def\valuexxx#1{\expandablevalue{#1}\endgroup}
% We have this subroutine so that we can handle at least some @value's
-% properly in indexes (we \let\value to this in \indexdummies). Ones
-% whose names contain - or _ still won't work, but we can't do anything
-% about that. The command has to be fully expandable (if the variable
-% is set), since the result winds up in the index file. This means that
-% if the variable's value contains other Texinfo commands, it's almost
-% certain it will fail (although perhaps we could fix that with
-% sufficient work to do a one-level expansion on the result, instead of
-% complete).
+% properly in indexes (we call \makevalueexpandable in \indexdummies).
+% The command has to be fully expandable (if the variable is set), since
+% the result winds up in the index file. This means that if the
+% variable's value contains other Texinfo commands, it's almost certain
+% it will fail (although perhaps we could fix that with sufficient work
+% to do a one-level expansion on the result, instead of complete).
%
\def\expandablevalue#1{%
\expandafter\ifx\csname SET#1\endcsname\relax
@@ -2818,55 +3092,36 @@ width0pt\relax} \fi
% @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
% with @set.
%
-\def\ifset{\parsearg\doifset}
-\def\doifset#1{%
- \expandafter\ifx\csname SET#1\endcsname\relax
- \let\next=\ifsetfail
- \else
- \let\next=\ifsetsucceed
- \fi
- \next
+% To get special treatment of `@end ifset,' call \makeond and the redefine.
+%
+\makecond{ifset}
+\def\ifset{\parsearg{\doifset{\let\next=\ifsetfail}}}
+\def\doifset#1#2{%
+ {%
+ \makevalueexpandable
+ \let\next=\empty
+ \expandafter\ifx\csname SET#2\endcsname\relax
+ #1% If not set, redefine \next.
+ \fi
+ \expandafter
+ }\next
}
-\def\ifsetsucceed{\conditionalsucceed{ifset}}
-\def\ifsetfail{\nestedignore{ifset}}
-\defineunmatchedend{ifset}
+\def\ifsetfail{\doignore{ifset}}
% @ifclear VAR ... @end ifclear reads the `...' iff VAR has never been
% defined with @set, or has been undefined with @clear.
%
-\def\ifclear{\parsearg\doifclear}
-\def\doifclear#1{%
- \expandafter\ifx\csname SET#1\endcsname\relax
- \let\next=\ifclearsucceed
- \else
- \let\next=\ifclearfail
- \fi
- \next
-}
-\def\ifclearsucceed{\conditionalsucceed{ifclear}}
-\def\ifclearfail{\nestedignore{ifclear}}
-\defineunmatchedend{ifclear}
-
-% @iftex, @ifnothtml, @ifnotinfo, @ifnotplaintext always succeed; we
-% read the text following, through the first @end iftex (etc.). Make
-% `@end iftex' (etc.) valid only after an @iftex.
+% The `\else' inside the `\doifset' parameter is a trick to reuse the
+% above code: if the variable is not set, do nothing, if it is set,
+% then redefine \next to \ifclearfail.
%
-\def\iftex{\conditionalsucceed{iftex}}
-\def\ifnothtml{\conditionalsucceed{ifnothtml}}
-\def\ifnotinfo{\conditionalsucceed{ifnotinfo}}
-\def\ifnotplaintext{\conditionalsucceed{ifnotplaintext}}
-\defineunmatchedend{iftex}
-\defineunmatchedend{ifnothtml}
-\defineunmatchedend{ifnotinfo}
-\defineunmatchedend{ifnotplaintext}
+\makecond{ifclear}
+\def\ifclear{\parsearg{\doifset{\else \let\next=\ifclearfail}}}
+\def\ifclearfail{\doignore{ifclear}}
-% True conditional. Since \set globally defines its variables, we can
-% just start and end a group (to keep the @end definition undefined at
-% the outer level).
-%
-\def\conditionalsucceed#1{\begingroup
- \expandafter\def\csname E#1\endcsname{\endgroup}%
-}
+% @dircategory CATEGORY -- specify a category of the dir file
+% which this file should belong to. Ignore this in TeX.
+\let\dircategory=\comment
% @defininfoenclose.
\let\definfoenclose=\comment
@@ -2876,9 +3131,8 @@ width0pt\relax} \fi
% Index generation facilities
% Define \newwrite to be identical to plain tex's \newwrite
-% except not \outer, so it can be used within \newindex.
-{\catcode`\@=11
-\gdef\newwrite{\alloc@7\write\chardef\sixt@@n}}
+% except not \outer, so it can be used within macros and \if's.
+\edef\newwrite{\makecsname{ptexnewwrite}}
% \newindex {foo} defines an index named foo.
% It automatically defines \fooindex such that
@@ -2917,10 +3171,10 @@ width0pt\relax} \fi
% @synindex foo bar makes index foo feed into index bar.
% Do this instead of @defindex foo if you don't want it as a separate index.
-%
+%
% @syncodeindex foo bar similar, but put all entries made for index foo
% inside @code.
-%
+%
\def\synindex#1 #2 {\dosynindex\doindex{#1}{#2}}
\def\syncodeindex#1 #2 {\dosynindex\docodeindex{#1}{#2}}
@@ -2962,204 +3216,205 @@ width0pt\relax} \fi
% Take care of Texinfo commands that can appear in an index entry.
% Since there are some commands we want to expand, and others we don't,
% we have to laboriously prevent expansion for those that we don't.
-%
+%
\def\indexdummies{%
+ \escapechar = `\\ % use backslash in output files.
\def\@{@}% change to @@ when we switch to @ as escape char in index files.
\def\ {\realbackslash\space }%
% Need these in case \tex is in effect and \{ is a \delimiter again.
% But can't use \lbracecmd and \rbracecmd because texindex assumes
- % braces and backslashes are used only as delimiters.
+ % braces and backslashes are used only as delimiters.
\let\{ = \mylbrace
\let\} = \myrbrace
%
- % \definedummyword defines \#1 as \realbackslash #1\space, thus
- % effectively preventing its expansion. This is used only for control
- % words, not control letters, because the \space would be incorrect
- % for control characters, but is needed to separate the control word
- % from whatever follows.
- %
- % For control letters, we have \definedummyletter, which omits the
- % space.
- %
- % These can be used both for control words that take an argument and
- % those that do not. If it is followed by {arg} in the input, then
- % that will dutifully get written to the index (or wherever).
- %
- \def\definedummyword##1{%
- \expandafter\def\csname ##1\endcsname{\realbackslash ##1\space}%
- }%
- \def\definedummyletter##1{%
- \expandafter\def\csname ##1\endcsname{\realbackslash ##1}%
- }%
- %
% Do the redefinitions.
\commondummies
}
-% For the aux file, @ is the escape character. So we want to redefine
-% everything using @ instead of \realbackslash. When everything uses
-% @, this will be simpler.
-%
+% For the aux and toc files, @ is the escape character. So we want to
+% redefine everything using @ as the escape character (instead of
+% \realbackslash, still used for index files). When everything uses @,
+% this will be simpler.
+%
\def\atdummies{%
\def\@{@@}%
\def\ {@ }%
\let\{ = \lbraceatcmd
\let\} = \rbraceatcmd
%
- % (See comments in \indexdummies.)
- \def\definedummyword##1{%
- \expandafter\def\csname ##1\endcsname{@##1\space}%
- }%
- \def\definedummyletter##1{%
- \expandafter\def\csname ##1\endcsname{@##1}%
- }%
- %
% Do the redefinitions.
\commondummies
}
-% Called from \indexdummies and \atdummies. \definedummyword and
-% \definedummyletter must be defined first.
-%
+% Called from \indexdummies and \atdummies.
+%
\def\commondummies{%
%
- \normalturnoffactive
+ % \definedummyword defines \#1 as \string\#1\space, thus effectively
+ % preventing its expansion. This is used only for control% words,
+ % not control letters, because the \space would be incorrect for
+ % control characters, but is needed to separate the control word
+ % from whatever follows.
%
- % Control letters and accents.
- \definedummyletter{_}%
- \definedummyletter{,}%
- \definedummyletter{"}%
- \definedummyletter{`}%
- \definedummyletter{'}%
- \definedummyletter{^}%
- \definedummyletter{~}%
- \definedummyletter{=}%
- \definedummyword{u}%
- \definedummyword{v}%
- \definedummyword{H}%
- \definedummyword{dotaccent}%
- \definedummyword{ringaccent}%
- \definedummyword{tieaccent}%
- \definedummyword{ubaraccent}%
- \definedummyword{udotaccent}%
- \definedummyword{dotless}%
- %
- % Other non-English letters.
- \definedummyword{AA}%
- \definedummyword{AE}%
- \definedummyword{L}%
- \definedummyword{OE}%
- \definedummyword{O}%
- \definedummyword{aa}%
- \definedummyword{ae}%
- \definedummyword{l}%
- \definedummyword{oe}%
- \definedummyword{o}%
- \definedummyword{ss}%
+ % For control letters, we have \definedummyletter, which omits the
+ % space.
+ %
+ % These can be used both for control words that take an argument and
+ % those that do not. If it is followed by {arg} in the input, then
+ % that will dutifully get written to the index (or wherever).
+ %
+ \def\definedummyword ##1{\def##1{\string##1\space}}%
+ \def\definedummyletter##1{\def##1{\string##1}}%
+ \let\definedummyaccent\definedummyletter
+ %
+ \commondummiesnofonts
+ %
+ \definedummyletter\_%
+ %
+ % Non-English letters.
+ \definedummyword\AA
+ \definedummyword\AE
+ \definedummyword\L
+ \definedummyword\OE
+ \definedummyword\O
+ \definedummyword\aa
+ \definedummyword\ae
+ \definedummyword\l
+ \definedummyword\oe
+ \definedummyword\o
+ \definedummyword\ss
+ \definedummyword\exclamdown
+ \definedummyword\questiondown
+ \definedummyword\ordf
+ \definedummyword\ordm
%
% Although these internal commands shouldn't show up, sometimes they do.
- \definedummyword{bf}%
- \definedummyword{gtr}%
- \definedummyword{hat}%
- \definedummyword{less}%
- \definedummyword{sf}%
- \definedummyword{sl}%
- \definedummyword{tclose}%
- \definedummyword{tt}%
- %
- % Texinfo font commands.
- \definedummyword{b}%
- \definedummyword{i}%
- \definedummyword{r}%
- \definedummyword{sc}%
- \definedummyword{t}%
- %
- \definedummyword{TeX}%
- \definedummyword{acronym}%
- \definedummyword{cite}%
- \definedummyword{code}%
- \definedummyword{command}%
- \definedummyword{dfn}%
- \definedummyword{dots}%
- \definedummyword{emph}%
- \definedummyword{env}%
- \definedummyword{file}%
- \definedummyword{kbd}%
- \definedummyword{key}%
- \definedummyword{math}%
- \definedummyword{option}%
- \definedummyword{samp}%
- \definedummyword{strong}%
- \definedummyword{uref}%
- \definedummyword{url}%
- \definedummyword{var}%
- \definedummyword{w}%
+ \definedummyword\bf
+ \definedummyword\gtr
+ \definedummyword\hat
+ \definedummyword\less
+ \definedummyword\sf
+ \definedummyword\sl
+ \definedummyword\tclose
+ \definedummyword\tt
+ %
+ \definedummyword\LaTeX
+ \definedummyword\TeX
%
% Assorted special characters.
- \definedummyword{bullet}%
- \definedummyword{copyright}%
- \definedummyword{dots}%
- \definedummyword{enddots}%
- \definedummyword{equiv}%
- \definedummyword{error}%
- \definedummyword{expansion}%
- \definedummyword{minus}%
- \definedummyword{pounds}%
- \definedummyword{point}%
- \definedummyword{print}%
- \definedummyword{result}%
- %
- % Handle some cases of @value -- where the variable name does not
- % contain - or _, and the value does not contain any
- % (non-fully-expandable) commands.
- \let\value = \expandablevalue
+ \definedummyword\bullet
+ \definedummyword\comma
+ \definedummyword\copyright
+ \definedummyword\registeredsymbol
+ \definedummyword\dots
+ \definedummyword\enddots
+ \definedummyword\equiv
+ \definedummyword\error
+ \definedummyword\euro
+ \definedummyword\expansion
+ \definedummyword\minus
+ \definedummyword\pounds
+ \definedummyword\point
+ \definedummyword\print
+ \definedummyword\result
+ %
+ % We want to disable all macros so that they are not expanded by \write.
+ \macrolist
%
- % Normal spaces, not active ones.
- \unsepspaces
+ \normalturnoffactive
%
- % No macro expansion.
- \turnoffmacros
+ % Handle some cases of @value -- where it does not contain any
+ % (non-fully-expandable) commands.
+ \makevalueexpandable
}
-% If an index command is used in an @example environment, any spaces
-% therein should become regular spaces in the raw index file, not the
-% expansion of \tie (\leavevmode \penalty \@M \ ).
-{\obeyspaces
- \gdef\unsepspaces{\obeyspaces\let =\space}}
-
+% \commondummiesnofonts: common to \commondummies and \indexnofonts.
+%
+% Better have this without active chars.
+{
+ \catcode`\~=\other
+ \gdef\commondummiesnofonts{%
+ % Control letters and accents.
+ \definedummyletter\!%
+ \definedummyaccent\"%
+ \definedummyaccent\'%
+ \definedummyletter\*%
+ \definedummyaccent\,%
+ \definedummyletter\.%
+ \definedummyletter\/%
+ \definedummyletter\:%
+ \definedummyaccent\=%
+ \definedummyletter\?%
+ \definedummyaccent\^%
+ \definedummyaccent\`%
+ \definedummyaccent\~%
+ \definedummyword\u
+ \definedummyword\v
+ \definedummyword\H
+ \definedummyword\dotaccent
+ \definedummyword\ringaccent
+ \definedummyword\tieaccent
+ \definedummyword\ubaraccent
+ \definedummyword\udotaccent
+ \definedummyword\dotless
+ %
+ % Texinfo font commands.
+ \definedummyword\b
+ \definedummyword\i
+ \definedummyword\r
+ \definedummyword\sc
+ \definedummyword\t
+ %
+ % Commands that take arguments.
+ \definedummyword\acronym
+ \definedummyword\cite
+ \definedummyword\code
+ \definedummyword\command
+ \definedummyword\dfn
+ \definedummyword\emph
+ \definedummyword\env
+ \definedummyword\file
+ \definedummyword\kbd
+ \definedummyword\key
+ \definedummyword\math
+ \definedummyword\option
+ \definedummyword\samp
+ \definedummyword\strong
+ \definedummyword\tie
+ \definedummyword\uref
+ \definedummyword\url
+ \definedummyword\var
+ \definedummyword\verb
+ \definedummyword\w
+ }
+}
% \indexnofonts is used when outputting the strings to sort the index
% by, and when constructing control sequence names. It eliminates all
% control sequences and just writes whatever the best ASCII sort string
% would be for a given command (usually its argument).
%
-\def\indexdummytex{TeX}
-\def\indexdummydots{...}
-%
\def\indexnofonts{%
+ % Accent commands should become @asis.
+ \def\definedummyaccent##1{\let##1\asis}%
+ % We can just ignore other control letters.
+ \def\definedummyletter##1{\let##1\empty}%
+ % Hopefully, all control words can become @asis.
+ \let\definedummyword\definedummyaccent
+ %
+ \commondummiesnofonts
+ %
+ % Don't no-op \tt, since it isn't a user-level command
+ % and is used in the definitions of the active chars like <, >, |, etc.
+ % Likewise with the other plain tex font commands.
+ %\let\tt=\asis
+ %
\def\ { }%
\def\@{@}%
% how to handle braces?
\def\_{\normalunderscore}%
%
- \let\,=\asis
- \let\"=\asis
- \let\`=\asis
- \let\'=\asis
- \let\^=\asis
- \let\~=\asis
- \let\==\asis
- \let\u=\asis
- \let\v=\asis
- \let\H=\asis
- \let\dotaccent=\asis
- \let\ringaccent=\asis
- \let\tieaccent=\asis
- \let\ubaraccent=\asis
- \let\udotaccent=\asis
- \let\dotless=\asis
- %
- % Other non-English letters.
+ % Non-English letters.
\def\AA{AA}%
\def\AE{AE}%
\def\L{L}%
@@ -3173,130 +3428,178 @@ width0pt\relax} \fi
\def\ss{ss}%
\def\exclamdown{!}%
\def\questiondown{?}%
+ \def\ordf{a}%
+ \def\ordm{o}%
%
- % Don't no-op \tt, since it isn't a user-level command
- % and is used in the definitions of the active chars like <, >, |, etc.
- % Likewise with the other plain tex font commands.
- %\let\tt=\asis
+ \def\LaTeX{LaTeX}%
+ \def\TeX{TeX}%
%
- % Texinfo font commands.
- \let\b=\asis
- \let\i=\asis
- \let\r=\asis
- \let\sc=\asis
- \let\t=\asis
- %
- \let\TeX=\indexdummytex
- \let\acronym=\asis
- \let\cite=\asis
- \let\code=\asis
- \let\command=\asis
- \let\dfn=\asis
- \let\dots=\indexdummydots
- \let\emph=\asis
- \let\env=\asis
- \let\file=\asis
- \let\kbd=\asis
- \let\key=\asis
- \let\math=\asis
- \let\option=\asis
- \let\samp=\asis
- \let\strong=\asis
- \let\uref=\asis
- \let\url=\asis
- \let\var=\asis
- \let\w=\asis
+ % Assorted special characters.
+ % (The following {} will end up in the sort string, but that's ok.)
+ \def\bullet{bullet}%
+ \def\comma{,}%
+ \def\copyright{copyright}%
+ \def\registeredsymbol{R}%
+ \def\dots{...}%
+ \def\enddots{...}%
+ \def\equiv{==}%
+ \def\error{error}%
+ \def\euro{euro}%
+ \def\expansion{==>}%
+ \def\minus{-}%
+ \def\pounds{pounds}%
+ \def\point{.}%
+ \def\print{-|}%
+ \def\result{=>}%
+ %
+ % We need to get rid of all macros, leaving only the arguments (if present).
+ % Of course this is not nearly correct, but it is the best we can do for now.
+ % makeinfo does not expand macros in the argument to @deffn, which ends up
+ % writing an index entry, and texindex isn't prepared for an index sort entry
+ % that starts with \.
+ %
+ % Since macro invocations are followed by braces, we can just redefine them
+ % to take a single TeX argument. The case of a macro invocation that
+ % goes to end-of-line is not handled.
+ %
+ \macrolist
}
\let\indexbackslash=0 %overridden during \printindex.
\let\SETmarginindex=\relax % put index entries in margin (undocumented)?
-% For \ifx comparisons.
-\def\emptymacro{\empty}
-
% Most index entries go through here, but \dosubind is the general case.
-%
-\def\doind#1#2{\dosubind{#1}{#2}\empty}
+% #1 is the index name, #2 is the entry text.
+\def\doind#1#2{\dosubind{#1}{#2}{}}
% Workhorse for all \fooindexes.
% #1 is name of index, #2 is stuff to put there, #3 is subentry --
-% \empty if called from \doind, as we usually are. The main exception
-% is with defuns, which call us directly.
+% empty if called from \doind, as we usually are (the main exception
+% is with most defuns, which call us directly).
%
\def\dosubind#1#2#3{%
+ \iflinks
+ {%
+ % Store the main index entry text (including the third arg).
+ \toks0 = {#2}%
+ % If third arg is present, precede it with a space.
+ \def\thirdarg{#3}%
+ \ifx\thirdarg\empty \else
+ \toks0 = \expandafter{\the\toks0 \space #3}%
+ \fi
+ %
+ \edef\writeto{\csname#1indfile\endcsname}%
+ %
+ \ifvmode
+ \dosubindsanitize
+ \else
+ \dosubindwrite
+ \fi
+ }%
+ \fi
+}
+
+% Write the entry in \toks0 to the index file:
+%
+\def\dosubindwrite{%
% Put the index entry in the margin if desired.
\ifx\SETmarginindex\relax\else
- \insert\margin{\hbox{\vrule height8pt depth3pt width0pt #2}}%
+ \insert\margin{\hbox{\vrule height8pt depth3pt width0pt \the\toks0}}%
\fi
- {%
- \count255=\lastpenalty
- {%
- \indexdummies % Must do this here, since \bf, etc expand at this stage
- \escapechar=`\\
- {%
- \let\folio = 0% We will expand all macros now EXCEPT \folio.
- \def\rawbackslashxx{\indexbackslash}% \indexbackslash isn't defined now
- % so it will be output as is; and it will print as backslash.
- %
- % The main index entry text.
- \toks0 = {#2}%
- %
- % If third arg is present, precede it with space in sort key.
- \def\thirdarg{#3}%
- \ifx\thirdarg\emptymacro \else
- % If the third (subentry) arg is present, add it to the index
- % line to write.
- \toks0 = \expandafter{\the\toks0 \space #3}%
- \fi
- %
- % Process the index entry with all font commands turned off, to
- % get the string to sort by.
- {\indexnofonts
- \edef\temp{\the\toks0}% need full expansion
- \xdef\indexsorttmp{\temp}%
- }%
- %
- % Set up the complete index entry, with both the sort key and
- % the original text, including any font commands. We write
- % three arguments to \entry to the .?? file (four in the
- % subentry case), texindex reduces to two when writing the .??s
- % sorted result.
- \edef\temp{%
- \write\csname#1indfile\endcsname{%
- \realbackslash entry{\indexsorttmp}{\folio}{\the\toks0}}%
- }%
- %
- % If a skip is the last thing on the list now, preserve it
- % by backing up by \lastskip, doing the \write, then inserting
- % the skip again. Otherwise, the whatsit generated by the
- % \write will make \lastskip zero. The result is that sequences
- % like this:
- % @end defun
- % @tindex whatever
- % @defun ...
- % will have extra space inserted, because the \medbreak in the
- % start of the @defun won't see the skip inserted by the @end of
- % the previous defun.
- %
- % But don't do any of this if we're not in vertical mode. We
- % don't want to do a \vskip and prematurely end a paragraph.
- %
- % Avoid page breaks due to these extra skips, too.
- %
- \iflinks
- \ifvmode
- \skip0 = \lastskip
- \ifdim\lastskip = 0pt \else \nobreak\vskip-\skip0 \fi
- \fi
- %
- \temp % do the write
- %
- \ifvmode \ifdim\skip0 = 0pt \else \nobreak\vskip\skip0 \fi \fi
- \fi
- }%
- }%
- \penalty\count255
+ %
+ % Remember, we are within a group.
+ \indexdummies % Must do this here, since \bf, etc expand at this stage
+ \def\backslashcurfont{\indexbackslash}% \indexbackslash isn't defined now
+ % so it will be output as is; and it will print as backslash.
+ %
+ % Process the index entry with all font commands turned off, to
+ % get the string to sort by.
+ {\indexnofonts
+ \edef\temp{\the\toks0}% need full expansion
+ \xdef\indexsorttmp{\temp}%
+ }%
+ %
+ % Set up the complete index entry, with both the sort key and
+ % the original text, including any font commands. We write
+ % three arguments to \entry to the .?? file (four in the
+ % subentry case), texindex reduces to two when writing the .??s
+ % sorted result.
+ \edef\temp{%
+ \write\writeto{%
+ \string\entry{\indexsorttmp}{\noexpand\folio}{\the\toks0}}%
}%
+ \temp
+}
+
+% Take care of unwanted page breaks:
+%
+% If a skip is the last thing on the list now, preserve it
+% by backing up by \lastskip, doing the \write, then inserting
+% the skip again. Otherwise, the whatsit generated by the
+% \write will make \lastskip zero. The result is that sequences
+% like this:
+% @end defun
+% @tindex whatever
+% @defun ...
+% will have extra space inserted, because the \medbreak in the
+% start of the @defun won't see the skip inserted by the @end of
+% the previous defun.
+%
+% But don't do any of this if we're not in vertical mode. We
+% don't want to do a \vskip and prematurely end a paragraph.
+%
+% Avoid page breaks due to these extra skips, too.
+%
+% But wait, there is a catch there:
+% We'll have to check whether \lastskip is zero skip. \ifdim is not
+% sufficient for this purpose, as it ignores stretch and shrink parts
+% of the skip. The only way seems to be to check the textual
+% representation of the skip.
+%
+% The following is almost like \def\zeroskipmacro{0.0pt} except that
+% the ``p'' and ``t'' characters have catcode \other, not 11 (letter).
+%
+\edef\zeroskipmacro{\expandafter\the\csname z@skip\endcsname}
+%
+% ..., ready, GO:
+%
+\def\dosubindsanitize{%
+ % \lastskip and \lastpenalty cannot both be nonzero simultaneously.
+ \skip0 = \lastskip
+ \edef\lastskipmacro{\the\lastskip}%
+ \count255 = \lastpenalty
+ %
+ % If \lastskip is nonzero, that means the last item was a
+ % skip. And since a skip is discardable, that means this
+ % -\skip0 glue we're inserting is preceded by a
+ % non-discardable item, therefore it is not a potential
+ % breakpoint, therefore no \nobreak needed.
+ \ifx\lastskipmacro\zeroskipmacro
+ \else
+ \vskip-\skip0
+ \fi
+ %
+ \dosubindwrite
+ %
+ \ifx\lastskipmacro\zeroskipmacro
+ % If \lastskip was zero, perhaps the last item was a penalty, and
+ % perhaps it was >=10000, e.g., a \nobreak. In that case, we want
+ % to re-insert the same penalty (values >10000 are used for various
+ % signals); since we just inserted a non-discardable item, any
+ % following glue (such as a \parskip) would be a breakpoint. For example:
+ %
+ % @deffn deffn-whatever
+ % @vindex index-whatever
+ % Description.
+ % would allow a break between the index-whatever whatsit
+ % and the "Description." paragraph.
+ \ifnum\count255>9999 \penalty\count255 \fi
+ \else
+ % On the other hand, if we had a nonzero \lastskip,
+ % this make-up glue would be preceded by a non-discardable item
+ % (the whatsit from the \write), so we must insert a \nobreak.
+ \nobreak\vskip\skip0
+ \fi
}
% The index entry written in the file actually looks like
@@ -3334,13 +3637,12 @@ width0pt\relax} \fi
% @printindex causes a particular index (the ??s file) to get printed.
% It does not print any chapter heading (usually an @unnumbered).
%
-\def\printindex{\parsearg\doprintindex}
-\def\doprintindex#1{\begingroup
+\parseargdef\printindex{\begingroup
\dobreak \chapheadingskip{10000}%
%
\smallfonts \rm
\tolerance = 9500
- \indexbreaks
+ \everypar = {}% don't want the \kern\-parindent from indentation suppression.
%
% See if the index file exists and is nonempty.
% Change catcode of @ here so that if the index file contains
@@ -3367,7 +3669,7 @@ width0pt\relax} \fi
% Index files are almost Texinfo source, but we use \ as the escape
% character. It would be better to use @, but that's too big a change
% to make right now.
- \def\indexbackslash{\rawbackslashxx}%
+ \def\indexbackslash{\backslashcurfont}%
\catcode`\\ = 0
\escapechar = `\\
\begindoublecolumns
@@ -3389,7 +3691,10 @@ width0pt\relax} \fi
\removelastskip
%
% We like breaks before the index initials, so insert a bonus.
- \penalty -300
+ \nobreak
+ \vskip 0pt plus 3\baselineskip
+ \penalty 0
+ \vskip 0pt plus -3\baselineskip
%
% Typeset the initial. Making this add up to a whole number of
% baselineskips increases the chance of the dots lining up from column
@@ -3399,80 +3704,100 @@ width0pt\relax} \fi
% No shrink because it confuses \balancecolumns.
\vskip 1.67\baselineskip plus .5\baselineskip
\leftline{\secbf #1}%
- \vskip .33\baselineskip plus .1\baselineskip
- %
% Do our best not to break after the initial.
\nobreak
+ \vskip .33\baselineskip plus .1\baselineskip
}}
-% This typesets a paragraph consisting of #1, dot leaders, and then #2
-% flush to the right margin. It is used for index and table of contents
-% entries. The paragraph is indented by \leftskip.
+% \entry typesets a paragraph consisting of the text (#1), dot leaders, and
+% then page number (#2) flushed to the right margin. It is used for index
+% and table of contents entries. The paragraph is indented by \leftskip.
%
-\def\entry#1#2{\begingroup
- %
- % Start a new paragraph if necessary, so our assignments below can't
- % affect previous text.
- \par
- %
- % Do not fill out the last line with white space.
- \parfillskip = 0in
- %
- % No extra space above this paragraph.
- \parskip = 0in
- %
- % Do not prefer a separate line ending with a hyphen to fewer lines.
- \finalhyphendemerits = 0
- %
- % \hangindent is only relevant when the entry text and page number
- % don't both fit on one line. In that case, bob suggests starting the
- % dots pretty far over on the line. Unfortunately, a large
- % indentation looks wrong when the entry text itself is broken across
- % lines. So we use a small indentation and put up with long leaders.
- %
- % \hangafter is reset to 1 (which is the value we want) at the start
- % of each paragraph, so we need not do anything with that.
- \hangindent = 2em
- %
- % When the entry text needs to be broken, just fill out the first line
- % with blank space.
- \rightskip = 0pt plus1fil
- %
- % A bit of stretch before each entry for the benefit of balancing columns.
- \vskip 0pt plus1pt
- %
- % Start a ``paragraph'' for the index entry so the line breaking
- % parameters we've set above will have an effect.
- \noindent
- %
- % Insert the text of the index entry. TeX will do line-breaking on it.
- #1%
- % The following is kludged to not output a line of dots in the index if
- % there are no page numbers. The next person who breaks this will be
- % cursed by a Unix daemon.
- \def\tempa{{\rm }}%
- \def\tempb{#2}%
- \edef\tempc{\tempa}%
- \edef\tempd{\tempb}%
- \ifx\tempc\tempd\ \else%
+% A straightforward implementation would start like this:
+% \def\entry#1#2{...
+% But this frozes the catcodes in the argument, and can cause problems to
+% @code, which sets - active. This problem was fixed by a kludge---
+% ``-'' was active throughout whole index, but this isn't really right.
+%
+% The right solution is to prevent \entry from swallowing the whole text.
+% --kasal, 21nov03
+\def\entry{%
+ \begingroup
+ %
+ % Start a new paragraph if necessary, so our assignments below can't
+ % affect previous text.
+ \par
+ %
+ % Do not fill out the last line with white space.
+ \parfillskip = 0in
+ %
+ % No extra space above this paragraph.
+ \parskip = 0in
+ %
+ % Do not prefer a separate line ending with a hyphen to fewer lines.
+ \finalhyphendemerits = 0
%
- % If we must, put the page number on a line of its own, and fill out
- % this line with blank space. (The \hfil is overwhelmed with the
- % fill leaders glue in \indexdotfill if the page number does fit.)
- \hfil\penalty50
- \null\nobreak\indexdotfill % Have leaders before the page number.
+ % \hangindent is only relevant when the entry text and page number
+ % don't both fit on one line. In that case, bob suggests starting the
+ % dots pretty far over on the line. Unfortunately, a large
+ % indentation looks wrong when the entry text itself is broken across
+ % lines. So we use a small indentation and put up with long leaders.
%
- % The `\ ' here is removed by the implicit \unskip that TeX does as
- % part of (the primitive) \par. Without it, a spurious underfull
- % \hbox ensues.
- \ifpdf
- \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
+ % \hangafter is reset to 1 (which is the value we want) at the start
+ % of each paragraph, so we need not do anything with that.
+ \hangindent = 2em
+ %
+ % When the entry text needs to be broken, just fill out the first line
+ % with blank space.
+ \rightskip = 0pt plus1fil
+ %
+ % A bit of stretch before each entry for the benefit of balancing
+ % columns.
+ \vskip 0pt plus1pt
+ %
+ % Swallow the left brace of the text (first parameter):
+ \afterassignment\doentry
+ \let\temp =
+}
+\def\doentry{%
+ \bgroup % Instead of the swallowed brace.
+ \noindent
+ \aftergroup\finishentry
+ % And now comes the text of the entry.
+}
+\def\finishentry#1{%
+ % #1 is the page number.
+ %
+ % The following is kludged to not output a line of dots in the index if
+ % there are no page numbers. The next person who breaks this will be
+ % cursed by a Unix daemon.
+ \def\tempa{{\rm }}%
+ \def\tempb{#1}%
+ \edef\tempc{\tempa}%
+ \edef\tempd{\tempb}%
+ \ifx\tempc\tempd
+ \ %
\else
- \ #2% The page number ends the paragraph.
+ %
+ % If we must, put the page number on a line of its own, and fill out
+ % this line with blank space. (The \hfil is overwhelmed with the
+ % fill leaders glue in \indexdotfill if the page number does fit.)
+ \hfil\penalty50
+ \null\nobreak\indexdotfill % Have leaders before the page number.
+ %
+ % The `\ ' here is removed by the implicit \unskip that TeX does as
+ % part of (the primitive) \par. Without it, a spurious underfull
+ % \hbox ensues.
+ \ifpdf
+ \pdfgettoks#1.%
+ \ \the\toksA
+ \else
+ \ #1%
+ \fi
\fi
- \fi%
- \par
-\endgroup}
+ \par
+ \endgroup
+}
% Like \dotfill except takes at least 1 em.
\def\indexdotfill{\cleaders
@@ -3583,7 +3908,7 @@ width0pt\relax} \fi
\wd0=\hsize \wd2=\hsize
\hbox to\pagewidth{\box0\hfil\box2}%
}
-%
+%
% All done with double columns.
\def\enddoublecolumns{%
\output = {%
@@ -3641,6 +3966,12 @@ width0pt\relax} \fi
\message{sectioning,}
% Chapters, sections, etc.
+% \unnumberedno is an oxymoron, of course. But we count the unnumbered
+% sections so that we can refer to them unambiguously in the pdf
+% outlines by their "section number". We avoid collisions with chapter
+% numbers by starting them at 10000. (If a document ever has 10000
+% chapters, we're in trouble anyway, I'm sure.)
+\newcount\unnumberedno \unnumberedno = 10000
\newcount\chapno
\newcount\secno \secno=0
\newcount\subsecno \subsecno=0
@@ -3648,9 +3979,12 @@ width0pt\relax} \fi
% This counter is funny since it counts through charcodes of letters A, B, ...
\newcount\appendixno \appendixno = `\@
+%
% \def\appendixletter{\char\the\appendixno}
-% We do the following for the sake of pdftex, which needs the actual
+% We do the following ugly conditional instead of the above simple
+% construct for the sake of pdftex, which needs the actual
% letter in the expansion, not just typeset.
+%
\def\appendixletter{%
\ifnum\appendixno=`A A%
\else\ifnum\appendixno=`B B%
@@ -3688,11 +4022,12 @@ width0pt\relax} \fi
% Each @chapter defines this as the name of the chapter.
% page headings and footings can use it. @section does likewise.
+% However, they are not reliable, because we don't use marks.
\def\thischapter{}
\def\thissection{}
\newcount\absseclevel % used to calculate proper heading level
-\newcount\secbase\secbase=0 % @raise/lowersections modify this count
+\newcount\secbase\secbase=0 % @raisesections/@lowersections modify this count
% @raisesections: treat @section as chapter, @subsection as section, etc.
\def\raisesections{\global\advance\secbase by -1}
@@ -3702,118 +4037,142 @@ width0pt\relax} \fi
\def\lowersections{\global\advance\secbase by 1}
\let\down=\lowersections % original BFox name
-% Choose a numbered-heading macro
-% #1 is heading level if unmodified by @raisesections or @lowersections
-% #2 is text for heading
-\def\numhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
-\ifcase\absseclevel
- \chapterzzz{#2}
-\or
- \seczzz{#2}
-\or
- \numberedsubseczzz{#2}
-\or
- \numberedsubsubseczzz{#2}
-\else
- \ifnum \absseclevel<0
- \chapterzzz{#2}
+% we only have subsub.
+\chardef\maxseclevel = 3
+%
+% A numbered section within an unnumbered changes to unnumbered too.
+% To achive this, remember the "biggest" unnum. sec. we are currently in:
+\chardef\unmlevel = \maxseclevel
+%
+% Trace whether the current chapter is an appendix or not:
+% \chapheadtype is "N" or "A", unnumbered chapters are ignored.
+\def\chapheadtype{N}
+
+% Choose a heading macro
+% #1 is heading type
+% #2 is heading level
+% #3 is text for heading
+\def\genhead#1#2#3{%
+ % Compute the abs. sec. level:
+ \absseclevel=#2
+ \advance\absseclevel by \secbase
+ % Make sure \absseclevel doesn't fall outside the range:
+ \ifnum \absseclevel < 0
+ \absseclevel = 0
\else
- \numberedsubsubseczzz{#2}
+ \ifnum \absseclevel > 3
+ \absseclevel = 3
+ \fi
\fi
-\fi
-}
-
-% like \numhead, but chooses appendix heading levels
-\def\apphead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
-\ifcase\absseclevel
- \appendixzzz{#2}
-\or
- \appendixsectionzzz{#2}
-\or
- \appendixsubseczzz{#2}
-\or
- \appendixsubsubseczzz{#2}
-\else
- \ifnum \absseclevel<0
- \appendixzzz{#2}
+ % The heading type:
+ \def\headtype{#1}%
+ \if \headtype U%
+ \ifnum \absseclevel < \unmlevel
+ \chardef\unmlevel = \absseclevel
+ \fi
\else
- \appendixsubsubseczzz{#2}
+ % Check for appendix sections:
+ \ifnum \absseclevel = 0
+ \edef\chapheadtype{\headtype}%
+ \else
+ \if \headtype A\if \chapheadtype N%
+ \errmessage{@appendix... within a non-appendix chapter}%
+ \fi\fi
+ \fi
+ % Check for numbered within unnumbered:
+ \ifnum \absseclevel > \unmlevel
+ \def\headtype{U}%
+ \else
+ \chardef\unmlevel = 3
+ \fi
\fi
-\fi
-}
-
-% like \numhead, but chooses numberless heading levels
-\def\unnmhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
-\ifcase\absseclevel
- \unnumberedzzz{#2}
-\or
- \unnumberedseczzz{#2}
-\or
- \unnumberedsubseczzz{#2}
-\or
- \unnumberedsubsubseczzz{#2}
-\else
- \ifnum \absseclevel<0
- \unnumberedzzz{#2}
+ % Now print the heading:
+ \if \headtype U%
+ \ifcase\absseclevel
+ \unnumberedzzz{#3}%
+ \or \unnumberedseczzz{#3}%
+ \or \unnumberedsubseczzz{#3}%
+ \or \unnumberedsubsubseczzz{#3}%
+ \fi
\else
- \unnumberedsubsubseczzz{#2}
+ \if \headtype A%
+ \ifcase\absseclevel
+ \appendixzzz{#3}%
+ \or \appendixsectionzzz{#3}%
+ \or \appendixsubseczzz{#3}%
+ \or \appendixsubsubseczzz{#3}%
+ \fi
+ \else
+ \ifcase\absseclevel
+ \chapterzzz{#3}%
+ \or \seczzz{#3}%
+ \or \numberedsubseczzz{#3}%
+ \or \numberedsubsubseczzz{#3}%
+ \fi
+ \fi
\fi
-\fi
+ \suppressfirstparagraphindent
}
-% @chapter, @appendix, @unnumbered.
-\def\thischaptername{No Chapter Title}
-\outer\def\chapter{\parsearg\chapteryyy}
-\def\chapteryyy #1{\numhead0{#1}} % normally numhead0 calls chapterzzz
-\def\chapterzzz #1{%
- \secno=0 \subsecno=0 \subsubsecno=0
- \global\advance \chapno by 1 \message{\putwordChapter\space \the\chapno}%
- \chapmacro {#1}{\the\chapno}%
- \gdef\thissection{#1}%
- \gdef\thischaptername{#1}%
- % We don't substitute the actual chapter name into \thischapter
- % because we don't want its macros evaluated now.
- \xdef\thischapter{\putwordChapter{} \the\chapno: \noexpand\thischaptername}%
- \writetocentry{chap}{#1}{{\the\chapno}}
- \donoderef
+% an interface:
+\def\numhead{\genhead N}
+\def\apphead{\genhead A}
+\def\unnmhead{\genhead U}
+
+% @chapter, @appendix, @unnumbered. Increment top-level counter, reset
+% all lower-level sectioning counters to zero.
+%
+% Also set \chaplevelprefix, which we prepend to @float sequence numbers
+% (e.g., figures), q.v. By default (before any chapter), that is empty.
+\let\chaplevelprefix = \empty
+%
+\outer\parseargdef\chapter{\numhead0{#1}} % normally numhead0 calls chapterzzz
+\def\chapterzzz#1{%
+ % section resetting is \global in case the chapter is in a group, such
+ % as an @include file.
+ \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
+ \global\advance\chapno by 1
+ %
+ % Used for \float.
+ \gdef\chaplevelprefix{\the\chapno.}%
+ \resetallfloatnos
+ %
+ \message{\putwordChapter\space \the\chapno}%
+ %
+ % Write the actual heading.
+ \chapmacro{#1}{Ynumbered}{\the\chapno}%
+ %
+ % So @section and the like are numbered underneath this chapter.
\global\let\section = \numberedsec
\global\let\subsection = \numberedsubsec
\global\let\subsubsection = \numberedsubsubsec
}
-% we use \chapno to avoid indenting back
-\def\appendixbox#1{%
- \setbox0 = \hbox{\putwordAppendix{} \the\chapno}%
- \hbox to \wd0{#1\hss}}
-
-\outer\def\appendix{\parsearg\appendixyyy}
-\def\appendixyyy #1{\apphead0{#1}} % normally apphead0 calls appendixzzz
-\def\appendixzzz #1{%
- \secno=0 \subsecno=0 \subsubsecno=0
- \global\advance \appendixno by 1
- \message{\putwordAppendix\space \appendixletter}%
- \chapmacro {#1}{\appendixbox{\putwordAppendix{} \appendixletter}}%
- \gdef\thissection{#1}%
- \gdef\thischaptername{#1}%
- \xdef\thischapter{\putwordAppendix{} \appendixletter: \noexpand\thischaptername}%
- \writetocentry{appendix}{#1}{{\appendixletter}}
- \appendixnoderef
+\outer\parseargdef\appendix{\apphead0{#1}} % normally apphead0 calls appendixzzz
+\def\appendixzzz#1{%
+ \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
+ \global\advance\appendixno by 1
+ \gdef\chaplevelprefix{\appendixletter.}%
+ \resetallfloatnos
+ %
+ \def\appendixnum{\putwordAppendix\space \appendixletter}%
+ \message{\appendixnum}%
+ %
+ \chapmacro{#1}{Yappendix}{\appendixletter}%
+ %
\global\let\section = \appendixsec
\global\let\subsection = \appendixsubsec
\global\let\subsubsection = \appendixsubsubsec
}
-% @centerchap is like @unnumbered, but the heading is centered.
-\outer\def\centerchap{\parsearg\centerchapyyy}
-\def\centerchapyyy #1{{\let\unnumbchapmacro=\centerchapmacro \unnumberedyyy{#1}}}
-
-% @top is like @unnumbered.
-\outer\def\top{\parsearg\unnumberedyyy}
-
-\outer\def\unnumbered{\parsearg\unnumberedyyy}
-\def\unnumberedyyy #1{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
-\def\unnumberedzzz #1{%
- \secno=0 \subsecno=0 \subsubsecno=0
+\outer\parseargdef\unnumbered{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
+\def\unnumberedzzz#1{%
+ \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
+ \global\advance\unnumberedno by 1
+ %
+ % Since an unnumbered has no number, no prefix for figures.
+ \global\let\chaplevelprefix = \empty
+ \resetallfloatnos
%
% This used to be simply \message{#1}, but TeX fully expands the
% argument to \message. Therefore, if #1 contained @-commands, TeX
@@ -3826,134 +4185,98 @@ width0pt\relax} \fi
% \the<toks register> to achieve this: TeX expands \the<toks> only once,
% simply yielding the contents of <toks register>. (We also do this for
% the toc entries.)
- \toks0 = {#1}\message{(\the\toks0)}%
+ \toks0 = {#1}%
+ \message{(\the\toks0)}%
+ %
+ \chapmacro{#1}{Ynothing}{\the\unnumberedno}%
%
- \unnumbchapmacro {#1}%
- \gdef\thischapter{#1}\gdef\thissection{#1}%
- \writetocentry{unnumbchap}{#1}{{\the\chapno}}
- \unnumbnoderef
\global\let\section = \unnumberedsec
\global\let\subsection = \unnumberedsubsec
\global\let\subsubsection = \unnumberedsubsubsec
}
+% @centerchap is like @unnumbered, but the heading is centered.
+\outer\parseargdef\centerchap{%
+ % Well, we could do the following in a group, but that would break
+ % an assumption that \chapmacro is called at the outermost level.
+ % Thus we are safer this way: --kasal, 24feb04
+ \let\centerparametersmaybe = \centerparameters
+ \unnmhead0{#1}%
+ \let\centerparametersmaybe = \relax
+}
+
+% @top is like @unnumbered.
+\let\top\unnumbered
+
% Sections.
-\outer\def\numberedsec{\parsearg\secyyy}
-\def\secyyy #1{\numhead1{#1}} % normally calls seczzz
-\def\seczzz #1{%
- \subsecno=0 \subsubsecno=0 \global\advance \secno by 1 %
- \gdef\thissection{#1}\secheading {#1}{\the\chapno}{\the\secno}%
- \writetocentry{sec}{#1}{{\the\chapno}{\the\secno}}
- \donoderef
- \nobreak
+\outer\parseargdef\numberedsec{\numhead1{#1}} % normally calls seczzz
+\def\seczzz#1{%
+ \global\subsecno=0 \global\subsubsecno=0 \global\advance\secno by 1
+ \sectionheading{#1}{sec}{Ynumbered}{\the\chapno.\the\secno}%
}
-\outer\def\appendixsection{\parsearg\appendixsecyyy}
-\outer\def\appendixsec{\parsearg\appendixsecyyy}
-\def\appendixsecyyy #1{\apphead1{#1}} % normally calls appendixsectionzzz
-\def\appendixsectionzzz #1{%
- \subsecno=0 \subsubsecno=0 \global\advance \secno by 1 %
- \gdef\thissection{#1}\secheading {#1}{\appendixletter}{\the\secno}%
- \writetocentry{sec}{#1}{{\appendixletter}{\the\secno}}
- \appendixnoderef
- \nobreak
+\outer\parseargdef\appendixsection{\apphead1{#1}} % normally calls appendixsectionzzz
+\def\appendixsectionzzz#1{%
+ \global\subsecno=0 \global\subsubsecno=0 \global\advance\secno by 1
+ \sectionheading{#1}{sec}{Yappendix}{\appendixletter.\the\secno}%
}
+\let\appendixsec\appendixsection
-\outer\def\unnumberedsec{\parsearg\unnumberedsecyyy}
-\def\unnumberedsecyyy #1{\unnmhead1{#1}} % normally calls unnumberedseczzz
-\def\unnumberedseczzz #1{%
- \plainsecheading {#1}\gdef\thissection{#1}%
- \writetocentry{unnumbsec}{#1}{{\the\chapno}{\the\secno}}
- \unnumbnoderef
- \nobreak
+\outer\parseargdef\unnumberedsec{\unnmhead1{#1}} % normally calls unnumberedseczzz
+\def\unnumberedseczzz#1{%
+ \global\subsecno=0 \global\subsubsecno=0 \global\advance\secno by 1
+ \sectionheading{#1}{sec}{Ynothing}{\the\unnumberedno.\the\secno}%
}
% Subsections.
-\outer\def\numberedsubsec{\parsearg\numberedsubsecyyy}
-\def\numberedsubsecyyy #1{\numhead2{#1}} % normally calls numberedsubseczzz
-\def\numberedsubseczzz #1{%
- \gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
- \subsecheading {#1}{\the\chapno}{\the\secno}{\the\subsecno}%
- \writetocentry{subsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}}
- \donoderef
- \nobreak
+\outer\parseargdef\numberedsubsec{\numhead2{#1}} % normally calls numberedsubseczzz
+\def\numberedsubseczzz#1{%
+ \global\subsubsecno=0 \global\advance\subsecno by 1
+ \sectionheading{#1}{subsec}{Ynumbered}{\the\chapno.\the\secno.\the\subsecno}%
}
-\outer\def\appendixsubsec{\parsearg\appendixsubsecyyy}
-\def\appendixsubsecyyy #1{\apphead2{#1}} % normally calls appendixsubseczzz
-\def\appendixsubseczzz #1{%
- \gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
- \subsecheading {#1}{\appendixletter}{\the\secno}{\the\subsecno}%
- \writetocentry{subsec}{#1}{{\appendixletter}{\the\secno}{\the\subsecno}}
- \appendixnoderef
- \nobreak
+\outer\parseargdef\appendixsubsec{\apphead2{#1}} % normally calls appendixsubseczzz
+\def\appendixsubseczzz#1{%
+ \global\subsubsecno=0 \global\advance\subsecno by 1
+ \sectionheading{#1}{subsec}{Yappendix}%
+ {\appendixletter.\the\secno.\the\subsecno}%
}
-\outer\def\unnumberedsubsec{\parsearg\unnumberedsubsecyyy}
-\def\unnumberedsubsecyyy #1{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
-\def\unnumberedsubseczzz #1{%
- \plainsubsecheading {#1}\gdef\thissection{#1}%
- \writetocentry{unnumbsubsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}}
- \unnumbnoderef
- \nobreak
+\outer\parseargdef\unnumberedsubsec{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
+\def\unnumberedsubseczzz#1{%
+ \global\subsubsecno=0 \global\advance\subsecno by 1
+ \sectionheading{#1}{subsec}{Ynothing}%
+ {\the\unnumberedno.\the\secno.\the\subsecno}%
}
% Subsubsections.
-\outer\def\numberedsubsubsec{\parsearg\numberedsubsubsecyyy}
-\def\numberedsubsubsecyyy #1{\numhead3{#1}} % normally numberedsubsubseczzz
-\def\numberedsubsubseczzz #1{%
- \gdef\thissection{#1}\global\advance \subsubsecno by 1 %
- \subsubsecheading {#1}
- {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
- \writetocentry{subsubsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}}
- \donoderef
- \nobreak
+\outer\parseargdef\numberedsubsubsec{\numhead3{#1}} % normally numberedsubsubseczzz
+\def\numberedsubsubseczzz#1{%
+ \global\advance\subsubsecno by 1
+ \sectionheading{#1}{subsubsec}{Ynumbered}%
+ {\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno}%
}
-\outer\def\appendixsubsubsec{\parsearg\appendixsubsubsecyyy}
-\def\appendixsubsubsecyyy #1{\apphead3{#1}} % normally appendixsubsubseczzz
-\def\appendixsubsubseczzz #1{%
- \gdef\thissection{#1}\global\advance \subsubsecno by 1 %
- \subsubsecheading {#1}
- {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
- \writetocentry{subsubsec}{#1}{{\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}}
- \appendixnoderef
- \nobreak
+\outer\parseargdef\appendixsubsubsec{\apphead3{#1}} % normally appendixsubsubseczzz
+\def\appendixsubsubseczzz#1{%
+ \global\advance\subsubsecno by 1
+ \sectionheading{#1}{subsubsec}{Yappendix}%
+ {\appendixletter.\the\secno.\the\subsecno.\the\subsubsecno}%
}
-\outer\def\unnumberedsubsubsec{\parsearg\unnumberedsubsubsecyyy}
-\def\unnumberedsubsubsecyyy #1{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
-\def\unnumberedsubsubseczzz #1{%
- \plainsubsubsecheading {#1}\gdef\thissection{#1}%
- \writetocentry{unnumbsubsubsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}}
- \unnumbnoderef
- \nobreak
+\outer\parseargdef\unnumberedsubsubsec{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
+\def\unnumberedsubsubseczzz#1{%
+ \global\advance\subsubsecno by 1
+ \sectionheading{#1}{subsubsec}{Ynothing}%
+ {\the\unnumberedno.\the\secno.\the\subsecno.\the\subsubsecno}%
}
-% These are variants which are not "outer", so they can appear in @ifinfo.
-% Actually, they should now be obsolete; ordinary section commands should work.
-\def\infotop{\parsearg\unnumberedzzz}
-\def\infounnumbered{\parsearg\unnumberedzzz}
-\def\infounnumberedsec{\parsearg\unnumberedseczzz}
-\def\infounnumberedsubsec{\parsearg\unnumberedsubseczzz}
-\def\infounnumberedsubsubsec{\parsearg\unnumberedsubsubseczzz}
-
-\def\infoappendix{\parsearg\appendixzzz}
-\def\infoappendixsec{\parsearg\appendixseczzz}
-\def\infoappendixsubsec{\parsearg\appendixsubseczzz}
-\def\infoappendixsubsubsec{\parsearg\appendixsubsubseczzz}
-
-\def\infochapter{\parsearg\chapterzzz}
-\def\infosection{\parsearg\sectionzzz}
-\def\infosubsection{\parsearg\subsectionzzz}
-\def\infosubsubsection{\parsearg\subsubsectionzzz}
-
% These macros control what the section commands do, according
% to what kind of chapter we are in (ordinary, appendix, or unnumbered).
% Define them by default for a numbered chapter.
-\global\let\section = \numberedsec
-\global\let\subsection = \numberedsubsec
-\global\let\subsubsection = \numberedsubsubsec
+\let\section = \numberedsec
+\let\subsection = \numberedsubsec
+\let\subsubsection = \numberedsubsubsec
% Define @majorheading, @heading and @subheading
@@ -3966,23 +4289,27 @@ width0pt\relax} \fi
% if justification is not attempted. Hence \raggedright.
-\def\majorheading{\parsearg\majorheadingzzz}
-\def\majorheadingzzz #1{%
+\def\majorheading{%
{\advance\chapheadingskip by 10pt \chapbreak }%
- {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
- \parindent=0pt\raggedright
- \rm #1\hfill}}\bigskip \par\penalty 200}
+ \parsearg\chapheadingzzz
+}
-\def\chapheading{\parsearg\chapheadingzzz}
-\def\chapheadingzzz #1{\chapbreak %
+\def\chapheading{\chapbreak \parsearg\chapheadingzzz}
+\def\chapheadingzzz#1{%
{\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
\parindent=0pt\raggedright
- \rm #1\hfill}}\bigskip \par\penalty 200}
+ \rm #1\hfill}}%
+ \bigskip \par\penalty 200\relax
+ \suppressfirstparagraphindent
+}
% @heading, @subheading, @subsubheading.
-\def\heading{\parsearg\plainsecheading}
-\def\subheading{\parsearg\plainsubsecheading}
-\def\subsubheading{\parsearg\plainsubsubsecheading}
+\parseargdef\heading{\sectionheading{#1}{sec}{Yomitfromtoc}{}
+ \suppressfirstparagraphindent}
+\parseargdef\subheading{\sectionheading{#1}{subsec}{Yomitfromtoc}{}
+ \suppressfirstparagraphindent}
+\parseargdef\subsubheading{\sectionheading{#1}{subsubsec}{Yomitfromtoc}{}
+ \suppressfirstparagraphindent}
% These macros generate a chapter, section, etc. heading only
% (including whitespace, linebreaking, etc. around it),
@@ -3991,8 +4318,6 @@ width0pt\relax} \fi
%%% Args are the skip and penalty (usually negative)
\def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
-\def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
-
%%% Define plain chapter starts, and page on/off switching for it
% Parameter controlling skip before chapter headings (if needed)
@@ -4015,7 +4340,7 @@ width0pt\relax} \fi
\global\let\pagealignmacro=\chappager
\global\def\HEADINGSon{\HEADINGSsingle}}
-\def\CHAPPAGodd{
+\def\CHAPPAGodd{%
\global\let\contentsalignmacro = \chapoddpage
\global\let\pchapsepmacro=\chapoddpage
\global\let\pagealignmacro=\chapoddpage
@@ -4023,116 +4348,193 @@ width0pt\relax} \fi
\CHAPPAGon
-\def\CHAPFplain{
-\global\let\chapmacro=\chfplain
-\global\let\unnumbchapmacro=\unnchfplain
-\global\let\centerchapmacro=\centerchfplain}
-
-% Plain chapter opening.
-% #1 is the text, #2 the chapter number or empty if unnumbered.
-\def\chfplain#1#2{%
+% Chapter opening.
+%
+% #1 is the text, #2 is the section type (Ynumbered, Ynothing,
+% Yappendix, Yomitfromtoc), #3 the chapter number.
+%
+% To test against our argument.
+\def\Ynothingkeyword{Ynothing}
+\def\Yomitfromtockeyword{Yomitfromtoc}
+\def\Yappendixkeyword{Yappendix}
+%
+\def\chapmacro#1#2#3{%
\pchapsepmacro
{%
\chapfonts \rm
- \def\chapnum{#2}%
- \setbox0 = \hbox{#2\ifx\chapnum\empty\else\enspace\fi}%
+ %
+ % Have to define \thissection before calling \donoderef, because the
+ % xref code eventually uses it. On the other hand, it has to be called
+ % after \pchapsepmacro, or the headline will change too soon.
+ \gdef\thissection{#1}%
+ \gdef\thischaptername{#1}%
+ %
+ % Only insert the separating space if we have a chapter/appendix
+ % number, and don't print the unnumbered ``number''.
+ \def\temptype{#2}%
+ \ifx\temptype\Ynothingkeyword
+ \setbox0 = \hbox{}%
+ \def\toctype{unnchap}%
+ \gdef\thischapter{#1}%
+ \else\ifx\temptype\Yomitfromtockeyword
+ \setbox0 = \hbox{}% contents like unnumbered, but no toc entry
+ \def\toctype{omit}%
+ \gdef\thischapter{}%
+ \else\ifx\temptype\Yappendixkeyword
+ \setbox0 = \hbox{\putwordAppendix{} #3\enspace}%
+ \def\toctype{app}%
+ % We don't substitute the actual chapter name into \thischapter
+ % because we don't want its macros evaluated now. And we don't
+ % use \thissection because that changes with each section.
+ %
+ \xdef\thischapter{\putwordAppendix{} \appendixletter:
+ \noexpand\thischaptername}%
+ \else
+ \setbox0 = \hbox{#3\enspace}%
+ \def\toctype{numchap}%
+ \xdef\thischapter{\putwordChapter{} \the\chapno:
+ \noexpand\thischaptername}%
+ \fi\fi\fi
+ %
+ % Write the toc entry for this chapter. Must come before the
+ % \donoderef, because we include the current node name in the toc
+ % entry, and \donoderef resets it to empty.
+ \writetocentry{\toctype}{#1}{#3}%
+ %
+ % For pdftex, we have to write out the node definition (aka, make
+ % the pdfdest) after any page break, but before the actual text has
+ % been typeset. If the destination for the pdf outline is after the
+ % text, then jumping from the outline may wind up with the text not
+ % being visible, for instance under high magnification.
+ \donoderef{#2}%
+ %
+ % Typeset the actual heading.
\vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
- \hangindent = \wd0 \centerparametersmaybe
+ \hangindent=\wd0 \centerparametersmaybe
\unhbox0 #1\par}%
}%
\nobreak\bigskip % no page break after a chapter title
\nobreak
}
-% Plain opening for unnumbered.
-\def\unnchfplain#1{\chfplain{#1}{}}
-
% @centerchap -- centered and unnumbered.
\let\centerparametersmaybe = \relax
-\def\centerchfplain#1{{%
- \def\centerparametersmaybe{%
- \advance\rightskip by 3\rightskip
- \leftskip = \rightskip
- \parfillskip = 0pt
- }%
- \chfplain{#1}{}%
-}}
+\def\centerparameters{%
+ \advance\rightskip by 3\rightskip
+ \leftskip = \rightskip
+ \parfillskip = 0pt
+}
-\CHAPFplain % The default
+% I don't think this chapter style is supported any more, so I'm not
+% updating it with the new noderef stuff. We'll see. --karl, 11aug03.
+%
+\def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
+%
\def\unnchfopen #1{%
\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
\parindent=0pt\raggedright
\rm #1\hfill}}\bigskip \par\nobreak
}
-
\def\chfopen #1#2{\chapoddpage {\chapfonts
\vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}%
\par\penalty 5000 %
}
-
\def\centerchfopen #1{%
\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
\parindent=0pt
\hfill {\rm #1}\hfill}}\bigskip \par\nobreak
}
+\def\CHAPFopen{%
+ \global\let\chapmacro=\chfopen
+ \global\let\centerchapmacro=\centerchfopen}
-\def\CHAPFopen{
-\global\let\chapmacro=\chfopen
-\global\let\unnumbchapmacro=\unnchfopen
-\global\let\centerchapmacro=\centerchfopen}
-
-% Section titles.
+% Section titles. These macros combine the section number parts and
+% call the generic \sectionheading to do the printing.
+%
\newskip\secheadingskip
-\def\secheadingbreak{\dobreak \secheadingskip {-1000}}
-\def\secheading#1#2#3{\sectionheading{sec}{#2.#3}{#1}}
-\def\plainsecheading#1{\sectionheading{sec}{}{#1}}
+\def\secheadingbreak{\dobreak \secheadingskip{-1000}}
% Subsection titles.
-\newskip \subsecheadingskip
-\def\subsecheadingbreak{\dobreak \subsecheadingskip {-500}}
-\def\subsecheading#1#2#3#4{\sectionheading{subsec}{#2.#3.#4}{#1}}
-\def\plainsubsecheading#1{\sectionheading{subsec}{}{#1}}
+\newskip\subsecheadingskip
+\def\subsecheadingbreak{\dobreak \subsecheadingskip{-500}}
% Subsubsection titles.
-\let\subsubsecheadingskip = \subsecheadingskip
-\let\subsubsecheadingbreak = \subsecheadingbreak
-\def\subsubsecheading#1#2#3#4#5{\sectionheading{subsubsec}{#2.#3.#4.#5}{#1}}
-\def\plainsubsubsecheading#1{\sectionheading{subsubsec}{}{#1}}
+\def\subsubsecheadingskip{\subsecheadingskip}
+\def\subsubsecheadingbreak{\subsecheadingbreak}
-% Print any size section title.
+% Print any size, any type, section title.
%
-% #1 is the section type (sec/subsec/subsubsec), #2 is the section
-% number (maybe empty), #3 the text.
-\def\sectionheading#1#2#3{%
- {%
- \expandafter\advance\csname #1headingskip\endcsname by \parskip
- \csname #1headingbreak\endcsname
- }%
+% #1 is the text, #2 is the section level (sec/subsec/subsubsec), #3 is
+% the section type for xrefs (Ynumbered, Ynothing, Yappendix), #4 is the
+% section number.
+%
+\def\sectionheading#1#2#3#4{%
{%
% Switch to the right set of fonts.
- \csname #1fonts\endcsname \rm
+ \csname #2fonts\endcsname \rm
+ %
+ % Insert space above the heading.
+ \csname #2headingbreak\endcsname
%
- % Only insert the separating space if we have a section number.
- \def\secnum{#2}%
- \setbox0 = \hbox{#2\ifx\secnum\empty\else\enspace\fi}%
+ % Only insert the space after the number if we have a section number.
+ \def\sectionlevel{#2}%
+ \def\temptype{#3}%
%
+ \ifx\temptype\Ynothingkeyword
+ \setbox0 = \hbox{}%
+ \def\toctype{unn}%
+ \gdef\thissection{#1}%
+ \else\ifx\temptype\Yomitfromtockeyword
+ % for @headings -- no section number, don't include in toc,
+ % and don't redefine \thissection.
+ \setbox0 = \hbox{}%
+ \def\toctype{omit}%
+ \let\sectionlevel=\empty
+ \else\ifx\temptype\Yappendixkeyword
+ \setbox0 = \hbox{#4\enspace}%
+ \def\toctype{app}%
+ \gdef\thissection{#1}%
+ \else
+ \setbox0 = \hbox{#4\enspace}%
+ \def\toctype{num}%
+ \gdef\thissection{#1}%
+ \fi\fi\fi
+ %
+ % Write the toc entry (before \donoderef). See comments in \chfplain.
+ \writetocentry{\toctype\sectionlevel}{#1}{#4}%
+ %
+ % Write the node reference (= pdf destination for pdftex).
+ % Again, see comments in \chfplain.
+ \donoderef{#3}%
+ %
+ % Output the actual section heading.
\vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
- \hangindent = \wd0 % zero if no section number
- \unhbox0 #3}%
+ \hangindent=\wd0 % zero if no section number
+ \unhbox0 #1}%
}%
- % Add extra space after the heading -- either a line space or a
- % paragraph space, whichever is more. (Some people like to set
- % \parskip to large values for some reason.) Don't allow stretch, though.
- \nobreak
- \ifdim\parskip>\normalbaselineskip
- \kern\parskip
- \else
- \kern\normalbaselineskip
- \fi
+ % Add extra space after the heading -- half of whatever came above it.
+ % Don't allow stretch, though.
+ \kern .5 \csname #2headingskip\endcsname
+ %
+ % Do not let the kern be a potential breakpoint, as it would be if it
+ % was followed by glue.
\nobreak
+ %
+ % We'll almost certainly start a paragraph next, so don't let that
+ % glue accumulate. (Not a breakpoint because it's preceded by a
+ % discardable item.)
+ \vskip-\parskip
+ %
+ % This is purely so the last item on the list is a known \penalty >
+ % 10000. This is so \startdefun can avoid allowing breakpoints after
+ % section headings. Otherwise, it would insert a valid breakpoint between:
+ %
+ % @section sec-whatever
+ % @deffn def-whatever
+ \penalty 10001
}
@@ -4141,119 +4543,173 @@ width0pt\relax} \fi
\newwrite\tocfile
% Write an entry to the toc file, opening it if necessary.
-% Called from @chapter, etc. We supply {\folio} at the end of the
-% argument, which will end up as the last argument to the \...entry macro.
+% Called from @chapter, etc.
+%
+% Example usage: \writetocentry{sec}{Section Name}{\the\chapno.\the\secno}
+% We append the current node name (if any) and page number as additional
+% arguments for the \{chap,sec,...}entry macros which will eventually
+% read this. The node name is used in the pdf outlines as the
+% destination to jump to.
%
-% Usage: \writetocentry{chap}{The Name of The Game}{{\the\chapno}}
% We open the .toc file for writing here instead of at @setfilename (or
% any other fixed time) so that @contents can be anywhere in the document.
+% But if #1 is `omit', then we don't do anything. This is used for the
+% table of contents chapter openings themselves.
%
\newif\iftocfileopened
+\def\omitkeyword{omit}%
+%
\def\writetocentry#1#2#3{%
- \iftocfileopened\else
- \immediate\openout\tocfile = \jobname.toc
- \global\tocfileopenedtrue
- \fi
- %
- \iflinks
- \toks0 = {#2}%
- \edef\temp{\write\tocfile{\realbackslash #1entry{\the\toks0}#3{\folio}}}%
- \temp
+ \edef\writetoctype{#1}%
+ \ifx\writetoctype\omitkeyword \else
+ \iftocfileopened\else
+ \immediate\openout\tocfile = \jobname.toc
+ \global\tocfileopenedtrue
+ \fi
+ %
+ \iflinks
+ {\atdummies
+ \edef\temp{%
+ \write\tocfile{@#1entry{#2}{#3}{\lastnode}{\noexpand\folio}}}%
+ \temp
+ }
+ \fi
\fi
%
- % Tell \shipout to create a page destination if we're doing pdf, which
- % will be the target of the links in the table of contents. We can't
- % just do it on every page because the title pages are numbered 1 and
- % 2 (the page numbers aren't printed), and so are the first two pages
- % of the document. Thus, we'd have two destinations named `1', and
- % two named `2'.
- \ifpdf \pdfmakepagedesttrue \fi
+ % Tell \shipout to create a pdf destination on each page, if we're
+ % writing pdf. These are used in the table of contents. We can't
+ % just write one on every page because the title pages are numbered
+ % 1 and 2 (the page numbers aren't printed), and so are the first
+ % two pages of the document. Thus, we'd have two destinations named
+ % `1', and two named `2'.
+ \ifpdf \global\pdfmakepagedesttrue \fi
+}
+
+
+% These characters do not print properly in the Computer Modern roman
+% fonts, so we must take special care. This is more or less redundant
+% with the Texinfo input format setup at the end of this file.
+%
+\def\activecatcodes{%
+ \catcode`\"=\active
+ \catcode`\$=\active
+ \catcode`\<=\active
+ \catcode`\>=\active
+ \catcode`\\=\active
+ \catcode`\^=\active
+ \catcode`\_=\active
+ \catcode`\|=\active
+ \catcode`\~=\active
+}
+
+
+% Read the toc file, which is essentially Texinfo input.
+\def\readtocfile{%
+ \setupdatafile
+ \activecatcodes
+ \input \jobname.toc
}
\newskip\contentsrightmargin \contentsrightmargin=1in
\newcount\savepageno
\newcount\lastnegativepageno \lastnegativepageno = -1
-% Finish up the main text and prepare to read what we've written
-% to \tocfile.
+% Prepare to read what we've written to \tocfile.
%
\def\startcontents#1{%
- % If @setchapternewpage on, and @headings double, the contents should
- % start on an odd page, unlike chapters. Thus, we maintain
- % \contentsalignmacro in parallel with \pagealignmacro.
- % From: Torbjorn Granlund <tege@matematik.su.se>
- \contentsalignmacro
- \immediate\closeout\tocfile
- %
- % Don't need to put `Contents' or `Short Contents' in the headline.
- % It is abundantly clear what they are.
- \unnumbchapmacro{#1}\def\thischapter{}%
- \savepageno = \pageno
- \begingroup % Set up to handle contents files properly.
- \catcode`\\=0 \catcode`\{=1 \catcode`\}=2 \catcode`\@=11
- % We can't do this, because then an actual ^ in a section
- % title fails, e.g., @chapter ^ -- exponentiation. --karl, 9jul97.
- %\catcode`\^=7 % to see ^^e4 as \"a etc. juha@piuha.ydi.vtt.fi
- \raggedbottom % Worry more about breakpoints than the bottom.
- \advance\hsize by -\contentsrightmargin % Don't use the full line length.
- %
- % Roman numerals for page numbers.
- \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
+ % If @setchapternewpage on, and @headings double, the contents should
+ % start on an odd page, unlike chapters. Thus, we maintain
+ % \contentsalignmacro in parallel with \pagealignmacro.
+ % From: Torbjorn Granlund <tege@matematik.su.se>
+ \contentsalignmacro
+ \immediate\closeout\tocfile
+ %
+ % Don't need to put `Contents' or `Short Contents' in the headline.
+ % It is abundantly clear what they are.
+ \def\thischapter{}%
+ \chapmacro{#1}{Yomitfromtoc}{}%
+ %
+ \savepageno = \pageno
+ \begingroup % Set up to handle contents files properly.
+ \raggedbottom % Worry more about breakpoints than the bottom.
+ \advance\hsize by -\contentsrightmargin % Don't use the full line length.
+ %
+ % Roman numerals for page numbers.
+ \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
}
% Normal (long) toc.
\def\contents{%
- \startcontents{\putwordTOC}%
- \openin 1 \jobname.toc
- \ifeof 1 \else
- \closein 1
- \input \jobname.toc
- \fi
- \vfill \eject
- \contentsalignmacro % in case @setchapternewpage odd is in effect
- \pdfmakeoutlines
- \endgroup
- \lastnegativepageno = \pageno
- \global\pageno = \savepageno
+ \startcontents{\putwordTOC}%
+ \openin 1 \jobname.toc
+ \ifeof 1 \else
+ \readtocfile
+ \fi
+ \vfill \eject
+ \contentsalignmacro % in case @setchapternewpage odd is in effect
+ \ifeof 1 \else
+ \pdfmakeoutlines
+ \fi
+ \closein 1
+ \endgroup
+ \lastnegativepageno = \pageno
+ \global\pageno = \savepageno
}
% And just the chapters.
\def\summarycontents{%
- \startcontents{\putwordShortTOC}%
- %
- \let\chapentry = \shortchapentry
- \let\appendixentry = \shortappendixentry
- \let\unnumbchapentry = \shortunnumberedentry
- % We want a true roman here for the page numbers.
- \secfonts
- \let\rm=\shortcontrm \let\bf=\shortcontbf
- \let\sl=\shortcontsl \let\tt=\shortconttt
- \rm
- \hyphenpenalty = 10000
- \advance\baselineskip by 1pt % Open it up a little.
- \def\secentry ##1##2##3##4{}
- \def\subsecentry ##1##2##3##4##5{}
- \def\subsubsecentry ##1##2##3##4##5##6{}
- \let\unnumbsecentry = \secentry
- \let\unnumbsubsecentry = \subsecentry
- \let\unnumbsubsubsecentry = \subsubsecentry
- \openin 1 \jobname.toc
- \ifeof 1 \else
- \closein 1
- \input \jobname.toc
- \fi
- \vfill \eject
- \contentsalignmacro % in case @setchapternewpage odd is in effect
- \endgroup
- \lastnegativepageno = \pageno
- \global\pageno = \savepageno
+ \startcontents{\putwordShortTOC}%
+ %
+ \let\numchapentry = \shortchapentry
+ \let\appentry = \shortchapentry
+ \let\unnchapentry = \shortunnchapentry
+ % We want a true roman here for the page numbers.
+ \secfonts
+ \let\rm=\shortcontrm \let\bf=\shortcontbf
+ \let\sl=\shortcontsl \let\tt=\shortconttt
+ \rm
+ \hyphenpenalty = 10000
+ \advance\baselineskip by 1pt % Open it up a little.
+ \def\numsecentry##1##2##3##4{}
+ \let\appsecentry = \numsecentry
+ \let\unnsecentry = \numsecentry
+ \let\numsubsecentry = \numsecentry
+ \let\appsubsecentry = \numsecentry
+ \let\unnsubsecentry = \numsecentry
+ \let\numsubsubsecentry = \numsecentry
+ \let\appsubsubsecentry = \numsecentry
+ \let\unnsubsubsecentry = \numsecentry
+ \openin 1 \jobname.toc
+ \ifeof 1 \else
+ \readtocfile
+ \fi
+ \closein 1
+ \vfill \eject
+ \contentsalignmacro % in case @setchapternewpage odd is in effect
+ \endgroup
+ \lastnegativepageno = \pageno
+ \global\pageno = \savepageno
}
\let\shortcontents = \summarycontents
-\ifpdf
- \pdfcatalog{/PageMode /UseOutlines}%
-\fi
+% Typeset the label for a chapter or appendix for the short contents.
+% The arg is, e.g., `A' for an appendix, or `3' for a chapter.
+%
+\def\shortchaplabel#1{%
+ % This space should be enough, since a single number is .5em, and the
+ % widest letter (M) is 1em, at least in the Computer Modern fonts.
+ % But use \hss just in case.
+ % (This space doesn't include the extra space that gets added after
+ % the label; that gets put in by \shortchapentry above.)
+ %
+ % We'd like to right-justify chapter numbers, but that looks strange
+ % with appendix letters. And right-justifying numbers and
+ % left-justifying letters looks strange when there is less than 10
+ % chapters. Have to read the whole toc once to know how many chapters
+ % there are before deciding ...
+ \hbox to 1em{#1\hss}%
+}
% These macros generate individual entries in the table of contents.
% The first argument is the chapter or section name.
@@ -4261,58 +4717,46 @@ width0pt\relax} \fi
% The arguments in between are the chapter number, section number, ...
% Chapters, in the main contents.
-\def\chapentry#1#2#3{\dochapentry{#2\labelspace#1}{#3}}
+\def\numchapentry#1#2#3#4{\dochapentry{#2\labelspace#1}{#4}}
%
% Chapters, in the short toc.
% See comments in \dochapentry re vbox and related settings.
-\def\shortchapentry#1#2#3{%
- \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#3\egroup}%
+\def\shortchapentry#1#2#3#4{%
+ \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#4\egroup}%
}
% Appendices, in the main contents.
-\def\appendixentry#1#2#3{%
- \dochapentry{\appendixbox{\putwordAppendix{} #2}\labelspace#1}{#3}}
+% Need the word Appendix, and a fixed-size box.
%
-% Appendices, in the short toc.
-\let\shortappendixentry = \shortchapentry
-
-% Typeset the label for a chapter or appendix for the short contents.
-% The arg is, e.g., `Appendix A' for an appendix, or `3' for a chapter.
-% We could simplify the code here by writing out an \appendixentry
-% command in the toc file for appendices, instead of using \chapentry
-% for both, but it doesn't seem worth it.
-%
-\newdimen\shortappendixwidth
+\def\appendixbox#1{%
+ % We use M since it's probably the widest letter.
+ \setbox0 = \hbox{\putwordAppendix{} M}%
+ \hbox to \wd0{\putwordAppendix{} #1\hss}}
%
-\def\shortchaplabel#1{%
- % This space should be enough, since a single number is .5em, and the
- % widest letter (M) is 1em, at least in the Computer Modern fonts.
- % But use \hss just in case.
- % (This space doesn't include the extra space that gets added after
- % the label; that gets put in by \shortchapentry above.)
- \dimen0 = 1em
- \hbox to \dimen0{#1\hss}%
-}
+\def\appentry#1#2#3#4{\dochapentry{\appendixbox{#2}\labelspace#1}{#4}}
% Unnumbered chapters.
-\def\unnumbchapentry#1#2#3{\dochapentry{#1}{#3}}
-\def\shortunnumberedentry#1#2#3{\tocentry{#1}{\doshortpageno\bgroup#3\egroup}}
+\def\unnchapentry#1#2#3#4{\dochapentry{#1}{#4}}
+\def\shortunnchapentry#1#2#3#4{\tocentry{#1}{\doshortpageno\bgroup#4\egroup}}
% Sections.
-\def\secentry#1#2#3#4{\dosecentry{#2.#3\labelspace#1}{#4}}
-\def\unnumbsecentry#1#2#3#4{\dosecentry{#1}{#4}}
+\def\numsecentry#1#2#3#4{\dosecentry{#2\labelspace#1}{#4}}
+\let\appsecentry=\numsecentry
+\def\unnsecentry#1#2#3#4{\dosecentry{#1}{#4}}
% Subsections.
-\def\subsecentry#1#2#3#4#5{\dosubsecentry{#2.#3.#4\labelspace#1}{#5}}
-\def\unnumbsubsecentry#1#2#3#4#5{\dosubsecentry{#1}{#5}}
+\def\numsubsecentry#1#2#3#4{\dosubsecentry{#2\labelspace#1}{#4}}
+\let\appsubsecentry=\numsubsecentry
+\def\unnsubsecentry#1#2#3#4{\dosubsecentry{#1}{#4}}
% And subsubsections.
-\def\subsubsecentry#1#2#3#4#5#6{%
- \dosubsubsecentry{#2.#3.#4.#5\labelspace#1}{#6}}
-\def\unnumbsubsubsecentry#1#2#3#4#5#6{\dosubsubsecentry{#1}{#6}}
+\def\numsubsubsecentry#1#2#3#4{\dosubsubsecentry{#2\labelspace#1}{#4}}
+\let\appsubsubsecentry=\numsubsubsecentry
+\def\unnsubsubsecentry#1#2#3#4{\dosubsubsecentry{#1}{#4}}
% This parameter controls the indentation of the various levels.
-\newdimen\tocindent \tocindent = 3pc
+% Same as \defaultparindent.
+\newdimen\tocindent \tocindent = 15pt
% Now for the actual typesetting. In all these, #1 is the text and #2 is the
% page number.
@@ -4343,17 +4787,8 @@ width0pt\relax} \fi
\tocentry{#1}{\dopageno\bgroup#2\egroup}%
\endgroup}
-% Final typesetting of a toc entry; we use the same \entry macro as for
-% the index entries, but we want to suppress hyphenation here. (We
-% can't do that in the \entry macro, since index entries might consist
-% of hyphenated-identifiers-that-do-not-fit-on-a-line-and-nothing-else.)
-\def\tocentry#1#2{\begingroup
- \vskip 0pt plus1pt % allow a little stretch for the sake of nice page breaks
- % Do not use \turnoffactive in these arguments. Since the toc is
- % typeset in cmr, characters such as _ would come out wrong; we
- % have to do the usual translation tricks.
- \entry{#1}{#2}%
-\endgroup}
+% We use the same \entry macro as for the index entries.
+\let\tocentry = \entry
% Space between chapter (or whatever) number and the title.
\def\labelspace{\hskip1em \relax}
@@ -4363,15 +4798,15 @@ width0pt\relax} \fi
\def\chapentryfonts{\secfonts \rm}
\def\secentryfonts{\textfonts}
-\let\subsecentryfonts = \textfonts
-\let\subsubsecentryfonts = \textfonts
+\def\subsecentryfonts{\textfonts}
+\def\subsubsecentryfonts{\textfonts}
\message{environments,}
% @foo ... @end foo.
% @point{}, @result{}, @expansion{}, @print{}, @equiv{}.
-%
+%
% Since these characters are used in examples, it should be an even number of
% \tt widths. Each \tt character is 1en, so two makes it 1em.
%
@@ -4383,7 +4818,7 @@ width0pt\relax} \fi
% The @error{} command.
% Adapted from the TeXbook's \boxit.
-%
+%
\newbox\errorbox
%
{\tentt \global\dimen0 = 3em}% Width of the box.
@@ -4391,10 +4826,10 @@ width0pt\relax} \fi
% The text. (`r' is open on the right, `e' somewhat less so on the left.)
\setbox0 = \hbox{\kern-.75pt \tensf error\kern-1.5pt}
%
-\global\setbox\errorbox=\hbox to \dimen0{\hfil
+\setbox\errorbox=\hbox to \dimen0{\hfil
\hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right.
\advance\hsize by -2\dimen2 % Rules.
- \vbox{
+ \vbox{%
\hrule height\dimen2
\hbox{\vrule width\dimen2 \kern3pt % Space to left of text.
\vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below.
@@ -4408,14 +4843,13 @@ width0pt\relax} \fi
% One exception: @ is still an escape character, so that @end tex works.
% But \@ or @@ will get a plain tex @ character.
-\def\tex{\begingroup
+\envdef\tex{%
\catcode `\\=0 \catcode `\{=1 \catcode `\}=2
\catcode `\$=3 \catcode `\&=4 \catcode `\#=6
\catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie
\catcode `\%=14
\catcode `\+=\other
\catcode `\"=\other
- \catcode `\==\other
\catcode `\|=\other
\catcode `\<=\other
\catcode `\>=\other
@@ -4430,20 +4864,24 @@ width0pt\relax} \fi
\let\equiv=\ptexequiv
\let\!=\ptexexclam
\let\i=\ptexi
+ \let\indent=\ptexindent
+ \let\noindent=\ptexnoindent
\let\{=\ptexlbrace
\let\+=\tabalign
\let\}=\ptexrbrace
\let\/=\ptexslash
\let\*=\ptexstar
\let\t=\ptext
+ \let\frenchspacing=\plainfrenchspacing
%
\def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
\def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
\def\@{@}%
-\let\Etex=\endgroup}
+}
+% There is no need to define \Etex.
% Define @lisp ... @end lisp.
-% @lisp does a \begingroup so it can rebind things,
+% @lisp environment forms a group so it can rebind things,
% including the definition of @end lisp (which normally is erroneous).
% Amount to narrow the margins by for @lisp.
@@ -4454,19 +4892,6 @@ width0pt\relax} \fi
% have any width.
\def\lisppar{\null\endgraf}
-% Make each space character in the input produce a normal interword
-% space in the output. Don't allow a line break at this space, as this
-% is used only in environments like @example, where each line of input
-% should produce a line of output anyway.
-%
-{\obeyspaces %
-\gdef\sepspaces{\obeyspaces\let =\tie}}
-
-% Define \obeyedspace to be our active space, whatever it is. This is
-% for use in \parsearg.
-{\sepspaces%
-\global\let\obeyedspace= }
-
% This space is always present above and below environments.
\newskip\envskipamount \envskipamount = 0pt
@@ -4476,7 +4901,8 @@ width0pt\relax} \fi
% start of the next paragraph will insert \parskip.
%
\def\aboveenvbreak{{%
- % =10000 instead of <10000 because of a special case in \itemzzz, q.v.
+ % =10000 instead of <10000 because of a special case in \itemzzz and
+ % \sectionheading, q.v.
\ifnum \lastpenalty=10000 \else
\advance\envskipamount by \parskip
\endgraf
@@ -4484,7 +4910,7 @@ width0pt\relax} \fi
\removelastskip
% it's not a good place to break if the last penalty was \nobreak
% or better ...
- \ifnum\lastpenalty>10000 \else \penalty-50 \fi
+ \ifnum\lastpenalty<10000 \penalty-50 \fi
\vskip\envskipamount
\fi
\fi
@@ -4492,7 +4918,8 @@ width0pt\relax} \fi
\let\afterenvbreak = \aboveenvbreak
-% \nonarrowing is a flag. If "set", @lisp etc don't narrow margins.
+% \nonarrowing is a flag. If "set", @lisp etc don't narrow margins; it will
+% also clear it, so that its embedded environments do the narrowing again.
\let\nonarrowing=\relax
% @cartouche ... @end cartouche: draw rectangle w/rounded corners around
@@ -4516,52 +4943,52 @@ width0pt\relax} \fi
%
\newskip\lskip\newskip\rskip
-\def\cartouche{%
-\par % can't be in the midst of a paragraph.
-\begingroup
- \lskip=\leftskip \rskip=\rightskip
- \leftskip=0pt\rightskip=0pt %we want these *outside*.
- \cartinner=\hsize \advance\cartinner by-\lskip
- \advance\cartinner by-\rskip
- \cartouter=\hsize
- \advance\cartouter by 18.4pt % allow for 3pt kerns on either
-% side, and for 6pt waste from
-% each corner char, and rule thickness
- \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
- % Flag to tell @lisp, etc., not to narrow margin.
- \let\nonarrowing=\comment
- \vbox\bgroup
- \baselineskip=0pt\parskip=0pt\lineskip=0pt
- \carttop
- \hbox\bgroup
- \hskip\lskip
- \vrule\kern3pt
- \vbox\bgroup
- \hsize=\cartinner
- \kern3pt
- \begingroup
- \baselineskip=\normbskip
- \lineskip=\normlskip
- \parskip=\normpskip
- \vskip -\parskip
+\envdef\cartouche{%
+ \ifhmode\par\fi % can't be in the midst of a paragraph.
+ \startsavinginserts
+ \lskip=\leftskip \rskip=\rightskip
+ \leftskip=0pt\rightskip=0pt % we want these *outside*.
+ \cartinner=\hsize \advance\cartinner by-\lskip
+ \advance\cartinner by-\rskip
+ \cartouter=\hsize
+ \advance\cartouter by 18.4pt % allow for 3pt kerns on either
+ % side, and for 6pt waste from
+ % each corner char, and rule thickness
+ \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
+ % Flag to tell @lisp, etc., not to narrow margin.
+ \let\nonarrowing = t%
+ \vbox\bgroup
+ \baselineskip=0pt\parskip=0pt\lineskip=0pt
+ \carttop
+ \hbox\bgroup
+ \hskip\lskip
+ \vrule\kern3pt
+ \vbox\bgroup
+ \kern3pt
+ \hsize=\cartinner
+ \baselineskip=\normbskip
+ \lineskip=\normlskip
+ \parskip=\normpskip
+ \vskip -\parskip
+ \comment % For explanation, see the end of \def\group.
+}
\def\Ecartouche{%
- \endgroup
- \kern3pt
- \egroup
- \kern3pt\vrule
- \hskip\rskip
- \egroup
- \cartbot
- \egroup
-\endgroup
-}}
+ \ifhmode\par\fi
+ \kern3pt
+ \egroup
+ \kern3pt\vrule
+ \hskip\rskip
+ \egroup
+ \cartbot
+ \egroup
+ \checkinserts
+}
% This macro is called at the beginning of all the @example variants,
% inside a group.
\def\nonfillstart{%
\aboveenvbreak
- \inENV % This group ends at the end of the body
\hfuzz = 12pt % Don't be fussy
\sepspaces % Make spaces be word-separators rather than space tokens.
\let\par = \lisppar % don't ignore blank lines
@@ -4569,121 +4996,139 @@ width0pt\relax} \fi
\parskip = 0pt
\parindent = 0pt
\emergencystretch = 0pt % don't try to avoid overfull boxes
- % @cartouche defines \nonarrowing to inhibit narrowing
- % at next level down.
\ifx\nonarrowing\relax
\advance \leftskip by \lispnarrowing
\exdentamount=\lispnarrowing
- \let\exdent=\nofillexdent
- \let\nonarrowing=\relax
+ \else
+ \let\nonarrowing = \relax
\fi
+ \let\exdent=\nofillexdent
}
-% Define the \E... control sequence only if we are inside the particular
-% environment, so the error checking in \end will work.
+% If you want all examples etc. small: @set dispenvsize small.
+% If you want even small examples the full size: @set dispenvsize nosmall.
+% This affects the following displayed environments:
+% @example, @display, @format, @lisp
%
-% To end an @example-like environment, we first end the paragraph (via
-% \afterenvbreak's vertical glue), and then the group. That way we keep
-% the zero \parskip that the environments set -- \parskip glue will be
-% inserted at the beginning of the next paragraph in the document, after
-% the environment.
-%
-\def\nonfillfinish{\afterenvbreak\endgroup}
+\def\smallword{small}
+\def\nosmallword{nosmall}
+\let\SETdispenvsize\relax
+\def\setnormaldispenv{%
+ \ifx\SETdispenvsize\smallword
+ \smallexamplefonts \rm
+ \fi
+}
+\def\setsmalldispenv{%
+ \ifx\SETdispenvsize\nosmallword
+ \else
+ \smallexamplefonts \rm
+ \fi
+}
-% @lisp: indented, narrowed, typewriter font.
-\def\lisp{\begingroup
- \nonfillstart
- \let\Elisp = \nonfillfinish
- \tt
- \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
- \gobble % eat return
+% We often define two environments, @foo and @smallfoo.
+% Let's do it by one command:
+\def\makedispenv #1#2{
+ \expandafter\envdef\csname#1\endcsname {\setnormaldispenv #2}
+ \expandafter\envdef\csname small#1\endcsname {\setsmalldispenv #2}
+ \expandafter\let\csname E#1\endcsname \afterenvbreak
+ \expandafter\let\csname Esmall#1\endcsname \afterenvbreak
}
-% @example: Same as @lisp.
-\def\example{\begingroup \def\Eexample{\nonfillfinish\endgroup}\lisp}
+% Define two synonyms:
+\def\maketwodispenvs #1#2#3{
+ \makedispenv{#1}{#3}
+ \makedispenv{#2}{#3}
+}
+% @lisp: indented, narrowed, typewriter font; @example: same as @lisp.
+%
% @smallexample and @smalllisp: use smaller fonts.
% Originally contributed by Pavel@xerox.
-\def\smalllisp{\begingroup
- \def\Esmalllisp{\nonfillfinish\endgroup}%
- \def\Esmallexample{\nonfillfinish\endgroup}%
- \smallexamplefonts
- \lisp
+%
+\maketwodispenvs {lisp}{example}{%
+ \nonfillstart
+ \tt
+ \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
+ \gobble % eat return
}
-\let\smallexample = \smalllisp
-
-% @display: same as @lisp except keep current font.
+% @display/@smalldisplay: same as @lisp except keep current font.
%
-\def\display{\begingroup
+\makedispenv {display}{%
\nonfillstart
- \let\Edisplay = \nonfillfinish
\gobble
}
-%
-% @smalldisplay: @display plus smaller fonts.
-%
-\def\smalldisplay{\begingroup
- \def\Esmalldisplay{\nonfillfinish\endgroup}%
- \smallexamplefonts \rm
- \display
-}
-% @format: same as @display except don't narrow margins.
+% @format/@smallformat: same as @display except don't narrow margins.
%
-\def\format{\begingroup
- \let\nonarrowing = t
+\makedispenv{format}{%
+ \let\nonarrowing = t%
\nonfillstart
- \let\Eformat = \nonfillfinish
\gobble
}
-%
-% @smallformat: @format plus smaller fonts.
-%
-\def\smallformat{\begingroup
- \def\Esmallformat{\nonfillfinish\endgroup}%
- \smallexamplefonts \rm
- \format
-}
-% @flushleft (same as @format).
-%
-\def\flushleft{\begingroup \def\Eflushleft{\nonfillfinish\endgroup}\format}
+% @flushleft: same as @format, but doesn't obey \SETdispenvsize.
+\envdef\flushleft{%
+ \let\nonarrowing = t%
+ \nonfillstart
+ \gobble
+}
+\let\Eflushleft = \afterenvbreak
% @flushright.
%
-\def\flushright{\begingroup
- \let\nonarrowing = t
+\envdef\flushright{%
+ \let\nonarrowing = t%
\nonfillstart
- \let\Eflushright = \nonfillfinish
\advance\leftskip by 0pt plus 1fill
\gobble
}
+\let\Eflushright = \afterenvbreak
% @quotation does normal linebreaking (hence we can't use \nonfillstart)
-% and narrows the margins.
+% and narrows the margins. We keep \parskip nonzero in general, since
+% we're doing normal filling. So, when using \aboveenvbreak and
+% \afterenvbreak, temporarily make \parskip 0.
%
-\def\quotation{%
- \begingroup\inENV %This group ends at the end of the @quotation body
+\envdef\quotation{%
{\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
\parindent=0pt
- % We have retained a nonzero parskip for the environment, since we're
- % doing normal filling. So to avoid extra space below the environment...
- \def\Equotation{\parskip = 0pt \nonfillfinish}%
%
% @cartouche defines \nonarrowing to inhibit narrowing at next level down.
\ifx\nonarrowing\relax
\advance\leftskip by \lispnarrowing
\advance\rightskip by \lispnarrowing
\exdentamount = \lispnarrowing
+ \else
\let\nonarrowing = \relax
\fi
+ \parsearg\quotationlabel
+}
+
+% We have retained a nonzero parskip for the environment, since we're
+% doing normal filling.
+%
+\def\Equotation{%
+ \par
+ \ifx\quotationauthor\undefined\else
+ % indent a bit.
+ \leftline{\kern 2\leftskip \sl ---\quotationauthor}%
+ \fi
+ {\parskip=0pt \afterenvbreak}%
+}
+
+% If we're given an argument, typeset it in bold with a colon after.
+\def\quotationlabel#1{%
+ \def\temp{#1}%
+ \ifx\temp\empty \else
+ {\bf #1: }%
+ \fi
}
% LaTeX-like @verbatim...@end verbatim and @verb{<char>...<char>}
-% If we want to allow any <char> as delimiter,
+% If we want to allow any <char> as delimiter,
% we need the curly braces so that makeinfo sees the @verb command, eg:
% `@verbx...x' would look like the '@verbx' command. --janneke@gnu.org
%
@@ -4700,7 +5145,7 @@ width0pt\relax} \fi
%
% [Knuth] p. 380
\def\uncatcodespecials{%
- \def\do##1{\catcode`##1=12}\dospecials}
+ \def\do##1{\catcode`##1=\other}\dospecials}
%
% [Knuth] pp. 380,381,391
% Disable Spanish ligatures ?` and !` of \tt font
@@ -4748,6 +5193,8 @@ width0pt\relax} \fi
}
\endgroup
\def\setupverbatim{%
+ \let\nonarrowing = t%
+ \nonfillstart
% Easiest (and conventionally used) font for verbatim
\tt
\def\par{\leavevmode\egroup\box0\endgraf}%
@@ -4761,15 +5208,15 @@ width0pt\relax} \fi
\everypar{\starttabbox}%
}
-% Do the @verb magic: verbatim text is quoted by unique
-% delimiter characters. Before first delimiter expect a
+% Do the @verb magic: verbatim text is quoted by unique
+% delimiter characters. Before first delimiter expect a
% right brace, after last delimiter expect closing brace:
%
% \def\doverb'{'<char>#1<char>'}'{#1}
%
% [Knuth] p. 382; only eat outer {}
\begingroup
- \catcode`[=1\catcode`]=2\catcode`\{=12\catcode`\}=12
+ \catcode`[=1\catcode`]=2\catcode`\{=\other\catcode`\}=\other
\gdef\doverb{#1[\def\next##1#1}[##1\endgroup]\next]
\endgroup
%
@@ -4781,18 +5228,11 @@ width0pt\relax} \fi
%
% \def\doverbatim#1@end verbatim{#1}
%
-% For Texinfo it's a lot easier than for LaTeX,
+% For Texinfo it's a lot easier than for LaTeX,
% because texinfo's \verbatim doesn't stop at '\end{verbatim}':
% we need not redefine '\', '{' and '}'.
%
% Inspired by LaTeX's verbatim command set [latex.ltx]
-%% Include LaTeX hack for completeness -- never know
-%% \begingroup
-%% \catcode`|=0 \catcode`[=1
-%% \catcode`]=2\catcode`\{=12\catcode`\}=12\catcode`\ =\active
-%% \catcode`\\=12|gdef|doverbatim#1@end verbatim[
-%% #1|endgroup|def|Everbatim[]|end[verbatim]]
-%% |endgroup
%
\begingroup
\catcode`\ =\active
@@ -4800,697 +5240,383 @@ width0pt\relax} \fi
% ignore everything up to the first ^^M, that's the newline at the end
% of the @verbatim input line itself. Otherwise we get an extra blank
% line in the output.
- \gdef\doverbatim#1^^M#2@end verbatim{#2\end{verbatim}}%
+ \xdef\doverbatim#1^^M#2@end verbatim{#2\noexpand\end\gobble verbatim}%
+ % We really want {...\end verbatim} in the body of the macro, but
+ % without the active space; thus we have to use \xdef and \gobble.
\endgroup
%
-\def\verbatim{%
- \def\Everbatim{\nonfillfinish\endgroup}%
- \begingroup
- \nonfillstart
- \advance\leftskip by -\defbodyindent
- \begingroup\setupverbatim\doverbatim
+\envdef\verbatim{%
+ \setupverbatim\doverbatim
}
+\let\Everbatim = \afterenvbreak
+
% @verbatiminclude FILE - insert text of file in verbatim environment.
%
-% Allow normal characters that we make active in the argument (a file name).
-\def\verbatiminclude{%
- \begingroup
- \catcode`\\=\other
- \catcode`~=\other
- \catcode`^=\other
- \catcode`_=\other
- \catcode`|=\other
- \catcode`<=\other
- \catcode`>=\other
- \catcode`+=\other
- \parsearg\doverbatiminclude
-}
-\def\setupverbatiminclude{%
- \begingroup
- \nonfillstart
- \advance\leftskip by -\defbodyindent
- \begingroup\setupverbatim
-}
+\def\verbatiminclude{\parseargusing\filenamecatcodes\doverbatiminclude}
%
\def\doverbatiminclude#1{%
- % Restore active chars for included file.
- \endgroup
- \begingroup
- \let\value=\expandablevalue
- \def\thisfile{#1}%
- \expandafter\expandafter\setupverbatiminclude\input\thisfile
- \endgroup
- \nonfillfinish
- \endgroup
+ {%
+ \makevalueexpandable
+ \setupverbatim
+ \input #1
+ \afterenvbreak
+ }%
}
% @copying ... @end copying.
-% Save the text away for @insertcopying later. Many commands won't be
-% allowed in this context, but that's ok.
-%
+% Save the text away for @insertcopying later.
+%
% We save the uninterpreted tokens, rather than creating a box.
% Saving the text in a box would be much easier, but then all the
% typesetting commands (@smallbook, font changes, etc.) have to be done
% beforehand -- and a) we want @copying to be done first in the source
% file; b) letting users define the frontmatter in as flexible order as
% possible is very desirable.
-%
-\def\copying{\begingroup
- % Define a command to swallow text until we reach `@end copying'.
- % \ is the escape char in this texinfo.tex file, so it is the
- % delimiter for the command; @ will be the escape char when we read
- % it, but that doesn't matter.
- \long\def\docopying##1\end copying{\gdef\copyingtext{##1}\enddocopying}%
- %
- % We must preserve ^^M's in the input file; see \insertcopying below.
- \catcode`\^^M = \active
- \docopying
-}
-
-% What we do to finish off the copying text.
%
-\def\enddocopying{\endgroup\ignorespaces}
-
-% @insertcopying. Here we must play games with ^^M's. On the one hand,
-% we need them to delimit commands such as `@end quotation', so they
-% must be active. On the other hand, we certainly don't want every
-% end-of-line to be a \par, as would happen with the normal active
-% definition of ^^M. On the third hand, two ^^M's in a row should still
-% generate a \par.
-%
-% Our approach is to make ^^M insert a space and a penalty1 normally;
-% then it can also check if \lastpenalty=1. If it does, then manually
-% do \par.
-%
-% This messes up the normal definitions of @c[omment], so we redefine
-% it. Similarly for @ignore. (These commands are used in the gcc
-% manual for man page generation.)
-%
-% Seems pretty fragile, most line-oriented commands will presumably
-% fail, but for the limited use of getting the copying text (which
-% should be quite simple) inserted, we can hope it's ok.
-%
-{\catcode`\^^M=\active %
-\gdef\insertcopying{\begingroup %
- \parindent = 0pt % looks wrong on title page
- \def^^M{%
- \ifnum \lastpenalty=1 %
- \par %
- \else %
- \space \penalty 1 %
- \fi %
- }%
- %
- % Fix @c[omment] for catcode 13 ^^M's.
- \def\c##1^^M{\ignorespaces}%
- \let\comment = \c %
- %
- % Don't bother jumping through all the hoops that \doignore does, it
- % would be very hard since the catcodes are already set.
- \long\def\ignore##1\end ignore{\ignorespaces}%
- %
- \copyingtext %
-\endgroup}%
+\def\copying{\checkenv{}\begingroup\scanargctxt\docopying}
+\def\docopying#1@end copying{\endgroup\def\copyingtext{#1}}
+%
+\def\insertcopying{%
+ \begingroup
+ \parindent = 0pt % paragraph indentation looks wrong on title page
+ \scanexp\copyingtext
+ \endgroup
}
\message{defuns,}
% @defun etc.
-% Allow user to change definition object font (\df) internally
-\def\setdeffont#1 {\csname DEF#1\endcsname}
-
\newskip\defbodyindent \defbodyindent=.4in
\newskip\defargsindent \defargsindent=50pt
\newskip\deflastargmargin \deflastargmargin=18pt
-\newcount\parencount
-
-% We want ()&[] to print specially on the defun line.
-%
-\def\activeparens{%
- \catcode`\(=\active \catcode`\)=\active
- \catcode`\&=\active
- \catcode`\[=\active \catcode`\]=\active
-}
-
-% Make control sequences which act like normal parenthesis chars.
-\let\lparen = ( \let\rparen = )
-
-{\activeparens % Now, smart parens don't turn on until &foo (see \amprm)
-
-% Be sure that we always have a definition for `(', etc. For example,
-% if the fn name has parens in it, \boldbrax will not be in effect yet,
-% so TeX would otherwise complain about undefined control sequence.
-\global\let(=\lparen \global\let)=\rparen
-\global\let[=\lbrack \global\let]=\rbrack
-
-\gdef\functionparens{\boldbrax\let&=\amprm\parencount=0 }
-\gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
-% This is used to turn on special parens
-% but make & act ordinary (given that it's active).
-\gdef\boldbraxnoamp{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb\let&=\ampnr}
-
-% Definitions of (, ) and & used in args for functions.
-% This is the definition of ( outside of all parentheses.
-\gdef\oprm#1 {{\rm\char`\(}#1 \bf \let(=\opnested
- \global\advance\parencount by 1
-}
-%
-% This is the definition of ( when already inside a level of parens.
-\gdef\opnested{\char`\(\global\advance\parencount by 1 }
-%
-\gdef\clrm{% Print a paren in roman if it is taking us back to depth of 0.
- % also in that case restore the outer-level definition of (.
- \ifnum \parencount=1 {\rm \char `\)}\sl \let(=\oprm \else \char `\) \fi
- \global\advance \parencount by -1 }
-% If we encounter &foo, then turn on ()-hacking afterwards
-\gdef\amprm#1 {{\rm\&#1}\let(=\oprm \let)=\clrm\ }
-%
-\gdef\normalparens{\boldbrax\let&=\ampnr}
-} % End of definition inside \activeparens
-%% These parens (in \boldbrax) actually are a little bolder than the
-%% contained text. This is especially needed for [ and ]
-\def\opnr{{\sf\char`\(}\global\advance\parencount by 1 }
-\def\clnr{{\sf\char`\)}\global\advance\parencount by -1 }
-\let\ampnr = \&
-\def\lbrb{{\bf\char`\[}}
-\def\rbrb{{\bf\char`\]}}
-
-% Active &'s sneak into the index arguments, so make sure it's defined.
-{
- \catcode`& = \active
- \global\let& = \ampnr
-}
-
-% \defname, which formats the name of the @def (not the args).
-% #1 is the function name.
-% #2 is the type of definition, such as "Function".
-%
-\def\defname#1#2{%
- % How we'll output the type name. Putting it in brackets helps
- % distinguish it from the body text that may end up on the next line
- % just below it.
- \ifempty{#2}%
- \def\defnametype{}%
+% Start the processing of @deffn:
+\def\startdefun{%
+ \ifnum\lastpenalty<10000
+ \medbreak
\else
- \def\defnametype{[\rm #2]}%
+ % If there are two @def commands in a row, we'll have a \nobreak,
+ % which is there to keep the function description together with its
+ % header. But if there's nothing but headers, we need to allow a
+ % break somewhere. Check specifically for penalty 10002, inserted
+ % by \defargscommonending, instead of 10000, since the sectioning
+ % commands also insert a nobreak penalty, and we don't want to allow
+ % a break between a section heading and a defun.
+ %
+ \ifnum\lastpenalty=10002 \penalty2000 \fi
+ %
+ % Similarly, after a section heading, do not allow a break.
+ % But do insert the glue.
+ \medskip % preceded by discardable penalty, so not a breakpoint
\fi
%
- % Get the values of \leftskip and \rightskip as they were outside the @def...
- \dimen2=\leftskip
- \advance\dimen2 by -\defbodyindent
- %
- % Figure out values for the paragraph shape.
- \setbox0=\hbox{\hskip \deflastargmargin{\defnametype}}%
- \dimen0=\hsize \advance \dimen0 by -\wd0 % compute size for first line
- \dimen1=\hsize \advance \dimen1 by -\defargsindent % size for continuations
- \parshape 2 0in \dimen0 \defargsindent \dimen1
- %
- % Output arg 2 ("Function" or some such) but stuck inside a box of
- % width 0 so it does not interfere with linebreaking.
- \noindent
- %
- {% Adjust \hsize to exclude the ambient margins,
- % so that \rightline will obey them.
- \advance \hsize by -\dimen2
- \dimen3 = 0pt % was -1.25pc
- \rlap{\rightline{\defnametype\kern\dimen3}}%
- }%
- %
- % Allow all lines to be underfull without complaint:
- \tolerance=10000 \hbadness=10000
- \advance\leftskip by -\defbodyindent
- \exdentamount=\defbodyindent
- {\df #1}\enskip % output function name
- % \defunargs will be called next to output the arguments, if any.
-}
-
-% Common pieces to start any @def...
-% #1 is the \E... control sequence to end the definition (which we define).
-% #2 is the \...x control sequence (which our caller defines).
-% #3 is the control sequence to process the header, such as \defunheader.
-%
-\def\parsebodycommon#1#2#3{%
- \begingroup\inENV
- % If there are two @def commands in a row, we'll have a \nobreak,
- % which is there to keep the function description together with its
- % header. But if there's nothing but headers, we want to allow a
- % break after all. Check for penalty 10002 (inserted by
- % \defargscommonending) instead of 10000, since the sectioning
- % commands insert a \penalty10000, and we don't want to allow a break
- % between a section heading and a defun.
- \ifnum\lastpenalty=10002 \penalty0 \fi
- \medbreak
- %
- % Define the \E... end token that this defining construct specifies
- % so that it will exit this group.
- \def#1{\endgraf\endgroup\medbreak}%
- %
\parindent=0in
\advance\leftskip by \defbodyindent
\exdentamount=\defbodyindent
}
-% Common part of the \...x definitions.
-%
-\def\defxbodycommon{%
- % As with \parsebodycommon above, allow line break if we have multiple
- % x headers in a row. It's not a great place, though.
- \ifnum\lastpenalty=10000 \penalty1000 \fi
+\def\dodefunx#1{%
+ % First, check whether we are in the right environment:
+ \checkenv#1%
%
- \begingroup\obeylines
-}
-
-% Process body of @defun, @deffn, @defmac, etc.
-%
-\def\defparsebody#1#2#3{%
- \parsebodycommon{#1}{#2}{#3}%
- \def#2{\defxbodycommon \activeparens \spacesplit#3}%
- \catcode\equalChar=\active
- \begingroup\obeylines\activeparens
- \spacesplit#3%
-}
-
-% #1, #2, #3 are the common arguments (see \parsebodycommon above).
-% #4, delimited by the space, is the class name.
-%
-\def\defmethparsebody#1#2#3#4 {%
- \parsebodycommon{#1}{#2}{#3}%
- \def#2##1 {\defxbodycommon \activeparens \spacesplit{#3{##1}}}%
- \begingroup\obeylines\activeparens
- % The \empty here prevents misinterpretation of a construct such as
- % @deffn {whatever} {Enharmonic comma}
- % See comments at \deftpparsebody, although in our case we don't have
- % to remove the \empty afterwards, since it is empty.
- \spacesplit{#3{#4}}\empty
+ % As above, allow line break if we have multiple x headers in a row.
+ % It's not a great place, though.
+ \ifnum\lastpenalty=10002 \penalty3000 \fi
+ %
+ % And now, it's time to reuse the body of the original defun:
+ \expandafter\gobbledefun#1%
}
+\def\gobbledefun#1\startdefun{}
-% Used for @deftypemethod and @deftypeivar.
-% #1, #2, #3 are the common arguments (see \defparsebody).
-% #4, delimited by a space, is the class name.
-% #5 is the method's return type.
+% \printdefunline \deffnheader{text}
%
-\def\deftypemethparsebody#1#2#3#4 #5 {%
- \parsebodycommon{#1}{#2}{#3}%
- \def#2##1 ##2 {\defxbodycommon \activeparens \spacesplit{#3{##1}{##2}}}%
- \begingroup\obeylines\activeparens
- \spacesplit{#3{#4}{#5}}%
-}
-
-% Used for @deftypeop. The change from \deftypemethparsebody is an
-% extra argument at the beginning which is the `category', instead of it
-% being the hardwired string `Method' or `Instance Variable'. We have
-% to account for this both in the \...x definition and in parsing the
-% input at hand. Thus also need a control sequence (passed as #5) for
-% the \E... definition to assign the category name to.
-%
-\def\deftypeopparsebody#1#2#3#4#5 #6 {%
- \parsebodycommon{#1}{#2}{#3}%
- \def#2##1 ##2 ##3 {\def#4{##1}%
- \defxbodycommon \activeparens \spacesplit{#3{##2}{##3}}}%
- \begingroup\obeylines\activeparens
- \spacesplit{#3{#5}{#6}}%
+\def\printdefunline#1#2{%
+ \begingroup
+ % call \deffnheader:
+ #1#2 \endheader
+ % common ending:
+ \interlinepenalty = 10000
+ \advance\rightskip by 0pt plus 1fil
+ \endgraf
+ \nobreak\vskip -\parskip
+ \penalty 10002 % signal to \startdefun and \dodefunx
+ % Some of the @defun-type tags do not enable magic parentheses,
+ % rendering the following check redundant. But we don't optimize.
+ \checkparencounts
+ \endgroup
}
-% For @defop.
-\def\defopparsebody #1#2#3#4#5 {%
- \parsebodycommon{#1}{#2}{#3}%
- \def#2##1 ##2 {\def#4{##1}%
- \defxbodycommon \activeparens \spacesplit{#3{##2}}}%
- \begingroup\obeylines\activeparens
- \spacesplit{#3{#5}}%
-}
+\def\Edefun{\endgraf\medbreak}
-% These parsing functions are similar to the preceding ones
-% except that they do not make parens into active characters.
-% These are used for "variables" since they have no arguments.
+% \makedefun{deffn} creates \deffn, \deffnx and \Edeffn;
+% the only thing remainnig is to define \deffnheader.
%
-\def\defvarparsebody #1#2#3{%
- \parsebodycommon{#1}{#2}{#3}%
- \def#2{\defxbodycommon \spacesplit#3}%
- \catcode\equalChar=\active
- \begingroup\obeylines
- \spacesplit#3%
-}
-
-% @defopvar.
-\def\defopvarparsebody #1#2#3#4#5 {%
- \parsebodycommon{#1}{#2}{#3}%
- \def#2##1 ##2 {\def#4{##1}%
- \defxbodycommon \spacesplit{#3{##2}}}%
- \begingroup\obeylines
- \spacesplit{#3{#5}}%
-}
-
-\def\defvrparsebody#1#2#3#4 {%
- \parsebodycommon{#1}{#2}{#3}%
- \def#2##1 {\defxbodycommon \spacesplit{#3{##1}}}%
- \begingroup\obeylines
- \spacesplit{#3{#4}}%
+\def\makedefun#1{%
+ \expandafter\let\csname E#1\endcsname = \Edefun
+ \edef\temp{\noexpand\domakedefun
+ \makecsname{#1}\makecsname{#1x}\makecsname{#1header}}%
+ \temp
}
-% This loses on `@deftp {Data Type} {struct termios}' -- it thinks the
-% type is just `struct', because we lose the braces in `{struct
-% termios}' when \spacesplit reads its undelimited argument. Sigh.
-% \let\deftpparsebody=\defvrparsebody
+% \domakedefun \deffn \deffnx \deffnheader
%
-% So, to get around this, we put \empty in with the type name. That
-% way, TeX won't find exactly `{...}' as an undelimited argument, and
-% won't strip off the braces.
+% Define \deffn and \deffnx, without parameters.
+% \deffnheader has to be defined explicitly.
%
-\def\deftpparsebody #1#2#3#4 {%
- \parsebodycommon{#1}{#2}{#3}%
- \def#2##1 {\defxbodycommon \spacesplit{#3{##1}}}%
- \begingroup\obeylines
- \spacesplit{\parsetpheaderline{#3{#4}}}\empty
+\def\domakedefun#1#2#3{%
+ \envdef#1{%
+ \startdefun
+ \parseargusing\activeparens{\printdefunline#3}%
+ }%
+ \def#2{\dodefunx#1}%
+ \def#3%
}
-% Fine, but then we have to eventually remove the \empty *and* the
-% braces (if any). That's what this does.
-%
-\def\removeemptybraces\empty#1\relax{#1}
+%%% Untyped functions:
-% After \spacesplit has done its work, this is called -- #1 is the final
-% thing to call, #2 the type name (which starts with \empty), and #3
-% (which might be empty) the arguments.
-%
-\def\parsetpheaderline#1#2#3{%
- #1{\removeemptybraces#2\relax}{#3}%
-}%
+% @deffn category name args
+\makedefun{deffn}{\deffngeneral{}}
-% Split up #2 (the rest of the input line) at the first space token.
-% call #1 with two arguments:
-% the first is all of #2 before the space token,
-% the second is all of #2 after that space token.
-% If #2 contains no space token, all of it is passed as the first arg
-% and the second is passed as empty.
-%
-{\obeylines %
- \gdef\spacesplit#1#2^^M{\endgroup\spacesplitx{#1}#2 \relax\spacesplitx}%
- \long\gdef\spacesplitx#1#2 #3#4\spacesplitx{%
- \ifx\relax #3%
- #1{#2}{}%
- \else %
- #1{#2}{#3#4}%
- \fi}%
-}
+% @deffn category class name args
+\makedefun{defop}#1 {\defopon{#1\ \putwordon}}
-% Define @defun.
+% \defopon {category on}class name args
+\def\defopon#1#2 {\deffngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
-% This is called to end the arguments processing for all the @def... commands.
+% \deffngeneral {subind}category name args
%
-\def\defargscommonending{%
- \interlinepenalty = 10000
- \advance\rightskip by 0pt plus 1fil
- \endgraf
- \nobreak\vskip -\parskip
- \penalty 10002 % signal to \parsebodycommon.
+\def\deffngeneral#1#2 #3 #4\endheader{%
+ % Remember that \dosubind{fn}{foo}{} is equivalent to \doind{fn}{foo}.
+ \dosubind{fn}{\code{#3}}{#1}%
+ \defname{#2}{}{#3}\magicamp\defunargs{#4\unskip}%
}
-% This expands the args and terminates the paragraph they comprise.
-%
-\def\defunargs#1{\functionparens \sl
-% Expand, preventing hyphenation at `-' chars.
-% Note that groups don't affect changes in \hyphenchar.
-% Set the font temporarily and use \font in case \setfont made \tensl a macro.
-{\tensl\hyphenchar\font=0}%
-#1%
-{\tensl\hyphenchar\font=45}%
-\ifnum\parencount=0 \else \errmessage{Unbalanced parentheses in @def}\fi%
- \defargscommonending
-}
+%%% Typed functions:
-\def\deftypefunargs #1{%
-% Expand, preventing hyphenation at `-' chars.
-% Note that groups don't affect changes in \hyphenchar.
-% Use \boldbraxnoamp, not \functionparens, so that & is not special.
-\boldbraxnoamp
-\tclose{#1}% avoid \code because of side effects on active chars
- \defargscommonending
-}
+% @deftypefn category type name args
+\makedefun{deftypefn}{\deftypefngeneral{}}
-% Do complete processing of one @defun or @defunx line already parsed.
+% @deftypeop category class type name args
+\makedefun{deftypeop}#1 {\deftypeopon{#1\ \putwordon}}
-% @deffn Command forward-char nchars
+% \deftypeopon {category on}class type name args
+\def\deftypeopon#1#2 {\deftypefngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
-\def\deffn{\defmethparsebody\Edeffn\deffnx\deffnheader}
-
-\def\deffnheader #1#2#3{\doind {fn}{\code{#2}}%
-\begingroup\defname {#2}{#1}\defunargs{#3}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
+% \deftypefngeneral {subind}category type name args
+%
+\def\deftypefngeneral#1#2 #3 #4 #5\endheader{%
+ \dosubind{fn}{\code{#4}}{#1}%
+ \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
}
-% @defun == @deffn Function
+%%% Typed variables:
-\def\defun{\defparsebody\Edefun\defunx\defunheader}
+% @deftypevr category type var args
+\makedefun{deftypevr}{\deftypecvgeneral{}}
-\def\defunheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
-\begingroup\defname {#1}{\putwordDeffunc}%
-\defunargs {#2}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
-}
+% @deftypecv category class type var args
+\makedefun{deftypecv}#1 {\deftypecvof{#1\ \putwordof}}
-% @deftypefun int foobar (int @var{foo}, float @var{bar})
+% \deftypecvof {category of}class type var args
+\def\deftypecvof#1#2 {\deftypecvgeneral{\putwordof\ \code{#2}}{#1\ \code{#2}} }
-\def\deftypefun{\defparsebody\Edeftypefun\deftypefunx\deftypefunheader}
-
-% #1 is the data type. #2 is the name and args.
-\def\deftypefunheader #1#2{\deftypefunheaderx{#1}#2 \relax}
-% #1 is the data type, #2 the name, #3 the args.
-\def\deftypefunheaderx #1#2 #3\relax{%
-\doind {fn}{\code{#2}}% Make entry in function index
-\begingroup\defname {\defheaderxcond#1\relax$.$#2}{\putwordDeftypefun}%
-\deftypefunargs {#3}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
+% \deftypecvgeneral {subind}category type var args
+%
+\def\deftypecvgeneral#1#2 #3 #4 #5\endheader{%
+ \dosubind{vr}{\code{#4}}{#1}%
+ \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
}
-% @deftypefn {Library Function} int foobar (int @var{foo}, float @var{bar})
+%%% Untyped variables:
-\def\deftypefn{\defmethparsebody\Edeftypefn\deftypefnx\deftypefnheader}
+% @defvr category var args
+\makedefun{defvr}#1 {\deftypevrheader{#1} {} }
-% \defheaderxcond#1\relax$.$
-% puts #1 in @code, followed by a space, but does nothing if #1 is null.
-\def\defheaderxcond#1#2$.${\ifx#1\relax\else\code{#1#2} \fi}
+% @defcv category class var args
+\makedefun{defcv}#1 {\defcvof{#1\ \putwordof}}
-% #1 is the classification. #2 is the data type. #3 is the name and args.
-\def\deftypefnheader #1#2#3{\deftypefnheaderx{#1}{#2}#3 \relax}
-% #1 is the classification, #2 the data type, #3 the name, #4 the args.
-\def\deftypefnheaderx #1#2#3 #4\relax{%
-\doind {fn}{\code{#3}}% Make entry in function index
-\begingroup
-\normalparens % notably, turn off `&' magic, which prevents
-% at least some C++ text from working
-\defname {\defheaderxcond#2\relax$.$#3}{#1}%
-\deftypefunargs {#4}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
-}
-
-% @defmac == @deffn Macro
+% \defcvof {category of}class var args
+\def\defcvof#1#2 {\deftypecvof{#1}#2 {} }
-\def\defmac{\defparsebody\Edefmac\defmacx\defmacheader}
-
-\def\defmacheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
-\begingroup\defname {#1}{\putwordDefmac}%
-\defunargs {#2}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
+%%% Type:
+% @deftp category name args
+\makedefun{deftp}#1 #2 #3\endheader{%
+ \doind{tp}{\code{#2}}%
+ \defname{#1}{}{#2}\defunargs{#3\unskip}%
}
-% @defspec == @deffn Special Form
-
-\def\defspec{\defparsebody\Edefspec\defspecx\defspecheader}
+% Remaining @defun-like shortcuts:
+\makedefun{defun}{\deffnheader{\putwordDeffunc} }
+\makedefun{defmac}{\deffnheader{\putwordDefmac} }
+\makedefun{defspec}{\deffnheader{\putwordDefspec} }
+\makedefun{deftypefun}{\deftypefnheader{\putwordDeffunc} }
+\makedefun{defvar}{\defvrheader{\putwordDefvar} }
+\makedefun{defopt}{\defvrheader{\putwordDefopt} }
+\makedefun{deftypevar}{\deftypevrheader{\putwordDefvar} }
+\makedefun{defmethod}{\defopon\putwordMethodon}
+\makedefun{deftypemethod}{\deftypeopon\putwordMethodon}
+\makedefun{defivar}{\defcvof\putwordInstanceVariableof}
+\makedefun{deftypeivar}{\deftypecvof\putwordInstanceVariableof}
-\def\defspecheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
-\begingroup\defname {#1}{\putwordDefspec}%
-\defunargs {#2}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
-}
-
-% @defop CATEGORY CLASS OPERATION ARG...
+% \defname, which formats the name of the @def (not the args).
+% #1 is the category, such as "Function".
+% #2 is the return type, if any.
+% #3 is the function name.
%
-\def\defop #1 {\def\defoptype{#1}%
-\defopparsebody\Edefop\defopx\defopheader\defoptype}
+% We are followed by (but not passed) the arguments, if any.
%
-\def\defopheader#1#2#3{%
- \dosubind{fn}{\code{#2}}{\putwordon\ \code{#1}}% function index entry
- \begingroup
- \defname{#2}{\defoptype\ \putwordon\ #1}%
- \defunargs{#3}%
- \endgroup
+\def\defname#1#2#3{%
+ % Get the values of \leftskip and \rightskip as they were outside the @def...
+ \advance\leftskip by -\defbodyindent
+ %
+ % How we'll format the type name. Putting it in brackets helps
+ % distinguish it from the body text that may end up on the next line
+ % just below it.
+ \def\temp{#1}%
+ \setbox0=\hbox{\kern\deflastargmargin \ifx\temp\empty\else [\rm\temp]\fi}
+ %
+ % Figure out line sizes for the paragraph shape.
+ % The first line needs space for \box0; but if \rightskip is nonzero,
+ % we need only space for the part of \box0 which exceeds it:
+ \dimen0=\hsize \advance\dimen0 by -\wd0 \advance\dimen0 by \rightskip
+ % The continuations:
+ \dimen2=\hsize \advance\dimen2 by -\defargsindent
+ % (plain.tex says that \dimen1 should be used only as global.)
+ \parshape 2 0in \dimen0 \defargsindent \dimen2
+ %
+ % Put the type name to the right margin.
+ \noindent
+ \hbox to 0pt{%
+ \hfil\box0 \kern-\hsize
+ % \hsize has to be shortened this way:
+ \kern\leftskip
+ % Intentionally do not respect \rightskip, since we need the space.
+ }%
+ %
+ % Allow all lines to be underfull without complaint:
+ \tolerance=10000 \hbadness=10000
+ \exdentamount=\defbodyindent
+ {%
+ % defun fonts. We use typewriter by default (used to be bold) because:
+ % . we're printing identifiers, they should be in tt in principle.
+ % . in languages with many accents, such as Czech or French, it's
+ % common to leave accents off identifiers. The result looks ok in
+ % tt, but exceedingly strange in rm.
+ % . we don't want -- and --- to be treated as ligatures.
+ % . this still does not fix the ?` and !` ligatures, but so far no
+ % one has made identifiers using them :).
+ \df \tt
+ \def\temp{#2}% return value type
+ \ifx\temp\empty\else \tclose{\temp} \fi
+ #3% output function name
+ }%
+ {\rm\enskip}% hskip 0.5 em of \tenrm
+ %
+ \boldbrax
+ % arguments will be output next, if any.
}
-% @deftypeop CATEGORY CLASS TYPE OPERATION ARG...
+% Print arguments in slanted roman (not ttsl), inconsistently with using
+% tt for the name. This is because literal text is sometimes needed in
+% the argument list (groff manual), and ttsl and tt are not very
+% distinguishable. Prevent hyphenation at `-' chars.
%
-\def\deftypeop #1 {\def\deftypeopcategory{#1}%
- \deftypeopparsebody\Edeftypeop\deftypeopx\deftypeopheader
- \deftypeopcategory}
-%
-% #1 is the class name, #2 the data type, #3 the operation name, #4 the args.
-\def\deftypeopheader#1#2#3#4{%
- \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index
- \begingroup
- \defname{\defheaderxcond#2\relax$.$#3}
- {\deftypeopcategory\ \putwordon\ \code{#1}}%
- \deftypefunargs{#4}%
- \endgroup
+\def\defunargs#1{%
+ % use sl by default (not ttsl),
+ % tt for the names.
+ \df \sl \hyphenchar\font=0
+ %
+ % On the other hand, if an argument has two dashes (for instance), we
+ % want a way to get ttsl. Let's try @var for that.
+ \let\var=\ttslanted
+ #1%
+ \sl\hyphenchar\font=45
}
-% @deftypemethod CLASS TYPE METHOD ARG...
-%
-\def\deftypemethod{%
- \deftypemethparsebody\Edeftypemethod\deftypemethodx\deftypemethodheader}
+% We want ()&[] to print specially on the defun line.
%
-% #1 is the class name, #2 the data type, #3 the method name, #4 the args.
-\def\deftypemethodheader#1#2#3#4{%
- \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index
- \begingroup
- \defname{\defheaderxcond#2\relax$.$#3}{\putwordMethodon\ \code{#1}}%
- \deftypefunargs{#4}%
- \endgroup
+\def\activeparens{%
+ \catcode`\(=\active \catcode`\)=\active
+ \catcode`\[=\active \catcode`\]=\active
+ \catcode`\&=\active
}
-% @deftypeivar CLASS TYPE VARNAME
-%
-\def\deftypeivar{%
- \deftypemethparsebody\Edeftypeivar\deftypeivarx\deftypeivarheader}
-%
-% #1 is the class name, #2 the data type, #3 the variable name.
-\def\deftypeivarheader#1#2#3{%
- \dosubind{vr}{\code{#3}}{\putwordof\ \code{#1}}% entry in variable index
- \begingroup
- \defname{\defheaderxcond#2\relax$.$#3}
- {\putwordInstanceVariableof\ \code{#1}}%
- \defvarargs{#3}%
- \endgroup
-}
+% Make control sequences which act like normal parenthesis chars.
+\let\lparen = ( \let\rparen = )
-% @defmethod == @defop Method
-%
-\def\defmethod{\defmethparsebody\Edefmethod\defmethodx\defmethodheader}
-%
-% #1 is the class name, #2 the method name, #3 the args.
-\def\defmethodheader#1#2#3{%
- \dosubind{fn}{\code{#2}}{\putwordon\ \code{#1}}% entry in function index
- \begingroup
- \defname{#2}{\putwordMethodon\ \code{#1}}%
- \defunargs{#3}%
- \endgroup
-}
+% Be sure that we always have a definition for `(', etc. For example,
+% if the fn name has parens in it, \boldbrax will not be in effect yet,
+% so TeX would otherwise complain about undefined control sequence.
+{
+ \activeparens
+ \global\let(=\lparen \global\let)=\rparen
+ \global\let[=\lbrack \global\let]=\rbrack
+ \global\let& = \&
-% @defcv {Class Option} foo-class foo-flag
+ \gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
+ \gdef\magicamp{\let&=\amprm}
+}
-\def\defcv #1 {\def\defcvtype{#1}%
-\defopvarparsebody\Edefcv\defcvx\defcvarheader\defcvtype}
+\newcount\parencount
-\def\defcvarheader #1#2#3{%
- \dosubind{vr}{\code{#2}}{\putwordof\ \code{#1}}% variable index entry
- \begingroup
- \defname{#2}{\defcvtype\ \putwordof\ #1}%
- \defvarargs{#3}%
- \endgroup
+% If we encounter &foo, then turn on ()-hacking afterwards
+\newif\ifampseen
+\def\amprm#1 {\ampseentrue{\bf\&#1 }}
+
+\def\parenfont{%
+ \ifampseen
+ % At the first level, print parens in roman,
+ % otherwise use the default font.
+ \ifnum \parencount=1 \rm \fi
+ \else
+ % The \sf parens (in \boldbrax) actually are a little bolder than
+ % the contained text. This is especially needed for [ and ] .
+ \sf
+ \fi
}
-
-% @defivar CLASS VARNAME == @defcv {Instance Variable} CLASS VARNAME
-%
-\def\defivar{\defvrparsebody\Edefivar\defivarx\defivarheader}
-%
-\def\defivarheader#1#2#3{%
- \dosubind{vr}{\code{#2}}{\putwordof\ \code{#1}}% entry in var index
- \begingroup
- \defname{#2}{\putwordInstanceVariableof\ #1}%
- \defvarargs{#3}%
- \endgroup
+\def\infirstlevel#1{%
+ \ifampseen
+ \ifnum\parencount=1
+ #1%
+ \fi
+ \fi
}
+\def\bfafterword#1 {#1 \bf}
-% @defvar
-% First, define the processing that is wanted for arguments of @defvar.
-% This is actually simple: just print them in roman.
-% This must expand the args and terminate the paragraph they make up
-\def\defvarargs #1{\normalparens #1%
- \defargscommonending
+\def\opnr{%
+ \global\advance\parencount by 1
+ {\parenfont(}%
+ \infirstlevel \bfafterword
}
-
-% @defvr Counter foo-count
-
-\def\defvr{\defvrparsebody\Edefvr\defvrx\defvrheader}
-
-\def\defvrheader #1#2#3{\doind {vr}{\code{#2}}%
-\begingroup\defname {#2}{#1}\defvarargs{#3}\endgroup}
-
-% @defvar == @defvr Variable
-
-\def\defvar{\defvarparsebody\Edefvar\defvarx\defvarheader}
-
-\def\defvarheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index
-\begingroup\defname {#1}{\putwordDefvar}%
-\defvarargs {#2}\endgroup %
+\def\clnr{%
+ {\parenfont)}%
+ \infirstlevel \sl
+ \global\advance\parencount by -1
}
-% @defopt == @defvr {User Option}
-
-\def\defopt{\defvarparsebody\Edefopt\defoptx\defoptheader}
-
-\def\defoptheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index
-\begingroup\defname {#1}{\putwordDefopt}%
-\defvarargs {#2}\endgroup %
+\newcount\brackcount
+\def\lbrb{%
+ \global\advance\brackcount by 1
+ {\bf[}%
+}
+\def\rbrb{%
+ {\bf]}%
+ \global\advance\brackcount by -1
}
-% @deftypevar int foobar
-
-\def\deftypevar{\defvarparsebody\Edeftypevar\deftypevarx\deftypevarheader}
-
-% #1 is the data type. #2 is the name, perhaps followed by text that
-% is actually part of the data type, which should not be put into the index.
-\def\deftypevarheader #1#2{%
-\dovarind#2 \relax% Make entry in variables index
-\begingroup\defname {\defheaderxcond#1\relax$.$#2}{\putwordDeftypevar}%
- \defargscommonending
-\endgroup}
-\def\dovarind#1 #2\relax{\doind{vr}{\code{#1}}}
-
-% @deftypevr {Global Flag} int enable
-
-\def\deftypevr{\defvrparsebody\Edeftypevr\deftypevrx\deftypevrheader}
-
-\def\deftypevrheader #1#2#3{\dovarind#3 \relax%
-\begingroup\defname {\defheaderxcond#2\relax$.$#3}{#1}
- \defargscommonending
-\endgroup}
-
-% Now define @deftp
-% Args are printed in bold, a slight difference from @defvar.
-
-\def\deftpargs #1{\bf \defvarargs{#1}}
-
-% @deftp Class window height width ...
-
-\def\deftp{\deftpparsebody\Edeftp\deftpx\deftpheader}
-
-\def\deftpheader #1#2#3{\doind {tp}{\code{#2}}%
-\begingroup\defname {#2}{#1}\deftpargs{#3}\endgroup}
-
-% These definitions are used if you use @defunx (etc.)
-% anywhere other than immediately after a @defun or @defunx.
-%
-\def\defcvx#1 {\errmessage{@defcvx in invalid context}}
-\def\deffnx#1 {\errmessage{@deffnx in invalid context}}
-\def\defivarx#1 {\errmessage{@defivarx in invalid context}}
-\def\defmacx#1 {\errmessage{@defmacx in invalid context}}
-\def\defmethodx#1 {\errmessage{@defmethodx in invalid context}}
-\def\defoptx #1 {\errmessage{@defoptx in invalid context}}
-\def\defopx#1 {\errmessage{@defopx in invalid context}}
-\def\defspecx#1 {\errmessage{@defspecx in invalid context}}
-\def\deftpx#1 {\errmessage{@deftpx in invalid context}}
-\def\deftypefnx#1 {\errmessage{@deftypefnx in invalid context}}
-\def\deftypefunx#1 {\errmessage{@deftypefunx in invalid context}}
-\def\deftypeivarx#1 {\errmessage{@deftypeivarx in invalid context}}
-\def\deftypemethodx#1 {\errmessage{@deftypemethodx in invalid context}}
-\def\deftypeopx#1 {\errmessage{@deftypeopx in invalid context}}
-\def\deftypevarx#1 {\errmessage{@deftypevarx in invalid context}}
-\def\deftypevrx#1 {\errmessage{@deftypevrx in invalid context}}
-\def\defunx#1 {\errmessage{@defunx in invalid context}}
-\def\defvarx#1 {\errmessage{@defvarx in invalid context}}
-\def\defvrx#1 {\errmessage{@defvrx in invalid context}}
+\def\checkparencounts{%
+ \ifnum\parencount=0 \else \badparencount \fi
+ \ifnum\brackcount=0 \else \badbrackcount \fi
+}
+\def\badparencount{%
+ \errmessage{Unbalanced parentheses in @def}%
+ \global\parencount=0
+}
+\def\badbrackcount{%
+ \errmessage{Unbalanced square braces in @def}%
+ \global\brackcount=0
+}
\message{macros,}
@@ -5499,42 +5625,69 @@ width0pt\relax} \fi
% To do this right we need a feature of e-TeX, \scantokens,
% which we arrange to emulate with a temporary file in ordinary TeX.
\ifx\eTeXversion\undefined
- \newwrite\macscribble
- \def\scanmacro#1{%
- \begingroup \newlinechar`\^^M
- % Undo catcode changes of \startcontents and \doprintindex
- \catcode`\@=0 \catcode`\\=\other \escapechar=`\@
- % Append \endinput to make sure that TeX does not see the ending newline.
- \toks0={#1\endinput}%
- \immediate\openout\macscribble=\jobname.tmp
- \immediate\write\macscribble{\the\toks0}%
- \immediate\closeout\macscribble
- \let\xeatspaces\eatspaces
- \input \jobname.tmp
- \endgroup
-}
-\else
-\def\scanmacro#1{%
-\begingroup \newlinechar`\^^M
-% Undo catcode changes of \startcontents and \doprintindex
-\catcode`\@=0 \catcode`\\=\other \escapechar=`\@
-\let\xeatspaces\eatspaces\scantokens{#1\endinput}\endgroup}
+ \newwrite\macscribble
+ \def\scantokens#1{%
+ \toks0={#1}%
+ \immediate\openout\macscribble=\jobname.tmp
+ \immediate\write\macscribble{\the\toks0}%
+ \immediate\closeout\macscribble
+ \input \jobname.tmp
+ }
\fi
+\def\scanmacro#1{%
+ \begingroup
+ \newlinechar`\^^M
+ \let\xeatspaces\eatspaces
+ % Undo catcode changes of \startcontents and \doprintindex
+ % When called from @insertcopying or (short)caption, we need active
+ % backslash to get it printed correctly. Previously, we had
+ % \catcode`\\=\other instead. We'll see whether a problem appears
+ % with macro expansion. --kasal, 19aug04
+ \catcode`\@=0 \catcode`\\=\active \escapechar=`\@
+ % ... and \example
+ \spaceisspace
+ %
+ % Append \endinput to make sure that TeX does not see the ending newline.
+ %
+ % I've verified that it is necessary both for e-TeX and for ordinary TeX
+ % --kasal, 29nov03
+ \scantokens{#1\endinput}%
+ \endgroup
+}
+
+\def\scanexp#1{%
+ \edef\temp{\noexpand\scanmacro{#1}}%
+ \temp
+}
+
\newcount\paramno % Count of parameters
\newtoks\macname % Macro name
\newif\ifrecursive % Is it recursive?
-\def\macrolist{} % List of all defined macros in the form
- % \do\macro1\do\macro2...
+
+% List of all defined macros in the form
+% \definedummyword\macro1\definedummyword\macro2...
+% Currently is also contains all @aliases; the list can be split
+% if there is a need.
+\def\macrolist{}
+
+% Add the macro to \macrolist
+\def\addtomacrolist#1{\expandafter \addtomacrolistxxx \csname#1\endcsname}
+\def\addtomacrolistxxx#1{%
+ \toks0 = \expandafter{\macrolist\definedummyword#1}%
+ \xdef\macrolist{\the\toks0}%
+}
% Utility routines.
-% Thisdoes \let #1 = #2, except with \csnames.
+% This does \let #1 = #2, with \csnames; that is,
+% \let \csname#1\endcsname = \csname#2\endcsname
+% (except of course we have to play expansion games).
+%
\def\cslet#1#2{%
-\expandafter\expandafter
-\expandafter\let
-\expandafter\expandafter
-\csname#1\endcsname
-\csname#2\endcsname}
+ \expandafter\let
+ \csname#1\expandafter\endcsname
+ \csname#2\endcsname
+}
% Trim leading and trailing spaces off a string.
% Concepts from aro-bend problem 15 (see CTAN).
@@ -5561,30 +5714,36 @@ width0pt\relax} \fi
% done by making ^^M (\endlinechar) catcode 12 when reading the macro
% body, and then making it the \newlinechar in \scanmacro.
-\def\macrobodyctxt{%
- \catcode`\~=\other
+\def\scanctxt{%
+ \catcode`\"=\other
+ \catcode`\+=\other
+ \catcode`\<=\other
+ \catcode`\>=\other
+ \catcode`\@=\other
\catcode`\^=\other
\catcode`\_=\other
\catcode`\|=\other
- \catcode`\<=\other
- \catcode`\>=\other
- \catcode`\+=\other
+ \catcode`\~=\other
+}
+
+\def\scanargctxt{%
+ \scanctxt
+ \catcode`\\=\other
+ \catcode`\^^M=\other
+}
+
+\def\macrobodyctxt{%
+ \scanctxt
\catcode`\{=\other
\catcode`\}=\other
- \catcode`\@=\other
\catcode`\^^M=\other
- \usembodybackslash}
+ \usembodybackslash
+}
\def\macroargctxt{%
- \catcode`\~=\other
- \catcode`\^=\other
- \catcode`\_=\other
- \catcode`\|=\other
- \catcode`\<=\other
- \catcode`\>=\other
- \catcode`\+=\other
- \catcode`\@=\other
- \catcode`\\=\other}
+ \scanctxt
+ \catcode`\\=\other
+}
% \mbodybackslash is the definition of \ in @macro bodies.
% It maps \foo\ => \csname macarg.foo\endcsname => #N
@@ -5615,25 +5774,21 @@ width0pt\relax} \fi
\else \errmessage{Macro name \the\macname\space already defined}\fi
\global\cslet{macsave.\the\macname}{\the\macname}%
\global\expandafter\let\csname ismacro.\the\macname\endcsname=1%
- % Add the macroname to \macrolist
- \toks0 = \expandafter{\macrolist\do}%
- \xdef\macrolist{\the\toks0
- \expandafter\noexpand\csname\the\macname\endcsname}%
+ \addtomacrolist{\the\macname}%
\fi
\begingroup \macrobodyctxt
\ifrecursive \expandafter\parsermacbody
\else \expandafter\parsemacbody
\fi}
-\def\unmacro{\parsearg\dounmacro}
-\def\dounmacro#1{%
+\parseargdef\unmacro{%
\if1\csname ismacro.#1\endcsname
\global\cslet{#1}{macsave.#1}%
\global\expandafter\let \csname ismacro.#1\endcsname=0%
% Remove the macro name from \macrolist:
\begingroup
\expandafter\let\csname#1\endcsname \relax
- \let\do\unmacrodo
+ \let\definedummyword\unmacrodo
\xdef\macrolist{\macrolist}%
\endgroup
\else
@@ -5643,12 +5798,12 @@ width0pt\relax} \fi
% Called by \do from \dounmacro on each macro. The idea is to omit any
% macro definitions that have been changed to \relax.
-%
+%
\def\unmacrodo#1{%
- \ifx#1\relax
+ \ifx #1\relax
% remove this
\else
- \noexpand\do \noexpand #1%
+ \noexpand\definedummyword \noexpand#1%
\fi
}
@@ -5767,25 +5922,23 @@ width0pt\relax} \fi
\expandafter\parsearg
\fi \next}
-% We mant to disable all macros during \shipout so that they are not
-% expanded by \write.
-\def\turnoffmacros{\begingroup \def\do##1{\let\noexpand##1=\relax}%
- \edef\next{\macrolist}\expandafter\endgroup\next}
-
% @alias.
% We need some trickery to remove the optional spaces around the equal
% sign. Just make them active and then expand them all to nothing.
-\def\alias{\begingroup\obeyspaces\parsearg\aliasxxx}
+\def\alias{\parseargusing\obeyspaces\aliasxxx}
\def\aliasxxx #1{\aliasyyy#1\relax}
-\def\aliasyyy #1=#2\relax{\ignoreactivespaces
-\edef\next{\global\let\expandafter\noexpand\csname#1\endcsname=%
- \expandafter\noexpand\csname#2\endcsname}%
-\expandafter\endgroup\next}
+\def\aliasyyy #1=#2\relax{%
+ {%
+ \expandafter\let\obeyedspace=\empty
+ \addtomacrolist{#1}%
+ \xdef\next{\global\let\makecsname{#1}=\makecsname{#2}}%
+ }%
+ \next
+}
\message{cross references,}
-% @xref etc.
\newwrite\auxfile
@@ -5797,64 +5950,68 @@ width0pt\relax} \fi
\def\inforefzzz #1,#2,#3,#4**{\putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}},
node \samp{\ignorespaces#1{}}}
-% @node's job is to define \lastnode.
-\def\node{\ENVcheck\parsearg\nodezzz}
-\def\nodezzz#1{\nodexxx #1,\finishnodeparse}
-\def\nodexxx#1,#2\finishnodeparse{\gdef\lastnode{#1}}
+% @node's only job in TeX is to define \lastnode, which is used in
+% cross-references. The @node line might or might not have commas, and
+% might or might not have spaces before the first comma, like:
+% @node foo , bar , ...
+% We don't want such trailing spaces in the node name.
+%
+\parseargdef\node{\checkenv{}\donode #1 ,\finishnodeparse}
+%
+% also remove a trailing comma, in case of something like this:
+% @node Help-Cross, , , Cross-refs
+\def\donode#1 ,#2\finishnodeparse{\dodonode #1,\finishnodeparse}
+\def\dodonode#1,#2\finishnodeparse{\gdef\lastnode{#1}}
+
\let\nwnode=\node
-\let\lastnode=\relax
-
-% The sectioning commands (@chapter, etc.) call these.
-\def\donoderef{%
- \ifx\lastnode\relax\else
- \expandafter\expandafter\expandafter\setref{\lastnode}%
- {Ysectionnumberandtype}%
- \global\let\lastnode=\relax
- \fi
-}
-\def\unnumbnoderef{%
- \ifx\lastnode\relax\else
- \expandafter\expandafter\expandafter\setref{\lastnode}{Ynothing}%
- \global\let\lastnode=\relax
- \fi
-}
-\def\appendixnoderef{%
- \ifx\lastnode\relax\else
- \expandafter\expandafter\expandafter\setref{\lastnode}%
- {Yappendixletterandtype}%
- \global\let\lastnode=\relax
+\let\lastnode=\empty
+
+% Write a cross-reference definition for the current node. #1 is the
+% type (Ynumbered, Yappendix, Ynothing).
+%
+\def\donoderef#1{%
+ \ifx\lastnode\empty\else
+ \setref{\lastnode}{#1}%
+ \global\let\lastnode=\empty
\fi
}
-
% @anchor{NAME} -- define xref target at arbitrary point.
%
\newcount\savesfregister
-\gdef\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
-\gdef\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
-\gdef\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
+%
+\def\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
+\def\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
+\def\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
% \setref{NAME}{SNT} defines a cross-reference point NAME (a node or an
-% anchor), namely NAME-title (the corresponding @chapter/etc. name),
-% NAME-pg (the page number), and NAME-snt (section number and type).
-% Called from \foonoderef.
-%
-% We have to set \indexdummies so commands such as @code in a section
-% title aren't expanded. It would be nicer not to expand the titles in
-% the first place, but there's so many layers that that is hard to do.
-%
-% Likewise, use \turnoffactive so that punctuation chars such as underscore
-% and backslash work in node names.
-%
-\def\setref#1#2{{%
- \atdummies
+% anchor), which consists of three parts:
+% 1) NAME-title - the current sectioning name taken from \thissection,
+% or the anchor name.
+% 2) NAME-snt - section number and type, passed as the SNT arg, or
+% empty for anchors.
+% 3) NAME-pg - the page number.
+%
+% This is called from \donoderef, \anchor, and \dofloat. In the case of
+% floats, there is an additional part, which is not written here:
+% 4) NAME-lof - the text as it should appear in a @listoffloats.
+%
+\def\setref#1#2{%
\pdfmkdest{#1}%
- %
- \turnoffactive
- \dosetq{#1-title}{Ytitle}%
- \dosetq{#1-pg}{Ypagenumber}%
- \dosetq{#1-snt}{#2}%
-}}
+ \iflinks
+ {%
+ \atdummies % preserve commands, but don't expand them
+ \edef\writexrdef##1##2{%
+ \write\auxfile{@xrdef{#1-% #1 of \setref, expanded by the \edef
+ ##1}{##2}}% these are parameters of \writexrdef
+ }%
+ \toks0 = \expandafter{\thissection}%
+ \immediate \writexrdef{title}{\the\toks0 }%
+ \immediate \writexrdef{snt}{\csname #2\endcsname}% \Ynumbered etc.
+ \writexrdef{pg}{\folio}% will be written later, during \shipout
+ }%
+ \fi
+}
% @xref, @pxref, and @ref generate cross-references. For \xrefX, #1 is
% the node name, #2 the name of the Info cross-reference, #3 the printed
@@ -5867,105 +6024,125 @@ width0pt\relax} \fi
\def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup
\unsepspaces
\def\printedmanual{\ignorespaces #5}%
- \def\printednodename{\ignorespaces #3}%
- \setbox1=\hbox{\printedmanual}%
- \setbox0=\hbox{\printednodename}%
+ \def\printedrefname{\ignorespaces #3}%
+ \setbox1=\hbox{\printedmanual\unskip}%
+ \setbox0=\hbox{\printedrefname\unskip}%
\ifdim \wd0 = 0pt
% No printed node name was explicitly given.
\expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax
% Use the node name inside the square brackets.
- \def\printednodename{\ignorespaces #1}%
+ \def\printedrefname{\ignorespaces #1}%
\else
% Use the actual chapter/section title appear inside
% the square brackets. Use the real section title if we have it.
\ifdim \wd1 > 0pt
% It is in another manual, so we don't have it.
- \def\printednodename{\ignorespaces #1}%
+ \def\printedrefname{\ignorespaces #1}%
\else
\ifhavexrefs
% We know the real title if we have the xref values.
- \def\printednodename{\refx{#1-title}{}}%
+ \def\printedrefname{\refx{#1-title}{}}%
\else
% Otherwise just copy the Info node name.
- \def\printednodename{\ignorespaces #1}%
+ \def\printedrefname{\ignorespaces #1}%
\fi%
\fi
\fi
\fi
%
- % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
- % insert empty discretionaries after hyphens, which means that it will
- % not find a line break at a hyphen in a node names. Since some manuals
- % are best written with fairly long node names, containing hyphens, this
- % is a loss. Therefore, we give the text of the node name again, so it
- % is as if TeX is seeing it for the first time.
+ % Make link in pdf output.
\ifpdf
\leavevmode
\getfilename{#4}%
- {\turnoffactive \otherbackslash
+ {\turnoffactive
+ % See comments at \activebackslashdouble.
+ {\activebackslashdouble \xdef\pdfxrefdest{#1}%
+ \backslashparens\pdfxrefdest}%
+ %
\ifnum\filenamelength>0
\startlink attr{/Border [0 0 0]}%
- goto file{\the\filename.pdf} name{#1}%
+ goto file{\the\filename.pdf} name{\pdfxrefdest}%
\else
\startlink attr{/Border [0 0 0]}%
- goto name{#1}%
+ goto name{\pdfmkpgn{\pdfxrefdest}}%
\fi
}%
\linkcolor
\fi
%
- \ifdim \wd1 > 0pt
- \putwordsection{} ``\printednodename'' \putwordin{} \cite{\printedmanual}%
- \else
- % _ (for example) has to be the character _ for the purposes of the
- % control sequence corresponding to the node, but it has to expand
- % into the usual \leavevmode...\vrule stuff for purposes of
- % printing. So we \turnoffactive for the \refx-snt, back on for the
- % printing, back off for the \refx-pg.
- {\turnoffactive \otherbackslash
- % Only output a following space if the -snt ref is nonempty; for
- % @unnumbered and @anchor, it won't be.
- \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
- \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
- }%
- % output the `[mynode]' via a macro.
- \xrefprintnodename\printednodename
+ % Float references are printed completely differently: "Figure 1.2"
+ % instead of "[somenode], p.3". We distinguish them by the
+ % LABEL-title being set to a magic string.
+ {%
+ % Have to otherify everything special to allow the \csname to
+ % include an _ in the xref name, etc.
+ \indexnofonts
+ \turnoffactive
+ \expandafter\global\expandafter\let\expandafter\Xthisreftitle
+ \csname XR#1-title\endcsname
+ }%
+ \iffloat\Xthisreftitle
+ % If the user specified the print name (third arg) to the ref,
+ % print it instead of our usual "Figure 1.2".
+ \ifdim\wd0 = 0pt
+ \refx{#1-snt}%
+ \else
+ \printedrefname
+ \fi
%
- % But we always want a comma and a space:
- ,\space
+ % if the user also gave the printed manual name (fifth arg), append
+ % "in MANUALNAME".
+ \ifdim \wd1 > 0pt
+ \space \putwordin{} \cite{\printedmanual}%
+ \fi
+ \else
+ % node/anchor (non-float) references.
%
- % output the `page 3'.
- \turnoffactive \otherbackslash \putwordpage\tie\refx{#1-pg}{}%
+ % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
+ % insert empty discretionaries after hyphens, which means that it will
+ % not find a line break at a hyphen in a node names. Since some manuals
+ % are best written with fairly long node names, containing hyphens, this
+ % is a loss. Therefore, we give the text of the node name again, so it
+ % is as if TeX is seeing it for the first time.
+ \ifdim \wd1 > 0pt
+ \putwordsection{} ``\printedrefname'' \putwordin{} \cite{\printedmanual}%
+ \else
+ % _ (for example) has to be the character _ for the purposes of the
+ % control sequence corresponding to the node, but it has to expand
+ % into the usual \leavevmode...\vrule stuff for purposes of
+ % printing. So we \turnoffactive for the \refx-snt, back on for the
+ % printing, back off for the \refx-pg.
+ {\turnoffactive
+ % Only output a following space if the -snt ref is nonempty; for
+ % @unnumbered and @anchor, it won't be.
+ \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
+ \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
+ }%
+ % output the `[mynode]' via a macro so it can be overridden.
+ \xrefprintnodename\printedrefname
+ %
+ % But we always want a comma and a space:
+ ,\space
+ %
+ % output the `page 3'.
+ \turnoffactive \putwordpage\tie\refx{#1-pg}{}%
+ \fi
\fi
\endlink
\endgroup}
% This macro is called from \xrefX for the `[nodename]' part of xref
% output. It's a separate macro only so it can be changed more easily,
-% since not square brackets don't work in some documents. Particularly
+% since square brackets don't work well in some documents. Particularly
% one that Bob is working on :).
-%
+%
\def\xrefprintnodename#1{[#1]}
-% \dosetq is called from \setref to do the actual \write (\iflinks).
+% Things referred to by \setref.
%
-\def\dosetq#1#2{%
- {\let\folio=0%
- \edef\next{\write\auxfile{\internalsetq{#1}{#2}}}%
- \iflinks \next \fi
- }%
-}
-
-% \internalsetq{foo}{page} expands into
-% CHARACTERS @xrdef{foo}{...expansion of \page...}
-\def\internalsetq#1#2{@xrdef{#1}{\csname #2\endcsname}}
-
-% Things to be expanded by \internalsetq.
-%
-\def\Ypagenumber{\folio}
-\def\Ytitle{\thissection}
\def\Ynothing{}
-\def\Ysectionnumberandtype{%
+\def\Yomitfromtoc{}
+\def\Ynumbered{%
\ifnum\secno=0
\putwordChapter@tie \the\chapno
\else \ifnum\subsecno=0
@@ -5976,8 +6153,7 @@ width0pt\relax} \fi
\putwordSection@tie \the\chapno.\the\secno.\the\subsecno.\the\subsubsecno
\fi\fi\fi
}
-
-\def\Yappendixletterandtype{%
+\def\Yappendix{%
\ifnum\secno=0
\putwordAppendix@tie @char\the\appendixno{}%
\else \ifnum\subsecno=0
@@ -5990,15 +6166,6 @@ width0pt\relax} \fi
\fi\fi\fi
}
-% Use TeX 3.0's \inputlineno to get the line number, for better error
-% messages, but if we're using an old version of TeX, don't do anything.
-%
-\ifx\inputlineno\thisisundefined
- \let\linenumber = \empty % Pre-3.0.
-\else
- \def\linenumber{\the\inputlineno:\space}
-\fi
-
% Define \refx{NAME}{SUFFIX} to reference a cross-reference string named NAME.
% If its value is nonempty, SUFFIX is output afterward.
%
@@ -6007,7 +6174,7 @@ width0pt\relax} \fi
\indexnofonts
\otherbackslash
\expandafter\global\expandafter\let\expandafter\thisrefX
- \csname X#1\endcsname
+ \csname XR#1\endcsname
}%
\ifx\thisrefX\relax
% If not defined, say something at least.
@@ -6029,12 +6196,45 @@ width0pt\relax} \fi
#2% Output the suffix in any case.
}
-% This is the macro invoked by entries in the aux file.
+% This is the macro invoked by entries in the aux file. Usually it's
+% just a \def (we prepend XR to the control sequence name to avoid
+% collisions). But if this is a float type, we have more work to do.
%
-\def\xrdef#1{\expandafter\gdef\csname X#1\endcsname}
+\def\xrdef#1#2{%
+ \expandafter\gdef\csname XR#1\endcsname{#2}% remember this xref value.
+ %
+ % Was that xref control sequence that we just defined for a float?
+ \expandafter\iffloat\csname XR#1\endcsname
+ % it was a float, and we have the (safe) float type in \iffloattype.
+ \expandafter\let\expandafter\floatlist
+ \csname floatlist\iffloattype\endcsname
+ %
+ % Is this the first time we've seen this float type?
+ \expandafter\ifx\floatlist\relax
+ \toks0 = {\do}% yes, so just \do
+ \else
+ % had it before, so preserve previous elements in list.
+ \toks0 = \expandafter{\floatlist\do}%
+ \fi
+ %
+ % Remember this xref in the control sequence \floatlistFLOATTYPE,
+ % for later use in \listoffloats.
+ \expandafter\xdef\csname floatlist\iffloattype\endcsname{\the\toks0{#1}}%
+ \fi
+}
% Read the last existing aux file, if any. No error if none exists.
-\def\readauxfile{\begingroup
+%
+\def\tryauxfile{%
+ \openin 1 \jobname.aux
+ \ifeof 1 \else
+ \readdatafile{aux}%
+ \global\havexrefstrue
+ \fi
+ \closein 1
+}
+
+\def\setupdatafile{%
\catcode`\^^@=\other
\catcode`\^^A=\other
\catcode`\^^B=\other
@@ -6092,41 +6292,39 @@ width0pt\relax} \fi
\catcode`\%=\other
\catcode`+=\other % avoid \+ for paranoia even though we've turned it off
%
- % Make the characters 128-255 be printing characters
+ % This is to support \ in node names and titles, since the \
+ % characters end up in a \csname. It's easier than
+ % leaving it active and making its active definition an actual \
+ % character. What I don't understand is why it works in the *value*
+ % of the xrdef. Seems like it should be a catcode12 \, and that
+ % should not typeset properly. But it works, so I'm moving on for
+ % now. --karl, 15jan04.
+ \catcode`\\=\other
+ %
+ % Make the characters 128-255 be printing characters.
{%
- \count 1=128
+ \count1=128
\def\loop{%
- \catcode\count 1=\other
- \advance\count 1 by 1
- \ifnum \count 1<256 \loop \fi
+ \catcode\count1=\other
+ \advance\count1 by 1
+ \ifnum \count1<256 \loop \fi
}%
}%
%
- % Turn off \ as an escape so we do not lose on
- % entries which were dumped with control sequences in their names.
- % For example, @xrdef{$\leq $-fun}{page ...} made by @defun ^^
- % Reference to such entries still does not work the way one would wish,
- % but at least they do not bomb out when the aux file is read in.
- \catcode`\\=\other
- %
- % @ is our escape character in .aux files.
+ % @ is our escape character in .aux files, and we need braces.
\catcode`\{=1
\catcode`\}=2
\catcode`\@=0
- %
- \openin 1 \jobname.aux
- \ifeof 1 \else
- \closein 1
- \input \jobname.aux
- \global\havexrefstrue
- \global\warnedobstrue
- \fi
- % Open the new aux file. TeX will close it automatically at exit.
- \openout\auxfile=\jobname.aux
-\endgroup}
+}
+\def\readdatafile#1{%
+\begingroup
+ \setupdatafile
+ \input\jobname.#1
+\endgroup}
-% Footnotes.
+\message{insertions,}
+% including footnotes.
\newcount \footnoteno
@@ -6140,19 +6338,19 @@ width0pt\relax} \fi
% @footnotestyle is meaningful for info output only.
\let\footnotestyle=\comment
-\let\ptexfootnote=\footnote
-
{\catcode `\@=11
%
% Auto-number footnotes. Otherwise like plain.
\gdef\footnote{%
+ \let\indent=\ptexindent
+ \let\noindent=\ptexnoindent
\global\advance\footnoteno by \@ne
\edef\thisfootno{$^{\the\footnoteno}$}%
%
% In case the footnote comes at the end of a sentence, preserve the
% extra spacing after we do the footnote number.
\let\@sf\empty
- \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\/\fi
+ \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\ptexslash\fi
%
% Remove inadvertent blank space before typesetting the footnote number.
\unskip
@@ -6163,17 +6361,12 @@ width0pt\relax} \fi
% Don't bother with the trickery in plain.tex to not require the
% footnote text as a parameter. Our footnotes don't need to be so general.
%
-% Oh yes, they do; otherwise, @ifset and anything else that uses
-% \parseargline fail inside footnotes because the tokens are fixed when
+% Oh yes, they do; otherwise, @ifset (and anything else that uses
+% \parseargline) fails inside footnotes because the tokens are fixed when
% the footnote is read. --karl, 16nov96.
%
-% The start of the footnote looks usually like this:
-\gdef\startfootins{\insert\footins\bgroup}
-%
-% ... but this macro is redefined inside @multitable.
-%
\gdef\dofootnote{%
- \startfootins
+ \insert\footins\bgroup
% We want to typeset this text as a normal paragraph, even if the
% footnote reference occurs in (for example) a display environment.
% So reset some parameters.
@@ -6209,40 +6402,66 @@ width0pt\relax} \fi
}
}%end \catcode `\@=11
-% @| inserts a changebar to the left of the current line. It should
-% surround any changed text. This approach does *not* work if the
-% change spans more than two lines of output. To handle that, we would
-% have adopt a much more difficult approach (putting marks into the main
-% vertical list for the beginning and end of each change).
+% In case a @footnote appears in a vbox, save the footnote text and create
+% the real \insert just after the vbox finished. Otherwise, the insertion
+% would be lost.
+% Similarily, if a @footnote appears inside an alignment, save the footnote
+% text to a box and make the \insert when a row of the table is finished.
+% And the same can be done for other insert classes. --kasal, 16nov03.
+
+% Replace the \insert primitive by a cheating macro.
+% Deeper inside, just make sure that the saved insertions are not spilled
+% out prematurely.
%
-\def\|{%
- % \vadjust can only be used in horizontal mode.
- \leavevmode
- %
- % Append this vertical mode material after the current line in the output.
- \vadjust{%
- % We want to insert a rule with the height and depth of the current
- % leading; that is exactly what \strutbox is supposed to record.
- \vskip-\baselineskip
- %
- % \vadjust-items are inserted at the left edge of the type. So
- % the \llap here moves out into the left-hand margin.
- \llap{%
- %
- % For a thicker or thinner bar, change the `1pt'.
- \vrule height\baselineskip width1pt
- %
- % This is the space between the bar and the text.
- \hskip 12pt
- }%
- }%
+\def\startsavinginserts{%
+ \ifx \insert\ptexinsert
+ \let\insert\saveinsert
+ \else
+ \let\checkinserts\relax
+ \fi
}
-% For a final copy, take out the rectangles
-% that mark overfull boxes (in case you have decided
-% that the text looks ok even though it passes the margin).
+% This \insert replacement works for both \insert\footins{foo} and
+% \insert\footins\bgroup foo\egroup, but it doesn't work for \insert27{foo}.
%
-\def\finalout{\overfullrule=0pt}
+\def\saveinsert#1{%
+ \edef\next{\noexpand\savetobox \makeSAVEname#1}%
+ \afterassignment\next
+ % swallow the left brace
+ \let\temp =
+}
+\def\makeSAVEname#1{\makecsname{SAVE\expandafter\gobble\string#1}}
+\def\savetobox#1{\global\setbox#1 = \vbox\bgroup \unvbox#1}
+
+\def\checksaveins#1{\ifvoid#1\else \placesaveins#1\fi}
+
+\def\placesaveins#1{%
+ \ptexinsert \csname\expandafter\gobblesave\string#1\endcsname
+ {\box#1}%
+}
+
+% eat @SAVE -- beware, all of them have catcode \other:
+{
+ \def\dospecials{\do S\do A\do V\do E} \uncatcodespecials % ;-)
+ \gdef\gobblesave @SAVE{}
+}
+
+% initialization:
+\def\newsaveins #1{%
+ \edef\next{\noexpand\newsaveinsX \makeSAVEname#1}%
+ \next
+}
+\def\newsaveinsX #1{%
+ \csname newbox\endcsname #1%
+ \expandafter\def\expandafter\checkinserts\expandafter{\checkinserts
+ \checksaveins #1}%
+}
+
+% initialize:
+\let\checkinserts\empty
+\newsaveins\footins
+\newsaveins\margin
+
% @image. We use the macros from epsf.tex to support this.
% If epsf.tex is not installed and @image is used, we complain.
@@ -6252,12 +6471,12 @@ width0pt\relax} \fi
% undone and the next image would fail.
\openin 1 = epsf.tex
\ifeof 1 \else
- \closein 1
% Do not bother showing banner with epsf.tex v2.7k (available in
% doc/epsf.tex and on ctan).
\def\epsfannounce{\toks0 = }%
\input epsf.tex
\fi
+\closein 1
%
% We will only complain once about lack of epsf.tex.
\newif\ifwarnednoepsf
@@ -6293,7 +6512,7 @@ width0pt\relax} \fi
\nobreak\bigskip
% Usually we'll have text after the image which will insert
% \parskip glue, so insert it here too to equalize the space
- % above and below.
+ % above and below.
\nobreak\vskip\parskip
\nobreak
\line\bgroup\hss
@@ -6313,6 +6532,269 @@ width0pt\relax} \fi
\endgroup}
+% @float FLOATTYPE,LABEL,LOC ... @end float for displayed figures, tables,
+% etc. We don't actually implement floating yet, we always include the
+% float "here". But it seemed the best name for the future.
+%
+\envparseargdef\float{\eatcommaspace\eatcommaspace\dofloat#1, , ,\finish}
+
+% There may be a space before second and/or third parameter; delete it.
+\def\eatcommaspace#1, {#1,}
+
+% #1 is the optional FLOATTYPE, the text label for this float, typically
+% "Figure", "Table", "Example", etc. Can't contain commas. If omitted,
+% this float will not be numbered and cannot be referred to.
+%
+% #2 is the optional xref label. Also must be present for the float to
+% be referable.
+%
+% #3 is the optional positioning argument; for now, it is ignored. It
+% will somehow specify the positions allowed to float to (here, top, bottom).
+%
+% We keep a separate counter for each FLOATTYPE, which we reset at each
+% chapter-level command.
+\let\resetallfloatnos=\empty
+%
+\def\dofloat#1,#2,#3,#4\finish{%
+ \let\thiscaption=\empty
+ \let\thisshortcaption=\empty
+ %
+ % don't lose footnotes inside @float.
+ %
+ % BEWARE: when the floats start float, we have to issue warning whenever an
+ % insert appears inside a float which could possibly float. --kasal, 26may04
+ %
+ \startsavinginserts
+ %
+ % We can't be used inside a paragraph.
+ \par
+ %
+ \vtop\bgroup
+ \def\floattype{#1}%
+ \def\floatlabel{#2}%
+ \def\floatloc{#3}% we do nothing with this yet.
+ %
+ \ifx\floattype\empty
+ \let\safefloattype=\empty
+ \else
+ {%
+ % the floattype might have accents or other special characters,
+ % but we need to use it in a control sequence name.
+ \indexnofonts
+ \turnoffactive
+ \xdef\safefloattype{\floattype}%
+ }%
+ \fi
+ %
+ % If label is given but no type, we handle that as the empty type.
+ \ifx\floatlabel\empty \else
+ % We want each FLOATTYPE to be numbered separately (Figure 1,
+ % Table 1, Figure 2, ...). (And if no label, no number.)
+ %
+ \expandafter\getfloatno\csname\safefloattype floatno\endcsname
+ \global\advance\floatno by 1
+ %
+ {%
+ % This magic value for \thissection is output by \setref as the
+ % XREFLABEL-title value. \xrefX uses it to distinguish float
+ % labels (which have a completely different output format) from
+ % node and anchor labels. And \xrdef uses it to construct the
+ % lists of floats.
+ %
+ \edef\thissection{\floatmagic=\safefloattype}%
+ \setref{\floatlabel}{Yfloat}%
+ }%
+ \fi
+ %
+ % start with \parskip glue, I guess.
+ \vskip\parskip
+ %
+ % Don't suppress indentation if a float happens to start a section.
+ \restorefirstparagraphindent
+}
+
+% we have these possibilities:
+% @float Foo,lbl & @caption{Cap}: Foo 1.1: Cap
+% @float Foo,lbl & no caption: Foo 1.1
+% @float Foo & @caption{Cap}: Foo: Cap
+% @float Foo & no caption: Foo
+% @float ,lbl & Caption{Cap}: 1.1: Cap
+% @float ,lbl & no caption: 1.1
+% @float & @caption{Cap}: Cap
+% @float & no caption:
+%
+\def\Efloat{%
+ \let\floatident = \empty
+ %
+ % In all cases, if we have a float type, it comes first.
+ \ifx\floattype\empty \else \def\floatident{\floattype}\fi
+ %
+ % If we have an xref label, the number comes next.
+ \ifx\floatlabel\empty \else
+ \ifx\floattype\empty \else % if also had float type, need tie first.
+ \appendtomacro\floatident{\tie}%
+ \fi
+ % the number.
+ \appendtomacro\floatident{\chaplevelprefix\the\floatno}%
+ \fi
+ %
+ % Start the printed caption with what we've constructed in
+ % \floatident, but keep it separate; we need \floatident again.
+ \let\captionline = \floatident
+ %
+ \ifx\thiscaption\empty \else
+ \ifx\floatident\empty \else
+ \appendtomacro\captionline{: }% had ident, so need a colon between
+ \fi
+ %
+ % caption text.
+ \appendtomacro\captionline{\scanexp\thiscaption}%
+ \fi
+ %
+ % If we have anything to print, print it, with space before.
+ % Eventually this needs to become an \insert.
+ \ifx\captionline\empty \else
+ \vskip.5\parskip
+ \captionline
+ %
+ % Space below caption.
+ \vskip\parskip
+ \fi
+ %
+ % If have an xref label, write the list of floats info. Do this
+ % after the caption, to avoid chance of it being a breakpoint.
+ \ifx\floatlabel\empty \else
+ % Write the text that goes in the lof to the aux file as
+ % \floatlabel-lof. Besides \floatident, we include the short
+ % caption if specified, else the full caption if specified, else nothing.
+ {%
+ \atdummies
+ % since we read the caption text in the macro world, where ^^M
+ % is turned into a normal character, we have to scan it back, so
+ % we don't write the literal three characters "^^M" into the aux file.
+ \scanexp{%
+ \xdef\noexpand\gtemp{%
+ \ifx\thisshortcaption\empty
+ \thiscaption
+ \else
+ \thisshortcaption
+ \fi
+ }%
+ }%
+ \immediate\write\auxfile{@xrdef{\floatlabel-lof}{\floatident
+ \ifx\gtemp\empty \else : \gtemp \fi}}%
+ }%
+ \fi
+ \egroup % end of \vtop
+ %
+ % place the captured inserts
+ %
+ % BEWARE: when the floats start float, we have to issue warning whenever an
+ % insert appears inside a float which could possibly float. --kasal, 26may04
+ %
+ \checkinserts
+}
+
+% Append the tokens #2 to the definition of macro #1, not expanding either.
+%
+\def\appendtomacro#1#2{%
+ \expandafter\def\expandafter#1\expandafter{#1#2}%
+}
+
+% @caption, @shortcaption
+%
+\def\caption{\docaption\thiscaption}
+\def\shortcaption{\docaption\thisshortcaption}
+\def\docaption{\checkenv\float \bgroup\scanargctxt\defcaption}
+\def\defcaption#1#2{\egroup \def#1{#2}}
+
+% The parameter is the control sequence identifying the counter we are
+% going to use. Create it if it doesn't exist and assign it to \floatno.
+\def\getfloatno#1{%
+ \ifx#1\relax
+ % Haven't seen this figure type before.
+ \csname newcount\endcsname #1%
+ %
+ % Remember to reset this floatno at the next chap.
+ \expandafter\gdef\expandafter\resetallfloatnos
+ \expandafter{\resetallfloatnos #1=0 }%
+ \fi
+ \let\floatno#1%
+}
+
+% \setref calls this to get the XREFLABEL-snt value. We want an @xref
+% to the FLOATLABEL to expand to "Figure 3.1". We call \setref when we
+% first read the @float command.
+%
+\def\Yfloat{\floattype@tie \chaplevelprefix\the\floatno}%
+
+% Magic string used for the XREFLABEL-title value, so \xrefX can
+% distinguish floats from other xref types.
+\def\floatmagic{!!float!!}
+
+% #1 is the control sequence we are passed; we expand into a conditional
+% which is true if #1 represents a float ref. That is, the magic
+% \thissection value which we \setref above.
+%
+\def\iffloat#1{\expandafter\doiffloat#1==\finish}
+%
+% #1 is (maybe) the \floatmagic string. If so, #2 will be the
+% (safe) float type for this float. We set \iffloattype to #2.
+%
+\def\doiffloat#1=#2=#3\finish{%
+ \def\temp{#1}%
+ \def\iffloattype{#2}%
+ \ifx\temp\floatmagic
+}
+
+% @listoffloats FLOATTYPE - print a list of floats like a table of contents.
+%
+\parseargdef\listoffloats{%
+ \def\floattype{#1}% floattype
+ {%
+ % the floattype might have accents or other special characters,
+ % but we need to use it in a control sequence name.
+ \indexnofonts
+ \turnoffactive
+ \xdef\safefloattype{\floattype}%
+ }%
+ %
+ % \xrdef saves the floats as a \do-list in \floatlistSAFEFLOATTYPE.
+ \expandafter\ifx\csname floatlist\safefloattype\endcsname \relax
+ \ifhavexrefs
+ % if the user said @listoffloats foo but never @float foo.
+ \message{\linenumber No `\safefloattype' floats to list.}%
+ \fi
+ \else
+ \begingroup
+ \leftskip=\tocindent % indent these entries like a toc
+ \let\do=\listoffloatsdo
+ \csname floatlist\safefloattype\endcsname
+ \endgroup
+ \fi
+}
+
+% This is called on each entry in a list of floats. We're passed the
+% xref label, in the form LABEL-title, which is how we save it in the
+% aux file. We strip off the -title and look up \XRLABEL-lof, which
+% has the text we're supposed to typeset here.
+%
+% Figures without xref labels will not be included in the list (since
+% they won't appear in the aux file).
+%
+\def\listoffloatsdo#1{\listoffloatsdoentry#1\finish}
+\def\listoffloatsdoentry#1-title\finish{{%
+ % Can't fully expand XR#1-lof because it can contain anything. Just
+ % pass the control sequence. On the other hand, XR#1-pg is just the
+ % page number, and we want to fully expand that so we can get a link
+ % in pdf output.
+ \toksA = \expandafter{\csname XR#1-lof\endcsname}%
+ %
+ % use the same \entry macro we use to generate the TOC and index.
+ \edef\writeentry{\noexpand\entry{\the\toksA}{\csname XR#1-pg\endcsname}}%
+ \writeentry
+}}
+
\message{localization,}
% and i18n.
@@ -6321,19 +6803,17 @@ width0pt\relax} \fi
% properly. Single argument is the language abbreviation.
% It would be nice if we could set up a hyphenation file here.
%
-\def\documentlanguage{\parsearg\dodocumentlanguage}
-\def\dodocumentlanguage#1{%
+\parseargdef\documentlanguage{%
\tex % read txi-??.tex file in plain TeX.
- % Read the file if it exists.
- \openin 1 txi-#1.tex
- \ifeof1
- \errhelp = \nolanghelp
- \errmessage{Cannot read language file txi-#1.tex}%
- \let\temp = \relax
- \else
- \def\temp{\input txi-#1.tex }%
- \fi
- \temp
+ % Read the file if it exists.
+ \openin 1 txi-#1.tex
+ \ifeof 1
+ \errhelp = \nolanghelp
+ \errmessage{Cannot read language file txi-#1.tex}%
+ \else
+ \input txi-#1.tex
+ \fi
+ \closein 1
\endgroup
}
\newhelp\nolanghelp{The given language definition file cannot be found or
@@ -6378,10 +6858,10 @@ should work if nowhere else does.}
\fi
}
-% Parameters in order: 1) textheight; 2) textwidth; 3) voffset;
-% 4) hoffset; 5) binding offset; 6) topskip; 7) physical page height; 8)
-% physical page width.
-%
+% Parameters in order: 1) textheight; 2) textwidth;
+% 3) voffset; 4) hoffset; 5) binding offset; 6) topskip;
+% 7) physical page height; 8) physical page width.
+%
% We also call \setleading{\textleading}, so the caller should define
% \textleading. The caller should also set \parskip.
%
@@ -6427,7 +6907,7 @@ should work if nowhere else does.}
{11in}{8.5in}%
}}
-% Use @smallbook to reset parameters for 7x9.5 (or so) format.
+% Use @smallbook to reset parameters for 7x9.25 trim size.
\def\smallbook{{\globaldefs = 1
\parskip = 2pt plus 1pt
\textleading = 12pt
@@ -6444,12 +6924,30 @@ should work if nowhere else does.}
\defbodyindent = .5cm
}}
+% Use @smallerbook to reset parameters for 6x9 trim size.
+% (Just testing, parameters still in flux.)
+\def\smallerbook{{\globaldefs = 1
+ \parskip = 1.5pt plus 1pt
+ \textleading = 12pt
+ %
+ \internalpagesizes{7.4in}{4.8in}%
+ {-.2in}{-.4in}%
+ {0pt}{14pt}%
+ {9in}{6in}%
+ %
+ \lispnarrowing = 0.25in
+ \tolerance = 700
+ \hfuzz = 1pt
+ \contentsrightmargin = 0pt
+ \defbodyindent = .4cm
+}}
+
% Use @afourpaper to print on European A4 paper.
\def\afourpaper{{\globaldefs = 1
\parskip = 3pt plus 2pt minus 1pt
\textleading = 13.2pt
%
- % Double-side printing via postscript on Laserjet 4050
+ % Double-side printing via postscript on Laserjet 4050
% prints double-sided nicely when \bindingoffset=10mm and \hoffset=-6mm.
% To change the settings for a different printer or situation, adjust
% \normaloffset until the front-side and back-side texts align. Then
@@ -6490,7 +6988,7 @@ should work if nowhere else does.}
\tableindent = 12mm
}}
-% A specific text layout, 24x15cm overall, intended for A4 paper.
+% A specific text layout, 24x15cm overall, intended for A4 paper.
\def\afourlatex{{\globaldefs = 1
\afourpaper
\internalpagesizes{237mm}{150mm}%
@@ -6516,8 +7014,7 @@ should work if nowhere else does.}
% Perhaps we should allow setting the margins, \topskip, \parskip,
% and/or leading, also. Or perhaps we should compute them somehow.
%
-\def\pagesizes{\parsearg\pagesizesxxx}
-\def\pagesizesxxx#1{\pagesizesyyy #1,,\finish}
+\parseargdef\pagesizes{\pagesizesyyy #1,,\finish}
\def\pagesizesyyy#1,#2,#3\finish{{%
\setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
\globaldefs = 1
@@ -6564,8 +7061,8 @@ should work if nowhere else does.}
\def\normalplus{+}
\def\normaldollar{$}%$ font-lock fix
-% This macro is used to make a character print one way in ttfont
-% where it can probably just be output, and another way in other fonts,
+% This macro is used to make a character print one way in \tt
+% (where it can probably be output as-is), and another way in other fonts,
% where something hairier probably needs to be done.
%
% #1 is what to print if we are indeed using \tt; #2 is what to print
@@ -6597,6 +7094,7 @@ should work if nowhere else does.}
\catcode`\_=\active
\def_{\ifusingtt\normalunderscore\_}
+\let\realunder=_
% Subroutine for the previous macro.
\def\_{\leavevmode \kern.07em \vbox{\hrule width.3em height.1ex}\kern .07em }
@@ -6613,13 +7111,6 @@ should work if nowhere else does.}
\catcode`\$=\active
\def${\ifusingit{{\sl\$}}\normaldollar}%$ font-lock fix
-% Set up an active definition for =, but don't enable it most of the time.
-{\catcode`\==\active
-\global\def={{\tt \char 61}}}
-
-\catcode`+=\active
-\catcode`\_=\active
-
% If a .fmt file is being used, characters that might appear in a file
% name cannot be active until we have parsed the command line.
% So turn them off again, and have \everyjob (or @setfilename) turn them on.
@@ -6628,23 +7119,25 @@ should work if nowhere else does.}
\catcode`\@=0
-% \rawbackslashxx outputs one backslash character in current font,
+% \backslashcurfont outputs one backslash character in current font,
% as in \char`\\.
-\global\chardef\rawbackslashxx=`\\
+\global\chardef\backslashcurfont=`\\
+\global\let\rawbackslashxx=\backslashcurfont % let existing .??s files work
-% \rawbackslash defines an active \ to do \rawbackslashxx.
+% \rawbackslash defines an active \ to do \backslashcurfont.
% \otherbackslash defines an active \ to be a literal `\' character with
% catcode other.
{\catcode`\\=\active
- @gdef@rawbackslash{@let\=@rawbackslashxx}
+ @gdef@rawbackslash{@let\=@backslashcurfont}
@gdef@otherbackslash{@let\=@realbackslash}
}
-% \realbackslash is an actual character `\' with catcode other.
-{\catcode`\\=\other @gdef@realbackslash{\}}
+% \realbackslash is an actual character `\' with catcode other, and
+% \doublebackslash is two of them (for the pdf outlines).
+{\catcode`\\=\other @gdef@realbackslash{\} @gdef@doublebackslash{\\}}
% \normalbackslash outputs one backslash in fixed width font.
-\def\normalbackslash{{\tt\rawbackslashxx}}
+\def\normalbackslash{{\tt\backslashcurfont}}
\catcode`\\=\active
@@ -6661,12 +7154,13 @@ should work if nowhere else does.}
@let>=@normalgreater
@let+=@normalplus
@let$=@normaldollar %$ font-lock fix
+ @unsepspaces
}
% Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of
% the literal character `\'. (Thus, \ is not expandable when this is in
% effect.)
-%
+%
@def@normalturnoffactive{@turnoffactive @let\=@normalbackslash}
% Make _ and + \other characters, temporarily.
@@ -6683,7 +7177,7 @@ should work if nowhere else does.}
% On the other hand, perhaps the file did not have a `\input texinfo'. Then
% the first `\{ in the file would cause an error. This macro tries to fix
% that, assuming it is called before the first `\' could plausibly occur.
-% Also back turn on active characters that might appear in the input
+% Also turn back on active characters that might appear in the input
% file name, in case not using a pre-dumped format.
%
@gdef@fixbackslash{%
@@ -6695,15 +7189,11 @@ should work if nowhere else does.}
% Say @foo, not \foo, in error messages.
@escapechar = `@@
-% These look ok in all fonts, so just make them not special.
+% These look ok in all fonts, so just make them not special.
@catcode`@& = @other
@catcode`@# = @other
@catcode`@% = @other
-@c Set initial fonts.
-@textfonts
-@rm
-
@c Local variables:
@c eval: (add-hook 'write-file-hooks 'time-stamp)
@@ -6712,3 +7202,9 @@ should work if nowhere else does.}
@c time-stamp-format: "%:y-%02m-%02d.%02H"
@c time-stamp-end: "}"
@c End:
+
+@c vim:sw=2:
+
+@ignore
+ arch-tag: e1b36e32-c96e-4135-a41a-0b2efa2ea115
+@end ignore
diff --git a/doc/version.texi b/doc/version.texi
index 7711f31..d69698f 100644
--- a/doc/version.texi
+++ b/doc/version.texi
@@ -1,4 +1,4 @@
-@set UPDATED 20 February 2006
-@set UPDATED-MONTH February 2006
-@set EDITION 2.5.33
-@set VERSION 2.5.33
+@set UPDATED 10 September 2007
+@set UPDATED-MONTH September 2007
+@set EDITION 2.5.34
+@set VERSION 2.5.34