From 43abfba723a6f4649e16d826c9c8af2937e7e4cc Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 25 May 2006 04:32:20 +0000 Subject: [PATCH] - Modified ccdv-win32 to show "Generating X" messages when running lemon and re2c instead of "Linking X". - Updated lemon and re2c to the latest versions and ported dehsupp to use them for code generation. (Xlatcc is next.) - Added function level linking for Makefile.mingw. SVN r144 (trunk) --- Makefile.mingw | 10 +- ccdv-win32.c | 27 +- docs/rh-log.txt | 5 + src/c_cvars.h | 47 +- src/r_main.h | 8 + src/x64inlines.h | 198 + tools/dehsupp/Makefile | 16 +- tools/dehsupp/dehsupp.c | 568 ++ tools/dehsupp/dehsupp.h | 124 + tools/dehsupp/dehsupp.vcproj | 284 +- tools/dehsupp/parse.c | 1258 +++ tools/dehsupp/parse.h | 34 + tools/dehsupp/parse.tab.c | 1981 ----- tools/dehsupp/parse.y | 1169 +-- tools/dehsupp/scanner.c | 1085 +++ tools/dehsupp/scanner.re | 176 + tools/lemon/lemon.c | 9343 +++++++++++----------- tools/lemon/lemon.vcproj | 321 +- tools/lemon/lempar.c | 58 +- tools/re2c/CHANGELOG | 141 + tools/re2c/Makefile.am | 47 - tools/re2c/Makefile.in | 472 -- tools/re2c/README | 58 +- tools/re2c/README.in | 165 - tools/re2c/aclocal.m4 | 157 - tools/re2c/actions.cc | 1444 ++-- tools/re2c/basics.h | 28 +- tools/re2c/code.cc | 1713 ++-- tools/re2c/code.h | 53 + tools/re2c/config.h.in | 118 - tools/re2c/{configwin.h => config_w32.h} | 61 +- tools/re2c/configure | 7415 ----------------- tools/re2c/configure.in | 59 - tools/re2c/dfa.cc | 533 +- tools/re2c/dfa.h | 386 +- tools/re2c/examples/push.re | 340 + tools/re2c/examples/repeater.re | 44 + tools/re2c/globals.h | 71 +- tools/re2c/ins.h | 53 +- tools/re2c/install-sh | 251 - tools/re2c/main.cc | 319 +- tools/re2c/makerpm.in | 45 - tools/re2c/mbo_getopt.cc | 153 +- tools/re2c/mbo_getopt.h | 34 +- tools/re2c/missing | 198 - tools/re2c/mkinstalldirs | 40 - tools/re2c/parser.cc | 932 ++- tools/re2c/parser.h | 60 +- tools/re2c/parser.y | 98 +- tools/re2c/re.h | 537 +- tools/re2c/re2c.1 | 663 +- tools/re2c/re2c.1.in | 601 -- tools/re2c/re2c.spec.in | 51 - tools/re2c/re2c.vcproj | 248 +- tools/re2c/scanner.cc | 2273 ++++-- tools/re2c/scanner.h | 82 +- tools/re2c/scanner.re | 295 +- tools/re2c/stamp-h.in | 0 tools/re2c/stream_lc.h | 425 + tools/re2c/substr.cc | 67 +- tools/re2c/substr.h | 103 +- tools/re2c/test.c | 162 - tools/re2c/test.re | 6 - tools/re2c/token.h | 27 +- tools/re2c/translate.cc | 122 +- tools/re2c/y.tab.h | 35 +- tools/xlatcc/xlat-parse.tab.c | 3268 ++++---- 67 files changed, 18740 insertions(+), 22425 deletions(-) create mode 100644 src/x64inlines.h create mode 100644 tools/dehsupp/dehsupp.c create mode 100644 tools/dehsupp/dehsupp.h create mode 100644 tools/dehsupp/parse.c create mode 100644 tools/dehsupp/parse.h delete mode 100644 tools/dehsupp/parse.tab.c create mode 100644 tools/dehsupp/scanner.c create mode 100644 tools/dehsupp/scanner.re create mode 100644 tools/re2c/CHANGELOG delete mode 100644 tools/re2c/Makefile.am delete mode 100644 tools/re2c/Makefile.in delete mode 100644 tools/re2c/README.in delete mode 100644 tools/re2c/aclocal.m4 create mode 100644 tools/re2c/code.h delete mode 100644 tools/re2c/config.h.in rename tools/re2c/{configwin.h => config_w32.h} (74%) delete mode 100644 tools/re2c/configure delete mode 100644 tools/re2c/configure.in create mode 100644 tools/re2c/examples/push.re create mode 100644 tools/re2c/examples/repeater.re delete mode 100644 tools/re2c/install-sh delete mode 100644 tools/re2c/makerpm.in delete mode 100644 tools/re2c/missing delete mode 100644 tools/re2c/mkinstalldirs delete mode 100644 tools/re2c/re2c.1.in delete mode 100644 tools/re2c/re2c.spec.in delete mode 100644 tools/re2c/stamp-h.in create mode 100644 tools/re2c/stream_lc.h delete mode 100644 tools/re2c/test.c delete mode 100644 tools/re2c/test.re diff --git a/Makefile.mingw b/Makefile.mingw index d68f8bb49..bd5bf5641 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -1,6 +1,9 @@ # Sub-makefile autogenerated by premake # And then tweaked by hand +# Where did you install the FMOD API to? Change this line so that the build process can find it. +FMODDIR = "c:/program files/fmodapi375win" + ifndef CC CC=gcc endif @@ -35,8 +38,6 @@ RELEASEOBJDIR = releaseobj CCDV = @ccdv -FMODDIR = "c:/program files/fmodapi375win" - CPPFLAGS = -DWIN32 -D_WIN32 -D_WINDOWS -DHAVE_STRUPR -DHAVE_FILELENGTH -DI_DO_NOT_LIKE_BIG_DOWNLOADS -D__forceinline=inline -MMD -Izlib -IFLAC -Isrc -Isrc/win32 -Isrc/g_doom -Isrc/g_heretic -I src/g_hexen -Isrc/g_raven -Isrc/g_strife -Isrc/g_shared -Isrc/oplsynth -Isrc/sound LDFLAGS += flac/libflac.a zlib/libz.a -lfmod -lwsock32 -lwinmm -lddraw -ldsound -ldxguid -ldinput8 -lole32 -luser32 -lgdi32 -lcomctl32 -lcomdlg32 -lsetupapi -lws2_32 -Wl,--subsystem,windows @@ -54,10 +55,11 @@ ifeq ($(CONFIG),Debug) endif ifeq ($(CONFIG),Release) OBJDIR = $(RELEASEOBJDIR) - CFLAGS += $(CPPFLAGS) -march=$(ARCH_TYPE) -mtune=$(TUNE_TYPE) -Wall -Wno-unused -O$(OPTLEVEL) -fomit-frame-pointer + CFLAGS += $(CPPFLAGS) -march=$(ARCH_TYPE) -mtune=$(TUNE_TYPE) -Wall -Wno-unused -O$(OPTLEVEL) -fomit-frame-pointer -pipe + CFLAGS += -ffunction-sections -fno-rtti CPPFLAGS += -DNDEBUG CXXFLAGS = $(CFLAGS) - LDFLAGS += -Wl,-Map=zdoomgcc.map + LDFLAGS += -s -Wl,-Map=zdoomgcc.map -Wl,--gc-sections TARGET = $(RELEASETARGET) endif diff --git a/ccdv-win32.c b/ccdv-win32.c index c84865c02..13b7ac28b 100644 --- a/ccdv-win32.c +++ b/ccdv-win32.c @@ -444,6 +444,8 @@ void mainCRTStartup(void) DWORD nread; int cc = 0; int yy = 0; + int gcc = 0; + int lemon = 0; CONSOLE_SCREEN_BUFFER_INFO bufferInfo; gExitStatus = 95; @@ -465,14 +467,25 @@ void mainCRTStartup(void) lstrcpy(gAction, "Running "); lstrcpyn(gAction+8, ext, extlen+1); - if (extlen == 2 && lstrcmpi(gAction+8, "ar") == CSTR_EQUAL) + if (extlen == 2 && lstrcmpi(gAction+8, "ar") == 0) { SetTarget(&gAr, arg, arglen); } + else if((extlen == 2 && + (lstrcmpi(gAction+8, "cc") == 0 || + lstrcmpi(gAction+8, "cl") == 0)) || + (extlen == 3 && lstrcmpi(gAction+8, "gcc") == 0)) + { + gcc = 1; + } + else if(extlen == 5 && lstrcmpi(gAction+8, "lemon") == 0) + { + lemon = 1; + } while(StepCmdLine(&cmdline, &arg, &arglen)) { - if(arglen == 2 && arg[0] == '-' && arg[1] == 'o') + if(gcc && arglen == 2 && arg[0] == '-' && arg[1] == 'o') { if(StepCmdLine(&cmdline, &arg, &arglen)) { @@ -496,6 +509,16 @@ void mainCRTStartup(void) SetTarget(&gTarget, arg, arglen); } else if(ext[0] == '.' && ext[1] == 'y') + { + if(lemon) + { + lstrcpy(gAction, "Generating"); + SetTarget(&gTarget, arg, arglen); + gTarget[arglen-1] = 'c'; + } + yy++; + } + else if(ext[0] == '.' && ext[1] == 'r' && ext[2] == 'e') { yy++; } diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 4a44feace..e28fb97b5 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,9 @@ May 24, 2006 +- Modified ccdv-win32 to show "Generating X" messages when running lemon and + re2c. +- Updated lemon and re2c to the latest versions and ported dehsupp to use them + for code generation. (Xlatcc is next.) +- Added function level linking for Makefile.mingw. - Disabled RTTI generation and enabled function-level linking in the VC 2005 zdoom project. - Fixed: TAG_MORE now uses __va_copy to copy the taglist when building with diff --git a/src/c_cvars.h b/src/c_cvars.h index e1034ff73..aa82588d0 100644 --- a/src/c_cvars.h +++ b/src/c_cvars.h @@ -149,35 +149,46 @@ private: static bool m_UseCallback; static bool m_DoNoSet; - // Writes all cvars that could effect demo sync to *demo_p. These are - // cvars that have either CVAR_SERVERINFO or CVAR_DEMOSAVE set. - friend void C_WriteCVars (byte **demo_p, DWORD filter, bool compact=false); - - // Read all cvars from *demo_p and set them appropriately. + friend void C_WriteCVars (byte **demo_p, DWORD filter, bool compact); friend void C_ReadCVars (byte **demo_p); - - // Backup demo cvars. Called before a demo starts playing to save all - // cvars the demo might change. friend void C_BackupCVars (void); - - // Finds a named cvar friend FBaseCVar *FindCVar (const char *var_name, FBaseCVar **prev); friend FBaseCVar *FindCVarSub (const char *var_name, int namelen); - - // Called from G_InitNew() friend void UnlatchCVars (void); - - // archive cvars to FILE f friend void C_ArchiveCVars (FConfigFile *f, int type); - - // initialize cvars to default values after they are created friend void C_SetCVarsToDefaults (void); - friend void FilterCompactCVars (TArray &cvars, DWORD filter); - friend void C_DeinitConsole(); }; +// Writes all cvars that could effect demo sync to *demo_p. These are +// cvars that have either CVAR_SERVERINFO or CVAR_DEMOSAVE set. +void C_WriteCVars (byte **demo_p, DWORD filter, bool compact=false); + +// Read all cvars from *demo_p and set them appropriately. +void C_ReadCVars (byte **demo_p); + +// Backup demo cvars. Called before a demo starts playing to save all +// cvars the demo might change. +void C_BackupCVars (void); + +// Finds a named cvar +FBaseCVar *FindCVar (const char *var_name, FBaseCVar **prev); +FBaseCVar *FindCVarSub (const char *var_name, int namelen); + +// Called from G_InitNew() +void UnlatchCVars (void); + +// archive cvars to FILE f +void C_ArchiveCVars (FConfigFile *f, int type); + +// initialize cvars to default values after they are created +void C_SetCVarsToDefaults (void); + +void FilterCompactCVars (TArray &cvars, DWORD filter); + +void C_DeinitConsole(); + class FBoolCVar : public FBaseCVar { public: diff --git a/src/r_main.h b/src/r_main.h index 75df83685..24a0cdba7 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -246,6 +246,14 @@ private: static FActiveInterpolation *curiposhash[INTERPOLATION_BUCKETS]; }; +void updateinterpolations(); +void setinterpolation(EInterpType, void *interptr); +void stopinterpolation(EInterpType, void *interptr); +void dointerpolations(fixed_t smoothratio); +void restoreinterpolations(); +void clearinterpolations(); +void SerializeInterpolations(FArchive &arc); + extern void R_FreePastViewers (); extern int stacked_extralight; diff --git a/src/x64inlines.h b/src/x64inlines.h new file mode 100644 index 000000000..3f5ab9e89 --- /dev/null +++ b/src/x64inlines.h @@ -0,0 +1,198 @@ +#if _MSC_VER +#pragma once +#endif + +__forceinline SDWORD Scale (SDWORD a, SDWORD b, SDWORD c) +{ + return (SDWORD)(((SQWORD)a*b)/c); +} + +__forceinline SDWORD MulScale (SDWORD a, SDWORD b, SDWORD c) +{ + return (SDWORD)(((SQWORD)a*b)>>c); +} + +__forceinline SDWORD MulScale1 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 1); } +__forceinline SDWORD MulScale2 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 2); } +__forceinline SDWORD MulScale3 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 3); } +__forceinline SDWORD MulScale4 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 4); } +__forceinline SDWORD MulScale5 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 5); } +__forceinline SDWORD MulScale6 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 6); } +__forceinline SDWORD MulScale7 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 7); } +__forceinline SDWORD MulScale8 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 8); } +__forceinline SDWORD MulScale9 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 9); } +__forceinline SDWORD MulScale10 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 10); } +__forceinline SDWORD MulScale11 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 11); } +__forceinline SDWORD MulScale12 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 12); } +__forceinline SDWORD MulScale13 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 13); } +__forceinline SDWORD MulScale14 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 14); } +__forceinline SDWORD MulScale15 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 15); } +__forceinline SDWORD MulScale16 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 16); } +__forceinline SDWORD MulScale17 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 17); } +__forceinline SDWORD MulScale18 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 18); } +__forceinline SDWORD MulScale19 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 19); } +__forceinline SDWORD MulScale20 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 20); } +__forceinline SDWORD MulScale21 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 21); } +__forceinline SDWORD MulScale22 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 22); } +__forceinline SDWORD MulScale23 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 23); } +__forceinline SDWORD MulScale24 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 24); } +__forceinline SDWORD MulScale25 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 25); } +__forceinline SDWORD MulScale26 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 26); } +__forceinline SDWORD MulScale27 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 27); } +__forceinline SDWORD MulScale28 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 28); } +__forceinline SDWORD MulScale29 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 29); } +__forceinline SDWORD MulScale30 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 30); } +__forceinline SDWORD MulScale31 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 31); } +__forceinline SDWORD MulScale32 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 32); } + +__forceinline SDWORD DMulScale (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD s) +{ + return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> s); +} + +__forceinline SDWORD DMulScale1 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 1); } +__forceinline SDWORD DMulScale2 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 2); } +__forceinline SDWORD DMulScale3 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 3); } +__forceinline SDWORD DMulScale4 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 4); } +__forceinline SDWORD DMulScale5 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 5); } +__forceinline SDWORD DMulScale6 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 6); } +__forceinline SDWORD DMulScale7 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 7); } +__forceinline SDWORD DMulScale8 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 8); } +__forceinline SDWORD DMulScale9 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 9); } +__forceinline SDWORD DMulScale10 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 10); } +__forceinline SDWORD DMulScale11 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 11); } +__forceinline SDWORD DMulScale12 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 12); } +__forceinline SDWORD DMulScale13 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 13); } +__forceinline SDWORD DMulScale14 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 14); } +__forceinline SDWORD DMulScale15 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 15); } +__forceinline SDWORD DMulScale16 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 16); } +__forceinline SDWORD DMulScale17 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 17); } +__forceinline SDWORD DMulScale18 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 18); } +__forceinline SDWORD DMulScale19 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 19); } +__forceinline SDWORD DMulScale20 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 20); } +__forceinline SDWORD DMulScale21 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 21); } +__forceinline SDWORD DMulScale22 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 22); } +__forceinline SDWORD DMulScale23 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 23); } +__forceinline SDWORD DMulScale24 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 24); } +__forceinline SDWORD DMulScale25 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 25); } +__forceinline SDWORD DMulScale26 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 26); } +__forceinline SDWORD DMulScale27 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 27); } +__forceinline SDWORD DMulScale28 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 28); } +__forceinline SDWORD DMulScale29 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 29); } +__forceinline SDWORD DMulScale30 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 30); } +__forceinline SDWORD DMulScale31 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 31); } +__forceinline SDWORD DMulScale32 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 32); } + +__forceinline SDWORD TMulScale1 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 1); } +__forceinline SDWORD TMulScale2 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 2); } +__forceinline SDWORD TMulScale3 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 3); } +__forceinline SDWORD TMulScale4 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 4); } +__forceinline SDWORD TMulScale5 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 5); } +__forceinline SDWORD TMulScale6 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 6); } +__forceinline SDWORD TMulScale7 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 7); } +__forceinline SDWORD TMulScale8 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 8); } +__forceinline SDWORD TMulScale9 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 9); } +__forceinline SDWORD TMulScale10 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 10); } +__forceinline SDWORD TMulScale11 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 11); } +__forceinline SDWORD TMulScale12 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 12); } +__forceinline SDWORD TMulScale13 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 13); } +__forceinline SDWORD TMulScale14 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 14); } +__forceinline SDWORD TMulScale15 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 15); } +__forceinline SDWORD TMulScale16 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 16); } +__forceinline SDWORD TMulScale17 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 17); } +__forceinline SDWORD TMulScale18 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 18); } +__forceinline SDWORD TMulScale19 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 19); } +__forceinline SDWORD TMulScale20 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 20); } +__forceinline SDWORD TMulScale21 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 21); } +__forceinline SDWORD TMulScale22 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 22); } +__forceinline SDWORD TMulScale23 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 23); } +__forceinline SDWORD TMulScale24 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 24); } +__forceinline SDWORD TMulScale25 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 25); } +__forceinline SDWORD TMulScale26 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 26); } +__forceinline SDWORD TMulScale27 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 27); } +__forceinline SDWORD TMulScale28 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 28); } +__forceinline SDWORD TMulScale29 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 29); } +__forceinline SDWORD TMulScale30 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 30); } +__forceinline SDWORD TMulScale31 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 31); } +__forceinline SDWORD TMulScale32 (SDWORD a, SDWORD b, SDWORD c, SDWORD d, SDWORD e, SDWORD f) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d + (SQWORD)e*f) >> 32); } + +__forceinline SDWORD BoundMulScale (SDWORD a, SDWORD b, SDWORD c) +{ + SQWORD x = ((SQWORD)a * b) >> c; + return x > 0x7FFFFFFFll ? 0x7FFFFFFF : + x < -0x80000000ll ? 0x80000000 : + (SDWORD)x; +} + +inline SDWORD DivScale (SDWORD a, SDWORD b, SDWORD c) +{ + return (SDWORD)(((SQWORD)a << c) / b); +} + +inline SDWORD DivScale1 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 1) / b); } +inline SDWORD DivScale2 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 2) / b); } +inline SDWORD DivScale3 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 3) / b); } +inline SDWORD DivScale4 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 4) / b); } +inline SDWORD DivScale5 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 5) / b); } +inline SDWORD DivScale6 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 6) / b); } +inline SDWORD DivScale7 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 7) / b); } +inline SDWORD DivScale8 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 8) / b); } +inline SDWORD DivScale9 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 9) / b); } +inline SDWORD DivScale10 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 10) / b); } +inline SDWORD DivScale11 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 11) / b); } +inline SDWORD DivScale12 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 12) / b); } +inline SDWORD DivScale13 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 13) / b); } +inline SDWORD DivScale14 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 14) / b); } +inline SDWORD DivScale15 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 15) / b); } +inline SDWORD DivScale16 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 16) / b); } +inline SDWORD DivScale17 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 17) / b); } +inline SDWORD DivScale18 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 18) / b); } +inline SDWORD DivScale19 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 19) / b); } +inline SDWORD DivScale20 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 20) / b); } +inline SDWORD DivScale21 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 21) / b); } +inline SDWORD DivScale22 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 22) / b); } +inline SDWORD DivScale23 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 23) / b); } +inline SDWORD DivScale24 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 24) / b); } +inline SDWORD DivScale25 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 25) / b); } +inline SDWORD DivScale26 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 26) / b); } +inline SDWORD DivScale27 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 27) / b); } +inline SDWORD DivScale28 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 28) / b); } +inline SDWORD DivScale29 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 29) / b); } +inline SDWORD DivScale30 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 30) / b); } +inline SDWORD DivScale31 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 31) / b); } +inline SDWORD DivScale32 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 32) / b); } + +__forceinline void clearbuf (void *buff, unsigned int count, SDWORD clear) +{ + SDWORD *b2 = (SDWORD *)buff; + for (unsigned int i = 0; i != count; ++i) + { + b2[i] = clear; + } +} + +__forceinline void clearbufshort (void *buff, unsigned int count, WORD clear) +{ + SWORD *b2 = (SWORD *)buff; + for (unsigned int i = 0; i != count; ++i) + { + b2[i] = clear; + } +} + +__forceinline SDWORD ksgn (SDWORD a) +{ + if (a < 0) return -1; + else if (a > 0) return 1; + else return 0; +} + +__forceinline int toint (float v) +{ + return int(v); +} + +__forceinline int quickertoint (float v) +{ + return int(v); +} diff --git a/tools/dehsupp/Makefile b/tools/dehsupp/Makefile index d7bd68cb9..cd4b2ed96 100644 --- a/tools/dehsupp/Makefile +++ b/tools/dehsupp/Makefile @@ -10,10 +10,12 @@ endif CC = gcc -BISON = bison -BISONFLAGS = +RE2C = ../re2c/re2c +LEMON = ../lemon/lemon +LEMONFLAGS = +RE2CFLAGS = -s -OBJS = parse.tab.o +OBJS = dehsupp.o parse.o scanner.o all: $(EXE) @@ -31,8 +33,14 @@ else rm -f *.o endif -parse.tab.o: parse.tab.c +%.o: %.c $(CCDV) $(CC) $(CFLAGS) -c -o $@ $< + +parse.h parse.c: parse.y + $(CCDV) $(LEMON) $(LEMONFLAGS) $< +scanner.c: scanner.re + $(CCDV) $(RE2C) $(RE2CFLAGS) -o $@ $< + parse.tab.c: parse.y $(CCDV) $(BISON) $(BISONFLAGS) -o $@ $< diff --git a/tools/dehsupp/dehsupp.c b/tools/dehsupp/dehsupp.c new file mode 100644 index 000000000..86595acfa --- /dev/null +++ b/tools/dehsupp/dehsupp.c @@ -0,0 +1,568 @@ +#include +#include +#include +#include +#include +#include +#include "dehsupp.h" + +FILE *Source, *Dest; +int SourceLine; +int ErrorCount; + +struct StringList *NameList, **NameListLast = &NameList; +int NameCount; + +name *ActionsList; +unsigned char *HeightsArray; +unsigned char *ActionMap; +unsigned short *CodePMap; +char *SpriteNames; +struct StateMapE *StateMaps; +name *SoundMaps; +name *InfoNamesArray; +struct ThingBitsE *ThingBitsMap; +struct RenderStylesE *RenderStylesMap; + +int ActionsListSize, MaxActionsListSize; +int HeightsSize, MaxHeightsSize; +int ActionMapSize, MaxActionMapSize; +int CodePMapSize, MaxCodePMapSize; +int SpriteNamesSize, MaxSpriteNamesSize; +int StateMapsSize, MaxStateMapsSize; +int SoundMapsSize, MaxSoundMapsSize; +int InfoNamesSize, MaxInfoNamesSize; +int ThingBitsMapSize, MaxThingBitsMapSize; +int RenderStylesSize, MaxRenderStylesSize; + +int main (int argc, char **argv) +{ + if (argc != 3) + { + printf ("Usage: dehsupp \n"); + return -1; + } + Source = fopen (argv[1], "r"); + if (Source == NULL) + { + printf ("Could not open %s\n", argv[1]); + return -2; + } + SourceLine = 1; + yyparse (); + fclose (Source); + if (ErrorCount) + { + printf ("There were %d errors\n", ErrorCount); + return -3; + } + SortNames (); + Dest = fopen (argv[2], "wb"); + if (Dest == NULL) + { + printf ("Could not open %s\n", argv[2]); + return -4; + } + WriteNameTable (); + WriteActions (); + WriteCodePConv (); + WriteSprites (); + WriteSounds (); + WriteInfoNames (); + WriteStates (); + WriteActionMap (); + WriteThingBits (); + WriteRenderStyles (); + WriteHeights (); + WriteLabel ("END "); + fclose (Dest); + return 0; +} + +void fail (int code, char *err) +{ + fclose (Dest); + printf ("%s\n", err); + exit (code); +} + +void *ParseAlloc(void *(*mallocProc)(size_t)); +void Parse(void *yyp, int yymajor, struct Token yyminor); +void ParseFree(void *p, void (*freeProc)(void*)); + +void yyparse (void) +{ + Scanner scanner = { Source }; + void *pParser = ParseAlloc (malloc); + struct Token token; + int tokentype; + + while ((tokentype = lex(&scanner, &token)) != EOI) + { + SourceLine = scanner.line; + Parse (pParser, tokentype, token); + } + memset (&token, 0, sizeof(token)); + Parse (pParser, 0, token); + ParseFree (pParser, free); +} + +name FindName (char *name) +{ + struct StringList *probe = NameList; + int count = 0; + + while (probe != NULL) + { + if (stricmp (probe->String, name) == 0) + { + return count; + } + count++; + probe = probe->Next; + } + return -1; +} + +name AddName (char *name) +{ + struct StringList *newone; + int index = FindName (name); + + if (index != -1) + return index; + + newone = malloc (sizeof(*newone) + strlen(name)); + strcpy (newone->String, name); + newone->Next = NULL; + *NameListLast = newone; + NameListLast = &newone->Next; + return NameCount++; +} + +int FindAction (char *namei) +{ + int name = FindName (namei); + + if (name != -1) + { + int i; + + for (i = 0; i < ActionsListSize; i++) + { + if (ActionsList[i] == name) + return i; + } + } + printf ("Line %d: Unknown action %s\n", SourceLine, namei); + ErrorCount++; + return -1; +} + +void AddAction (char *name) +{ + int newname = AddName (name); + if (ActionsListSize == MaxActionsListSize) + { + MaxActionsListSize = MaxActionsListSize ? MaxActionsListSize * 2 : 256; + ActionsList = realloc (ActionsList, MaxActionsListSize*sizeof(*ActionsList)); + } + ActionsList[ActionsListSize++] = newname; +} + +void AddHeight (int h) +{ + if (MaxHeightsSize == HeightsSize) + { + MaxHeightsSize = MaxHeightsSize ? MaxHeightsSize * 2 : 256; + HeightsArray = realloc (HeightsArray, MaxHeightsSize); + } + HeightsArray[HeightsSize++] = h; +} + +void AddActionMap (char *name) +{ + int index = FindAction (name); + + if (index != -1) + { + if (ActionMapSize == MaxActionMapSize) + { + MaxActionMapSize = MaxActionMapSize ? MaxActionMapSize * 2 : 256; + ActionMap = realloc (ActionMap, MaxActionMapSize*sizeof(*ActionMap)); + } + ActionMap[ActionMapSize++] = index; + } +} + +void AddCodeP (int codep) +{ + if (CodePMapSize == MaxCodePMapSize) + { + MaxCodePMapSize = MaxCodePMapSize ? MaxCodePMapSize * 2 : 256; + CodePMap = realloc (CodePMap, MaxCodePMapSize*sizeof(*CodePMap)); + } + CodePMap[CodePMapSize++] = codep; +} + +void AddSpriteName (char *name) +{ + if (strlen (name) != 4) + { + printf ("Line %d: Sprite name %s must be 4 characters\n", SourceLine, name); + ErrorCount++; + return; + } + if (SpriteNamesSize == MaxSpriteNamesSize) + { + MaxSpriteNamesSize = MaxSpriteNamesSize ? MaxSpriteNamesSize * 2 : 256*4; + SpriteNames = realloc (SpriteNames, MaxSpriteNamesSize*sizeof(*SpriteNames)); + } + SpriteNames[SpriteNamesSize+0] = toupper (name[0]); + SpriteNames[SpriteNamesSize+1] = toupper (name[1]); + SpriteNames[SpriteNamesSize+2] = toupper (name[2]); + SpriteNames[SpriteNamesSize+3] = toupper (name[3]); + SpriteNamesSize += 4; +} + +void AddSoundMap (char *name) +{ + if (SoundMapsSize == MaxSoundMapsSize) + { + MaxSoundMapsSize = MaxSoundMapsSize ? MaxSoundMapsSize * 2 : 256; + SoundMaps = realloc (SoundMaps, MaxSoundMapsSize*sizeof(*SoundMaps)); + } + SoundMaps[SoundMapsSize++] = AddName (name); +} + +void AddInfoName (char *name) +{ + if (InfoNamesSize == MaxInfoNamesSize) + { + MaxInfoNamesSize = MaxInfoNamesSize ? MaxInfoNamesSize * 2 : 256; + InfoNamesArray = realloc (InfoNamesArray, MaxInfoNamesSize*sizeof(*InfoNamesArray)); + } + InfoNamesArray[InfoNamesSize++] = AddName (name); +} + +void AddStateMap (char *name, int state, int count) +{ + if (count == 0) + { + printf ("Line %d: Count is 0. Is this right?\n", SourceLine); + return; + } + if ((unsigned)count > 255) + { + printf ("Line %d: Count must be in the range 1-255\n", SourceLine); + ErrorCount++; + } + if (StateMapsSize == MaxStateMapsSize) + { + MaxStateMapsSize = MaxStateMapsSize ? MaxStateMapsSize*2 : 256; + StateMaps = realloc (StateMaps, MaxStateMapsSize*sizeof(*StateMaps)); + } + StateMaps[StateMapsSize].Name = AddName (name); + StateMaps[StateMapsSize].State = state; + StateMaps[StateMapsSize].Count = count; + StateMapsSize++; +} + +void AddThingBits (char *name, int bitnum, int flagnum) +{ + if ((unsigned)bitnum > 31) + { + printf ("Line %d: Bit %d must be in the range 0-31\n", SourceLine, bitnum); + ErrorCount++; + return; + } + if (MaxThingBitsMapSize == ThingBitsMapSize) + { + MaxThingBitsMapSize = MaxThingBitsMapSize ? MaxThingBitsMapSize*2 : 128; + ThingBitsMap = realloc (ThingBitsMap, MaxThingBitsMapSize*sizeof(*ThingBitsMap)); + } + ThingBitsMap[ThingBitsMapSize].Name = AddName (name); + ThingBitsMap[ThingBitsMapSize].BitNum = bitnum; + ThingBitsMap[ThingBitsMapSize].FlagNum = flagnum; + ThingBitsMapSize++; +} + +void AddRenderStyle (char *name, int stylenum) +{ + if ((unsigned)stylenum > 255) + { + printf ("Line %d: %s must be in the range 0-255\n", SourceLine, name); + ErrorCount++; + return; + } + if (MaxRenderStylesSize == RenderStylesSize) + { + MaxRenderStylesSize = MaxRenderStylesSize ? MaxRenderStylesSize*2 : 16; + RenderStylesMap = realloc (RenderStylesMap, MaxRenderStylesSize*sizeof(*RenderStylesMap)); + } + RenderStylesMap[RenderStylesSize].Name = AddName (name); + RenderStylesMap[RenderStylesSize].StyleNum = stylenum; + RenderStylesSize++; +} + +int sortfunc (const void *a, const void *b) +{ + return stricmp (((struct StringSorter *)a)->Entry->String, + ((struct StringSorter *)b)->Entry->String); +} + +void SortNames () +{ + name *remap = malloc (NameCount * sizeof(*remap)); + struct StringSorter *sorter = malloc (NameCount * sizeof(*sorter)); + struct StringList *probe, **prev; + int i; + + for (i = 0, probe = NameList; probe != NULL; probe = probe->Next, i++) + { + sorter[i].OldName = i; + sorter[i].Entry = probe; + } + + // There are some warnings here, though I have no idea why. + qsort (sorter, NameCount, sizeof(*sorter), sortfunc); + + for (i = 0, prev = &NameList; i < NameCount; i++) + { + *prev = sorter[i].Entry; + prev = &sorter[i].Entry->Next; + } + *prev = NULL; + + for (i = 0; i < NameCount; i++) + { + remap[sorter[i].OldName] = i; + } + + for (i = 0; i < ActionsListSize; i++) + { + ActionsList[i] = remap[ActionsList[i]]; + } + for (i = 0; i < SoundMapsSize; i++) + { + SoundMaps[i] = remap[SoundMaps[i]]; + } + for (i = 0; i < InfoNamesSize; i++) + { + InfoNamesArray[i] = remap[InfoNamesArray[i]]; + } + for (i = 0; i < StateMapsSize; i++) + { + StateMaps[i].Name = remap[StateMaps[i].Name]; + } + for (i = 0; i < ThingBitsMapSize; i++) + { + ThingBitsMap[i].Name = remap[ThingBitsMap[i].Name]; + } + for (i = 0; i < RenderStylesSize; i++) + { + RenderStylesMap[i].Name = remap[RenderStylesMap[i].Name]; + } +} + +int yyerror (char *s) +{ + printf ("Line %d: %s\n", SourceLine, s); + ErrorCount++; + return 0; +} + +void WriteWord (int word) +{ + putc (word >> 8, Dest); + putc (word & 255, Dest); +} + +void WriteLabel (char *label) +{ + fwrite (label, 1, 4, Dest); +} + +void WriteWords (int count, short *array) +{ + int i; + + WriteWord (count); + for (i = 0; i < count; i++) + { + WriteWord (array[i]); + } +} + +void WriteBytes (int count, unsigned char *array) +{ + WriteWord (count); + fwrite (array, 1, count, Dest); +} + +void WriteNameTable () +{ + struct StringList *probe; + int i, size; + + WriteLabel ("NAME"); + // Count the length of each string, including nulls + for (probe = NameList, size = 0; probe != NULL; probe = probe->Next) + { + size += (int)strlen (probe->String) + 1; + } + + if (size == 0) + { + WriteWord (2); // Size of this lump + WriteWord (0); // Number of names + return; + } + size += NameCount*2 + 2; + if (size >= 65536) + { + fail (-5, "Name table is larger than 64K"); + } + WriteWord (size); // Size of this lump + WriteWord (NameCount); // Number of names + + // Write each name's offset from the first name, which is stored + // immediately after this list + for (i = size = 0, probe = NameList; i < NameCount; i++, probe = probe->Next) + { + WriteWord (size); + size += (int)strlen (probe->String) + 1; + } + + // Write each name's string in order now + for (probe = NameList; probe != NULL; probe = probe->Next) + { + fputs (probe->String, Dest); + putc (0, Dest); + } +} + +typedef struct +{ + name Name; + short Num; +} NameNum; + +int sortfunc2 (const void *a, const void *b) +{ + return ((NameNum *)a)->Name - ((NameNum *)b)->Name; +} + +void WriteActions () +{ + NameNum *sorter = malloc (ActionsListSize * sizeof(*sorter)); + int i; + + WriteLabel ("ACTF"); + WriteWord (ActionsListSize); + + for (i = 0; i < ActionsListSize; i++) + { + sorter[i].Name = ActionsList[i]; + sorter[i].Num = i; + } + // warnings here. ignore. + qsort (sorter, ActionsListSize, sizeof(*sorter), sortfunc2); + for (i = 0; i < ActionsListSize; i++) + { + WriteWord (sorter[i].Name); + WriteWord (sorter[i].Num); + } + free (sorter); +} + +void WriteActionMap () +{ + WriteLabel ("ACTM"); + WriteBytes (ActionMapSize, ActionMap); +} + +void WriteHeights () +{ + WriteLabel ("HIGH"); + WriteBytes (HeightsSize, HeightsArray); +} + +void WriteCodePConv () +{ + WriteLabel ("CODP"); + WriteWords (CodePMapSize, (short *)CodePMap); +} + +void WriteSprites () +{ + WriteLabel ("SPRN"); + WriteWord (SpriteNamesSize / 4); + fwrite (SpriteNames, SpriteNamesSize, 1, Dest); +} + +void WriteStates () +{ + int i; + + WriteLabel ("STAT"); + WriteWord (StateMapsSize); + for (i = 0; i < StateMapsSize; i++) + { + WriteWord (StateMaps[i].Name); + putc (StateMaps[i].State, Dest); + putc (StateMaps[i].Count, Dest); + } +} + +void WriteSounds () +{ + WriteLabel ("SND "); + WriteWords (SoundMapsSize, SoundMaps); +} + +void WriteInfoNames () +{ + WriteLabel ("INFN"); + WriteWords (InfoNamesSize, InfoNamesArray); +} + +int sortfunc3 (const void *a, const void *b) +{ + return ((struct ThingBitsE *)a)->Name - ((struct ThingBitsE *)b)->Name; +} + +void WriteThingBits () +{ + int i; + + WriteLabel ("TBIT"); + WriteWord (ThingBitsMapSize); + // warnings here; ignore them + qsort (ThingBitsMap, ThingBitsMapSize, sizeof(*ThingBitsMap), sortfunc3); + for (i = 0; i < ThingBitsMapSize; i++) + { + WriteWord (ThingBitsMap[i].Name); + putc (ThingBitsMap[i].BitNum | (ThingBitsMap[i].FlagNum<<5), Dest); + } +} + +int sortfunc4 (const void *a, const void *b) +{ + return ((struct RenderStylesE *)a)->Name - ((struct RenderStylesE *)b)->Name; +} + +void WriteRenderStyles () +{ + int i; + + WriteLabel ("REND"); + WriteWord (RenderStylesSize); + // More warnings; ignore + qsort (RenderStylesMap, RenderStylesSize, sizeof(*RenderStylesMap), sortfunc4); + for (i = 0; i < RenderStylesSize; i++) + { + WriteWord (RenderStylesMap[i].Name); + putc (RenderStylesMap[i].StyleNum, Dest); + } +} diff --git a/tools/dehsupp/dehsupp.h b/tools/dehsupp/dehsupp.h new file mode 100644 index 000000000..e40043c4a --- /dev/null +++ b/tools/dehsupp/dehsupp.h @@ -0,0 +1,124 @@ +#include +#include "parse.h" + +typedef enum { false, true } bool; +typedef short name; +typedef unsigned char uchar; +typedef unsigned int uint; + +typedef struct Scanner { + FILE *fd; + uchar *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof; + uint line; +} Scanner; + +struct Token +{ + int val; + char *string; +}; + +int lex(Scanner *s, struct Token *tok); + +int yyerror (char *s); +void yyparse (void); + +extern FILE *Source, *Dest; +extern int SourceLine; +extern int ErrorCount; + + +void WriteWord (int word); +void WriteLabel (char *label); +void WriteWords (int count, short *array); +void WriteBytes (int count, unsigned char *array); + +void WriteNameTable (); + +void WriteActions (); +void WriteActionMap (); +void WriteHeights (); +void WriteCodePConv (); +void WriteSprites (); +void WriteStates (); +void WriteSounds (); +void WriteInfoNames (); +void WriteThingBits (); +void WriteRenderStyles (); + + +struct StringList +{ + struct StringList *Next; + char String[1]; +}; + +struct StringSorter +{ + name OldName; + struct StringList *Entry; +}; + +extern struct StringList *NameList, **NameListLast; +extern int NameCount; + +name AddName (char *name); +name FindName (char *name); + +void SortNames (); + +struct StateMapE +{ + name Name; + unsigned char State; + unsigned char Count; +}; + +struct ThingBitsE +{ + name Name; + unsigned char BitNum; + unsigned char FlagNum; +}; + +struct RenderStylesE +{ + name Name; + unsigned char StyleNum; +}; + +void AddAction (char *name); +int FindAction (char *name); + +extern name *ActionsList; +extern unsigned char *HeightsArray; +extern unsigned char *ActionMap; +extern unsigned short *CodePMap; +extern char *SpriteNames; +extern struct StateMapE *StateMaps; +extern name *SoundMaps; +extern name *InfoNamesArray; +extern struct ThingBitsE *ThingBitsMap; +extern struct RenderStylesE *RenderStylesMap; + +extern int ActionsListSize, MaxActionsListSize; +extern int HeightsSize, MaxHeightsSize; +extern int ActionMapSize, MaxActionMapSize; +extern int CodePMapSize, MaxCodePMapSize; +extern int SpriteNamesSize, MaxSpriteNamesSize; +extern int StateMapsSize, MaxStateMapsSize; +extern int SoundMapsSize, MaxSoundMapsSize; +extern int InfoNamesSize, MaxInfoNamesSize; +extern int ThingBitsMapSize, MaxThingBitsMapSize; +extern int RenderStylesSize, MaxRenderStylesSize; + +void AddHeight (int h); +void AddActionMap (char *name); +void AddCodeP (int codep); +void AddSpriteName (char *name); +void AddStateMap (char *name, int type, int count); +void AddSoundMap (char *sound); +void AddInfoName (char *sound); +void AddThingBits (char *name, int bitnum, int flagnum); +void AddRenderStyle (char *name, int stylenum); + diff --git a/tools/dehsupp/dehsupp.vcproj b/tools/dehsupp/dehsupp.vcproj index f1363bb90..83c807341 100644 --- a/tools/dehsupp/dehsupp.vcproj +++ b/tools/dehsupp/dehsupp.vcproj @@ -47,7 +47,7 @@ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;__STDC__=0" MinimalRebuild="true" BasicRuntimeChecks="3" - RuntimeLibrary="1" + RuntimeLibrary="3" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="true" @@ -98,84 +98,6 @@ CommandLine="copy "$(TargetPath)" "$(ProjectDir)\$(TargetFileName)"" /> - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + @@ -385,8 +375,9 @@ > + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/dehsupp/parse.c b/tools/dehsupp/parse.c new file mode 100644 index 000000000..c90f59dad --- /dev/null +++ b/tools/dehsupp/parse.c @@ -0,0 +1,1258 @@ +/* Driver template for the LEMON parser generator. +** The author disclaims copyright to this source code. +*/ +/* First off, code is include which follows the "include" declaration +** in the input file. */ +#include +#ifndef NDEBUG +#include +#endif +#line 1 "parse.y" + +#include +#include "dehsupp.h" +#line 16 "parse.c" +#include "parse.h" +/* Next is all token values, in a form suitable for use by makeheaders. +** This section will be null unless lemon is run with the -m switch. +*/ +/* +** These constants (all generated automatically by the parser generator) +** specify the various kinds of tokens (terminals) that the parser +** understands. +** +** Each symbol here is a terminal symbol in the grammar. +*/ +#if INTERFACE +#define OR 1 +#define XOR 2 +#define AND 3 +#define MINUS 4 +#define PLUS 5 +#define MULTIPLY 6 +#define DIVIDE 7 +#define NEG 8 +#define EOI 9 +#define PRINT 10 +#define LPAREN 11 +#define RPAREN 12 +#define COMMA 13 +#define STRING 14 +#define ENDL 15 +#define NUM 16 +#define Actions 17 +#define LBRACE 18 +#define RBRACE 19 +#define SEMICOLON 20 +#define SYM 21 +#define OrgHeights 22 +#define ActionList 23 +#define RBARCE 24 +#define CodePConv 25 +#define OrgSprNames 26 +#define StateMap 27 +#define FirstState 28 +#define SpawnState 29 +#define DeathState 30 +#define SoundMap 31 +#define InfoNames 32 +#define ThingBits 33 +#define RenderStyles 34 +#endif +/* Make sure the INTERFACE macro is defined. +*/ +#ifndef INTERFACE +# define INTERFACE 1 +#endif +/* The next thing included is series of defines which control +** various aspects of the generated parser. +** YYCODETYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 terminals +** and nonterminals. "int" is used otherwise. +** YYNOCODE is a number of type YYCODETYPE which corresponds +** to no legal terminal or nonterminal number. This +** number is used to fill in empty slots of the hash +** table. +** YYFALLBACK If defined, this indicates that one or more tokens +** have fall-back values which should be used if the +** original value of the token will not parse. +** YYACTIONTYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 rules and +** states combined. "int" is used otherwise. +** ParseTOKENTYPE is the data type used for minor tokens given +** directly to the parser from the tokenizer. +** YYMINORTYPE is the data type used for all minor tokens. +** This is typically a union of many types, one of +** which is ParseTOKENTYPE. The entry in the union +** for base tokens is called "yy0". +** YYSTACKDEPTH is the maximum depth of the parser's stack. +** ParseARG_SDECL A static variable declaration for the %extra_argument +** ParseARG_PDECL A parameter declaration for the %extra_argument +** ParseARG_STORE Code to store %extra_argument into yypParser +** ParseARG_FETCH Code to extract %extra_argument from yypParser +** YYNSTATE the combined number of states. +** YYNRULE the number of rules in the grammar +** YYERRORSYMBOL is the code number of the error symbol. If not +** defined, then do no error processing. +*/ +#define YYCODETYPE unsigned char +#define YYNOCODE 68 +#define YYACTIONTYPE unsigned char +#if INTERFACE +#define ParseTOKENTYPE struct Token +#endif +typedef union { + ParseTOKENTYPE yy0; + int yy62; + int yy135; +} YYMINORTYPE; +#define YYSTACKDEPTH 100 +#if INTERFACE +#define ParseARG_SDECL +#define ParseARG_PDECL +#define ParseARG_FETCH +#define ParseARG_STORE +#endif +#define YYNSTATE 140 +#define YYNRULE 77 +#define YYERRORSYMBOL 35 +#define YYERRSYMDT yy135 +#define YY_NO_ACTION (YYNSTATE+YYNRULE+2) +#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) +#define YY_ERROR_ACTION (YYNSTATE+YYNRULE) + +/* Next are that tables used to determine what action to take based on the +** current state and lookahead token. These tables are used to implement +** functions that take a state number and lookahead value and return an +** action integer. +** +** Suppose the action integer is N. Then the action is determined as +** follows +** +** 0 <= N < YYNSTATE Shift N. That is, push the lookahead +** token onto the stack and goto state N. +** +** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. +** +** N == YYNSTATE+YYNRULE A syntax error has occurred. +** +** N == YYNSTATE+YYNRULE+1 The parser accepts its input. +** +** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused +** slots in the yy_action[] table. +** +** The action table is constructed as a single large table named yy_action[]. +** Given state S and lookahead X, the action is computed as +** +** yy_action[ yy_shift_ofst[S] + X ] +** +** If the index value yy_shift_ofst[S]+X is out of range or if the value +** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] +** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table +** and that yy_default[S] should be used instead. +** +** The formula above is for computing the action when the lookahead is +** a terminal symbol. If the lookahead is a non-terminal (as occurs after +** a reduce action) then the yy_reduce_ofst[] array is used in place of +** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of +** YY_SHIFT_USE_DFLT. +** +** The following are the tables generated in this section: +** +** yy_action[] A single table containing all actions. +** yy_lookahead[] A table containing the lookahead for each entry in +** yy_action. Used to detect hash collisions. +** yy_shift_ofst[] For each state, the offset into yy_action for +** shifting terminals. +** yy_reduce_ofst[] For each state, the offset into yy_action for +** shifting non-terminals after a reduce. +** yy_default[] Default action for each state. +*/ +static const YYACTIONTYPE yy_action[] = { + /* 0 */ 137, 131, 130, 126, 120, 119, 118, 117, 109, 101, + /* 10 */ 95, 94, 80, 14, 17, 20, 23, 18, 15, 71, + /* 20 */ 20, 23, 18, 15, 86, 60, 45, 68, 76, 84, + /* 30 */ 93, 77, 36, 74, 66, 57, 73, 16, 14, 17, + /* 40 */ 20, 23, 18, 15, 17, 20, 23, 18, 15, 11, + /* 50 */ 33, 16, 14, 17, 20, 23, 18, 15, 21, 32, + /* 60 */ 82, 50, 128, 61, 72, 16, 14, 17, 20, 23, + /* 70 */ 18, 15, 54, 139, 18, 15, 132, 32, 16, 14, + /* 80 */ 17, 20, 23, 18, 15, 96, 97, 98, 55, 99, + /* 90 */ 78, 138, 16, 14, 17, 20, 23, 18, 15, 19, + /* 100 */ 19, 83, 77, 36, 40, 90, 24, 24, 44, 100, + /* 110 */ 129, 103, 103, 67, 62, 81, 58, 8, 65, 70, + /* 120 */ 69, 79, 59, 64, 22, 33, 38, 9, 52, 63, + /* 130 */ 56, 107, 30, 85, 218, 1, 7, 127, 87, 47, + /* 140 */ 136, 10, 89, 49, 88, 48, 13, 115, 91, 3, + /* 150 */ 46, 121, 133, 2, 92, 28, 12, 29, 34, 53, + /* 160 */ 37, 39, 51, 4, 134, 135, 102, 111, 43, 25, + /* 170 */ 124, 6, 75, 106, 41, 26, 113, 42, 5, 108, + /* 180 */ 35, 31, 125, 146, 105, 110, 104, 146, 123, 116, + /* 190 */ 27, 122, 114, 112, +}; +static const YYCODETYPE yy_lookahead[] = { + /* 0 */ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + /* 10 */ 48, 49, 10, 2, 3, 4, 5, 6, 7, 17, + /* 20 */ 4, 5, 6, 7, 22, 23, 61, 25, 26, 27, + /* 30 */ 50, 51, 52, 31, 32, 33, 34, 1, 2, 3, + /* 40 */ 4, 5, 6, 7, 3, 4, 5, 6, 7, 13, + /* 50 */ 52, 1, 2, 3, 4, 5, 6, 7, 13, 52, + /* 60 */ 21, 63, 64, 13, 19, 1, 2, 3, 4, 5, + /* 70 */ 6, 7, 65, 66, 6, 7, 12, 52, 1, 2, + /* 80 */ 3, 4, 5, 6, 7, 28, 29, 30, 58, 59, + /* 90 */ 13, 66, 1, 2, 3, 4, 5, 6, 7, 4, + /* 100 */ 4, 50, 51, 52, 52, 59, 11, 11, 56, 14, + /* 110 */ 15, 16, 16, 13, 13, 13, 13, 13, 13, 19, + /* 120 */ 19, 19, 19, 19, 13, 52, 52, 13, 54, 24, + /* 130 */ 19, 14, 13, 19, 36, 37, 18, 64, 19, 57, + /* 140 */ 20, 18, 21, 55, 12, 62, 13, 21, 21, 11, + /* 150 */ 53, 21, 21, 13, 20, 18, 13, 18, 52, 52, + /* 160 */ 52, 52, 52, 18, 20, 52, 20, 52, 52, 18, + /* 170 */ 20, 18, 60, 14, 52, 18, 52, 52, 18, 21, + /* 180 */ 52, 52, 20, 67, 21, 20, 20, 67, 21, 20, + /* 190 */ 18, 21, 21, 20, +}; +#define YY_SHIFT_USE_DFLT (-1) +#define YY_SHIFT_MAX 87 +static const short yy_shift_ofst[] = { + /* 0 */ -1, 2, 95, 95, 96, 96, 96, 96, 96, 96, + /* 10 */ 39, 96, 96, 57, 96, 96, 96, 96, 96, 96, + /* 20 */ 96, 96, 96, 96, 96, 130, 126, 163, 121, 117, + /* 30 */ 39, 50, 77, 36, 64, 91, 91, 91, 91, 91, + /* 40 */ 91, 11, 41, 16, 45, 100, 101, 102, 103, 105, + /* 50 */ 104, 68, 111, 68, 114, 119, 169, 160, 171, 173, + /* 60 */ 172, 170, 167, 165, 162, 158, 157, 159, 153, 150, + /* 70 */ 166, 151, 146, 145, 139, 143, 137, 140, 131, 134, + /* 80 */ 138, 127, 133, 132, 123, 120, 118, 144, +}; +#define YY_REDUCE_USE_DFLT (-39) +#define YY_REDUCE_MAX 30 +static const short yy_reduce_ofst[] = { + /* 0 */ 98, -38, -20, 51, 7, -2, 52, 74, 73, 25, + /* 10 */ 30, 129, 128, 112, 125, 124, 122, 116, 115, 113, + /* 20 */ 110, 109, 108, 107, 106, 97, 83, 88, 82, -35, + /* 30 */ 46, +}; +static const YYACTIONTYPE yy_default[] = { + /* 0 */ 141, 140, 155, 155, 213, 208, 184, 176, 217, 217, + /* 10 */ 192, 217, 217, 217, 217, 217, 217, 217, 217, 217, + /* 20 */ 217, 217, 217, 217, 217, 172, 204, 180, 188, 200, + /* 30 */ 217, 217, 217, 217, 217, 195, 159, 178, 177, 186, + /* 40 */ 185, 166, 168, 167, 217, 217, 217, 217, 217, 217, + /* 50 */ 217, 163, 217, 162, 217, 217, 217, 217, 217, 217, + /* 60 */ 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, + /* 70 */ 217, 217, 217, 217, 217, 217, 217, 156, 217, 217, + /* 80 */ 217, 217, 217, 217, 217, 217, 217, 217, 154, 189, + /* 90 */ 194, 190, 187, 157, 153, 152, 196, 197, 198, 193, + /* 100 */ 158, 151, 183, 161, 199, 181, 202, 201, 182, 150, + /* 110 */ 179, 164, 203, 165, 206, 205, 175, 149, 148, 147, + /* 120 */ 146, 173, 211, 174, 171, 207, 145, 210, 209, 160, + /* 130 */ 144, 143, 170, 216, 191, 169, 212, 142, 215, 214, +}; +#define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0])) + +/* The next table maps tokens into fallback tokens. If a construct +** like the following: +** +** %fallback ID X Y Z. +** +** appears in the grammer, then ID becomes a fallback token for X, Y, +** and Z. Whenever one of the tokens X, Y, or Z is input to the parser +** but it does not parse, the type of the token is changed to ID and +** the parse is retried before an error is thrown. +*/ +#ifdef YYFALLBACK +static const YYCODETYPE yyFallback[] = { +}; +#endif /* YYFALLBACK */ + +/* The following structure represents a single element of the +** parser's stack. Information stored includes: +** +** + The state number for the parser at this level of the stack. +** +** + The value of the token stored at this level of the stack. +** (In other words, the "major" token.) +** +** + The semantic value stored at this level of the stack. This is +** the information used by the action routines in the grammar. +** It is sometimes called the "minor" token. +*/ +struct yyStackEntry { + int stateno; /* The state-number */ + int major; /* The major token value. This is the code + ** number for the token at this stack level */ + YYMINORTYPE minor; /* The user-supplied minor token value. This + ** is the value of the token */ +}; +typedef struct yyStackEntry yyStackEntry; + +/* The state of the parser is completely contained in an instance of +** the following structure */ +struct yyParser { + int yyidx; /* Index of top element in stack */ + int yyerrcnt; /* Shifts left before out of the error */ + ParseARG_SDECL /* A place to hold %extra_argument */ + yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ +}; +typedef struct yyParser yyParser; + +#ifndef NDEBUG +#include +static FILE *yyTraceFILE = 0; +static char *yyTracePrompt = 0; +#endif /* NDEBUG */ + +#ifndef NDEBUG +/* +** Turn parser tracing on by giving a stream to which to write the trace +** and a prompt to preface each trace message. Tracing is turned off +** by making either argument NULL +** +** Inputs: +**
    +**
  • A FILE* to which trace output should be written. +** If NULL, then tracing is turned off. +**
  • A prefix string written at the beginning of every +** line of trace output. If NULL, then tracing is +** turned off. +**
+** +** Outputs: +** None. +*/ +void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ + yyTraceFILE = TraceFILE; + yyTracePrompt = zTracePrompt; + if( yyTraceFILE==0 ) yyTracePrompt = 0; + else if( yyTracePrompt==0 ) yyTraceFILE = 0; +} +#endif /* NDEBUG */ + +#ifndef NDEBUG +/* For tracing shifts, the names of all terminals and nonterminals +** are required. The following table supplies these names */ +static const char *const yyTokenName[] = { + "$", "OR", "XOR", "AND", + "MINUS", "PLUS", "MULTIPLY", "DIVIDE", + "NEG", "EOI", "PRINT", "LPAREN", + "RPAREN", "COMMA", "STRING", "ENDL", + "NUM", "Actions", "LBRACE", "RBRACE", + "SEMICOLON", "SYM", "OrgHeights", "ActionList", + "RBARCE", "CodePConv", "OrgSprNames", "StateMap", + "FirstState", "SpawnState", "DeathState", "SoundMap", + "InfoNames", "ThingBits", "RenderStyles", "error", + "main", "translation_unit", "external_declaration", "print_statement", + "actions_def", "org_heights_def", "action_list_def", "codep_conv_def", + "org_spr_names_def", "state_map_def", "sound_map_def", "info_names_def", + "thing_bits_def", "render_styles_def", "print_list", "print_item", + "exp", "actions_list", "org_heights_list", "action_list_list", + "codep_conv_list", "org_spr_names_list", "state_map_list", "state_map_entry", + "state_type", "sound_map_list", "info_names_list", "thing_bits_list", + "thing_bits_entry", "render_styles_list", "render_styles_entry", +}; +#endif /* NDEBUG */ + +#ifndef NDEBUG +/* For tracing reduce actions, the names of all rules are required. +*/ +static const char *const yyRuleName[] = { + /* 0 */ "main ::= translation_unit", + /* 1 */ "translation_unit ::=", + /* 2 */ "translation_unit ::= translation_unit external_declaration", + /* 3 */ "external_declaration ::= print_statement", + /* 4 */ "external_declaration ::= actions_def", + /* 5 */ "external_declaration ::= org_heights_def", + /* 6 */ "external_declaration ::= action_list_def", + /* 7 */ "external_declaration ::= codep_conv_def", + /* 8 */ "external_declaration ::= org_spr_names_def", + /* 9 */ "external_declaration ::= state_map_def", + /* 10 */ "external_declaration ::= sound_map_def", + /* 11 */ "external_declaration ::= info_names_def", + /* 12 */ "external_declaration ::= thing_bits_def", + /* 13 */ "external_declaration ::= render_styles_def", + /* 14 */ "print_statement ::= PRINT LPAREN print_list RPAREN", + /* 15 */ "print_list ::=", + /* 16 */ "print_list ::= print_item", + /* 17 */ "print_list ::= print_item COMMA print_list", + /* 18 */ "print_item ::= STRING", + /* 19 */ "print_item ::= exp", + /* 20 */ "print_item ::= ENDL", + /* 21 */ "exp ::= NUM", + /* 22 */ "exp ::= exp PLUS exp", + /* 23 */ "exp ::= exp MINUS exp", + /* 24 */ "exp ::= exp MULTIPLY exp", + /* 25 */ "exp ::= exp DIVIDE exp", + /* 26 */ "exp ::= exp OR exp", + /* 27 */ "exp ::= exp AND exp", + /* 28 */ "exp ::= exp XOR exp", + /* 29 */ "exp ::= MINUS exp", + /* 30 */ "exp ::= LPAREN exp RPAREN", + /* 31 */ "actions_def ::= Actions LBRACE actions_list RBRACE SEMICOLON", + /* 32 */ "actions_list ::=", + /* 33 */ "actions_list ::= SYM", + /* 34 */ "actions_list ::= actions_list COMMA SYM", + /* 35 */ "org_heights_def ::= OrgHeights LBRACE org_heights_list RBRACE SEMICOLON", + /* 36 */ "org_heights_list ::=", + /* 37 */ "org_heights_list ::= exp", + /* 38 */ "org_heights_list ::= org_heights_list COMMA exp", + /* 39 */ "action_list_def ::= ActionList LBRACE action_list_list RBARCE SEMICOLON", + /* 40 */ "action_list_list ::=", + /* 41 */ "action_list_list ::= SYM", + /* 42 */ "action_list_list ::= action_list_list COMMA SYM", + /* 43 */ "codep_conv_def ::= CodePConv LBRACE codep_conv_list RBRACE SEMICOLON", + /* 44 */ "codep_conv_list ::=", + /* 45 */ "codep_conv_list ::= exp", + /* 46 */ "codep_conv_list ::= codep_conv_list COMMA exp", + /* 47 */ "org_spr_names_def ::= OrgSprNames LBRACE org_spr_names_list RBRACE SEMICOLON", + /* 48 */ "org_spr_names_list ::=", + /* 49 */ "org_spr_names_list ::= SYM", + /* 50 */ "org_spr_names_list ::= org_spr_names_list COMMA SYM", + /* 51 */ "state_map_def ::= StateMap LBRACE state_map_list RBRACE SEMICOLON", + /* 52 */ "state_map_list ::=", + /* 53 */ "state_map_list ::= state_map_entry", + /* 54 */ "state_map_list ::= state_map_list COMMA state_map_entry", + /* 55 */ "state_map_entry ::= SYM COMMA state_type COMMA exp", + /* 56 */ "state_type ::= FirstState", + /* 57 */ "state_type ::= SpawnState", + /* 58 */ "state_type ::= DeathState", + /* 59 */ "sound_map_def ::= SoundMap LBRACE sound_map_list RBRACE SEMICOLON", + /* 60 */ "sound_map_list ::=", + /* 61 */ "sound_map_list ::= STRING", + /* 62 */ "sound_map_list ::= sound_map_list COMMA STRING", + /* 63 */ "info_names_def ::= InfoNames LBRACE info_names_list RBRACE SEMICOLON", + /* 64 */ "info_names_list ::=", + /* 65 */ "info_names_list ::= SYM", + /* 66 */ "info_names_list ::= info_names_list COMMA SYM", + /* 67 */ "thing_bits_def ::= ThingBits LBRACE thing_bits_list RBRACE SEMICOLON", + /* 68 */ "thing_bits_list ::=", + /* 69 */ "thing_bits_list ::= thing_bits_entry", + /* 70 */ "thing_bits_list ::= thing_bits_list COMMA thing_bits_entry", + /* 71 */ "thing_bits_entry ::= exp COMMA exp COMMA SYM", + /* 72 */ "render_styles_def ::= RenderStyles LBRACE render_styles_list RBRACE SEMICOLON", + /* 73 */ "render_styles_list ::=", + /* 74 */ "render_styles_list ::= render_styles_entry", + /* 75 */ "render_styles_list ::= render_styles_list COMMA render_styles_entry", + /* 76 */ "render_styles_entry ::= exp COMMA SYM", +}; +#endif /* NDEBUG */ + +/* +** This function returns the symbolic name associated with a token +** value. +*/ +const char *ParseTokenName(int tokenType){ +#ifndef NDEBUG + if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){ + return yyTokenName[tokenType]; + }else{ + return "Unknown"; + } +#else + return ""; +#endif +} + +/* +** This function allocates a new parser. +** The only argument is a pointer to a function which works like +** malloc. +** +** Inputs: +** A pointer to the function used to allocate memory. +** +** Outputs: +** A pointer to a parser. This pointer is used in subsequent calls +** to Parse and ParseFree. +*/ +void *ParseAlloc(void *(*mallocProc)(size_t)){ + yyParser *pParser; + pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); + if( pParser ){ + pParser->yyidx = -1; + } + return pParser; +} + +/* The following function deletes the value associated with a +** symbol. The symbol can be either a terminal or nonterminal. +** "yymajor" is the symbol code, and "yypminor" is a pointer to +** the value. +*/ +static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ + switch( yymajor ){ + /* Here is inserted the actions which take place when a + ** terminal or non-terminal is destroyed. This can happen + ** when the symbol is popped from the stack during a + ** reduce or during error processing or when a parser is + ** being destroyed before it is finished parsing. + ** + ** Note: during a reduce, the only symbols destroyed are those + ** which appear on the RHS of the rule, but which are not used + ** inside the C code. + */ + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 26: + case 27: + case 28: + case 29: + case 30: + case 31: + case 32: + case 33: + case 34: +#line 8 "parse.y" +{ if ((yypminor->yy0).string) free((yypminor->yy0).string); } +#line 534 "parse.c" + break; + default: break; /* If no destructor action specified: do nothing */ + } +} + +/* +** Pop the parser's stack once. +** +** If there is a destructor routine associated with the token which +** is popped from the stack, then call it. +** +** Return the major token number for the symbol popped. +*/ +static int yy_pop_parser_stack(yyParser *pParser){ + YYCODETYPE yymajor; + yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; + + if( pParser->yyidx<0 ) return 0; +#ifndef NDEBUG + if( yyTraceFILE && pParser->yyidx>=0 ){ + fprintf(yyTraceFILE,"%sPopping %s\n", + yyTracePrompt, + yyTokenName[yytos->major]); + } +#endif + yymajor = yytos->major; + yy_destructor( yymajor, &yytos->minor); + pParser->yyidx--; + return yymajor; +} + +/* +** Deallocate and destroy a parser. Destructors are all called for +** all stack elements before shutting the parser down. +** +** Inputs: +**
    +**
  • A pointer to the parser. This should be a pointer +** obtained from ParseAlloc. +**
  • A pointer to a function used to reclaim memory obtained +** from malloc. +**
+*/ +void ParseFree( + void *p, /* The parser to be deleted */ + void (*freeProc)(void*) /* Function used to reclaim memory */ +){ + yyParser *pParser = (yyParser*)p; + if( pParser==0 ) return; + while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); + (*freeProc)((void*)pParser); +} + +/* +** Find the appropriate action for a parser given the terminal +** look-ahead token iLookAhead. +** +** If the look-ahead token is YYNOCODE, then check to see if the action is +** independent of the look-ahead. If it is, return the action, otherwise +** return YY_NO_ACTION. +*/ +static int yy_find_shift_action( + yyParser *pParser, /* The parser */ + int iLookAhead /* The look-ahead token */ +){ + int i; + int stateno = pParser->yystack[pParser->yyidx].stateno; + + if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){ + return yy_default[stateno]; + } + if( iLookAhead==YYNOCODE ){ + return YY_NO_ACTION; + } + i += iLookAhead; + if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ +#ifdef YYFALLBACK + int iFallback; /* Fallback token */ + if( iLookAhead %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); + } +#endif + return yy_find_shift_action(pParser, iFallback); + } +#endif + return yy_default[stateno]; + }else{ + return yy_action[i]; + } +} + +/* +** Find the appropriate action for a parser given the non-terminal +** look-ahead token iLookAhead. +** +** If the look-ahead token is YYNOCODE, then check to see if the action is +** independent of the look-ahead. If it is, return the action, otherwise +** return YY_NO_ACTION. +*/ +static int yy_find_reduce_action( + int stateno, /* Current state number */ + int iLookAhead /* The look-ahead token */ +){ + int i; + /* int stateno = pParser->yystack[pParser->yyidx].stateno; */ + + if( stateno>YY_REDUCE_MAX || + (i = yy_reduce_ofst[stateno])==YY_REDUCE_USE_DFLT ){ + return yy_default[stateno]; + } + if( iLookAhead==YYNOCODE ){ + return YY_NO_ACTION; + } + i += iLookAhead; + if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ + return yy_default[stateno]; + }else{ + return yy_action[i]; + } +} + +/* +** Perform a shift action. +*/ +static void yy_shift( + yyParser *yypParser, /* The parser to be shifted */ + int yyNewState, /* The new state to shift in */ + int yyMajor, /* The major token to shift in */ + YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */ +){ + yyStackEntry *yytos; + yypParser->yyidx++; + if( yypParser->yyidx>=YYSTACKDEPTH ){ + ParseARG_FETCH; + yypParser->yyidx--; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will execute if the parser + ** stack every overflows */ + ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ + return; + } + yytos = &yypParser->yystack[yypParser->yyidx]; + yytos->stateno = yyNewState; + yytos->major = yyMajor; + yytos->minor = *yypMinor; +#ifndef NDEBUG + if( yyTraceFILE && yypParser->yyidx>0 ){ + int i; + fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); + fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); + for(i=1; i<=yypParser->yyidx; i++) + fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); + fprintf(yyTraceFILE,"\n"); + } +#endif +} + +/* The following table contains information about every rule that +** is used during the reduce. +*/ +static const struct { + YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ + unsigned char nrhs; /* Number of right-hand side symbols in the rule */ +} yyRuleInfo[] = { + { 36, 1 }, + { 37, 0 }, + { 37, 2 }, + { 38, 1 }, + { 38, 1 }, + { 38, 1 }, + { 38, 1 }, + { 38, 1 }, + { 38, 1 }, + { 38, 1 }, + { 38, 1 }, + { 38, 1 }, + { 38, 1 }, + { 38, 1 }, + { 39, 4 }, + { 50, 0 }, + { 50, 1 }, + { 50, 3 }, + { 51, 1 }, + { 51, 1 }, + { 51, 1 }, + { 52, 1 }, + { 52, 3 }, + { 52, 3 }, + { 52, 3 }, + { 52, 3 }, + { 52, 3 }, + { 52, 3 }, + { 52, 3 }, + { 52, 2 }, + { 52, 3 }, + { 40, 5 }, + { 53, 0 }, + { 53, 1 }, + { 53, 3 }, + { 41, 5 }, + { 54, 0 }, + { 54, 1 }, + { 54, 3 }, + { 42, 5 }, + { 55, 0 }, + { 55, 1 }, + { 55, 3 }, + { 43, 5 }, + { 56, 0 }, + { 56, 1 }, + { 56, 3 }, + { 44, 5 }, + { 57, 0 }, + { 57, 1 }, + { 57, 3 }, + { 45, 5 }, + { 58, 0 }, + { 58, 1 }, + { 58, 3 }, + { 59, 5 }, + { 60, 1 }, + { 60, 1 }, + { 60, 1 }, + { 46, 5 }, + { 61, 0 }, + { 61, 1 }, + { 61, 3 }, + { 47, 5 }, + { 62, 0 }, + { 62, 1 }, + { 62, 3 }, + { 48, 5 }, + { 63, 0 }, + { 63, 1 }, + { 63, 3 }, + { 64, 5 }, + { 49, 5 }, + { 65, 0 }, + { 65, 1 }, + { 65, 3 }, + { 66, 3 }, +}; + +static void yy_accept(yyParser*); /* Forward Declaration */ + +/* +** Perform a reduce action and the shift that must immediately +** follow the reduce. +*/ +static void yy_reduce( + yyParser *yypParser, /* The parser */ + int yyruleno /* Number of the rule by which to reduce */ +){ + int yygoto; /* The next state */ + int yyact; /* The next action */ + YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ + yyStackEntry *yymsp; /* The top of the parser's stack */ + int yysize; /* Amount to pop the stack */ + ParseARG_FETCH; + yymsp = &yypParser->yystack[yypParser->yyidx]; +#ifndef NDEBUG + if( yyTraceFILE && yyruleno>=0 + && yyruleno + ** { ... } // User supplied code + ** #line + ** break; + */ + case 14: +#line 37 "parse.y" +{ + printf ("\n"); + yy_destructor(10,&yymsp[-3].minor); + yy_destructor(11,&yymsp[-2].minor); + yy_destructor(12,&yymsp[0].minor); +} +#line 841 "parse.c" + break; + case 18: +#line 45 "parse.y" +{ printf ("%s", yymsp[0].minor.yy0.string); } +#line 846 "parse.c" + break; + case 19: +#line 46 "parse.y" +{ printf ("%d", yymsp[0].minor.yy62); } +#line 851 "parse.c" + break; + case 20: +#line 47 "parse.y" +{ printf ("\n"); yy_destructor(15,&yymsp[0].minor); +} +#line 857 "parse.c" + break; + case 21: +#line 50 "parse.y" +{ yygotominor.yy62 = yymsp[0].minor.yy0.val; } +#line 862 "parse.c" + break; + case 22: +#line 51 "parse.y" +{ yygotominor.yy62 = yymsp[-2].minor.yy62 + yymsp[0].minor.yy62; yy_destructor(5,&yymsp[-1].minor); +} +#line 868 "parse.c" + break; + case 23: +#line 52 "parse.y" +{ yygotominor.yy62 = yymsp[-2].minor.yy62 - yymsp[0].minor.yy62; yy_destructor(4,&yymsp[-1].minor); +} +#line 874 "parse.c" + break; + case 24: +#line 53 "parse.y" +{ yygotominor.yy62 = yymsp[-2].minor.yy62 * yymsp[0].minor.yy62; yy_destructor(6,&yymsp[-1].minor); +} +#line 880 "parse.c" + break; + case 25: +#line 54 "parse.y" +{ yygotominor.yy62 = yymsp[-2].minor.yy62 / yymsp[0].minor.yy62; yy_destructor(7,&yymsp[-1].minor); +} +#line 886 "parse.c" + break; + case 26: +#line 55 "parse.y" +{ yygotominor.yy62 = yymsp[-2].minor.yy62 | yymsp[0].minor.yy62; yy_destructor(1,&yymsp[-1].minor); +} +#line 892 "parse.c" + break; + case 27: +#line 56 "parse.y" +{ yygotominor.yy62 = yymsp[-2].minor.yy62 & yymsp[0].minor.yy62; yy_destructor(3,&yymsp[-1].minor); +} +#line 898 "parse.c" + break; + case 28: +#line 57 "parse.y" +{ yygotominor.yy62 = yymsp[-2].minor.yy62 ^ yymsp[0].minor.yy62; yy_destructor(2,&yymsp[-1].minor); +} +#line 904 "parse.c" + break; + case 29: +#line 58 "parse.y" +{ yygotominor.yy62 = -yymsp[0].minor.yy62; yy_destructor(4,&yymsp[-1].minor); +} +#line 910 "parse.c" + break; + case 30: +#line 59 "parse.y" +{ yygotominor.yy62 = yymsp[-1].minor.yy62; yy_destructor(11,&yymsp[-2].minor); + yy_destructor(12,&yymsp[0].minor); +} +#line 917 "parse.c" + break; + case 33: +#line 65 "parse.y" +{ AddAction (yymsp[0].minor.yy0.string); } +#line 922 "parse.c" + break; + case 34: +#line 66 "parse.y" +{ AddAction (yymsp[0].minor.yy0.string); yy_destructor(13,&yymsp[-1].minor); +} +#line 928 "parse.c" + break; + case 37: +#line 72 "parse.y" +{ AddHeight (yymsp[0].minor.yy62); } +#line 933 "parse.c" + break; + case 38: +#line 73 "parse.y" +{ AddHeight (yymsp[0].minor.yy62); yy_destructor(13,&yymsp[-1].minor); +} +#line 939 "parse.c" + break; + case 41: +#line 79 "parse.y" +{ AddActionMap (yymsp[0].minor.yy0.string); } +#line 944 "parse.c" + break; + case 42: +#line 80 "parse.y" +{ AddActionMap (yymsp[0].minor.yy0.string); yy_destructor(13,&yymsp[-1].minor); +} +#line 950 "parse.c" + break; + case 45: +#line 86 "parse.y" +{ AddCodeP (yymsp[0].minor.yy62); } +#line 955 "parse.c" + break; + case 46: +#line 87 "parse.y" +{ AddCodeP (yymsp[0].minor.yy62); yy_destructor(13,&yymsp[-1].minor); +} +#line 961 "parse.c" + break; + case 49: +#line 93 "parse.y" +{ AddSpriteName (yymsp[0].minor.yy0.string); } +#line 966 "parse.c" + break; + case 50: +#line 94 "parse.y" +{ AddSpriteName (yymsp[0].minor.yy0.string); yy_destructor(13,&yymsp[-1].minor); +} +#line 972 "parse.c" + break; + case 55: +#line 103 "parse.y" +{ AddStateMap (yymsp[-4].minor.yy0.string, yymsp[-2].minor.yy62, yymsp[0].minor.yy62); yy_destructor(13,&yymsp[-3].minor); + yy_destructor(13,&yymsp[-1].minor); +} +#line 979 "parse.c" + break; + case 56: +#line 106 "parse.y" +{ yygotominor.yy62 = 0; yy_destructor(28,&yymsp[0].minor); +} +#line 985 "parse.c" + break; + case 57: +#line 107 "parse.y" +{ yygotominor.yy62 = 1; yy_destructor(29,&yymsp[0].minor); +} +#line 991 "parse.c" + break; + case 58: +#line 108 "parse.y" +{ yygotominor.yy62 = 2; yy_destructor(30,&yymsp[0].minor); +} +#line 997 "parse.c" + break; + case 61: +#line 114 "parse.y" +{ AddSoundMap (yymsp[0].minor.yy0.string); } +#line 1002 "parse.c" + break; + case 62: +#line 115 "parse.y" +{ AddSoundMap (yymsp[0].minor.yy0.string); yy_destructor(13,&yymsp[-1].minor); +} +#line 1008 "parse.c" + break; + case 65: +#line 121 "parse.y" +{ AddInfoName (yymsp[0].minor.yy0.string); } +#line 1013 "parse.c" + break; + case 66: +#line 122 "parse.y" +{ AddInfoName (yymsp[0].minor.yy0.string); yy_destructor(13,&yymsp[-1].minor); +} +#line 1019 "parse.c" + break; + case 71: +#line 131 "parse.y" +{ AddThingBits (yymsp[0].minor.yy0.string, yymsp[-4].minor.yy62, yymsp[-2].minor.yy62); yy_destructor(13,&yymsp[-3].minor); + yy_destructor(13,&yymsp[-1].minor); +} +#line 1026 "parse.c" + break; + case 76: +#line 140 "parse.y" +{ AddRenderStyle (yymsp[0].minor.yy0.string, yymsp[-2].minor.yy62); yy_destructor(13,&yymsp[-1].minor); +} +#line 1032 "parse.c" + break; + }; + yygoto = yyRuleInfo[yyruleno].lhs; + yysize = yyRuleInfo[yyruleno].nrhs; + yypParser->yyidx -= yysize; + yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto); + if( yyact < YYNSTATE ){ +#ifdef NDEBUG + /* If we are not debugging and the reduce action popped at least + ** one element off the stack, then we can push the new element back + ** onto the stack here, and skip the stack overflow test in yy_shift(). + ** That gives a significant speed improvement. */ + if( yysize ){ + yypParser->yyidx++; + yymsp -= yysize-1; + yymsp->stateno = yyact; + yymsp->major = yygoto; + yymsp->minor = yygotominor; + }else +#endif + { + yy_shift(yypParser,yyact,yygoto,&yygotominor); + } + }else if( yyact == YYNSTATE + YYNRULE + 1 ){ + yy_accept(yypParser); + } +} + +/* +** The following code executes when the parse fails +*/ +static void yy_parse_failed( + yyParser *yypParser /* The parser */ +){ + ParseARG_FETCH; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will be executed whenever the + ** parser fails */ + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} + +/* +** The following code executes when a syntax error first occurs. +*/ +static void yy_syntax_error( + yyParser *yypParser, /* The parser */ + int yymajor, /* The major type of the error token */ + YYMINORTYPE yyminor /* The minor type of the error token */ +){ + ParseARG_FETCH; +#define TOKEN (yyminor.yy0) + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} + +/* +** The following is executed when the parser accepts +*/ +static void yy_accept( + yyParser *yypParser /* The parser */ +){ + ParseARG_FETCH; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will be executed whenever the + ** parser accepts */ + ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} + +/* The main parser program. +** The first argument is a pointer to a structure obtained from +** "ParseAlloc" which describes the current state of the parser. +** The second argument is the major token number. The third is +** the minor token. The fourth optional argument is whatever the +** user wants (and specified in the grammar) and is available for +** use by the action routines. +** +** Inputs: +**
    +**
  • A pointer to the parser (an opaque structure.) +**
  • The major token number. +**
  • The minor token number. +**
  • An option argument of a grammar-specified type. +**
+** +** Outputs: +** None. +*/ +void Parse( + void *yyp, /* The parser */ + int yymajor, /* The major token code number */ + ParseTOKENTYPE yyminor /* The value for the token */ + ParseARG_PDECL /* Optional %extra_argument parameter */ +){ + YYMINORTYPE yyminorunion; + int yyact; /* The parser action. */ + int yyendofinput; /* True if we are at the end of input */ + int yyerrorhit = 0; /* True if yymajor has invoked an error */ + yyParser *yypParser; /* The parser */ + + /* (re)initialize the parser, if necessary */ + yypParser = (yyParser*)yyp; + if( yypParser->yyidx<0 ){ + /* if( yymajor==0 ) return; // not sure why this was here... */ + yypParser->yyidx = 0; + yypParser->yyerrcnt = -1; + yypParser->yystack[0].stateno = 0; + yypParser->yystack[0].major = 0; + } + yyminorunion.yy0 = yyminor; + yyendofinput = (yymajor==0); + ParseARG_STORE; + +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); + } +#endif + + do{ + yyact = yy_find_shift_action(yypParser,yymajor); + if( yyactyyerrcnt--; + if( yyendofinput && yypParser->yyidx>=0 ){ + yymajor = 0; + }else{ + yymajor = YYNOCODE; + } + }else if( yyact < YYNSTATE + YYNRULE ){ + yy_reduce(yypParser,yyact-YYNSTATE); + }else if( yyact == YY_ERROR_ACTION ){ + int yymx; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); + } +#endif +#ifdef YYERRORSYMBOL + /* A syntax error has occurred. + ** The response to an error depends upon whether or not the + ** grammar defines an error token "ERROR". + ** + ** This is what we do if the grammar does define ERROR: + ** + ** * Call the %syntax_error function. + ** + ** * Begin popping the stack until we enter a state where + ** it is legal to shift the error symbol, then shift + ** the error symbol. + ** + ** * Set the error count to three. + ** + ** * Begin accepting and shifting new tokens. No new error + ** processing will occur until three tokens have been + ** shifted successfully. + ** + */ + if( yypParser->yyerrcnt<0 ){ + yy_syntax_error(yypParser,yymajor,yyminorunion); + } + yymx = yypParser->yystack[yypParser->yyidx].major; + if( yymx==YYERRORSYMBOL || yyerrorhit ){ +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sDiscard input token %s\n", + yyTracePrompt,yyTokenName[yymajor]); + } +#endif + yy_destructor(yymajor,&yyminorunion); + yymajor = YYNOCODE; + }else{ + while( + yypParser->yyidx >= 0 && + yymx != YYERRORSYMBOL && + (yyact = yy_find_reduce_action( + yypParser->yystack[yypParser->yyidx].stateno, + YYERRORSYMBOL)) >= YYNSTATE + ){ + yy_pop_parser_stack(yypParser); + } + if( yypParser->yyidx < 0 || yymajor==0 ){ + yy_destructor(yymajor,&yyminorunion); + yy_parse_failed(yypParser); + yymajor = YYNOCODE; + }else if( yymx!=YYERRORSYMBOL ){ + YYMINORTYPE u2; + u2.YYERRSYMDT = 0; + yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); + } + } + yypParser->yyerrcnt = 3; + yyerrorhit = 1; +#else /* YYERRORSYMBOL is not defined */ + /* This is what we do if the grammar does not define ERROR: + ** + ** * Report an error message, and throw away the input token. + ** + ** * If the input token is $, then fail the parse. + ** + ** As before, subsequent error messages are suppressed until + ** three input tokens have been successfully shifted. + */ + if( yypParser->yyerrcnt<=0 ){ + yy_syntax_error(yypParser,yymajor,yyminorunion); + } + yypParser->yyerrcnt = 3; + yy_destructor(yymajor,&yyminorunion); + if( yyendofinput ){ + yy_parse_failed(yypParser); + } + yymajor = YYNOCODE; +#endif + }else{ + yy_accept(yypParser); + yymajor = YYNOCODE; + } + }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); + return; +} diff --git a/tools/dehsupp/parse.h b/tools/dehsupp/parse.h new file mode 100644 index 000000000..c31082399 --- /dev/null +++ b/tools/dehsupp/parse.h @@ -0,0 +1,34 @@ +#define OR 1 +#define XOR 2 +#define AND 3 +#define MINUS 4 +#define PLUS 5 +#define MULTIPLY 6 +#define DIVIDE 7 +#define NEG 8 +#define EOI 9 +#define PRINT 10 +#define LPAREN 11 +#define RPAREN 12 +#define COMMA 13 +#define STRING 14 +#define ENDL 15 +#define NUM 16 +#define Actions 17 +#define LBRACE 18 +#define RBRACE 19 +#define SEMICOLON 20 +#define SYM 21 +#define OrgHeights 22 +#define ActionList 23 +#define RBARCE 24 +#define CodePConv 25 +#define OrgSprNames 26 +#define StateMap 27 +#define FirstState 28 +#define SpawnState 29 +#define DeathState 30 +#define SoundMap 31 +#define InfoNames 32 +#define ThingBits 33 +#define RenderStyles 34 diff --git a/tools/dehsupp/parse.tab.c b/tools/dehsupp/parse.tab.c deleted file mode 100644 index 5f2de7311..000000000 --- a/tools/dehsupp/parse.tab.c +++ /dev/null @@ -1,1981 +0,0 @@ - -/* A Bison parser, made from parse.y - by GNU Bison version 1.28 */ - -#define YYBISON 1 /* Identify Bison output. */ - -#define NUM 257 -#define SYM 258 -#define STRING 259 -#define PRINT 260 -#define ENDL 261 -#define Actions 262 -#define OrgHeights 263 -#define ActionList 264 -#define CodePConv 265 -#define OrgSprNames 266 -#define StateMap 267 -#define SoundMap 268 -#define InfoNames 269 -#define ThingBits 270 -#define FirstState 271 -#define SpawnState 272 -#define DeathState 273 -#define RenderStyles 274 -#define NEG 275 - -#line 1 "parse.y" - -#include -#include -#include -#include -#include - -typedef enum { false, true } bool; -typedef short name; - -// verbose doesn't seem to help all that much -//#define YYERROR_VERBOSE 1 - -int yyerror (char *s); -int yylex (void); -int yyparse (); - -FILE *Source, *Dest; -int SourceLine; -int ErrorCount; - - -void WriteWord (int word); -void WriteLabel (char *label); -void WriteWords (int count, short *array); -void WriteBytes (int count, unsigned char *array); - -void WriteNameTable (); - -void WriteActions (); -void WriteActionMap (); -void WriteHeights (); -void WriteCodePConv (); -void WriteSprites (); -void WriteStates (); -void WriteSounds (); -void WriteInfoNames (); -void WriteThingBits (); -void WriteRenderStyles (); - - -static bool FindToken (char *tok, int *type); - -struct StringList -{ - struct StringList *Next; - char String[1]; -}; - -struct StringSorter -{ - name OldName; - struct StringList *Entry; -}; - -struct StringList *NameList, **NameListLast = &NameList; -int NameCount; - -static name AddName (char *name); -static name FindName (char *name); - -static void SortNames (); - -struct StateMapE -{ - name Name; - unsigned char State; - unsigned char Count; -}; - -struct ThingBitsE -{ - name Name; - unsigned char BitNum; - unsigned char FlagNum; -}; - -struct RenderStylesE -{ - name Name; - unsigned char StyleNum; -}; - -static void AddAction (char *name); -static int FindAction (char *name); - -name *ActionsList; -unsigned char *HeightsArray; -unsigned char *ActionMap; -unsigned short *CodePMap; -char *SpriteNames; -struct StateMapE *StateMaps; -name *SoundMaps; -name *InfoNamesArray; -struct ThingBitsE *ThingBitsMap; -struct RenderStylesE *RenderStylesMap; - -int ActionsListSize, MaxActionsListSize; -int HeightsSize, MaxHeightsSize; -int ActionMapSize, MaxActionMapSize; -int CodePMapSize, MaxCodePMapSize; -int SpriteNamesSize, MaxSpriteNamesSize; -int StateMapsSize, MaxStateMapsSize; -int SoundMapsSize, MaxSoundMapsSize; -int InfoNamesSize, MaxInfoNamesSize; -int ThingBitsMapSize, MaxThingBitsMapSize; -int RenderStylesSize, MaxRenderStylesSize; - -static void AddHeight (int h); -static void AddActionMap (char *name); -static void AddCodeP (int codep); -static void AddSpriteName (char *name); -static void AddStateMap (char *name, int type, int count); -static void AddSoundMap (char *sound); -static void AddInfoName (char *sound); -static void AddThingBits (char *name, int bitnum, int flagnum); -static void AddRenderStyle (char *name, int stylenum); - - -#line 121 "parse.y" -typedef union { - int val; - char sym[80]; - char string[80]; -} YYSTYPE; -#include - -#ifndef __cplusplus -#ifndef __STDC__ -#define const -#endif -#endif - - - -#define YYFINAL 141 -#define YYFLAG -32768 -#define YYNTBASE 35 - -#define YYTRANSLATE(x) ((unsigned)(x) <= 275 ? yytranslate[x] : 65) - -static const char yytranslate[] = { 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 23, 2, 29, - 30, 26, 25, 31, 24, 2, 27, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 34, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 22, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 32, 21, 33, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 1, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 28 -}; - -#if YYDEBUG != 0 -static const short yyprhs[] = { 0, - 0, 2, 6, 10, 14, 18, 22, 26, 30, 33, - 37, 38, 41, 46, 47, 49, 53, 55, 57, 59, - 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, - 81, 87, 88, 90, 94, 100, 101, 103, 107, 113, - 114, 116, 120, 126, 127, 129, 133, 139, 140, 142, - 146, 152, 153, 155, 159, 165, 167, 169, 171, 177, - 178, 180, 184, 190, 191, 193, 197, 203, 204, 206, - 210, 216, 222, 223, 225, 229 -}; - -static const short yyrhs[] = { 3, - 0, 35, 25, 35, 0, 35, 24, 35, 0, 35, - 26, 35, 0, 35, 27, 35, 0, 35, 21, 35, - 0, 35, 23, 35, 0, 35, 22, 35, 0, 24, - 35, 0, 29, 35, 30, 0, 0, 36, 40, 0, - 6, 29, 38, 30, 0, 0, 39, 0, 39, 31, - 38, 0, 5, 0, 35, 0, 7, 0, 37, 0, - 41, 0, 43, 0, 45, 0, 47, 0, 49, 0, - 51, 0, 55, 0, 57, 0, 59, 0, 62, 0, - 8, 32, 42, 33, 34, 0, 0, 4, 0, 42, - 31, 4, 0, 9, 32, 44, 33, 34, 0, 0, - 35, 0, 44, 31, 35, 0, 10, 32, 46, 33, - 34, 0, 0, 4, 0, 46, 31, 4, 0, 11, - 32, 48, 33, 34, 0, 0, 35, 0, 48, 31, - 35, 0, 12, 32, 50, 33, 34, 0, 0, 4, - 0, 50, 31, 4, 0, 13, 32, 52, 33, 34, - 0, 0, 53, 0, 52, 31, 53, 0, 4, 31, - 54, 31, 35, 0, 17, 0, 18, 0, 19, 0, - 14, 32, 56, 33, 34, 0, 0, 5, 0, 56, - 31, 5, 0, 15, 32, 58, 33, 34, 0, 0, - 4, 0, 58, 31, 4, 0, 16, 32, 60, 33, - 34, 0, 0, 61, 0, 60, 31, 61, 0, 35, - 31, 35, 31, 4, 0, 20, 32, 63, 33, 34, - 0, 0, 64, 0, 63, 31, 64, 0, 35, 31, - 4, 0 -}; - -#endif - -#if YYDEBUG != 0 -static const short yyrline[] = { 0, - 161, 163, 164, 165, 166, 167, 168, 169, 170, 171, - 174, 175, 178, 185, 187, 188, 191, 193, 194, 197, - 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, - 211, 215, 217, 218, 221, 225, 227, 228, 231, 235, - 237, 238, 241, 245, 247, 248, 251, 255, 257, 258, - 261, 265, 267, 268, 271, 275, 277, 278, 281, 285, - 287, 288, 291, 295, 297, 298, 301, 305, 307, 308, - 311, 315, 319, 321, 322, 325 -}; -#endif - - -#if YYDEBUG != 0 || defined (YYERROR_VERBOSE) - -static const char * const yytname[] = { "$","error","$undefined.","NUM","SYM", -"STRING","PRINT","ENDL","Actions","OrgHeights","ActionList","CodePConv","OrgSprNames", -"StateMap","SoundMap","InfoNames","ThingBits","FirstState","SpawnState","DeathState", -"RenderStyles","'|'","'^'","'&'","'-'","'+'","'*'","'/'","NEG","'('","')'","','", -"'{'","'}'","';'","exp","translation_unit","print_statement","print_list","print_item", -"external_declaration","ActionsDef","ActionsList","OrgHeightsDef","OrgHeightsList", -"ActionListDef","ActionListList","CodePConvDef","CodePConvList","OrgSprNamesDef", -"OrgSprNamesList","StateMapDef","StateMapList","StateMapEntry","StateType","SoundMapDef", -"SoundMapList","InfoNamesDef","InfoNamesList","ThingBitsDef","ThingBitsList", -"ThingBitsEntry","RenderStylesDef","RenderStylesList","RenderStylesEntry", NULL -}; -#endif - -static const short yyr1[] = { 0, - 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, - 36, 36, 37, 38, 38, 38, 39, 39, 39, 40, - 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, - 41, 42, 42, 42, 43, 44, 44, 44, 45, 46, - 46, 46, 47, 48, 48, 48, 49, 50, 50, 50, - 51, 52, 52, 52, 53, 54, 54, 54, 55, 56, - 56, 56, 57, 58, 58, 58, 59, 60, 60, 60, - 61, 62, 63, 63, 63, 64 -}; - -static const short yyr2[] = { 0, - 1, 3, 3, 3, 3, 3, 3, 3, 2, 3, - 0, 2, 4, 0, 1, 3, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 5, 0, 1, 3, 5, 0, 1, 3, 5, 0, - 1, 3, 5, 0, 1, 3, 5, 0, 1, 3, - 5, 0, 1, 3, 5, 1, 1, 1, 5, 0, - 1, 3, 5, 0, 1, 3, 5, 0, 1, 3, - 5, 5, 0, 1, 3, 3 -}; - -static const short yydefact[] = { 11, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 20, 12, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 14, 32, 36, 40, 44, 48, - 52, 60, 64, 68, 73, 1, 17, 19, 0, 0, - 18, 0, 15, 33, 0, 37, 0, 41, 0, 45, - 0, 49, 0, 0, 0, 53, 61, 0, 65, 0, - 0, 0, 69, 0, 0, 74, 9, 0, 0, 0, - 0, 0, 0, 0, 0, 13, 14, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 10, 6, 8, 7, 3, 2, 4, 5, 16, 34, - 31, 38, 35, 42, 39, 46, 43, 50, 47, 56, - 57, 58, 0, 54, 51, 62, 59, 66, 63, 0, - 70, 67, 76, 75, 72, 0, 0, 55, 71, 0, - 0 -}; - -static const short yydefgoto[] = { 41, - 1, 13, 42, 43, 14, 15, 45, 16, 47, 17, - 49, 18, 51, 19, 53, 20, 55, 56, 123, 21, - 58, 22, 60, 23, 62, 63, 24, 65, 66 -}; - -static const short yypact[] = {-32768, - 50, -23, -3, 23, 35, 39, 75, 76, 95, 96, - 97, 98,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, --32768,-32768,-32768,-32768, -2, 77, 1, 127, 1, 128, - 129, 34, 130, 1, 1,-32768,-32768,-32768, 1, 1, - 73, 105, 106,-32768, -10, 73, -5,-32768, 7, 73, - 18,-32768, 21, 107, 49,-32768,-32768, 88,-32768, 89, - -7, 92,-32768, 10, 93,-32768,-32768, 63, 1, 1, - 1, 1, 1, 1, 1,-32768, -2, 132, 108, 1, - 109, 135, 110, 1, 111, 136, 112, -8, 129, 113, - 143, 115, 137, 116, 1, 1, 117, 148, 1, 119, --32768, 79, 87, 91, 65, 65,-32768,-32768,-32768,-32768, --32768, 73,-32768,-32768,-32768, 73,-32768,-32768,-32768,-32768, --32768,-32768, 123,-32768,-32768,-32768,-32768,-32768,-32768, 52, --32768,-32768,-32768,-32768,-32768, 1, 151, 73,-32768, 156, --32768 -}; - -static const short yypgoto[] = { -27, --32768,-32768, 80,-32768,-32768,-32768,-32768,-32768,-32768,-32768, --32768,-32768,-32768,-32768,-32768,-32768,-32768, 69,-32768,-32768, --32768,-32768,-32768,-32768,-32768, 64,-32768,-32768, 60 -}; - - -#define YYLAST 160 - - -static const short yytable[] = { 46, - 36, 50, 37, 36, 38, 25, 61, 64, 120, 121, - 122, 67, 68, 69, 70, 71, 72, 73, 74, 75, - 78, 39, 79, 95, 39, 80, 40, 81, 26, 40, - 69, 70, 71, 72, 73, 74, 75, 82, 57, 83, - 98, 102, 103, 104, 105, 106, 107, 108, 84, 140, - 85, 86, 112, 87, 27, 2, 116, 3, 4, 5, - 6, 7, 8, 9, 10, 11, 28, 130, 61, 12, - 29, 64, 69, 70, 71, 72, 73, 74, 75, 89, - 44, 90, 137, 69, 70, 71, 72, 73, 74, 75, - 74, 75, 101, 69, 70, 71, 72, 73, 74, 75, - 70, 71, 72, 73, 74, 75, 30, 31, 138, 71, - 72, 73, 74, 75, 72, 73, 74, 75, 91, 93, - 92, 94, 96, 99, 97, 100, 32, 33, 34, 35, - 48, 52, 54, 59, 76, 110, 77, 88, 114, 118, - 128, 111, 113, 115, 117, 119, 125, 126, 127, 129, - 132, 133, 135, 136, 139, 141, 109, 124, 134, 131 -}; - -static const short yycheck[] = { 27, - 3, 29, 5, 3, 7, 29, 34, 35, 17, 18, - 19, 39, 40, 21, 22, 23, 24, 25, 26, 27, - 31, 24, 33, 31, 24, 31, 29, 33, 32, 29, - 21, 22, 23, 24, 25, 26, 27, 31, 5, 33, - 31, 69, 70, 71, 72, 73, 74, 75, 31, 0, - 33, 31, 80, 33, 32, 6, 84, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 32, 95, 96, 20, - 32, 99, 21, 22, 23, 24, 25, 26, 27, 31, - 4, 33, 31, 21, 22, 23, 24, 25, 26, 27, - 26, 27, 30, 21, 22, 23, 24, 25, 26, 27, - 22, 23, 24, 25, 26, 27, 32, 32, 136, 23, - 24, 25, 26, 27, 24, 25, 26, 27, 31, 31, - 33, 33, 31, 31, 33, 33, 32, 32, 32, 32, - 4, 4, 4, 4, 30, 4, 31, 31, 4, 4, - 4, 34, 34, 34, 34, 34, 34, 5, 34, 34, - 34, 4, 34, 31, 4, 0, 77, 89, 99, 96 -}; -/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ -#line 3 "/usr/local/share/bison.simple" -/* This file comes from bison-1.28. */ - -/* Skeleton output parser for bison, - Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - 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. */ - -/* As a special exception, when this file is copied by Bison into a - Bison output file, you may use that output file without restriction. - This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ - -/* This is the parser code that is written into each bison parser - when the %semantic_parser declaration is not specified in the grammar. - It was written by Richard Stallman by simplifying the hairy parser - used when %semantic_parser is specified. */ - -#ifndef YYSTACK_USE_ALLOCA -#ifdef alloca -#define YYSTACK_USE_ALLOCA -#else /* alloca not defined */ -#ifdef __GNUC__ -#define YYSTACK_USE_ALLOCA -#define alloca __builtin_alloca -#else /* not GNU C. */ -#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386)) -#define YYSTACK_USE_ALLOCA -#include -#else /* not sparc */ -/* We think this test detects Watcom and Microsoft C. */ -/* This used to test MSDOS, but that is a bad idea - since that symbol is in the user namespace. */ -#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__) -#if 0 /* No need for malloc.h, which pollutes the namespace; - instead, just don't use alloca. */ -#include -#endif -#else /* not MSDOS, or __TURBOC__ */ -#if defined(_AIX) -/* I don't know what this was needed for, but it pollutes the namespace. - So I turned it off. rms, 2 May 1997. */ -/* #include */ - #pragma alloca -#define YYSTACK_USE_ALLOCA -#else /* not MSDOS, or __TURBOC__, or _AIX */ -#if 0 -#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up, - and on HPUX 10. Eventually we can turn this on. */ -#define YYSTACK_USE_ALLOCA -#define alloca __builtin_alloca -#endif /* __hpux */ -#endif -#endif /* not _AIX */ -#endif /* not MSDOS, or __TURBOC__ */ -#endif /* not sparc */ -#endif /* not GNU C */ -#endif /* alloca not defined */ -#endif /* YYSTACK_USE_ALLOCA not defined */ - -#ifdef YYSTACK_USE_ALLOCA -#define YYSTACK_ALLOC alloca -#else -#define YYSTACK_ALLOC malloc -#endif - -/* Note: there must be only one dollar sign in this file. - It is replaced by the list of actions, each action - as one case of the switch. */ - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY -2 -#define YYEOF 0 -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrlab1 -/* Like YYERROR except do call yyerror. - This remains here temporarily to ease the - transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ -#define YYFAIL goto yyerrlab -#define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(token, value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { yychar = (token), yylval = (value); \ - yychar1 = YYTRANSLATE (yychar); \ - YYPOPSTACK; \ - goto yybackup; \ - } \ - else \ - { yyerror ("syntax error: cannot back up"); YYERROR; } \ -while (0) - -#define YYTERROR 1 -#define YYERRCODE 256 - -#ifndef YYPURE -#define YYLEX yylex() -#endif - -#ifdef YYPURE -#ifdef YYLSP_NEEDED -#ifdef YYLEX_PARAM -#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM) -#else -#define YYLEX yylex(&yylval, &yylloc) -#endif -#else /* not YYLSP_NEEDED */ -#ifdef YYLEX_PARAM -#define YYLEX yylex(&yylval, YYLEX_PARAM) -#else -#define YYLEX yylex(&yylval) -#endif -#endif /* not YYLSP_NEEDED */ -#endif - -/* If nonreentrant, generate the variables here */ - -#ifndef YYPURE - -int yychar; /* the lookahead symbol */ -YYSTYPE yylval; /* the semantic value of the */ - /* lookahead symbol */ - -#ifdef YYLSP_NEEDED -YYLTYPE yylloc; /* location data for the lookahead */ - /* symbol */ -#endif - -int yynerrs; /* number of parse errors so far */ -#endif /* not YYPURE */ - -#if YYDEBUG != 0 -int yydebug; /* nonzero means print parse trace */ -/* Since this is uninitialized, it does not stop multiple parsers - from coexisting. */ -#endif - -/* YYINITDEPTH indicates the initial size of the parser's stacks */ - -#ifndef YYINITDEPTH -#define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH is the maximum size the stacks can grow to - (effective only if the built-in stack extension method is used). */ - -#if YYMAXDEPTH == 0 -#undef YYMAXDEPTH -#endif - -#ifndef YYMAXDEPTH -#define YYMAXDEPTH 10000 -#endif - -/* Define __yy_memcpy. Note that the size argument - should be passed with type unsigned int, because that is what the non-GCC - definitions require. With GCC, __builtin_memcpy takes an arg - of type size_t, but it can handle unsigned int. */ - -#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ -#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT) -#else /* not GNU C or C++ */ -#ifndef __cplusplus - -/* This is the most reliable way to avoid incompatibilities - in available built-in functions on various systems. */ -static void -__yy_memcpy (to, from, count) - char *to; - char *from; - unsigned int count; -{ - register char *f = from; - register char *t = to; - register int i = count; - - while (i-- > 0) - *t++ = *f++; -} - -#else /* __cplusplus */ - -/* This is the most reliable way to avoid incompatibilities - in available built-in functions on various systems. */ -static void -__yy_memcpy (char *to, char *from, unsigned int count) -{ - register char *t = to; - register char *f = from; - register int i = count; - - while (i-- > 0) - *t++ = *f++; -} - -#endif -#endif - -#line 217 "/usr/local/share/bison.simple" - -/* The user can define YYPARSE_PARAM as the name of an argument to be passed - into yyparse. The argument should have type void *. - It should actually point to an object. - Grammar actions can access the variable by casting it - to the proper pointer type. */ - -#ifdef YYPARSE_PARAM -#ifdef __cplusplus -#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM -#define YYPARSE_PARAM_DECL -#else /* not __cplusplus */ -#define YYPARSE_PARAM_ARG YYPARSE_PARAM -#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; -#endif /* not __cplusplus */ -#else /* not YYPARSE_PARAM */ -#define YYPARSE_PARAM_ARG -#define YYPARSE_PARAM_DECL -#endif /* not YYPARSE_PARAM */ - -/* Prevent warning if -Wstrict-prototypes. */ -#ifdef __GNUC__ -#ifdef YYPARSE_PARAM -int yyparse (void *); -#else -int yyparse (void); -#endif -#endif - -int -yyparse(YYPARSE_PARAM_ARG) - YYPARSE_PARAM_DECL -{ - register int yystate; - register int yyn; - register short *yyssp; - register YYSTYPE *yyvsp; - int yyerrstatus; /* number of tokens to shift before error messages enabled */ - int yychar1 = 0; /* lookahead token as an internal (translated) token number */ - - short yyssa[YYINITDEPTH]; /* the state stack */ - YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */ - - short *yyss = yyssa; /* refer to the stacks thru separate pointers */ - YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */ - -#ifdef YYLSP_NEEDED - YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ - YYLTYPE *yyls = yylsa; - YYLTYPE *yylsp; - -#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) -#else -#define YYPOPSTACK (yyvsp--, yyssp--) -#endif - - int yystacksize = YYINITDEPTH; - int yyfree_stacks = 0; - -#ifdef YYPURE - int yychar; - YYSTYPE yylval; - int yynerrs; -#ifdef YYLSP_NEEDED - YYLTYPE yylloc; -#endif -#endif - - YYSTYPE yyval; /* the variable used to return */ - /* semantic values from the action */ - /* routines */ - - int yylen; - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Starting parse\n"); -#endif - - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - - yyssp = yyss - 1; - yyvsp = yyvs; -#ifdef YYLSP_NEEDED - yylsp = yyls; -#endif - -/* Push a new state, which is found in yystate . */ -/* In all cases, when you get here, the value and location stacks - have just been pushed. so pushing a state here evens the stacks. */ -yynewstate: - - *++yyssp = yystate; - - if (yyssp >= yyss + yystacksize - 1) - { - /* Give user a chance to reallocate the stack */ - /* Use copies of these so that the &'s don't force the real ones into memory. */ - YYSTYPE *yyvs1 = yyvs; - short *yyss1 = yyss; -#ifdef YYLSP_NEEDED - YYLTYPE *yyls1 = yyls; -#endif - - /* Get the current used size of the three stacks, in elements. */ - int size = yyssp - yyss + 1; - -#ifdef yyoverflow - /* Each stack pointer address is followed by the size of - the data in use in that stack, in bytes. */ -#ifdef YYLSP_NEEDED - /* This used to be a conditional around just the two extra args, - but that might be undefined if yyoverflow is a macro. */ - yyoverflow("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yyls1, size * sizeof (*yylsp), - &yystacksize); -#else - yyoverflow("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yystacksize); -#endif - - yyss = yyss1; yyvs = yyvs1; -#ifdef YYLSP_NEEDED - yyls = yyls1; -#endif -#else /* no yyoverflow */ - /* Extend the stack our own way. */ - if (yystacksize >= YYMAXDEPTH) - { - yyerror("parser stack overflow"); - if (yyfree_stacks) - { - free (yyss); - free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif - } - return 2; - } - yystacksize *= 2; - if (yystacksize > YYMAXDEPTH) - yystacksize = YYMAXDEPTH; -#ifndef YYSTACK_USE_ALLOCA - yyfree_stacks = 1; -#endif - yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp)); - __yy_memcpy ((char *)yyss, (char *)yyss1, - size * (unsigned int) sizeof (*yyssp)); - yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp)); - __yy_memcpy ((char *)yyvs, (char *)yyvs1, - size * (unsigned int) sizeof (*yyvsp)); -#ifdef YYLSP_NEEDED - yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp)); - __yy_memcpy ((char *)yyls, (char *)yyls1, - size * (unsigned int) sizeof (*yylsp)); -#endif -#endif /* no yyoverflow */ - - yyssp = yyss + size - 1; - yyvsp = yyvs + size - 1; -#ifdef YYLSP_NEEDED - yylsp = yyls + size - 1; -#endif - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Stack size increased to %d\n", yystacksize); -#endif - - if (yyssp >= yyss + yystacksize - 1) - YYABORT; - } - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Entering state %d\n", yystate); -#endif - - goto yybackup; - yybackup: - -/* Do appropriate processing given the current state. */ -/* Read a lookahead token if we need one and don't already have one. */ -/* yyresume: */ - - /* First try to decide what to do without reference to lookahead token. */ - - yyn = yypact[yystate]; - if (yyn == YYFLAG) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* yychar is either YYEMPTY or YYEOF - or a valid token in external form. */ - - if (yychar == YYEMPTY) - { -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Reading a token: "); -#endif - yychar = YYLEX; - } - - /* Convert token to internal form (in yychar1) for indexing tables with */ - - if (yychar <= 0) /* This means end of input. */ - { - yychar1 = 0; - yychar = YYEOF; /* Don't call YYLEX any more */ - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Now at end of input.\n"); -#endif - } - else - { - yychar1 = YYTRANSLATE(yychar); - -#if YYDEBUG != 0 - if (yydebug) - { - fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); - /* Give the individual parser a way to print the precise meaning - of a token, for further debugging info. */ -#ifdef YYPRINT - YYPRINT (stderr, yychar, yylval); -#endif - fprintf (stderr, ")\n"); - } -#endif - } - - yyn += yychar1; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) - goto yydefault; - - yyn = yytable[yyn]; - - /* yyn is what to do for this token type in this state. - Negative => reduce, -yyn is rule number. - Positive => shift, yyn is new state. - New state is final state => don't bother to shift, - just return success. - 0, or most negative number => error. */ - - if (yyn < 0) - { - if (yyn == YYFLAG) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - else if (yyn == 0) - goto yyerrlab; - - if (yyn == YYFINAL) - YYACCEPT; - - /* Shift the lookahead token. */ - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); -#endif - - /* Discard the token being shifted unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; - - *++yyvsp = yylval; -#ifdef YYLSP_NEEDED - *++yylsp = yylloc; -#endif - - /* count tokens shifted since error; after three, turn off error status. */ - if (yyerrstatus) yyerrstatus--; - - yystate = yyn; - goto yynewstate; - -/* Do the default action for the current state. */ -yydefault: - - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - -/* Do a reduction. yyn is the number of a rule to reduce with. */ -yyreduce: - yylen = yyr2[yyn]; - if (yylen > 0) - yyval = yyvsp[1-yylen]; /* implement default value of the action */ - -#if YYDEBUG != 0 - if (yydebug) - { - int i; - - fprintf (stderr, "Reducing via rule %d (line %d), ", - yyn, yyrline[yyn]); - - /* Print the symbols being reduced, and their result. */ - for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) - fprintf (stderr, "%s ", yytname[yyrhs[i]]); - fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); - } -#endif - - - switch (yyn) { - -case 2: -#line 163 "parse.y" -{ yyval.val = yyvsp[-2].val + yyvsp[0].val; ; - break;} -case 3: -#line 164 "parse.y" -{ yyval.val = yyvsp[-2].val - yyvsp[0].val; ; - break;} -case 4: -#line 165 "parse.y" -{ yyval.val = yyvsp[-2].val * yyvsp[0].val; ; - break;} -case 5: -#line 166 "parse.y" -{ yyval.val = yyvsp[-2].val / yyvsp[0].val; ; - break;} -case 6: -#line 167 "parse.y" -{ yyval.val = yyvsp[-2].val | yyvsp[0].val; ; - break;} -case 7: -#line 168 "parse.y" -{ yyval.val = yyvsp[-2].val & yyvsp[0].val; ; - break;} -case 8: -#line 169 "parse.y" -{ yyval.val = yyvsp[-2].val ^ yyvsp[0].val; ; - break;} -case 9: -#line 170 "parse.y" -{ yyval.val = -yyvsp[0].val ; - break;} -case 10: -#line 171 "parse.y" -{ yyval.val = yyvsp[-1].val; ; - break;} -case 13: -#line 180 "parse.y" -{ - printf ("\n"); - ; - break;} -case 17: -#line 192 "parse.y" -{ printf ("%s", yyvsp[0].string); ; - break;} -case 18: -#line 193 "parse.y" -{ printf ("%d", yyvsp[0].val); ; - break;} -case 19: -#line 194 "parse.y" -{ printf ("\n"); ; - break;} -case 33: -#line 217 "parse.y" -{ AddAction (yyvsp[0].sym); ; - break;} -case 34: -#line 218 "parse.y" -{ AddAction (yyvsp[0].sym); ; - break;} -case 37: -#line 227 "parse.y" -{ AddHeight (yyvsp[0].val); ; - break;} -case 38: -#line 228 "parse.y" -{ AddHeight (yyvsp[0].val); ; - break;} -case 41: -#line 237 "parse.y" -{ AddActionMap (yyvsp[0].sym); ; - break;} -case 42: -#line 238 "parse.y" -{ AddActionMap (yyvsp[0].sym); ; - break;} -case 45: -#line 247 "parse.y" -{ AddCodeP (yyvsp[0].val); ; - break;} -case 46: -#line 248 "parse.y" -{ AddCodeP (yyvsp[0].val); ; - break;} -case 49: -#line 257 "parse.y" -{ AddSpriteName (yyvsp[0].sym); ; - break;} -case 50: -#line 258 "parse.y" -{ AddSpriteName (yyvsp[0].sym); ; - break;} -case 55: -#line 272 "parse.y" -{ AddStateMap (yyvsp[-4].sym, yyvsp[-2].val, yyvsp[0].val); ; - break;} -case 56: -#line 276 "parse.y" -{ yyval.val = 0; ; - break;} -case 57: -#line 277 "parse.y" -{ yyval.val = 1; ; - break;} -case 58: -#line 278 "parse.y" -{ yyval.val = 2; ; - break;} -case 61: -#line 287 "parse.y" -{ AddSoundMap (yyvsp[0].string); ; - break;} -case 62: -#line 288 "parse.y" -{ AddSoundMap (yyvsp[0].string); ; - break;} -case 65: -#line 297 "parse.y" -{ AddInfoName (yyvsp[0].sym); ; - break;} -case 66: -#line 298 "parse.y" -{ AddInfoName (yyvsp[0].sym); ; - break;} -case 71: -#line 312 "parse.y" -{ AddThingBits (yyvsp[0].sym, yyvsp[-4].val, yyvsp[-2].val); ; - break;} -case 76: -#line 326 "parse.y" -{ AddRenderStyle (yyvsp[0].sym, yyvsp[-2].val); ; - break;} -} - /* the action file gets copied in in place of this dollarsign */ -#line 543 "/usr/local/share/bison.simple" - - yyvsp -= yylen; - yyssp -= yylen; -#ifdef YYLSP_NEEDED - yylsp -= yylen; -#endif - -#if YYDEBUG != 0 - if (yydebug) - { - short *ssp1 = yyss - 1; - fprintf (stderr, "state stack now"); - while (ssp1 != yyssp) - fprintf (stderr, " %d", *++ssp1); - fprintf (stderr, "\n"); - } -#endif - - *++yyvsp = yyval; - -#ifdef YYLSP_NEEDED - yylsp++; - if (yylen == 0) - { - yylsp->first_line = yylloc.first_line; - yylsp->first_column = yylloc.first_column; - yylsp->last_line = (yylsp-1)->last_line; - yylsp->last_column = (yylsp-1)->last_column; - yylsp->text = 0; - } - else - { - yylsp->last_line = (yylsp+yylen-1)->last_line; - yylsp->last_column = (yylsp+yylen-1)->last_column; - } -#endif - - /* Now "shift" the result of the reduction. - Determine what state that goes to, - based on the state we popped back to - and the rule number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTBASE] + *yyssp; - if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTBASE]; - - goto yynewstate; - -yyerrlab: /* here on detecting error */ - - if (! yyerrstatus) - /* If not already recovering from an error, report this error. */ - { - ++yynerrs; - -#ifdef YYERROR_VERBOSE - yyn = yypact[yystate]; - - if (yyn > YYFLAG && yyn < YYLAST) - { - int size = 0; - char *msg; - int x, count; - - count = 0; - /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ - for (x = (yyn < 0 ? -yyn : 0); - x < (sizeof(yytname) / sizeof(char *)); x++) - if (yycheck[x + yyn] == x) - size += strlen(yytname[x]) + 15, count++; - msg = (char *) malloc(size + 15); - if (msg != 0) - { - strcpy(msg, "parse error"); - - if (count < 5) - { - count = 0; - for (x = (yyn < 0 ? -yyn : 0); - x < (sizeof(yytname) / sizeof(char *)); x++) - if (yycheck[x + yyn] == x) - { - strcat(msg, count == 0 ? ", expecting `" : " or `"); - strcat(msg, yytname[x]); - strcat(msg, "'"); - count++; - } - } - yyerror(msg); - free(msg); - } - else - yyerror ("parse error; also virtual memory exceeded"); - } - else -#endif /* YYERROR_VERBOSE */ - yyerror("parse error"); - } - - goto yyerrlab1; -yyerrlab1: /* here on error raised explicitly by an action */ - - if (yyerrstatus == 3) - { - /* if just tried and failed to reuse lookahead token after an error, discard it. */ - - /* return failure if at end of input */ - if (yychar == YYEOF) - YYABORT; - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); -#endif - - yychar = YYEMPTY; - } - - /* Else will try to reuse lookahead token - after shifting the error token. */ - - yyerrstatus = 3; /* Each real token shifted decrements this */ - - goto yyerrhandle; - -yyerrdefault: /* current state does not do anything special for the error token. */ - -#if 0 - /* This is wrong; only states that explicitly want error tokens - should shift them. */ - yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/ - if (yyn) goto yydefault; -#endif - -yyerrpop: /* pop the current state because it cannot handle the error token */ - - if (yyssp == yyss) YYABORT; - yyvsp--; - yystate = *--yyssp; -#ifdef YYLSP_NEEDED - yylsp--; -#endif - -#if YYDEBUG != 0 - if (yydebug) - { - short *ssp1 = yyss - 1; - fprintf (stderr, "Error: state stack now"); - while (ssp1 != yyssp) - fprintf (stderr, " %d", *++ssp1); - fprintf (stderr, "\n"); - } -#endif - -yyerrhandle: - - yyn = yypact[yystate]; - if (yyn == YYFLAG) - goto yyerrdefault; - - yyn += YYTERROR; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) - goto yyerrdefault; - - yyn = yytable[yyn]; - if (yyn < 0) - { - if (yyn == YYFLAG) - goto yyerrpop; - yyn = -yyn; - goto yyreduce; - } - else if (yyn == 0) - goto yyerrpop; - - if (yyn == YYFINAL) - YYACCEPT; - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Shifting error token, "); -#endif - - *++yyvsp = yylval; -#ifdef YYLSP_NEEDED - *++yylsp = yylloc; -#endif - - yystate = yyn; - goto yynewstate; - - yyacceptlab: - /* YYACCEPT comes here. */ - if (yyfree_stacks) - { - free (yyss); - free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif - } - return 0; - - yyabortlab: - /* YYABORT comes here. */ - if (yyfree_stacks) - { - free (yyss); - free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif - } - return 1; -} -#line 329 "parse.y" - - -#include -#include - -// bison.simple #defines const to nothing -#ifdef const -#undef const -#endif - -int yylex (void) -{ - char token[80]; - int toksize; - int buildup; - int c; - -loop: - if (Source == NULL) - { - return 0; - } - while (isspace (c = fgetc (Source)) && c != EOF) - { - if (c == '\n') - { - SourceLine++; - } - } - - if (c == EOF) - { - return 0; - } - if (isdigit (c)) - { - buildup = c - '0'; - if (c == '0') - { - c = fgetc (Source); - if (c == 'x' || c == 'X') - { - for (;;) - { - c = fgetc (Source); - if (isdigit (c)) - { - buildup = (buildup<<4) + c - '0'; - } - else if (c >= 'a' && c <= 'f') - { - buildup = (buildup<<4) + c - 'a' + 10; - } - else if (c >= 'A' && c <= 'F') - { - buildup = (buildup<<4) + c - 'A' + 10; - } - else - { - ungetc (c, Source); - yylval.val = buildup; - return NUM; - } - } - } - else - { - ungetc (c, Source); - } - } - while (isdigit (c = fgetc (Source))) - { - buildup = buildup*10 + c - '0'; - } - ungetc (c, Source); - yylval.val = buildup; - return NUM; - } - if (isalpha (c)) - { - token[0] = c; - toksize = 1; - while (toksize < 79 && (isalnum (c = fgetc (Source)) || c == '_')) - { - token[toksize++] = c; - } - token[toksize] = 0; - if (toksize == 79 && isalnum (c)) - { - while (isalnum (c = fgetc (Source))) - ; - } - ungetc (c, Source); - if (FindToken (token, &buildup)) - { - return buildup; - } - strcpy (yylval.sym, token); - return SYM; - } - if (c == '/') - { - c = fgetc (Source); - if (c == '*') - { - for (;;) - { - while ((c = fgetc (Source)) != '*' && c != EOF) - { - if (c == '\n') - SourceLine++; - } - if (c == EOF) - return 0; - if ((c = fgetc (Source)) == '/') - goto loop; - if (c == EOF) - return 0; - ungetc (c, Source); - } - } - else if (c == '/') - { - while ((c = fgetc (Source)) != '\n' && c != EOF) - ; - if (c == '\n') - SourceLine++; - else if (c == EOF) - return 0; - goto loop; - } - else - { - ungetc (c, Source); - return '/'; - } - } - if (c == '"') - { - int tokensize = 0; - while ((c = fgetc (Source)) != '"' && c != EOF) - { - if (c == '\\') - { - c = fgetc (Source); - if (c != '"' && c != EOF) - { - ungetc (c, Source); - c = '\\'; - } - } - if (tokensize < 79) - { - yylval.string[tokensize++] = c; - } - } - yylval.string[tokensize] = 0; - return STRING; - } - return c; -} - -static bool FindToken (char *tok, int *type) -{ - static const char tokens[][13] = - { - "endl", "print", "Actions", - "OrgHeights", "ActionList", "CodePConv", "OrgSprNames", - "StateMap", "SoundMap", "InfoNames", "ThingBits", - "DeathState", "SpawnState", "FirstState", "RenderStyles" - }; - static const short types[] = - { - ENDL, PRINT, Actions, - OrgHeights, ActionList, CodePConv, OrgSprNames, - StateMap, SoundMap, InfoNames, ThingBits, - DeathState, SpawnState, FirstState, RenderStyles - }; - int i; - - for (i = sizeof(tokens)/sizeof(tokens[0])-1; i >= 0; i--) - { - if (strcmp (tok, tokens[i]) == 0) - { - *type = types[i]; - return 1; - } - } - return 0; -} - -static name FindName (char *name) -{ - struct StringList *probe = NameList; - int count = 0; - - while (probe != NULL) - { - if (stricmp (probe->String, name) == 0) - { - return count; - } - count++; - probe = probe->Next; - } - return -1; -} - -static name AddName (char *name) -{ - struct StringList *newone; - int index = FindName (name); - - if (index != -1) - return index; - - newone = malloc (sizeof(*newone) + strlen(name)); - strcpy (newone->String, name); - newone->Next = NULL; - *NameListLast = newone; - NameListLast = &newone->Next; - return NameCount++; -} - -static int FindAction (char *namei) -{ - int name = FindName (namei); - - if (name != -1) - { - int i; - - for (i = 0; i < ActionsListSize; i++) - { - if (ActionsList[i] == name) - return i; - } - } - printf ("Line %d: Unknown action %s\n", SourceLine, namei); - ErrorCount++; - return -1; -} - -static void AddAction (char *name) -{ - int newname = AddName (name); - if (ActionsListSize == MaxActionsListSize) - { - MaxActionsListSize = MaxActionsListSize ? MaxActionsListSize * 2 : 256; - ActionsList = realloc (ActionsList, MaxActionsListSize*sizeof(*ActionsList)); - } - ActionsList[ActionsListSize++] = newname; -} - -static void AddHeight (int h) -{ - if (MaxHeightsSize == HeightsSize) - { - MaxHeightsSize = MaxHeightsSize ? MaxHeightsSize * 2 : 256; - HeightsArray = realloc (HeightsArray, MaxHeightsSize); - } - HeightsArray[HeightsSize++] = h; -} - -static void AddActionMap (char *name) -{ - int index = FindAction (name); - - if (index != -1) - { - if (ActionMapSize == MaxActionMapSize) - { - MaxActionMapSize = MaxActionMapSize ? MaxActionMapSize * 2 : 256; - ActionMap = realloc (ActionMap, MaxActionMapSize*sizeof(*ActionMap)); - } - ActionMap[ActionMapSize++] = index; - } -} - -static void AddCodeP (int codep) -{ - if (CodePMapSize == MaxCodePMapSize) - { - MaxCodePMapSize = MaxCodePMapSize ? MaxCodePMapSize * 2 : 256; - CodePMap = realloc (CodePMap, MaxCodePMapSize*sizeof(*CodePMap)); - } - CodePMap[CodePMapSize++] = codep; -} - -static void AddSpriteName (char *name) -{ - if (strlen (name) != 4) - { - printf ("Line %d: Sprite name %s must be 4 characters\n", SourceLine, name); - ErrorCount++; - return; - } - if (SpriteNamesSize == MaxSpriteNamesSize) - { - MaxSpriteNamesSize = MaxSpriteNamesSize ? MaxSpriteNamesSize * 2 : 256*4; - SpriteNames = realloc (SpriteNames, MaxSpriteNamesSize*sizeof(*SpriteNames)); - } - SpriteNames[SpriteNamesSize+0] = toupper (name[0]); - SpriteNames[SpriteNamesSize+1] = toupper (name[1]); - SpriteNames[SpriteNamesSize+2] = toupper (name[2]); - SpriteNames[SpriteNamesSize+3] = toupper (name[3]); - SpriteNamesSize += 4; -} - -static void AddSoundMap (char *name) -{ - if (SoundMapsSize == MaxSoundMapsSize) - { - MaxSoundMapsSize = MaxSoundMapsSize ? MaxSoundMapsSize * 2 : 256; - SoundMaps = realloc (SoundMaps, MaxSoundMapsSize*sizeof(*SoundMaps)); - } - SoundMaps[SoundMapsSize++] = AddName (name); -} - -static void AddInfoName (char *name) -{ - if (InfoNamesSize == MaxInfoNamesSize) - { - MaxInfoNamesSize = MaxInfoNamesSize ? MaxInfoNamesSize * 2 : 256; - InfoNamesArray = realloc (InfoNamesArray, MaxInfoNamesSize*sizeof(*InfoNamesArray)); - } - InfoNamesArray[InfoNamesSize++] = AddName (name); -} - -static void AddStateMap (char *name, int state, int count) -{ - if (count == 0) - { - printf ("Line %d: Count is 0. Is this right?\n", SourceLine); - return; - } - if ((unsigned)count > 255) - { - printf ("Line %d: Count must be in the range 1-255\n", SourceLine); - ErrorCount++; - } - if (StateMapsSize == MaxStateMapsSize) - { - MaxStateMapsSize = MaxStateMapsSize ? MaxStateMapsSize*2 : 256; - StateMaps = realloc (StateMaps, MaxStateMapsSize*sizeof(*StateMaps)); - } - StateMaps[StateMapsSize].Name = AddName (name); - StateMaps[StateMapsSize].State = state; - StateMaps[StateMapsSize].Count = count; - StateMapsSize++; -} - -static void AddThingBits (char *name, int bitnum, int flagnum) -{ - if ((unsigned)bitnum > 31) - { - printf ("Line %d: Bit %d must be in the range 0-31\n", SourceLine, bitnum); - ErrorCount++; - return; - } - if (MaxThingBitsMapSize == ThingBitsMapSize) - { - MaxThingBitsMapSize = MaxThingBitsMapSize ? MaxThingBitsMapSize*2 : 128; - ThingBitsMap = realloc (ThingBitsMap, MaxThingBitsMapSize*sizeof(*ThingBitsMap)); - } - ThingBitsMap[ThingBitsMapSize].Name = AddName (name); - ThingBitsMap[ThingBitsMapSize].BitNum = bitnum; - ThingBitsMap[ThingBitsMapSize].FlagNum = flagnum; - ThingBitsMapSize++; -} - -static void AddRenderStyle (char *name, int stylenum) -{ - if ((unsigned)stylenum > 255) - { - printf ("Line %d: %s must be in the range 0-255\n", SourceLine, name); - ErrorCount++; - return; - } - if (MaxRenderStylesSize == RenderStylesSize) - { - MaxRenderStylesSize = MaxRenderStylesSize ? MaxRenderStylesSize*2 : 16; - RenderStylesMap = realloc (RenderStylesMap, MaxRenderStylesSize*sizeof(*RenderStylesMap)); - } - RenderStylesMap[RenderStylesSize].Name = AddName (name); - RenderStylesMap[RenderStylesSize].StyleNum = stylenum; - RenderStylesSize++; -} - -static int sortfunc (const void *a, const void *b) -{ - return stricmp (((struct StringSorter *)a)->Entry->String, - ((struct StringSorter *)b)->Entry->String); -} - -static void SortNames () -{ - name *remap = malloc (NameCount * sizeof(*remap)); - struct StringSorter *sorter = malloc (NameCount * sizeof(*sorter)); - struct StringList *probe, **prev; - int i; - - for (i = 0, probe = NameList; probe != NULL; probe = probe->Next, i++) - { - sorter[i].OldName = i; - sorter[i].Entry = probe; - } - - // There are some warnings here, though I have no idea why. - qsort (sorter, NameCount, sizeof(*sorter), sortfunc); - - for (i = 0, prev = &NameList; i < NameCount; i++) - { - *prev = sorter[i].Entry; - prev = &sorter[i].Entry->Next; - } - *prev = NULL; - - for (i = 0; i < NameCount; i++) - { - remap[sorter[i].OldName] = i; - } - - for (i = 0; i < ActionsListSize; i++) - { - ActionsList[i] = remap[ActionsList[i]]; - } - for (i = 0; i < SoundMapsSize; i++) - { - SoundMaps[i] = remap[SoundMaps[i]]; - } - for (i = 0; i < InfoNamesSize; i++) - { - InfoNamesArray[i] = remap[InfoNamesArray[i]]; - } - for (i = 0; i < StateMapsSize; i++) - { - StateMaps[i].Name = remap[StateMaps[i].Name]; - } - for (i = 0; i < ThingBitsMapSize; i++) - { - ThingBitsMap[i].Name = remap[ThingBitsMap[i].Name]; - } - for (i = 0; i < RenderStylesSize; i++) - { - RenderStylesMap[i].Name = remap[RenderStylesMap[i].Name]; - } -} - -int yyerror (char *s) -{ - printf ("Line %d: %s\n", SourceLine, s); - ErrorCount++; - return 0; -} - -int main (int argc, char **argv) -{ - if (argc != 3) - { - printf ("Usage: dehsupp \n"); - return -1; - } - Source = fopen (argv[1], "r"); - if (Source == NULL) - { - printf ("Could not open %s\n", argv[1]); - return -2; - } - SourceLine = 1; - yyparse (); - fclose (Source); - if (ErrorCount) - { - printf ("There were %d errors\n", ErrorCount); - return -3; - } - SortNames (); - Dest = fopen (argv[2], "wb"); - if (Dest == NULL) - { - printf ("Could not open %s\n", argv[2]); - return -4; - } - WriteNameTable (); - WriteActions (); - WriteCodePConv (); - WriteSprites (); - WriteSounds (); - WriteInfoNames (); - WriteStates (); - WriteActionMap (); - WriteThingBits (); - WriteRenderStyles (); - WriteHeights (); - WriteLabel ("END "); - fclose (Dest); - return 0; -} - -void fail (int code, char *err) -{ - fclose (Dest); - printf ("%s\n", err); - exit (code); -} - -void WriteWord (int word) -{ - putc (word >> 8, Dest); - putc (word & 255, Dest); -} - -void WriteLabel (char *label) -{ - fwrite (label, 1, 4, Dest); -} - -void WriteWords (int count, short *array) -{ - int i; - - WriteWord (count); - for (i = 0; i < count; i++) - { - WriteWord (array[i]); - } -} - -void WriteBytes (int count, unsigned char *array) -{ - WriteWord (count); - fwrite (array, 1, count, Dest); -} - -void WriteNameTable () -{ - struct StringList *probe; - int i, size; - - WriteLabel ("NAME"); - // Count the length of each string, including nulls - for (probe = NameList, size = 0; probe != NULL; probe = probe->Next) - { - size += (int)strlen (probe->String) + 1; - } - - if (size == 0) - { - WriteWord (2); // Size of this lump - WriteWord (0); // Number of names - return; - } - size += NameCount*2 + 2; - if (size >= 65536) - { - fail (-5, "Name table is larger than 64K"); - } - WriteWord (size); // Size of this lump - WriteWord (NameCount); // Number of names - - // Write each name's offset from the first name, which is stored - // immediately after this list - for (i = size = 0, probe = NameList; i < NameCount; i++, probe = probe->Next) - { - WriteWord (size); - size += (int)strlen (probe->String) + 1; - } - - // Write each name's string in order now - for (probe = NameList; probe != NULL; probe = probe->Next) - { - fputs (probe->String, Dest); - putc (0, Dest); - } -} - -typedef struct -{ - name Name; - short Num; -} NameNum; - -int sortfunc2 (const void *a, const void *b) -{ - return ((NameNum *)a)->Name - ((NameNum *)b)->Name; -} - -void WriteActions () -{ - NameNum *sorter = malloc (ActionsListSize * sizeof(*sorter)); - int i; - - WriteLabel ("ACTF"); - WriteWord (ActionsListSize); - - for (i = 0; i < ActionsListSize; i++) - { - sorter[i].Name = ActionsList[i]; - sorter[i].Num = i; - } - // warnings here. ignore. - qsort (sorter, ActionsListSize, sizeof(*sorter), sortfunc2); - for (i = 0; i < ActionsListSize; i++) - { - WriteWord (sorter[i].Name); - WriteWord (sorter[i].Num); - } - free (sorter); -} - -void WriteActionMap () -{ - WriteLabel ("ACTM"); - WriteBytes (ActionMapSize, ActionMap); -} - -void WriteHeights () -{ - WriteLabel ("HIGH"); - WriteBytes (HeightsSize, HeightsArray); -} - -void WriteCodePConv () -{ - WriteLabel ("CODP"); - WriteWords (CodePMapSize, (short *)CodePMap); -} - -void WriteSprites () -{ - WriteLabel ("SPRN"); - WriteWord (SpriteNamesSize / 4); - fwrite (SpriteNames, SpriteNamesSize, 1, Dest); -} - -void WriteStates () -{ - int i; - - WriteLabel ("STAT"); - WriteWord (StateMapsSize); - for (i = 0; i < StateMapsSize; i++) - { - WriteWord (StateMaps[i].Name); - putc (StateMaps[i].State, Dest); - putc (StateMaps[i].Count, Dest); - } -} - -void WriteSounds () -{ - WriteLabel ("SND "); - WriteWords (SoundMapsSize, SoundMaps); -} - -void WriteInfoNames () -{ - WriteLabel ("INFN"); - WriteWords (InfoNamesSize, InfoNamesArray); -} - -static int sortfunc3 (const void *a, const void *b) -{ - return ((struct ThingBitsE *)a)->Name - ((struct ThingBitsE *)b)->Name; -} - -void WriteThingBits () -{ - int i; - - WriteLabel ("TBIT"); - WriteWord (ThingBitsMapSize); - // warnings here; ignore them - qsort (ThingBitsMap, ThingBitsMapSize, sizeof(*ThingBitsMap), sortfunc3); - for (i = 0; i < ThingBitsMapSize; i++) - { - WriteWord (ThingBitsMap[i].Name); - putc (ThingBitsMap[i].BitNum | (ThingBitsMap[i].FlagNum<<5), Dest); - } -} - -static int sortfunc4 (const void *a, const void *b) -{ - return ((struct RenderStylesE *)a)->Name - ((struct RenderStylesE *)b)->Name; -} - -void WriteRenderStyles () -{ - int i; - - WriteLabel ("REND"); - WriteWord (RenderStylesSize); - // More warnings; ignore - qsort (RenderStylesMap, RenderStylesSize, sizeof(*RenderStylesMap), sortfunc4); - for (i = 0; i < RenderStylesSize; i++) - { - WriteWord (RenderStylesMap[i].Name); - putc (RenderStylesMap[i].StyleNum, Dest); - } -} diff --git a/tools/dehsupp/parse.y b/tools/dehsupp/parse.y index fbec9524d..f12cacfa5 100644 --- a/tools/dehsupp/parse.y +++ b/tools/dehsupp/parse.y @@ -1,1029 +1,140 @@ -%{ -#include -#include -#include -#include -#include - -typedef enum { false, true } bool; -typedef short name; - -// verbose doesn't seem to help all that much -//#define YYERROR_VERBOSE 1 - -int yyerror (char *s); -int yylex (void); -int yyparse (); - -FILE *Source, *Dest; -int SourceLine; -int ErrorCount; - - -void WriteWord (int word); -void WriteLabel (char *label); -void WriteWords (int count, short *array); -void WriteBytes (int count, unsigned char *array); - -void WriteNameTable (); - -void WriteActions (); -void WriteActionMap (); -void WriteHeights (); -void WriteCodePConv (); -void WriteSprites (); -void WriteStates (); -void WriteSounds (); -void WriteInfoNames (); -void WriteThingBits (); -void WriteRenderStyles (); - - -static bool FindToken (char *tok, int *type); - -struct StringList -{ - struct StringList *Next; - char String[1]; -}; - -struct StringSorter -{ - name OldName; - struct StringList *Entry; -}; - -struct StringList *NameList, **NameListLast = &NameList; -int NameCount; - -static name AddName (char *name); -static name FindName (char *name); - -static void SortNames (); - -struct StateMapE -{ - name Name; - unsigned char State; - unsigned char Count; -}; - -struct ThingBitsE -{ - name Name; - unsigned char BitNum; - unsigned char FlagNum; -}; - -struct RenderStylesE -{ - name Name; - unsigned char StyleNum; -}; - -static void AddAction (char *name); -static int FindAction (char *name); - -name *ActionsList; -unsigned char *HeightsArray; -unsigned char *ActionMap; -unsigned short *CodePMap; -char *SpriteNames; -struct StateMapE *StateMaps; -name *SoundMaps; -name *InfoNamesArray; -struct ThingBitsE *ThingBitsMap; -struct RenderStylesE *RenderStylesMap; - -int ActionsListSize, MaxActionsListSize; -int HeightsSize, MaxHeightsSize; -int ActionMapSize, MaxActionMapSize; -int CodePMapSize, MaxCodePMapSize; -int SpriteNamesSize, MaxSpriteNamesSize; -int StateMapsSize, MaxStateMapsSize; -int SoundMapsSize, MaxSoundMapsSize; -int InfoNamesSize, MaxInfoNamesSize; -int ThingBitsMapSize, MaxThingBitsMapSize; -int RenderStylesSize, MaxRenderStylesSize; - -static void AddHeight (int h); -static void AddActionMap (char *name); -static void AddCodeP (int codep); -static void AddSpriteName (char *name); -static void AddStateMap (char *name, int type, int count); -static void AddSoundMap (char *sound); -static void AddInfoName (char *sound); -static void AddThingBits (char *name, int bitnum, int flagnum); -static void AddRenderStyle (char *name, int stylenum); - -%} - -%union { - int val; - char sym[80]; - char string[80]; -} - -%token NUM -%token SYM -%token STRING - -%type exp -%type StateType; - -%token PRINT -%token ENDL -%token Actions -%token OrgHeights -%token ActionList -%token CodePConv -%token OrgSprNames -%token StateMap -%token SoundMap -%token InfoNames -%token ThingBits -%token FirstState -%token SpawnState -%token DeathState -%token RenderStyles - -%left '|' -%left '^' -%left '&' -%left '-' '+' -%left '*' '/' -%left NEG - -%start translation_unit - -%% - -exp: - NUM - | exp '+' exp { $$ = $1 + $3; } - | exp '-' exp { $$ = $1 - $3; } - | exp '*' exp { $$ = $1 * $3; } - | exp '/' exp { $$ = $1 / $3; } - | exp '|' exp { $$ = $1 | $3; } - | exp '&' exp { $$ = $1 & $3; } - | exp '^' exp { $$ = $1 ^ $3; } - | '-' exp %prec NEG { $$ = -$2 } - | '(' exp ')' { $$ = $2; } -; - -translation_unit: /* empty line */ - | translation_unit external_declaration -; - -print_statement: - PRINT '(' print_list ')' - { - printf ("\n"); - } -; - -print_list: - /* EMPTY */ - | print_item - | print_item ',' print_list -; - -print_item: - STRING { printf ("%s", $1); } - | exp { printf ("%d", $1); } - | ENDL { printf ("\n"); } -; - -external_declaration: - print_statement - | ActionsDef - | OrgHeightsDef - | ActionListDef - | CodePConvDef - | OrgSprNamesDef - | StateMapDef - | SoundMapDef - | InfoNamesDef - | ThingBitsDef - | RenderStylesDef -; - -ActionsDef: - Actions '{' ActionsList '}' ';' -; - -ActionsList: - /* empty */ - | SYM { AddAction ($1); } - | ActionsList ',' SYM { AddAction ($3); } -; - -OrgHeightsDef: - OrgHeights '{' OrgHeightsList '}' ';' -; - -OrgHeightsList: - /* empty */ - | exp { AddHeight ($1); } - | OrgHeightsList ',' exp { AddHeight ($3); } -; - -ActionListDef: - ActionList '{' ActionListList '}' ';' -; - -ActionListList: - /* empty */ - | SYM { AddActionMap ($1); } - | ActionListList ',' SYM { AddActionMap ($3); } -; - -CodePConvDef: - CodePConv '{' CodePConvList '}' ';' -; - -CodePConvList: - /* empty */ - | exp { AddCodeP ($1); } - | CodePConvList ',' exp { AddCodeP ($3); } -; - -OrgSprNamesDef: - OrgSprNames '{' OrgSprNamesList '}' ';' -; - -OrgSprNamesList: - /* empty */ - | SYM { AddSpriteName ($1); } - | OrgSprNamesList ',' SYM { AddSpriteName ($3); } -; - -StateMapDef: - StateMap '{' StateMapList '}' ';' -; - -StateMapList: - /* empty */ - | StateMapEntry - | StateMapList ',' StateMapEntry -; - -StateMapEntry: - SYM ',' StateType ',' exp { AddStateMap ($1, $3, $5); } -; - -StateType: - FirstState { $$ = 0; } - | SpawnState { $$ = 1; } - | DeathState { $$ = 2; } -; - -SoundMapDef: - SoundMap '{' SoundMapList '}' ';' -; - -SoundMapList: - /*empty */ - | STRING { AddSoundMap ($1); } - | SoundMapList ',' STRING { AddSoundMap ($3); } -; - -InfoNamesDef: - InfoNames '{' InfoNamesList '}' ';' -; - -InfoNamesList: - /* empty */ - | SYM { AddInfoName ($1); } - | InfoNamesList ',' SYM { AddInfoName ($3); } -; - -ThingBitsDef: - ThingBits '{' ThingBitsList '}' ';' -; - -ThingBitsList: - /* empty */ - | ThingBitsEntry - | ThingBitsList ',' ThingBitsEntry -; - -ThingBitsEntry: - exp ',' exp ',' SYM { AddThingBits ($5, $1, $3); } -; - -RenderStylesDef: - RenderStyles '{' RenderStylesList '}' ';' -; - -RenderStylesList: - /* empty */ - | RenderStylesEntry - | RenderStylesList ',' RenderStylesEntry -; - -RenderStylesEntry: - exp ',' SYM { AddRenderStyle ($3, $1); } -; - -%% - -#include -#include - -// bison.simple #defines const to nothing -#ifdef const -#undef const -#endif - -int yylex (void) -{ - char token[80]; - int toksize; - int buildup; - int c; - -loop: - if (Source == NULL) - { - return 0; - } - while (isspace (c = fgetc (Source)) && c != EOF) - { - if (c == '\n') - { - SourceLine++; - } - } - - if (c == EOF) - { - return 0; - } - if (isdigit (c)) - { - buildup = c - '0'; - if (c == '0') - { - c = fgetc (Source); - if (c == 'x' || c == 'X') - { - for (;;) - { - c = fgetc (Source); - if (isdigit (c)) - { - buildup = (buildup<<4) + c - '0'; - } - else if (c >= 'a' && c <= 'f') - { - buildup = (buildup<<4) + c - 'a' + 10; - } - else if (c >= 'A' && c <= 'F') - { - buildup = (buildup<<4) + c - 'A' + 10; - } - else - { - ungetc (c, Source); - yylval.val = buildup; - return NUM; - } - } - } - else - { - ungetc (c, Source); - } - } - while (isdigit (c = fgetc (Source))) - { - buildup = buildup*10 + c - '0'; - } - ungetc (c, Source); - yylval.val = buildup; - return NUM; - } - if (isalpha (c)) - { - token[0] = c; - toksize = 1; - while (toksize < 79 && (isalnum (c = fgetc (Source)) || c == '_')) - { - token[toksize++] = c; - } - token[toksize] = 0; - if (toksize == 79 && isalnum (c)) - { - while (isalnum (c = fgetc (Source))) - ; - } - ungetc (c, Source); - if (FindToken (token, &buildup)) - { - return buildup; - } - strcpy (yylval.sym, token); - return SYM; - } - if (c == '/') - { - c = fgetc (Source); - if (c == '*') - { - for (;;) - { - while ((c = fgetc (Source)) != '*' && c != EOF) - { - if (c == '\n') - SourceLine++; - } - if (c == EOF) - return 0; - if ((c = fgetc (Source)) == '/') - goto loop; - if (c == EOF) - return 0; - ungetc (c, Source); - } - } - else if (c == '/') - { - while ((c = fgetc (Source)) != '\n' && c != EOF) - ; - if (c == '\n') - SourceLine++; - else if (c == EOF) - return 0; - goto loop; - } - else - { - ungetc (c, Source); - return '/'; - } - } - if (c == '"') - { - int tokensize = 0; - while ((c = fgetc (Source)) != '"' && c != EOF) - { - if (c == '\\') - { - c = fgetc (Source); - if (c != '"' && c != EOF) - { - ungetc (c, Source); - c = '\\'; - } - } - if (tokensize < 79) - { - yylval.string[tokensize++] = c; - } - } - yylval.string[tokensize] = 0; - return STRING; - } - return c; -} - -static bool FindToken (char *tok, int *type) -{ - static const char tokens[][13] = - { - "endl", "print", "Actions", - "OrgHeights", "ActionList", "CodePConv", "OrgSprNames", - "StateMap", "SoundMap", "InfoNames", "ThingBits", - "DeathState", "SpawnState", "FirstState", "RenderStyles" - }; - static const short types[] = - { - ENDL, PRINT, Actions, - OrgHeights, ActionList, CodePConv, OrgSprNames, - StateMap, SoundMap, InfoNames, ThingBits, - DeathState, SpawnState, FirstState, RenderStyles - }; - int i; - - for (i = sizeof(tokens)/sizeof(tokens[0])-1; i >= 0; i--) - { - if (strcmp (tok, tokens[i]) == 0) - { - *type = types[i]; - return 1; - } - } - return 0; -} - -static name FindName (char *name) -{ - struct StringList *probe = NameList; - int count = 0; - - while (probe != NULL) - { - if (stricmp (probe->String, name) == 0) - { - return count; - } - count++; - probe = probe->Next; - } - return -1; -} - -static name AddName (char *name) -{ - struct StringList *newone; - int index = FindName (name); - - if (index != -1) - return index; - - newone = malloc (sizeof(*newone) + strlen(name)); - strcpy (newone->String, name); - newone->Next = NULL; - *NameListLast = newone; - NameListLast = &newone->Next; - return NameCount++; -} - -static int FindAction (char *namei) -{ - int name = FindName (namei); - - if (name != -1) - { - int i; - - for (i = 0; i < ActionsListSize; i++) - { - if (ActionsList[i] == name) - return i; - } - } - printf ("Line %d: Unknown action %s\n", SourceLine, namei); - ErrorCount++; - return -1; -} - -static void AddAction (char *name) -{ - int newname = AddName (name); - if (ActionsListSize == MaxActionsListSize) - { - MaxActionsListSize = MaxActionsListSize ? MaxActionsListSize * 2 : 256; - ActionsList = realloc (ActionsList, MaxActionsListSize*sizeof(*ActionsList)); - } - ActionsList[ActionsListSize++] = newname; -} - -static void AddHeight (int h) -{ - if (MaxHeightsSize == HeightsSize) - { - MaxHeightsSize = MaxHeightsSize ? MaxHeightsSize * 2 : 256; - HeightsArray = realloc (HeightsArray, MaxHeightsSize); - } - HeightsArray[HeightsSize++] = h; -} - -static void AddActionMap (char *name) -{ - int index = FindAction (name); - - if (index != -1) - { - if (ActionMapSize == MaxActionMapSize) - { - MaxActionMapSize = MaxActionMapSize ? MaxActionMapSize * 2 : 256; - ActionMap = realloc (ActionMap, MaxActionMapSize*sizeof(*ActionMap)); - } - ActionMap[ActionMapSize++] = index; - } -} - -static void AddCodeP (int codep) -{ - if (CodePMapSize == MaxCodePMapSize) - { - MaxCodePMapSize = MaxCodePMapSize ? MaxCodePMapSize * 2 : 256; - CodePMap = realloc (CodePMap, MaxCodePMapSize*sizeof(*CodePMap)); - } - CodePMap[CodePMapSize++] = codep; -} - -static void AddSpriteName (char *name) -{ - if (strlen (name) != 4) - { - printf ("Line %d: Sprite name %s must be 4 characters\n", SourceLine, name); - ErrorCount++; - return; - } - if (SpriteNamesSize == MaxSpriteNamesSize) - { - MaxSpriteNamesSize = MaxSpriteNamesSize ? MaxSpriteNamesSize * 2 : 256*4; - SpriteNames = realloc (SpriteNames, MaxSpriteNamesSize*sizeof(*SpriteNames)); - } - SpriteNames[SpriteNamesSize+0] = toupper (name[0]); - SpriteNames[SpriteNamesSize+1] = toupper (name[1]); - SpriteNames[SpriteNamesSize+2] = toupper (name[2]); - SpriteNames[SpriteNamesSize+3] = toupper (name[3]); - SpriteNamesSize += 4; -} - -static void AddSoundMap (char *name) -{ - if (SoundMapsSize == MaxSoundMapsSize) - { - MaxSoundMapsSize = MaxSoundMapsSize ? MaxSoundMapsSize * 2 : 256; - SoundMaps = realloc (SoundMaps, MaxSoundMapsSize*sizeof(*SoundMaps)); - } - SoundMaps[SoundMapsSize++] = AddName (name); -} - -static void AddInfoName (char *name) -{ - if (InfoNamesSize == MaxInfoNamesSize) - { - MaxInfoNamesSize = MaxInfoNamesSize ? MaxInfoNamesSize * 2 : 256; - InfoNamesArray = realloc (InfoNamesArray, MaxInfoNamesSize*sizeof(*InfoNamesArray)); - } - InfoNamesArray[InfoNamesSize++] = AddName (name); -} - -static void AddStateMap (char *name, int state, int count) -{ - if (count == 0) - { - printf ("Line %d: Count is 0. Is this right?\n", SourceLine); - return; - } - if ((unsigned)count > 255) - { - printf ("Line %d: Count must be in the range 1-255\n", SourceLine); - ErrorCount++; - } - if (StateMapsSize == MaxStateMapsSize) - { - MaxStateMapsSize = MaxStateMapsSize ? MaxStateMapsSize*2 : 256; - StateMaps = realloc (StateMaps, MaxStateMapsSize*sizeof(*StateMaps)); - } - StateMaps[StateMapsSize].Name = AddName (name); - StateMaps[StateMapsSize].State = state; - StateMaps[StateMapsSize].Count = count; - StateMapsSize++; -} - -static void AddThingBits (char *name, int bitnum, int flagnum) -{ - if ((unsigned)bitnum > 31) - { - printf ("Line %d: Bit %d must be in the range 0-31\n", SourceLine, bitnum); - ErrorCount++; - return; - } - if (MaxThingBitsMapSize == ThingBitsMapSize) - { - MaxThingBitsMapSize = MaxThingBitsMapSize ? MaxThingBitsMapSize*2 : 128; - ThingBitsMap = realloc (ThingBitsMap, MaxThingBitsMapSize*sizeof(*ThingBitsMap)); - } - ThingBitsMap[ThingBitsMapSize].Name = AddName (name); - ThingBitsMap[ThingBitsMapSize].BitNum = bitnum; - ThingBitsMap[ThingBitsMapSize].FlagNum = flagnum; - ThingBitsMapSize++; -} - -static void AddRenderStyle (char *name, int stylenum) -{ - if ((unsigned)stylenum > 255) - { - printf ("Line %d: %s must be in the range 0-255\n", SourceLine, name); - ErrorCount++; - return; - } - if (MaxRenderStylesSize == RenderStylesSize) - { - MaxRenderStylesSize = MaxRenderStylesSize ? MaxRenderStylesSize*2 : 16; - RenderStylesMap = realloc (RenderStylesMap, MaxRenderStylesSize*sizeof(*RenderStylesMap)); - } - RenderStylesMap[RenderStylesSize].Name = AddName (name); - RenderStylesMap[RenderStylesSize].StyleNum = stylenum; - RenderStylesSize++; -} - -static int sortfunc (const void *a, const void *b) -{ - return stricmp (((struct StringSorter *)a)->Entry->String, - ((struct StringSorter *)b)->Entry->String); -} - -static void SortNames () -{ - name *remap = malloc (NameCount * sizeof(*remap)); - struct StringSorter *sorter = malloc (NameCount * sizeof(*sorter)); - struct StringList *probe, **prev; - int i; - - for (i = 0, probe = NameList; probe != NULL; probe = probe->Next, i++) - { - sorter[i].OldName = i; - sorter[i].Entry = probe; - } - - // There are some warnings here, though I have no idea why. - qsort (sorter, NameCount, sizeof(*sorter), sortfunc); - - for (i = 0, prev = &NameList; i < NameCount; i++) - { - *prev = sorter[i].Entry; - prev = &sorter[i].Entry->Next; - } - *prev = NULL; - - for (i = 0; i < NameCount; i++) - { - remap[sorter[i].OldName] = i; - } - - for (i = 0; i < ActionsListSize; i++) - { - ActionsList[i] = remap[ActionsList[i]]; - } - for (i = 0; i < SoundMapsSize; i++) - { - SoundMaps[i] = remap[SoundMaps[i]]; - } - for (i = 0; i < InfoNamesSize; i++) - { - InfoNamesArray[i] = remap[InfoNamesArray[i]]; - } - for (i = 0; i < StateMapsSize; i++) - { - StateMaps[i].Name = remap[StateMaps[i].Name]; - } - for (i = 0; i < ThingBitsMapSize; i++) - { - ThingBitsMap[i].Name = remap[ThingBitsMap[i].Name]; - } - for (i = 0; i < RenderStylesSize; i++) - { - RenderStylesMap[i].Name = remap[RenderStylesMap[i].Name]; - } -} - -int yyerror (char *s) -{ - printf ("Line %d: %s\n", SourceLine, s); - ErrorCount++; - return 0; -} - -int main (int argc, char **argv) -{ - if (argc != 3) - { - printf ("Usage: dehsupp \n"); - return -1; - } - Source = fopen (argv[1], "r"); - if (Source == NULL) - { - printf ("Could not open %s\n", argv[1]); - return -2; - } - SourceLine = 1; - yyparse (); - fclose (Source); - if (ErrorCount) - { - printf ("There were %d errors\n", ErrorCount); - return -3; - } - SortNames (); - Dest = fopen (argv[2], "wb"); - if (Dest == NULL) - { - printf ("Could not open %s\n", argv[2]); - return -4; - } - WriteNameTable (); - WriteActions (); - WriteCodePConv (); - WriteSprites (); - WriteSounds (); - WriteInfoNames (); - WriteStates (); - WriteActionMap (); - WriteThingBits (); - WriteRenderStyles (); - WriteHeights (); - WriteLabel ("END "); - fclose (Dest); - return 0; -} - -void fail (int code, char *err) -{ - fclose (Dest); - printf ("%s\n", err); - exit (code); -} - -void WriteWord (int word) -{ - putc (word >> 8, Dest); - putc (word & 255, Dest); -} - -void WriteLabel (char *label) -{ - fwrite (label, 1, 4, Dest); -} - -void WriteWords (int count, short *array) -{ - int i; - - WriteWord (count); - for (i = 0; i < count; i++) - { - WriteWord (array[i]); - } -} - -void WriteBytes (int count, unsigned char *array) -{ - WriteWord (count); - fwrite (array, 1, count, Dest); -} - -void WriteNameTable () -{ - struct StringList *probe; - int i, size; - - WriteLabel ("NAME"); - // Count the length of each string, including nulls - for (probe = NameList, size = 0; probe != NULL; probe = probe->Next) - { - size += (int)strlen (probe->String) + 1; - } - - if (size == 0) - { - WriteWord (2); // Size of this lump - WriteWord (0); // Number of names - return; - } - size += NameCount*2 + 2; - if (size >= 65536) - { - fail (-5, "Name table is larger than 64K"); - } - WriteWord (size); // Size of this lump - WriteWord (NameCount); // Number of names - - // Write each name's offset from the first name, which is stored - // immediately after this list - for (i = size = 0, probe = NameList; i < NameCount; i++, probe = probe->Next) - { - WriteWord (size); - size += (int)strlen (probe->String) + 1; - } - - // Write each name's string in order now - for (probe = NameList; probe != NULL; probe = probe->Next) - { - fputs (probe->String, Dest); - putc (0, Dest); - } -} - -typedef struct -{ - name Name; - short Num; -} NameNum; - -int sortfunc2 (const void *a, const void *b) -{ - return ((NameNum *)a)->Name - ((NameNum *)b)->Name; -} - -void WriteActions () -{ - NameNum *sorter = malloc (ActionsListSize * sizeof(*sorter)); - int i; - - WriteLabel ("ACTF"); - WriteWord (ActionsListSize); - - for (i = 0; i < ActionsListSize; i++) - { - sorter[i].Name = ActionsList[i]; - sorter[i].Num = i; - } - // warnings here. ignore. - qsort (sorter, ActionsListSize, sizeof(*sorter), sortfunc2); - for (i = 0; i < ActionsListSize; i++) - { - WriteWord (sorter[i].Name); - WriteWord (sorter[i].Num); - } - free (sorter); -} - -void WriteActionMap () -{ - WriteLabel ("ACTM"); - WriteBytes (ActionMapSize, ActionMap); -} - -void WriteHeights () -{ - WriteLabel ("HIGH"); - WriteBytes (HeightsSize, HeightsArray); -} - -void WriteCodePConv () -{ - WriteLabel ("CODP"); - WriteWords (CodePMapSize, (short *)CodePMap); -} - -void WriteSprites () -{ - WriteLabel ("SPRN"); - WriteWord (SpriteNamesSize / 4); - fwrite (SpriteNames, SpriteNamesSize, 1, Dest); -} - -void WriteStates () -{ - int i; - - WriteLabel ("STAT"); - WriteWord (StateMapsSize); - for (i = 0; i < StateMapsSize; i++) - { - WriteWord (StateMaps[i].Name); - putc (StateMaps[i].State, Dest); - putc (StateMaps[i].Count, Dest); - } -} - -void WriteSounds () -{ - WriteLabel ("SND "); - WriteWords (SoundMapsSize, SoundMaps); -} - -void WriteInfoNames () -{ - WriteLabel ("INFN"); - WriteWords (InfoNamesSize, InfoNamesArray); -} - -static int sortfunc3 (const void *a, const void *b) -{ - return ((struct ThingBitsE *)a)->Name - ((struct ThingBitsE *)b)->Name; -} - -void WriteThingBits () -{ - int i; - - WriteLabel ("TBIT"); - WriteWord (ThingBitsMapSize); - // warnings here; ignore them - qsort (ThingBitsMap, ThingBitsMapSize, sizeof(*ThingBitsMap), sortfunc3); - for (i = 0; i < ThingBitsMapSize; i++) - { - WriteWord (ThingBitsMap[i].Name); - putc (ThingBitsMap[i].BitNum | (ThingBitsMap[i].FlagNum<<5), Dest); - } -} - -static int sortfunc4 (const void *a, const void *b) -{ - return ((struct RenderStylesE *)a)->Name - ((struct RenderStylesE *)b)->Name; -} - -void WriteRenderStyles () -{ - int i; - - WriteLabel ("REND"); - WriteWord (RenderStylesSize); - // More warnings; ignore - qsort (RenderStylesMap, RenderStylesSize, sizeof(*RenderStylesMap), sortfunc4); - for (i = 0; i < RenderStylesSize; i++) - { - WriteWord (RenderStylesMap[i].Name); - putc (RenderStylesMap[i].StyleNum, Dest); - } -} +%include{ +#include +#include "dehsupp.h" +} + +%token_type {struct Token} + +%token_destructor { if ($$.string) free($$.string); } + +%left OR. +%left XOR. +%left AND. +%left MINUS PLUS. +%left MULTIPLY DIVIDE. +%left NEG. + +%left EOI. + +main ::= translation_unit. + +translation_unit ::= . /* empty */ +translation_unit ::= translation_unit external_declaration. + +external_declaration ::= print_statement. +external_declaration ::= actions_def. +external_declaration ::= org_heights_def. +external_declaration ::= action_list_def. +external_declaration ::= codep_conv_def. +external_declaration ::= org_spr_names_def. +external_declaration ::= state_map_def. +external_declaration ::= sound_map_def. +external_declaration ::= info_names_def. +external_declaration ::= thing_bits_def. +external_declaration ::= render_styles_def. + +print_statement ::= PRINT LPAREN print_list RPAREN. +{ + printf ("\n"); +} + +print_list ::= . /* EMPTY */ +print_list ::= print_item. +print_list ::= print_item COMMA print_list. + +print_item ::= STRING(A). { printf ("%s", A.string); } +print_item ::= exp(A). { printf ("%d", A); } +print_item ::= ENDL. { printf ("\n"); } + +%type exp {int} +exp(A) ::= NUM(B). { A = B.val; } +exp(A) ::= exp(B) PLUS exp(C). { A = B + C; } +exp(A) ::= exp(B) MINUS exp(C). { A = B - C; } +exp(A) ::= exp(B) MULTIPLY exp(C). { A = B * C; } +exp(A) ::= exp(B) DIVIDE exp(C). { A = B / C; } +exp(A) ::= exp(B) OR exp(C). { A = B | C; } +exp(A) ::= exp(B) AND exp(C). { A = B & C; } +exp(A) ::= exp(B) XOR exp(C). { A = B ^ C; } +exp(A) ::= MINUS exp(B). [NEG] { A = -B; } +exp(A) ::= LPAREN exp(B) RPAREN. { A = B; } + + +actions_def ::= Actions LBRACE actions_list RBRACE SEMICOLON. + +actions_list ::= . /* empty */ +actions_list ::= SYM(A). { AddAction (A.string); } +actions_list ::= actions_list COMMA SYM(A). { AddAction (A.string); } + + +org_heights_def ::= OrgHeights LBRACE org_heights_list RBRACE SEMICOLON. + +org_heights_list ::= . /* empty */ +org_heights_list ::= exp(A). { AddHeight (A); } +org_heights_list ::= org_heights_list COMMA exp(A). { AddHeight (A); } + + +action_list_def ::= ActionList LBRACE action_list_list RBARCE SEMICOLON. + +action_list_list ::= . /* empty */ +action_list_list ::= SYM(A). { AddActionMap (A.string); } +action_list_list ::= action_list_list COMMA SYM(A). { AddActionMap (A.string); } + + +codep_conv_def ::= CodePConv LBRACE codep_conv_list RBRACE SEMICOLON. + +codep_conv_list ::= . /* empty */ +codep_conv_list ::= exp(A). { AddCodeP (A); } +codep_conv_list ::= codep_conv_list COMMA exp(A). { AddCodeP (A); } + + +org_spr_names_def ::= OrgSprNames LBRACE org_spr_names_list RBRACE SEMICOLON. + +org_spr_names_list ::= . /* empty */ +org_spr_names_list ::= SYM(A). { AddSpriteName (A.string); } +org_spr_names_list ::= org_spr_names_list COMMA SYM(A). { AddSpriteName (A.string); } + + +state_map_def ::= StateMap LBRACE state_map_list RBRACE SEMICOLON. + +state_map_list ::= . /* empty */ +state_map_list ::= state_map_entry. +state_map_list ::= state_map_list COMMA state_map_entry. + +state_map_entry ::= SYM(A) COMMA state_type(B) COMMA exp(C). { AddStateMap (A.string, B, C); } + +%type state_type {int} +state_type(A) ::= FirstState. { A = 0; } +state_type(A) ::= SpawnState. { A = 1; } +state_type(A) ::= DeathState. { A = 2; } + + +sound_map_def ::= SoundMap LBRACE sound_map_list RBRACE SEMICOLON. + +sound_map_list ::= . /* empty */ +sound_map_list ::= STRING(A). { AddSoundMap (A.string); } +sound_map_list ::= sound_map_list COMMA STRING(A). { AddSoundMap (A.string); } + + +info_names_def ::= InfoNames LBRACE info_names_list RBRACE SEMICOLON. + +info_names_list ::= . /* empty */ +info_names_list ::= SYM(A). { AddInfoName (A.string); } +info_names_list ::= info_names_list COMMA SYM(A). { AddInfoName (A.string); } + + +thing_bits_def ::= ThingBits LBRACE thing_bits_list RBRACE SEMICOLON. + +thing_bits_list ::= . /* empty */ +thing_bits_list ::= thing_bits_entry. +thing_bits_list ::= thing_bits_list COMMA thing_bits_entry. + +thing_bits_entry ::= exp(A) COMMA exp(B) COMMA SYM(C). { AddThingBits (C.string, A, B); } + + +render_styles_def ::= RenderStyles LBRACE render_styles_list RBRACE SEMICOLON. + +render_styles_list ::= . /* empty */ +render_styles_list ::= render_styles_entry. +render_styles_list ::= render_styles_list COMMA render_styles_entry. + +render_styles_entry ::= exp(A) COMMA SYM(B). { AddRenderStyle (B.string, A); } diff --git a/tools/dehsupp/scanner.c b/tools/dehsupp/scanner.c new file mode 100644 index 000000000..c44b2df88 --- /dev/null +++ b/tools/dehsupp/scanner.c @@ -0,0 +1,1085 @@ +/* Generated by re2c 0.10.3 on Wed May 24 23:26:39 2006 */ +#line 1 "scanner.re" +#include +#include +#include +#include "dehsupp.h" + +#define BSIZE 8192 + +#define YYCTYPE uchar +#define YYCURSOR cursor +#define YYLIMIT s->lim +#define YYMARKER s->ptr +#define YYFILL(n) {cursor = fill(s, cursor);} + +#define RET(i) {s->cur = cursor; return i;} + +uchar *fill(Scanner *s, uchar *cursor) +{ + if(!s->eof) + { + ptrdiff_t cnt = s->tok - s->bot; + if(cnt) + { + memcpy(s->bot, s->tok, s->lim - s->tok); + s->tok = s->bot; + s->ptr -= cnt; + cursor -= cnt; + s->pos -= cnt; + s->lim -= cnt; + } + if((s->top - s->lim) < BSIZE) + { + uchar *buf = (uchar*) malloc(((s->lim - s->bot) + BSIZE)*sizeof(uchar)); + memcpy(buf, s->tok, s->lim - s->tok); + s->tok = buf; + s->ptr = &buf[s->ptr - s->bot]; + cursor = &buf[cursor - s->bot]; + s->pos = &buf[s->pos - s->bot]; + s->lim = &buf[s->lim - s->bot]; + s->top = &s->lim[BSIZE]; + free(s->bot); + s->bot = buf; + } + if((cnt = fread((char*) s->lim, 1, BSIZE, s->fd)) != BSIZE) + { + s->eof = &s->lim[cnt]; *(s->eof)++ = '\n'; + } + s->lim += cnt; + } + return cursor; +} + +int scan(Scanner *s) +{ + uchar *cursor = s->cur; +std: + s->tok = cursor; +#line 64 "scanner.re" + + + +#line 64 "scanner.c" +{ + YYCTYPE yych; + unsigned int yyaccept = 0; + + if((YYLIMIT - YYCURSOR) < 13) YYFILL(13); + yych = *YYCURSOR; + switch(yych){ + case 0x09: + case 0x0B: + case 0x0C: + case ' ': goto yy22; + case 0x0A: goto yy46; + case '"': goto yy20; + case '&': goto yy28; + case '(': goto yy36; + case '*': goto yy34; + case '+': goto yy32; + case ',': goto yy40; + case '-': goto yy30; + case '/': goto yy2; + case '0': goto yy17; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy19; + case ';': goto yy44; + case 'A': goto yy7; + case 'B': + case 'E': + case 'G': + case 'H': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'P': + case 'Q': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy16; + case 'C': goto yy9; + case 'D': goto yy13; + case 'F': goto yy14; + case 'I': goto yy11; + case 'O': goto yy8; + case 'R': goto yy15; + case 'S': goto yy10; + case 'T': goto yy12; + case '^': goto yy26; + case 'e': goto yy4; + case 'p': goto yy6; + case '{': goto yy42; + case '|': goto yy24; + case '}': goto yy38; + default: goto yy48; + } +yy2: + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + if(yych == '*') goto yy198; + if(yych == '/') goto yy196; +yy3: +#line 107 "scanner.re" + { RET(DIVIDE); } +#line 163 "scanner.c" +yy4: + ++YYCURSOR; + if((yych = *YYCURSOR) == 'n') goto yy192; + goto yy70; +yy5: +#line 91 "scanner.re" + { RET(SYM); } +#line 171 "scanner.c" +yy6: + yych = *++YYCURSOR; + if(yych == 'r') goto yy187; + goto yy70; +yy7: + yych = *++YYCURSOR; + if(yych == 'c') goto yy175; + goto yy70; +yy8: + yych = *++YYCURSOR; + if(yych == 'r') goto yy156; + goto yy70; +yy9: + yych = *++YYCURSOR; + if(yych == 'o') goto yy147; + goto yy70; +yy10: + yych = *++YYCURSOR; + if(yych <= 'p') { + if(yych <= 'n') goto yy70; + if(yych <= 'o') goto yy121; + goto yy122; + } else { + if(yych == 't') goto yy123; + goto yy70; + } +yy11: + yych = *++YYCURSOR; + if(yych == 'n') goto yy112; + goto yy70; +yy12: + yych = *++YYCURSOR; + if(yych == 'h') goto yy103; + goto yy70; +yy13: + yych = *++YYCURSOR; + if(yych == 'e') goto yy93; + goto yy70; +yy14: + yych = *++YYCURSOR; + if(yych == 'i') goto yy83; + goto yy70; +yy15: + yych = *++YYCURSOR; + if(yych == 'e') goto yy71; + goto yy70; +yy16: + yych = *++YYCURSOR; + goto yy70; +yy17: + yyaccept = 1; + yych = *(YYMARKER = ++YYCURSOR); + if(yych == 'X') goto yy66; + if(yych == 'x') goto yy66; + goto yy65; +yy18: +#line 94 "scanner.re" + { RET(NUM); } +#line 230 "scanner.c" +yy19: + yych = *++YYCURSOR; + goto yy63; +yy20: + yyaccept = 2; + yych = *(YYMARKER = ++YYCURSOR); + if(yych != 0x0A) goto yy52; +yy21: +#line 124 "scanner.re" + { + printf("unexpected character: %c\n", *s->tok); + goto std; + } +#line 244 "scanner.c" +yy22: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy50; +yy23: +#line 99 "scanner.re" + { goto std; } +#line 252 "scanner.c" +yy24: + ++YYCURSOR; +#line 101 "scanner.re" + { RET(OR); } +#line 257 "scanner.c" +yy26: + ++YYCURSOR; +#line 102 "scanner.re" + { RET(XOR); } +#line 262 "scanner.c" +yy28: + ++YYCURSOR; +#line 103 "scanner.re" + { RET(AND); } +#line 267 "scanner.c" +yy30: + ++YYCURSOR; +#line 104 "scanner.re" + { RET(MINUS); } +#line 272 "scanner.c" +yy32: + ++YYCURSOR; +#line 105 "scanner.re" + { RET(PLUS); } +#line 277 "scanner.c" +yy34: + ++YYCURSOR; +#line 106 "scanner.re" + { RET(MULTIPLY); } +#line 282 "scanner.c" +yy36: + ++YYCURSOR; +#line 108 "scanner.re" + { RET(LPAREN); } +#line 287 "scanner.c" +yy38: + ++YYCURSOR; +#line 109 "scanner.re" + { RET(RPAREN); } +#line 292 "scanner.c" +yy40: + ++YYCURSOR; +#line 110 "scanner.re" + { RET(COMMA); } +#line 297 "scanner.c" +yy42: + ++YYCURSOR; +#line 111 "scanner.re" + { RET(LBRACE); } +#line 302 "scanner.c" +yy44: + ++YYCURSOR; +#line 113 "scanner.re" + { RET(SEMICOLON); } +#line 307 "scanner.c" +yy46: + ++YYCURSOR; +#line 117 "scanner.re" + { + if(cursor == s->eof) RET(EOI); + s->pos = cursor; s->line++; + goto std; + } +#line 316 "scanner.c" +yy48: + yych = *++YYCURSOR; + goto yy21; +yy49: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy50: + if(yych <= 0x0A) { + if(yych == 0x09) goto yy49; + goto yy23; + } else { + if(yych <= 0x0C) goto yy49; + if(yych == ' ') goto yy49; + goto yy23; + } +yy51: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy52: + if(yych <= '!') { + if(yych != 0x0A) goto yy51; + } else { + if(yych <= '"') goto yy55; + if(yych == '\\') goto yy54; + goto yy51; + } +yy53: + YYCURSOR = YYMARKER; + if(yyaccept <= 1) { + if(yyaccept <= 0) { + goto yy3; + } else { + goto yy18; + } + } else { + goto yy21; + } +yy54: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + if(yych <= 'b') { + if(yych <= '7') { + if(yych <= '&') { + if(yych == '"') goto yy51; + goto yy53; + } else { + if(yych <= '\'') goto yy51; + if(yych <= '/') goto yy53; + goto yy58; + } + } else { + if(yych <= '[') { + if(yych == '?') goto yy51; + goto yy53; + } else { + if(yych <= '\\') goto yy51; + if(yych <= '`') goto yy53; + goto yy51; + } + } + } else { + if(yych <= 'r') { + if(yych <= 'm') { + if(yych == 'f') goto yy51; + goto yy53; + } else { + if(yych <= 'n') goto yy51; + if(yych <= 'q') goto yy53; + goto yy51; + } + } else { + if(yych <= 'u') { + if(yych == 't') goto yy51; + goto yy53; + } else { + if(yych <= 'v') goto yy51; + if(yych == 'x') goto yy57; + goto yy53; + } + } + } +yy55: + ++YYCURSOR; +#line 97 "scanner.re" + { RET(STRING); } +#line 405 "scanner.c" +yy57: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + if(yych <= '@') { + if(yych <= '/') goto yy53; + if(yych <= '9') goto yy60; + goto yy53; + } else { + if(yych <= 'F') goto yy60; + if(yych <= '`') goto yy53; + if(yych <= 'f') goto yy60; + goto yy53; + } +yy58: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + if(yych <= '"') { + if(yych == 0x0A) goto yy53; + if(yych <= '!') goto yy51; + goto yy55; + } else { + if(yych <= '7') { + if(yych <= '/') goto yy51; + goto yy58; + } else { + if(yych == '\\') goto yy54; + goto yy51; + } + } +yy60: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + if(yych <= '9') { + if(yych <= '!') { + if(yych == 0x0A) goto yy53; + goto yy51; + } else { + if(yych <= '"') goto yy55; + if(yych <= '/') goto yy51; + goto yy60; + } + } else { + if(yych <= '[') { + if(yych <= '@') goto yy51; + if(yych <= 'F') goto yy60; + goto yy51; + } else { + if(yych <= '\\') goto yy54; + if(yych <= '`') goto yy51; + if(yych <= 'f') goto yy60; + goto yy51; + } + } +yy62: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy63: + if(yych <= '/') goto yy18; + if(yych <= '9') goto yy62; + goto yy18; +yy64: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy65: + if(yych <= '/') goto yy18; + if(yych <= '9') goto yy64; + goto yy18; +yy66: + yych = *++YYCURSOR; + if(yych <= '@') { + if(yych <= '/') goto yy53; + if(yych >= ':') goto yy53; + } else { + if(yych <= 'F') goto yy67; + if(yych <= '`') goto yy53; + if(yych >= 'g') goto yy53; + } +yy67: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + if(yych <= '@') { + if(yych <= '/') goto yy18; + if(yych <= '9') goto yy67; + goto yy18; + } else { + if(yych <= 'F') goto yy67; + if(yych <= '`') goto yy18; + if(yych <= 'f') goto yy67; + goto yy18; + } +yy69: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy70: + if(yych <= 'Z') { + if(yych <= '/') goto yy5; + if(yych <= '9') goto yy69; + if(yych <= '@') goto yy5; + goto yy69; + } else { + if(yych <= '_') { + if(yych <= '^') goto yy5; + goto yy69; + } else { + if(yych <= '`') goto yy5; + if(yych <= 'z') goto yy69; + goto yy5; + } + } +yy71: + yych = *++YYCURSOR; + if(yych != 'n') goto yy70; + yych = *++YYCURSOR; + if(yych != 'd') goto yy70; + yych = *++YYCURSOR; + if(yych != 'e') goto yy70; + yych = *++YYCURSOR; + if(yych != 'r') goto yy70; + yych = *++YYCURSOR; + if(yych != 'S') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'y') goto yy70; + yych = *++YYCURSOR; + if(yych != 'l') goto yy70; + yych = *++YYCURSOR; + if(yych != 'e') goto yy70; + yych = *++YYCURSOR; + if(yych != 's') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy82; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy82; + if(yych <= 'z') goto yy69; + } + } +yy82: +#line 89 "scanner.re" + { RET(RenderStyles); } +#line 559 "scanner.c" +yy83: + yych = *++YYCURSOR; + if(yych != 'r') goto yy70; + yych = *++YYCURSOR; + if(yych != 's') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'S') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'a') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'e') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy92; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy92; + if(yych <= 'z') goto yy69; + } + } +yy92: +#line 88 "scanner.re" + { RET(FirstState); } +#line 593 "scanner.c" +yy93: + yych = *++YYCURSOR; + if(yych != 'a') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'h') goto yy70; + yych = *++YYCURSOR; + if(yych != 'S') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'a') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'e') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy102; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy102; + if(yych <= 'z') goto yy69; + } + } +yy102: +#line 86 "scanner.re" + { RET(DeathState); } +#line 627 "scanner.c" +yy103: + yych = *++YYCURSOR; + if(yych != 'i') goto yy70; + yych = *++YYCURSOR; + if(yych != 'n') goto yy70; + yych = *++YYCURSOR; + if(yych != 'g') goto yy70; + yych = *++YYCURSOR; + if(yych != 'B') goto yy70; + yych = *++YYCURSOR; + if(yych != 'i') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 's') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy111; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy111; + if(yych <= 'z') goto yy69; + } + } +yy111: +#line 85 "scanner.re" + { RET(ThingBits); } +#line 659 "scanner.c" +yy112: + yych = *++YYCURSOR; + if(yych != 'f') goto yy70; + yych = *++YYCURSOR; + if(yych != 'o') goto yy70; + yych = *++YYCURSOR; + if(yych != 'N') goto yy70; + yych = *++YYCURSOR; + if(yych != 'a') goto yy70; + yych = *++YYCURSOR; + if(yych != 'm') goto yy70; + yych = *++YYCURSOR; + if(yych != 'e') goto yy70; + yych = *++YYCURSOR; + if(yych != 's') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy120; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy120; + if(yych <= 'z') goto yy69; + } + } +yy120: +#line 84 "scanner.re" + { RET(InfoNames); } +#line 691 "scanner.c" +yy121: + yych = *++YYCURSOR; + if(yych == 'u') goto yy140; + goto yy70; +yy122: + yych = *++YYCURSOR; + if(yych == 'a') goto yy131; + goto yy70; +yy123: + yych = *++YYCURSOR; + if(yych != 'a') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'e') goto yy70; + yych = *++YYCURSOR; + if(yych != 'M') goto yy70; + yych = *++YYCURSOR; + if(yych != 'a') goto yy70; + yych = *++YYCURSOR; + if(yych != 'p') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy130; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy130; + if(yych <= 'z') goto yy69; + } + } +yy130: +#line 82 "scanner.re" + { RET(StateMap); } +#line 729 "scanner.c" +yy131: + yych = *++YYCURSOR; + if(yych != 'w') goto yy70; + yych = *++YYCURSOR; + if(yych != 'n') goto yy70; + yych = *++YYCURSOR; + if(yych != 'S') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'a') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'e') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy139; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy139; + if(yych <= 'z') goto yy69; + } + } +yy139: +#line 87 "scanner.re" + { RET(SpawnState); } +#line 761 "scanner.c" +yy140: + yych = *++YYCURSOR; + if(yych != 'n') goto yy70; + yych = *++YYCURSOR; + if(yych != 'd') goto yy70; + yych = *++YYCURSOR; + if(yych != 'M') goto yy70; + yych = *++YYCURSOR; + if(yych != 'a') goto yy70; + yych = *++YYCURSOR; + if(yych != 'p') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy146; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy146; + if(yych <= 'z') goto yy69; + } + } +yy146: +#line 83 "scanner.re" + { RET(SoundMap); } +#line 789 "scanner.c" +yy147: + yych = *++YYCURSOR; + if(yych != 'd') goto yy70; + yych = *++YYCURSOR; + if(yych != 'e') goto yy70; + yych = *++YYCURSOR; + if(yych != 'P') goto yy70; + yych = *++YYCURSOR; + if(yych != 'C') goto yy70; + yych = *++YYCURSOR; + if(yych != 'o') goto yy70; + yych = *++YYCURSOR; + if(yych != 'n') goto yy70; + yych = *++YYCURSOR; + if(yych != 'v') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy155; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy155; + if(yych <= 'z') goto yy69; + } + } +yy155: +#line 80 "scanner.re" + { RET(CodePConv); } +#line 821 "scanner.c" +yy156: + yych = *++YYCURSOR; + if(yych != 'g') goto yy70; + yych = *++YYCURSOR; + if(yych == 'H') goto yy158; + if(yych == 'S') goto yy159; + goto yy70; +yy158: + yych = *++YYCURSOR; + if(yych == 'e') goto yy168; + goto yy70; +yy159: + yych = *++YYCURSOR; + if(yych != 'p') goto yy70; + yych = *++YYCURSOR; + if(yych != 'r') goto yy70; + yych = *++YYCURSOR; + if(yych != 'N') goto yy70; + yych = *++YYCURSOR; + if(yych != 'a') goto yy70; + yych = *++YYCURSOR; + if(yych != 'm') goto yy70; + yych = *++YYCURSOR; + if(yych != 'e') goto yy70; + yych = *++YYCURSOR; + if(yych != 's') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy167; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy167; + if(yych <= 'z') goto yy69; + } + } +yy167: +#line 81 "scanner.re" + { RET(OrgSprNames); } +#line 864 "scanner.c" +yy168: + yych = *++YYCURSOR; + if(yych != 'i') goto yy70; + yych = *++YYCURSOR; + if(yych != 'g') goto yy70; + yych = *++YYCURSOR; + if(yych != 'h') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 's') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy174; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy174; + if(yych <= 'z') goto yy69; + } + } +yy174: +#line 78 "scanner.re" + { RET(OrgHeights); } +#line 892 "scanner.c" +yy175: + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + yych = *++YYCURSOR; + if(yych != 'i') goto yy70; + yych = *++YYCURSOR; + if(yych != 'o') goto yy70; + yych = *++YYCURSOR; + if(yych != 'n') goto yy70; + yych = *++YYCURSOR; + if(yych == 'L') goto yy182; + if(yych != 's') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy181; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy181; + if(yych <= 'z') goto yy69; + } + } +yy181: +#line 77 "scanner.re" + { RET(Actions); } +#line 921 "scanner.c" +yy182: + yych = *++YYCURSOR; + if(yych != 'i') goto yy70; + yych = *++YYCURSOR; + if(yych != 's') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy186; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy186; + if(yych <= 'z') goto yy69; + } + } +yy186: +#line 79 "scanner.re" + { RET(ActionList); } +#line 945 "scanner.c" +yy187: + yych = *++YYCURSOR; + if(yych != 'i') goto yy70; + yych = *++YYCURSOR; + if(yych != 'n') goto yy70; + yych = *++YYCURSOR; + if(yych != 't') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy191; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy191; + if(yych <= 'z') goto yy69; + } + } +yy191: +#line 76 "scanner.re" + { RET(PRINT); } +#line 969 "scanner.c" +yy192: + yych = *++YYCURSOR; + if(yych != 'd') goto yy70; + yych = *++YYCURSOR; + if(yych != 'l') goto yy70; + ++YYCURSOR; + if((yych = *YYCURSOR) <= 'Z') { + if(yych <= '/') goto yy195; + if(yych <= '9') goto yy69; + if(yych >= 'A') goto yy69; + } else { + if(yych <= '_') { + if(yych >= '_') goto yy69; + } else { + if(yych <= '`') goto yy195; + if(yych <= 'z') goto yy69; + } + } +yy195: +#line 75 "scanner.re" + { RET(ENDL); } +#line 991 "scanner.c" +yy196: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + if(yych == 0x0A) goto yy200; + goto yy196; +yy198: + ++YYCURSOR; +#line 67 "scanner.re" + { goto comment; } +#line 1002 "scanner.c" +yy200: + ++YYCURSOR; +#line 69 "scanner.re" + { + if(cursor == s->eof) RET(EOI); + s->tok = s->pos = cursor; s->line++; + goto std; + } +#line 1011 "scanner.c" +} +#line 128 "scanner.re" + + +comment: + +#line 1018 "scanner.c" +{ + YYCTYPE yych; + if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + if(yych == 0x0A) goto yy206; + if(yych != '*') goto yy208; + ++YYCURSOR; + if((yych = *YYCURSOR) == '/') goto yy209; +yy205: +#line 139 "scanner.re" + { goto comment; } +#line 1030 "scanner.c" +yy206: + ++YYCURSOR; +#line 134 "scanner.re" + { + if(cursor == s->eof) RET(EOI); + s->tok = s->pos = cursor; s->line++; + goto comment; + } +#line 1039 "scanner.c" +yy208: + yych = *++YYCURSOR; + goto yy205; +yy209: + ++YYCURSOR; +#line 132 "scanner.re" + { goto std; } +#line 1047 "scanner.c" +} +#line 140 "scanner.re" + +} + +int lex(Scanner *s, struct Token *tok) +{ + int tokentype = scan(s); + char *p, *q; + + tok->val = 0; + tok->string = NULL; + + switch (tokentype) + { + case NUM: + tok->val = strtol((char *)s->tok, NULL, 0); + break; + + case STRING: + tok->string = (char *)malloc(s->cur - s->tok - 1); + strncpy(tok->string, (char *)s->tok + 1, s->cur - s->tok - 2); + tok->string[s->cur - s->tok - 2] = '\0'; + for (p = q = tok->string; *p; ++p, ++q) + { + if (p[0] == '\\' && p[1] == '\\') + ++p; + *q = *p; + } + break; + + case SYM: + tok->string = (char *)malloc(s->cur - s->tok + 1); + strncpy(tok->string, (char *)s->tok, s->cur - s->tok); + tok->string[s->cur - s->tok] = '\0'; + break; + } + return tokentype; +} diff --git a/tools/dehsupp/scanner.re b/tools/dehsupp/scanner.re new file mode 100644 index 000000000..20baccb94 --- /dev/null +++ b/tools/dehsupp/scanner.re @@ -0,0 +1,176 @@ +#include +#include +#include +#include "dehsupp.h" + +#define BSIZE 8192 + +#define YYCTYPE uchar +#define YYCURSOR cursor +#define YYLIMIT s->lim +#define YYMARKER s->ptr +#define YYFILL(n) {cursor = fill(s, cursor);} + +#define RET(i) {s->cur = cursor; return i;} + +uchar *fill(Scanner *s, uchar *cursor) +{ + if(!s->eof) + { + ptrdiff_t cnt = s->tok - s->bot; + if(cnt) + { + memcpy(s->bot, s->tok, s->lim - s->tok); + s->tok = s->bot; + s->ptr -= cnt; + cursor -= cnt; + s->pos -= cnt; + s->lim -= cnt; + } + if((s->top - s->lim) < BSIZE) + { + uchar *buf = (uchar*) malloc(((s->lim - s->bot) + BSIZE)*sizeof(uchar)); + memcpy(buf, s->tok, s->lim - s->tok); + s->tok = buf; + s->ptr = &buf[s->ptr - s->bot]; + cursor = &buf[cursor - s->bot]; + s->pos = &buf[s->pos - s->bot]; + s->lim = &buf[s->lim - s->bot]; + s->top = &s->lim[BSIZE]; + free(s->bot); + s->bot = buf; + } + if((cnt = fread((char*) s->lim, 1, BSIZE, s->fd)) != BSIZE) + { + s->eof = &s->lim[cnt]; *(s->eof)++ = '\n'; + } + s->lim += cnt; + } + return cursor; +} + +int scan(Scanner *s) +{ + uchar *cursor = s->cur; +std: + s->tok = cursor; +/*!re2c +any = [\000-\377]; +O = [0-7]; +D = [0-9]; +L = [a-zA-Z_]; +H = [a-fA-F0-9]; +ESC = [\\] ([abfnrtv?'"\\] | "x" H+ | O+); +*/ + +/*!re2c + "/*" { goto comment; } /* C comment */ + "//" (any\"\n")* "\n" /* C++ comment */ + { + if(cursor == s->eof) RET(EOI); + s->tok = s->pos = cursor; s->line++; + goto std; + } + + "endl" { RET(ENDL); } + "print" { RET(PRINT); } + "Actions" { RET(Actions); } + "OrgHeights" { RET(OrgHeights); } + "ActionList" { RET(ActionList); } + "CodePConv" { RET(CodePConv); } + "OrgSprNames" { RET(OrgSprNames); } + "StateMap" { RET(StateMap); } + "SoundMap" { RET(SoundMap); } + "InfoNames" { RET(InfoNames); } + "ThingBits" { RET(ThingBits); } + "DeathState" { RET(DeathState); } + "SpawnState" { RET(SpawnState); } + "FirstState" { RET(FirstState); } + "RenderStyles" { RET(RenderStyles); } + + L (L|D)* { RET(SYM); } + + ("0" [xX] H+) | ("0" D+) | (D+) + { RET(NUM); } + + (["] (ESC|any\[\n\\"])* ["]) + { RET(STRING); } + + [ \t\v\f]+ { goto std; } + + "|" { RET(OR); } + "^" { RET(XOR); } + "&" { RET(AND); } + "-" { RET(MINUS); } + "+" { RET(PLUS); } + "*" { RET(MULTIPLY); } + "/" { RET(DIVIDE); } + "(" { RET(LPAREN); } + "}" { RET(RPAREN); } + "," { RET(COMMA); } + "{" { RET(LBRACE); } + "}" { RET(RBRACE); } + ";" { RET(SEMICOLON); } + + + "\n" + { + if(cursor == s->eof) RET(EOI); + s->pos = cursor; s->line++; + goto std; + } + + any + { + printf("unexpected character: %c\n", *s->tok); + goto std; + } +*/ + +comment: +/*!re2c + "*/" { goto std; } + "\n" + { + if(cursor == s->eof) RET(EOI); + s->tok = s->pos = cursor; s->line++; + goto comment; + } + any { goto comment; } +*/ +} + +int lex(Scanner *s, struct Token *tok) +{ + int tokentype = scan(s); + char *p, *q; + + tok->val = 0; + tok->string = NULL; + + switch (tokentype) + { + case NUM: + tok->val = strtol((char *)s->tok, NULL, 0); + break; + + case STRING: + tok->string = (char *)malloc(s->cur - s->tok - 1); + strncpy(tok->string, (char *)s->tok + 1, s->cur - s->tok - 2); + tok->string[s->cur - s->tok - 2] = '\0'; + for (p = q = tok->string; *p; ++p, ++q) + { + if (p[0] == '\\' && p[1] == '\\') + ++p; + *q = *p; + } + break; + + case SYM: + tok->string = (char *)malloc(s->cur - s->tok + 1); + strncpy(tok->string, (char *)s->tok, s->cur - s->tok); + tok->string[s->cur - s->tok] = '\0'; + break; + } + return tokentype; +} diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index 18652fbcf..86f7cf689 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -1,4588 +1,4755 @@ -/* -** This file contains all sources (including headers) to the LEMON -** LALR(1) parser generator. The sources have been combined into a -** single file to make it easy to include LEMON in the source tree -** and Makefile of another program. -** -** The author of this program disclaims copyright. -*/ -#include -#include -#include -#include -#include - -#ifndef __WIN32__ -# if defined(_WIN32) || defined(WIN32) -# define __WIN32__ -# endif -#endif - -/* #define PRIVATE static */ -#define PRIVATE - -#ifdef TEST -#define MAXRHS 5 /* Set low to exercise exception code */ -#else -#define MAXRHS 1000 -#endif - -char *msort(); - -/******** From the file "action.h" *************************************/ -struct action *Action_new(); -struct action *Action_sort(); - -/********* From the file "assert.h" ************************************/ -void myassert(); -#ifndef NDEBUG -# define assert(X) if(!(X))myassert(__FILE__,__LINE__) -#else -# define assert(X) -#endif - -/********** From the file "build.h" ************************************/ -void FindRulePrecedences(); -void FindFirstSets(); -void FindStates(); -void FindLinks(); -void FindFollowSets(); -void FindActions(); - -/********* From the file "configlist.h" *********************************/ -void Configlist_init(/* void */); -struct config *Configlist_add(/* struct rule *, int */); -struct config *Configlist_addbasis(/* struct rule *, int */); -void Configlist_closure(/* void */); -void Configlist_sort(/* void */); -void Configlist_sortbasis(/* void */); -struct config *Configlist_return(/* void */); -struct config *Configlist_basis(/* void */); -void Configlist_eat(/* struct config * */); -void Configlist_reset(/* void */); - -/********* From the file "error.h" ***************************************/ -void ErrorMsg(const char *, int,const char *, ...); - -/****** From the file "option.h" ******************************************/ -struct s_options { - enum { OPT_FLAG=1, OPT_INT, OPT_DBL, OPT_STR, - OPT_FFLAG, OPT_FINT, OPT_FDBL, OPT_FSTR} type; - char *label; - char *arg; - char *message; -}; -int OptInit(/* char**,struct s_options*,FILE* */); -int OptNArgs(/* void */); -char *OptArg(/* int */); -void OptErr(/* int */); -void OptPrint(/* void */); - -/******** From the file "parse.h" *****************************************/ -void Parse(/* struct lemon *lemp */); - -/********* From the file "plink.h" ***************************************/ -struct plink *Plink_new(/* void */); -void Plink_add(/* struct plink **, struct config * */); -void Plink_copy(/* struct plink **, struct plink * */); -void Plink_delete(/* struct plink * */); - -/********** From the file "report.h" *************************************/ -void Reprint(/* struct lemon * */); -void ReportOutput(/* struct lemon * */); -void ReportTable(/* struct lemon * */); -void ReportHeader(/* struct lemon * */); -void CompressTables(/* struct lemon * */); - -/********** From the file "set.h" ****************************************/ -void SetSize(/* int N */); /* All sets will be of size N */ -char *SetNew(/* void */); /* A new set for element 0..N */ -void SetFree(/* char* */); /* Deallocate a set */ - -int SetAdd(/* char*,int */); /* Add element to a set */ -int SetUnion(/* char *A,char *B */); /* A <- A U B, thru element N */ - -#define SetFind(X,Y) (X[Y]) /* True if Y is in set X */ - -/********** From the file "struct.h" *************************************/ -/* -** Principal data structures for the LEMON parser generator. -*/ - -typedef enum {B_FALSE=0, B_TRUE} Boolean; - -/* Symbols (terminals and nonterminals) of the grammar are stored -** in the following: */ -struct symbol { - char *name; /* Name of the symbol */ - int index; /* Index number for this symbol */ - enum { - TERMINAL, - NONTERMINAL - } type; /* Symbols are all either TERMINALS or NTs */ - struct rule *rule; /* Linked list of rules of this (if an NT) */ - struct symbol *fallback; /* fallback token in case this token doesn't parse */ - int prec; /* Precedence if defined (-1 otherwise) */ - enum e_assoc { - LEFT, - RIGHT, - NONE, - UNK - } assoc; /* Associativity if predecence is defined */ - char *firstset; /* First-set for all rules of this symbol */ - Boolean lambda; /* True if NT and can generate an empty string */ - char *destructor; /* Code which executes whenever this symbol is - ** popped from the stack during error processing */ - int destructorln; /* Line number of destructor code */ - char *datatype; /* The data type of information held by this - ** object. Only used if type==NONTERMINAL */ - int dtnum; /* The data type number. In the parser, the value - ** stack is a union. The .yy%d element of this - ** union is the correct data type for this object */ -}; - -/* Each production rule in the grammar is stored in the following -** structure. */ -struct rule { - struct symbol *lhs; /* Left-hand side of the rule */ - char *lhsalias; /* Alias for the LHS (NULL if none) */ - int ruleline; /* Line number for the rule */ - int nrhs; /* Number of RHS symbols */ - struct symbol **rhs; /* The RHS symbols */ - char **rhsalias; /* An alias for each RHS symbol (NULL if none) */ - int line; /* Line number at which code begins */ - char *code; /* The code executed when this rule is reduced */ - struct symbol *precsym; /* Precedence symbol for this rule */ - int index; /* An index number for this rule */ - Boolean canReduce; /* True if this rule is ever reduced */ - struct rule *nextlhs; /* Next rule with the same LHS */ - struct rule *next; /* Next rule in the global list */ -}; - -/* A configuration is a production rule of the grammar together with -** a mark (dot) showing how much of that rule has been processed so far. -** Configurations also contain a follow-set which is a list of terminal -** symbols which are allowed to immediately follow the end of the rule. -** Every configuration is recorded as an instance of the following: */ -struct config { - struct rule *rp; /* The rule upon which the configuration is based */ - int dot; /* The parse point */ - char *fws; /* Follow-set for this configuration only */ - struct plink *fplp; /* Follow-set forward propagation links */ - struct plink *bplp; /* Follow-set backwards propagation links */ - struct state *stp; /* Pointer to state which contains this */ - enum { - COMPLETE, /* The status is used during followset and */ - INCOMPLETE /* shift computations */ - } status; - struct config *next; /* Next configuration in the state */ - struct config *bp; /* The next basis configuration */ -}; - -/* Every shift or reduce operation is stored as one of the following */ -struct action { - struct symbol *sp; /* The look-ahead symbol */ - enum e_action { - SHIFT, - ACCEPT, - REDUCE, - ERROR, - CONFLICT, /* Was a reduce, but part of a conflict */ - SH_RESOLVED, /* Was a shift. Precedence resolved conflict */ - RD_RESOLVED, /* Was reduce. Precedence resolved conflict */ - NOT_USED /* Deleted by compression */ - } type; - union { - struct state *stp; /* The new state, if a shift */ - struct rule *rp; /* The rule, if a reduce */ - } x; - struct action *next; /* Next action for this state */ - struct action *collide; /* Next action with the same hash */ -}; - -/* Each state of the generated parser's finite state machine -** is encoded as an instance of the following structure. */ -struct state { - struct config *bp; /* The basis configurations for this state */ - struct config *cfp; /* All configurations in this set */ - int index; /* Sequencial number for this state */ - struct action *ap; /* Array of actions for this state */ - int nTknAct, nNtAct; /* Number of actions on terminals and nonterminals */ - int iTknOfst, iNtOfst; /* yy_action[] offset for terminals and nonterms */ - int iDflt; /* Default action */ -}; -#define NO_OFFSET (-2147483647) - -/* A followset propagation link indicates that the contents of one -** configuration followset should be propagated to another whenever -** the first changes. */ -struct plink { - struct config *cfp; /* The configuration to which linked */ - struct plink *next; /* The next propagate link */ -}; - -/* The state vector for the entire parser generator is recorded as -** follows. (LEMON uses no global variables and makes little use of -** static variables. Fields in the following structure can be thought -** of as begin global variables in the program.) */ -struct lemon { - struct state **sorted; /* Table of states sorted by state number */ - struct rule *rule; /* List of all rules */ - int nstate; /* Number of states */ - int nrule; /* Number of rules */ - int nsymbol; /* Number of terminal and nonterminal symbols */ - int nterminal; /* Number of terminal symbols */ - struct symbol **symbols; /* Sorted array of pointers to symbols */ - int errorcnt; /* Number of errors */ - struct symbol *errsym; /* The error symbol */ - char *name; /* Name of the generated parser */ - char *arg; /* Declaration of the 3th argument to parser */ - char *tokentype; /* Type of terminal symbols in the parser stack */ - char *vartype; /* The default type of non-terminal symbols */ - char *start; /* Name of the start symbol for the grammar */ - char *stacksize; /* Size of the parser stack */ - char *include; /* Code to put at the start of the C file */ - int includeln; /* Line number for start of include code */ - char *error; /* Code to execute when an error is seen */ - int errorln; /* Line number for start of error code */ - char *overflow; /* Code to execute on a stack overflow */ - int overflowln; /* Line number for start of overflow code */ - char *failure; /* Code to execute on parser failure */ - int failureln; /* Line number for start of failure code */ - char *accept; /* Code to execute when the parser excepts */ - int acceptln; /* Line number for the start of accept code */ - char *extracode; /* Code appended to the generated file */ - int extracodeln; /* Line number for the start of the extra code */ - char *tokendest; /* Code to execute to destroy token data */ - int tokendestln; /* Line number for token destroyer code */ - char *vardest; /* Code for the default non-terminal destructor */ - int vardestln; /* Line number for default non-term destructor code*/ - char *filename; /* Name of the input file */ - char *outname; /* Name of the current output file */ - char *tokenprefix; /* A prefix added to token names in the .h file */ - int nconflict; /* Number of parsing conflicts */ - int tablesize; /* Size of the parse tables */ - int basisflag; /* Print only basis configurations */ - int has_fallback; /* True if any %fallback is seen in the grammer */ - char *argv0; /* Name of the program */ -}; - -#define MemoryCheck(X) if((X)==0){ \ - extern void memory_error(); \ - memory_error(); \ -} - -/**************** From the file "table.h" *********************************/ -/* -** All code in this file has been automatically generated -** from a specification in the file -** "table.q" -** by the associative array code building program "aagen". -** Do not edit this file! Instead, edit the specification -** file, then rerun aagen. -*/ -/* -** Code for processing tables in the LEMON parser generator. -*/ - -/* Routines for handling a strings */ - -char *Strsafe(); - -void Strsafe_init(/* void */); -int Strsafe_insert(/* char * */); -char *Strsafe_find(/* char * */); - -/* Routines for handling symbols of the grammar */ - -struct symbol *Symbol_new(); -int Symbolcmpp(/* struct symbol **, struct symbol ** */); -void Symbol_init(/* void */); -int Symbol_insert(/* struct symbol *, char * */); -struct symbol *Symbol_find(/* char * */); -struct symbol *Symbol_Nth(/* int */); -int Symbol_count(/* */); -struct symbol **Symbol_arrayof(/* */); - -/* Routines to manage the state table */ - -int Configcmp(/* struct config *, struct config * */); -struct state *State_new(); -void State_init(/* void */); -int State_insert(/* struct state *, struct config * */); -struct state *State_find(/* struct config * */); -struct state **State_arrayof(/* */); - -/* Routines used for efficiency in Configlist_add */ - -void Configtable_init(/* void */); -int Configtable_insert(/* struct config * */); -struct config *Configtable_find(/* struct config * */); -void Configtable_clear(/* int(*)(struct config *) */); -/****************** From the file "action.c" *******************************/ -/* -** Routines processing parser actions in the LEMON parser generator. -*/ - -/* Allocate a new parser action */ -struct action *Action_new(){ - static struct action *freelist = 0; - struct action *new; - - if( freelist==0 ){ - int i; - int amt = 100; - freelist = (struct action *)malloc( sizeof(struct action)*amt ); - if( freelist==0 ){ - fprintf(stderr,"Unable to allocate memory for a new parser action."); - exit(1); - } - for(i=0; inext; - return new; -} - -/* Compare two actions */ -static int actioncmp(ap1,ap2) -struct action *ap1; -struct action *ap2; -{ - int rc; - rc = ap1->sp->index - ap2->sp->index; - if( rc==0 ) rc = (int)ap1->type - (int)ap2->type; - if( rc==0 ){ - assert( ap1->type==REDUCE || ap1->type==RD_RESOLVED || ap1->type==CONFLICT); - assert( ap2->type==REDUCE || ap2->type==RD_RESOLVED || ap2->type==CONFLICT); - rc = ap1->x.rp->index - ap2->x.rp->index; - } - return rc; -} - -/* Sort parser actions */ -struct action *Action_sort(ap) -struct action *ap; -{ - ap = (struct action *)msort((char *)ap,(char **)&ap->next,actioncmp); - return ap; -} - -void Action_add(app,type,sp,arg) -struct action **app; -enum e_action type; -struct symbol *sp; -char *arg; -{ - struct action *new; - new = Action_new(); - new->next = *app; - *app = new; - new->type = type; - new->sp = sp; - if( type==SHIFT ){ - new->x.stp = (struct state *)arg; - }else{ - new->x.rp = (struct rule *)arg; - } -} -/********************** New code to implement the "acttab" module ***********/ -/* -** This module implements routines use to construct the yy_action[] table. -*/ - -/* -** The state of the yy_action table under construction is an instance of -** the following structure -*/ -typedef struct acttab acttab; -struct acttab { - int nAction; /* Number of used slots in aAction[] */ - int nActionAlloc; /* Slots allocated for aAction[] */ - struct { - int lookahead; /* Value of the lookahead token */ - int action; /* Action to take on the given lookahead */ - } *aAction, /* The yy_action[] table under construction */ - *aLookahead; /* A single new transaction set */ - int mnLookahead; /* Minimum aLookahead[].lookahead */ - int mnAction; /* Action associated with mnLookahead */ - int mxLookahead; /* Maximum aLookahead[].lookahead */ - int nLookahead; /* Used slots in aLookahead[] */ - int nLookaheadAlloc; /* Slots allocated in aLookahead[] */ -}; - -/* Return the number of entries in the yy_action table */ -#define acttab_size(X) ((X)->nAction) - -/* The value for the N-th entry in yy_action */ -#define acttab_yyaction(X,N) ((X)->aAction[N].action) - -/* The value for the N-th entry in yy_lookahead */ -#define acttab_yylookahead(X,N) ((X)->aAction[N].lookahead) - -/* Free all memory associated with the given acttab */ -void acttab_free(acttab *p){ - free( p->aAction ); - free( p->aLookahead ); - free( p ); -} - -/* Allocate a new acttab structure */ -acttab *acttab_alloc(void){ - acttab *p = malloc( sizeof(*p) ); - if( p==0 ){ - fprintf(stderr,"Unable to allocate memory for a new acttab."); - exit(1); - } - memset(p, 0, sizeof(*p)); - return p; -} - -/* Add a new action to the current transaction set -*/ -void acttab_action(acttab *p, int lookahead, int action){ - if( p->nLookahead>=p->nLookaheadAlloc ){ - p->nLookaheadAlloc += 25; - p->aLookahead = realloc( p->aLookahead, - sizeof(p->aLookahead[0])*p->nLookaheadAlloc ); - if( p->aLookahead==0 ){ - fprintf(stderr,"malloc failed\n"); - exit(1); - } - } - if( p->nLookahead==0 ){ - p->mxLookahead = lookahead; - p->mnLookahead = lookahead; - p->mnAction = action; - }else{ - if( p->mxLookaheadmxLookahead = lookahead; - if( p->mnLookahead>lookahead ){ - p->mnLookahead = lookahead; - p->mnAction = action; - } - } - p->aLookahead[p->nLookahead].lookahead = lookahead; - p->aLookahead[p->nLookahead].action = action; - p->nLookahead++; -} - -/* -** Add the transaction set built up with prior calls to acttab_action() -** into the current action table. Then reset the transaction set back -** to an empty set in preparation for a new round of acttab_action() calls. -** -** Return the offset into the action table of the new transaction. -*/ -int acttab_insert(acttab *p){ - int i, j, k, n; - assert( p->nLookahead>0 ); - - /* Make sure we have enough space to hold the expanded action table - ** in the worst case. The worst case occurs if the transaction set - ** must be appended to the current action table - */ - n = p->mxLookahead + 1; - if( p->nAction + n >= p->nActionAlloc ){ - int oldAlloc = p->nActionAlloc; - p->nActionAlloc = p->nAction + n + p->nActionAlloc + 20; - p->aAction = realloc( p->aAction, - sizeof(p->aAction[0])*p->nActionAlloc); - if( p->aAction==0 ){ - fprintf(stderr,"malloc failed\n"); - exit(1); - } - for(i=oldAlloc; inActionAlloc; i++){ - p->aAction[i].lookahead = -1; - p->aAction[i].action = -1; - } - } - - /* Scan the existing action table looking for an offset where we can - ** insert the current transaction set. Fall out of the loop when that - ** offset is found. In the worst case, we fall out of the loop when - ** i reaches p->nAction, which means we append the new transaction set. - ** - ** i is the index in p->aAction[] where p->mnLookahead is inserted. - */ - for(i=0; inAction+p->mnLookahead; i++){ - if( p->aAction[i].lookahead<0 ){ - for(j=0; jnLookahead; j++){ - k = p->aLookahead[j].lookahead - p->mnLookahead + i; - if( k<0 ) break; - if( p->aAction[k].lookahead>=0 ) break; - } - if( jnLookahead ) continue; - for(j=0; jnAction; j++){ - if( p->aAction[j].lookahead==j+p->mnLookahead-i ) break; - } - if( j==p->nAction ){ - break; /* Fits in empty slots */ - } - }else if( p->aAction[i].lookahead==p->mnLookahead ){ - if( p->aAction[i].action!=p->mnAction ) continue; - for(j=0; jnLookahead; j++){ - k = p->aLookahead[j].lookahead - p->mnLookahead + i; - if( k<0 || k>=p->nAction ) break; - if( p->aLookahead[j].lookahead!=p->aAction[k].lookahead ) break; - if( p->aLookahead[j].action!=p->aAction[k].action ) break; - } - if( jnLookahead ) continue; - n = 0; - for(j=0; jnAction; j++){ - if( p->aAction[j].lookahead<0 ) continue; - if( p->aAction[j].lookahead==j+p->mnLookahead-i ) n++; - } - if( n==p->nLookahead ){ - break; /* Same as a prior transaction set */ - } - } - } - /* Insert transaction set at index i. */ - for(j=0; jnLookahead; j++){ - k = p->aLookahead[j].lookahead - p->mnLookahead + i; - p->aAction[k] = p->aLookahead[j]; - if( k>=p->nAction ) p->nAction = k+1; - } - p->nLookahead = 0; - - /* Return the offset that is added to the lookahead in order to get the - ** index into yy_action of the action */ - return i - p->mnLookahead; -} - -/********************** From the file "assert.c" ****************************/ -/* -** A more efficient way of handling assertions. -*/ -void myassert(file,line) -char *file; -int line; -{ - fprintf(stderr,"Assertion failed on line %d of file \"%s\"\n",line,file); - exit(1); -} -/********************** From the file "build.c" *****************************/ -/* -** Routines to construction the finite state machine for the LEMON -** parser generator. -*/ - -/* Find a precedence symbol of every rule in the grammar. -** -** Those rules which have a precedence symbol coded in the input -** grammar using the "[symbol]" construct will already have the -** rp->precsym field filled. Other rules take as their precedence -** symbol the first RHS symbol with a defined precedence. If there -** are not RHS symbols with a defined precedence, the precedence -** symbol field is left blank. -*/ -void FindRulePrecedences(xp) -struct lemon *xp; -{ - struct rule *rp; - for(rp=xp->rule; rp; rp=rp->next){ - if( rp->precsym==0 ){ - int i; - for(i=0; inrhs; i++){ - if( rp->rhs[i]->prec>=0 ){ - rp->precsym = rp->rhs[i]; - break; - } - } - } - } - return; -} - -/* Find all nonterminals which will generate the empty string. -** Then go back and compute the first sets of every nonterminal. -** The first set is the set of all terminal symbols which can begin -** a string generated by that nonterminal. -*/ -void FindFirstSets(lemp) -struct lemon *lemp; -{ - int i; - struct rule *rp; - int progress; - - for(i=0; insymbol; i++){ - lemp->symbols[i]->lambda = B_FALSE; - } - for(i=lemp->nterminal; insymbol; i++){ - lemp->symbols[i]->firstset = SetNew(); - } - - /* First compute all lambdas */ - do{ - progress = 0; - for(rp=lemp->rule; rp; rp=rp->next){ - if( rp->lhs->lambda ) continue; - for(i=0; inrhs; i++){ - if( rp->rhs[i]->lambda==B_FALSE ) break; - } - if( i==rp->nrhs ){ - rp->lhs->lambda = B_TRUE; - progress = 1; - } - } - }while( progress ); - - /* Now compute all first sets */ - do{ - struct symbol *s1, *s2; - progress = 0; - for(rp=lemp->rule; rp; rp=rp->next){ - s1 = rp->lhs; - for(i=0; inrhs; i++){ - s2 = rp->rhs[i]; - if( s2->type==TERMINAL ){ - progress += SetAdd(s1->firstset,s2->index); - break; - }else if( s1==s2 ){ - if( s1->lambda==B_FALSE ) break; - }else{ - progress += SetUnion(s1->firstset,s2->firstset); - if( s2->lambda==B_FALSE ) break; - } - } - } - }while( progress ); - return; -} - -/* Compute all LR(0) states for the grammar. Links -** are added to between some states so that the LR(1) follow sets -** can be computed later. -*/ -PRIVATE struct state *getstate(/* struct lemon * */); /* forward reference */ -void FindStates(lemp) -struct lemon *lemp; -{ - struct symbol *sp; - struct rule *rp; - - Configlist_init(); - - /* Find the start symbol */ - if( lemp->start ){ - sp = Symbol_find(lemp->start); - if( sp==0 ){ - ErrorMsg(lemp->filename,0, -"The specified start symbol \"%s\" is not \ -in a nonterminal of the grammar. \"%s\" will be used as the start \ -symbol instead.",lemp->start,lemp->rule->lhs->name); - lemp->errorcnt++; - sp = lemp->rule->lhs; - } - }else{ - sp = lemp->rule->lhs; - } - - /* Make sure the start symbol doesn't occur on the right-hand side of - ** any rule. Report an error if it does. (YACC would generate a new - ** start symbol in this case.) */ - for(rp=lemp->rule; rp; rp=rp->next){ - int i; - for(i=0; inrhs; i++){ - if( rp->rhs[i]==sp ){ - ErrorMsg(lemp->filename,0, -"The start symbol \"%s\" occurs on the \ -right-hand side of a rule. This will result in a parser which \ -does not work properly.",sp->name); - lemp->errorcnt++; - } - } - } - - /* The basis configuration set for the first state - ** is all rules which have the start symbol as their - ** left-hand side */ - for(rp=sp->rule; rp; rp=rp->nextlhs){ - struct config *newcfp; - newcfp = Configlist_addbasis(rp,0); - SetAdd(newcfp->fws,0); - } - - /* Compute the first state. All other states will be - ** computed automatically during the computation of the first one. - ** The returned pointer to the first state is not used. */ - (void)getstate(lemp); - return; -} - -/* Return a pointer to a state which is described by the configuration -** list which has been built from calls to Configlist_add. -*/ -PRIVATE void buildshifts(/* struct lemon *, struct state * */); /* Forwd ref */ -PRIVATE struct state *getstate(lemp) -struct lemon *lemp; -{ - struct config *cfp, *bp; - struct state *stp; - - /* Extract the sorted basis of the new state. The basis was constructed - ** by prior calls to "Configlist_addbasis()". */ - Configlist_sortbasis(); - bp = Configlist_basis(); - - /* Get a state with the same basis */ - stp = State_find(bp); - if( stp ){ - /* A state with the same basis already exists! Copy all the follow-set - ** propagation links from the state under construction into the - ** preexisting state, then return a pointer to the preexisting state */ - struct config *x, *y; - for(x=bp, y=stp->bp; x && y; x=x->bp, y=y->bp){ - Plink_copy(&y->bplp,x->bplp); - Plink_delete(x->fplp); - x->fplp = x->bplp = 0; - } - cfp = Configlist_return(); - Configlist_eat(cfp); - }else{ - /* This really is a new state. Construct all the details */ - Configlist_closure(lemp); /* Compute the configuration closure */ - Configlist_sort(); /* Sort the configuration closure */ - cfp = Configlist_return(); /* Get a pointer to the config list */ - stp = State_new(); /* A new state structure */ - MemoryCheck(stp); - stp->bp = bp; /* Remember the configuration basis */ - stp->cfp = cfp; /* Remember the configuration closure */ - stp->index = lemp->nstate++; /* Every state gets a sequence number */ - stp->ap = 0; /* No actions, yet. */ - State_insert(stp,stp->bp); /* Add to the state table */ - buildshifts(lemp,stp); /* Recursively compute successor states */ - } - return stp; -} - -/* Construct all successor states to the given state. A "successor" -** state is any state which can be reached by a shift action. -*/ -PRIVATE void buildshifts(lemp,stp) -struct lemon *lemp; -struct state *stp; /* The state from which successors are computed */ -{ - struct config *cfp; /* For looping thru the config closure of "stp" */ - struct config *bcfp; /* For the inner loop on config closure of "stp" */ - struct config *new; /* */ - struct symbol *sp; /* Symbol following the dot in configuration "cfp" */ - struct symbol *bsp; /* Symbol following the dot in configuration "bcfp" */ - struct state *newstp; /* A pointer to a successor state */ - - /* Each configuration becomes complete after it contibutes to a successor - ** state. Initially, all configurations are incomplete */ - for(cfp=stp->cfp; cfp; cfp=cfp->next) cfp->status = INCOMPLETE; - - /* Loop through all configurations of the state "stp" */ - for(cfp=stp->cfp; cfp; cfp=cfp->next){ - if( cfp->status==COMPLETE ) continue; /* Already used by inner loop */ - if( cfp->dot>=cfp->rp->nrhs ) continue; /* Can't shift this config */ - Configlist_reset(); /* Reset the new config set */ - sp = cfp->rp->rhs[cfp->dot]; /* Symbol after the dot */ - - /* For every configuration in the state "stp" which has the symbol "sp" - ** following its dot, add the same configuration to the basis set under - ** construction but with the dot shifted one symbol to the right. */ - for(bcfp=cfp; bcfp; bcfp=bcfp->next){ - if( bcfp->status==COMPLETE ) continue; /* Already used */ - if( bcfp->dot>=bcfp->rp->nrhs ) continue; /* Can't shift this one */ - bsp = bcfp->rp->rhs[bcfp->dot]; /* Get symbol after dot */ - if( bsp!=sp ) continue; /* Must be same as for "cfp" */ - bcfp->status = COMPLETE; /* Mark this config as used */ - new = Configlist_addbasis(bcfp->rp,bcfp->dot+1); - Plink_add(&new->bplp,bcfp); - } - - /* Get a pointer to the state described by the basis configuration set - ** constructed in the preceding loop */ - newstp = getstate(lemp); - - /* The state "newstp" is reached from the state "stp" by a shift action - ** on the symbol "sp" */ - Action_add(&stp->ap,SHIFT,sp,(char *)newstp); - } -} - -/* -** Construct the propagation links -*/ -void FindLinks(lemp) -struct lemon *lemp; -{ - int i; - struct config *cfp, *other; - struct state *stp; - struct plink *plp; - - /* Housekeeping detail: - ** Add to every propagate link a pointer back to the state to - ** which the link is attached. */ - for(i=0; instate; i++){ - stp = lemp->sorted[i]; - for(cfp=stp->cfp; cfp; cfp=cfp->next){ - cfp->stp = stp; - } - } - - /* Convert all backlinks into forward links. Only the forward - ** links are used in the follow-set computation. */ - for(i=0; instate; i++){ - stp = lemp->sorted[i]; - for(cfp=stp->cfp; cfp; cfp=cfp->next){ - for(plp=cfp->bplp; plp; plp=plp->next){ - other = plp->cfp; - Plink_add(&other->fplp,cfp); - } - } - } -} - -/* Compute all followsets. -** -** A followset is the set of all symbols which can come immediately -** after a configuration. -*/ -void FindFollowSets(lemp) -struct lemon *lemp; -{ - int i; - struct config *cfp; - struct plink *plp; - int progress; - int change; - - for(i=0; instate; i++){ - for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){ - cfp->status = INCOMPLETE; - } - } - - do{ - progress = 0; - for(i=0; instate; i++){ - for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){ - if( cfp->status==COMPLETE ) continue; - for(plp=cfp->fplp; plp; plp=plp->next){ - change = SetUnion(plp->cfp->fws,cfp->fws); - if( change ){ - plp->cfp->status = INCOMPLETE; - progress = 1; - } - } - cfp->status = COMPLETE; - } - } - }while( progress ); -} - -static int resolve_conflict(); - -/* Compute the reduce actions, and resolve conflicts. -*/ -void FindActions(lemp) -struct lemon *lemp; -{ - int i,j; - struct config *cfp; - struct state *stp; - struct symbol *sp; - struct rule *rp; - - /* Add all of the reduce actions - ** A reduce action is added for each element of the followset of - ** a configuration which has its dot at the extreme right. - */ - for(i=0; instate; i++){ /* Loop over all states */ - stp = lemp->sorted[i]; - for(cfp=stp->cfp; cfp; cfp=cfp->next){ /* Loop over all configurations */ - if( cfp->rp->nrhs==cfp->dot ){ /* Is dot at extreme right? */ - for(j=0; jnterminal; j++){ - if( SetFind(cfp->fws,j) ){ - /* Add a reduce action to the state "stp" which will reduce by the - ** rule "cfp->rp" if the lookahead symbol is "lemp->symbols[j]" */ - Action_add(&stp->ap,REDUCE,lemp->symbols[j],(char *)cfp->rp); - } - } - } - } - } - - /* Add the accepting token */ - if( lemp->start ){ - sp = Symbol_find(lemp->start); - if( sp==0 ) sp = lemp->rule->lhs; - }else{ - sp = lemp->rule->lhs; - } - /* Add to the first state (which is always the starting state of the - ** finite state machine) an action to ACCEPT if the lookahead is the - ** start nonterminal. */ - Action_add(&lemp->sorted[0]->ap,ACCEPT,sp,0); - - /* Resolve conflicts */ - for(i=0; instate; i++){ - struct action *ap, *nap; - struct state *stp; - stp = lemp->sorted[i]; - assert( stp->ap ); - stp->ap = Action_sort(stp->ap); - for(ap=stp->ap; ap && ap->next; ap=ap->next){ - for(nap=ap->next; nap && nap->sp==ap->sp; nap=nap->next){ - /* The two actions "ap" and "nap" have the same lookahead. - ** Figure out which one should be used */ - lemp->nconflict += resolve_conflict(ap,nap,lemp->errsym); - } - } - } - - /* Report an error for each rule that can never be reduced. */ - for(rp=lemp->rule; rp; rp=rp->next) rp->canReduce = B_FALSE; - for(i=0; instate; i++){ - struct action *ap; - for(ap=lemp->sorted[i]->ap; ap; ap=ap->next){ - if( ap->type==REDUCE ) ap->x.rp->canReduce = B_TRUE; - } - } - for(rp=lemp->rule; rp; rp=rp->next){ - if( rp->canReduce ) continue; - ErrorMsg(lemp->filename,rp->ruleline,"This rule can not be reduced.\n"); - lemp->errorcnt++; - } -} - -/* Resolve a conflict between the two given actions. If the -** conflict can't be resolve, return non-zero. -** -** NO LONGER TRUE: -** To resolve a conflict, first look to see if either action -** is on an error rule. In that case, take the action which -** is not associated with the error rule. If neither or both -** actions are associated with an error rule, then try to -** use precedence to resolve the conflict. -** -** If either action is a SHIFT, then it must be apx. This -** function won't work if apx->type==REDUCE and apy->type==SHIFT. -*/ -static int resolve_conflict(apx,apy,errsym) -struct action *apx; -struct action *apy; -struct symbol *errsym; /* The error symbol (if defined. NULL otherwise) */ -{ - struct symbol *spx, *spy; - int errcnt = 0; - assert( apx->sp==apy->sp ); /* Otherwise there would be no conflict */ - if( apx->type==SHIFT && apy->type==REDUCE ){ - spx = apx->sp; - spy = apy->x.rp->precsym; - if( spy==0 || spx->prec<0 || spy->prec<0 ){ - /* Not enough precedence information. */ - apy->type = CONFLICT; - errcnt++; - }else if( spx->prec>spy->prec ){ /* Lower precedence wins */ - apy->type = RD_RESOLVED; - }else if( spx->precprec ){ - apx->type = SH_RESOLVED; - }else if( spx->prec==spy->prec && spx->assoc==RIGHT ){ /* Use operator */ - apy->type = RD_RESOLVED; /* associativity */ - }else if( spx->prec==spy->prec && spx->assoc==LEFT ){ /* to break tie */ - apx->type = SH_RESOLVED; - }else{ - assert( spx->prec==spy->prec && spx->assoc==NONE ); - apy->type = CONFLICT; - errcnt++; - } - }else if( apx->type==REDUCE && apy->type==REDUCE ){ - spx = apx->x.rp->precsym; - spy = apy->x.rp->precsym; - if( spx==0 || spy==0 || spx->prec<0 || - spy->prec<0 || spx->prec==spy->prec ){ - apy->type = CONFLICT; - errcnt++; - }else if( spx->prec>spy->prec ){ - apy->type = RD_RESOLVED; - }else if( spx->precprec ){ - apx->type = RD_RESOLVED; - } - }else{ - assert( - apx->type==SH_RESOLVED || - apx->type==RD_RESOLVED || - apx->type==CONFLICT || - apy->type==SH_RESOLVED || - apy->type==RD_RESOLVED || - apy->type==CONFLICT - ); - /* The REDUCE/SHIFT case cannot happen because SHIFTs come before - ** REDUCEs on the list. If we reach this point it must be because - ** the parser conflict had already been resolved. */ - } - return errcnt; -} -/********************* From the file "configlist.c" *************************/ -/* -** Routines to processing a configuration list and building a state -** in the LEMON parser generator. -*/ - -static struct config *freelist = 0; /* List of free configurations */ -static struct config *current = 0; /* Top of list of configurations */ -static struct config **currentend = 0; /* Last on list of configs */ -static struct config *basis = 0; /* Top of list of basis configs */ -static struct config **basisend = 0; /* End of list of basis configs */ - -/* Return a pointer to a new configuration */ -PRIVATE struct config *newconfig(){ - struct config *new; - if( freelist==0 ){ - int i; - int amt = 3; - freelist = (struct config *)malloc( sizeof(struct config)*amt ); - if( freelist==0 ){ - fprintf(stderr,"Unable to allocate memory for a new configuration."); - exit(1); - } - for(i=0; inext; - return new; -} - -/* The configuration "old" is no longer used */ -PRIVATE void deleteconfig(old) -struct config *old; -{ - old->next = freelist; - freelist = old; -} - -/* Initialized the configuration list builder */ -void Configlist_init(){ - current = 0; - currentend = ¤t; - basis = 0; - basisend = &basis; - Configtable_init(); - return; -} - -/* Initialized the configuration list builder */ -void Configlist_reset(){ - current = 0; - currentend = ¤t; - basis = 0; - basisend = &basis; - Configtable_clear(0); - return; -} - -/* Add another configuration to the configuration list */ -struct config *Configlist_add(rp,dot) -struct rule *rp; /* The rule */ -int dot; /* Index into the RHS of the rule where the dot goes */ -{ - struct config *cfp, model; - - assert( currentend!=0 ); - model.rp = rp; - model.dot = dot; - cfp = Configtable_find(&model); - if( cfp==0 ){ - cfp = newconfig(); - cfp->rp = rp; - cfp->dot = dot; - cfp->fws = SetNew(); - cfp->stp = 0; - cfp->fplp = cfp->bplp = 0; - cfp->next = 0; - cfp->bp = 0; - *currentend = cfp; - currentend = &cfp->next; - Configtable_insert(cfp); - } - return cfp; -} - -/* Add a basis configuration to the configuration list */ -struct config *Configlist_addbasis(rp,dot) -struct rule *rp; -int dot; -{ - struct config *cfp, model; - - assert( basisend!=0 ); - assert( currentend!=0 ); - model.rp = rp; - model.dot = dot; - cfp = Configtable_find(&model); - if( cfp==0 ){ - cfp = newconfig(); - cfp->rp = rp; - cfp->dot = dot; - cfp->fws = SetNew(); - cfp->stp = 0; - cfp->fplp = cfp->bplp = 0; - cfp->next = 0; - cfp->bp = 0; - *currentend = cfp; - currentend = &cfp->next; - *basisend = cfp; - basisend = &cfp->bp; - Configtable_insert(cfp); - } - return cfp; -} - -/* Compute the closure of the configuration list */ -void Configlist_closure(lemp) -struct lemon *lemp; -{ - struct config *cfp, *newcfp; - struct rule *rp, *newrp; - struct symbol *sp, *xsp; - int i, dot; - - assert( currentend!=0 ); - for(cfp=current; cfp; cfp=cfp->next){ - rp = cfp->rp; - dot = cfp->dot; - if( dot>=rp->nrhs ) continue; - sp = rp->rhs[dot]; - if( sp->type==NONTERMINAL ){ - if( sp->rule==0 && sp!=lemp->errsym ){ - ErrorMsg(lemp->filename,rp->line,"Nonterminal \"%s\" has no rules.", - sp->name); - lemp->errorcnt++; - } - for(newrp=sp->rule; newrp; newrp=newrp->nextlhs){ - newcfp = Configlist_add(newrp,0); - for(i=dot+1; inrhs; i++){ - xsp = rp->rhs[i]; - if( xsp->type==TERMINAL ){ - SetAdd(newcfp->fws,xsp->index); - break; - }else{ - SetUnion(newcfp->fws,xsp->firstset); - if( xsp->lambda==B_FALSE ) break; - } - } - if( i==rp->nrhs ) Plink_add(&cfp->fplp,newcfp); - } - } - } - return; -} - -/* Sort the configuration list */ -void Configlist_sort(){ - current = (struct config *)msort((char *)current,(char **)&(current->next),Configcmp); - currentend = 0; - return; -} - -/* Sort the basis configuration list */ -void Configlist_sortbasis(){ - basis = (struct config *)msort((char *)current,(char **)&(current->bp),Configcmp); - basisend = 0; - return; -} - -/* Return a pointer to the head of the configuration list and -** reset the list */ -struct config *Configlist_return(){ - struct config *old; - old = current; - current = 0; - currentend = 0; - return old; -} - -/* Return a pointer to the head of the configuration list and -** reset the list */ -struct config *Configlist_basis(){ - struct config *old; - old = basis; - basis = 0; - basisend = 0; - return old; -} - -/* Free all elements of the given configuration list */ -void Configlist_eat(cfp) -struct config *cfp; -{ - struct config *nextcfp; - for(; cfp; cfp=nextcfp){ - nextcfp = cfp->next; - assert( cfp->fplp==0 ); - assert( cfp->bplp==0 ); - if( cfp->fws ) SetFree(cfp->fws); - deleteconfig(cfp); - } - return; -} -/***************** From the file "error.c" *********************************/ -/* -** Code for printing error message. -*/ - -/* Find a good place to break "msg" so that its length is at least "min" -** but no more than "max". Make the point as close to max as possible. -*/ -static int findbreak(msg,min,max) -char *msg; -int min; -int max; -{ - int i,spot; - char c; - for(i=spot=min; i<=max; i++){ - c = msg[i]; - if( c=='\t' ) msg[i] = ' '; - if( c=='\n' ){ msg[i] = ' '; spot = i; break; } - if( c==0 ){ spot = i; break; } - if( c=='-' && i0 ){ - sprintf(prefix,"%.*s:%d: ",PREFIXLIMIT-10,filename,lineno); - }else{ - sprintf(prefix,"%.*s: ",PREFIXLIMIT-10,filename); - } - prefixsize = strlen(prefix); - availablewidth = LINEWIDTH - prefixsize; - - /* Generate the error message */ - vsprintf(errmsg,format,ap); - va_end(ap); - errmsgsize = strlen(errmsg); - /* Remove trailing '\n's from the error message. */ - while( errmsgsize>0 && errmsg[errmsgsize-1]=='\n' ){ - errmsg[--errmsgsize] = 0; - } - - /* Print the error message */ - base = 0; - while( errmsg[base]!=0 ){ - end = restart = findbreak(&errmsg[base],0,availablewidth); - restart += base; - while( errmsg[restart]==' ' ) restart++; - fprintf(stdout,"%s%.*s\n",prefix,end,&errmsg[base]); - base = restart; - } -} -/**************** From the file "main.c" ************************************/ -/* -** Main program file for the LEMON parser generator. -*/ - -/* Report an out-of-memory condition and abort. This function -** is used mostly by the "MemoryCheck" macro in struct.h -*/ -void memory_error(){ - fprintf(stderr,"Out of memory. Aborting...\n"); - exit(1); -} - -static int nDefine = 0; /* Number of -D options on the command line */ -static char **azDefine = 0; /* Name of the -D macros */ - -/* This routine is called with the argument to each -D command-line option. -** Add the macro defined to the azDefine array. -*/ -static void handle_D_option(char *z){ - char **paz; - nDefine++; - azDefine = realloc(azDefine, sizeof(azDefine[0])*nDefine); - if( azDefine==0 ){ - fprintf(stderr,"out of memory\n"); - exit(1); - } - paz = &azDefine[nDefine-1]; - *paz = malloc( strlen(z)+1 ); - if( *paz==0 ){ - fprintf(stderr,"out of memory\n"); - exit(1); - } - strcpy(*paz, z); - for(z=*paz; *z && *z!='='; z++){} - *z = 0; -} - - -/* The main program. Parse the command line and do it... */ -int main(argc,argv) -int argc; -char **argv; -{ - static int version = 0; - static int rpflag = 0; - static int basisflag = 0; - static int compress = 0; - static int quiet = 0; - static int statistics = 0; - static int mhflag = 0; - static struct s_options options[] = { - {OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."}, - {OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."}, - {OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."}, - {OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."}, - {OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file"}, - {OPT_FLAG, "q", (char*)&quiet, "(Quiet) Don't print the report file."}, - {OPT_FLAG, "s", (char*)&statistics, - "Print parser stats to standard output."}, - {OPT_FLAG, "x", (char*)&version, "Print the version number."}, - {OPT_FLAG,0,0,0} - }; - int i; - struct lemon lem; - - OptInit(argv,options,stderr); - if( version ){ - printf("Lemon version 1.0\n"); - exit(0); - } - if( OptNArgs()!=1 ){ - fprintf(stderr,"Exactly one filename argument is required.\n"); - exit(1); - } - lem.errorcnt = 0; - - /* Initialize the machine */ - Strsafe_init(); - Symbol_init(); - State_init(); - lem.argv0 = argv[0]; - lem.filename = OptArg(0); - lem.basisflag = basisflag; - lem.has_fallback = 0; - lem.nconflict = 0; - lem.name = lem.include = lem.arg = lem.tokentype = lem.start = 0; - lem.vartype = 0; - lem.stacksize = 0; - lem.error = lem.overflow = lem.failure = lem.accept = lem.tokendest = - lem.tokenprefix = lem.outname = lem.extracode = 0; - lem.vardest = 0; - lem.tablesize = 0; - Symbol_new("$"); - lem.errsym = Symbol_new("error"); - - /* Parse the input file */ - Parse(&lem); - if( lem.errorcnt ) exit(lem.errorcnt); - if( lem.rule==0 ){ - fprintf(stderr,"Empty grammar.\n"); - exit(1); - } - - /* Count and index the symbols of the grammar */ - lem.nsymbol = Symbol_count(); - Symbol_new("{default}"); - lem.symbols = Symbol_arrayof(); - for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i; - qsort(lem.symbols,lem.nsymbol+1,sizeof(struct symbol*), - (int(*)(const void *,const void *))Symbolcmpp); - for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i; - for(i=1; isupper(lem.symbols[i]->name[0]); i++); - lem.nterminal = i; - - /* Generate a reprint of the grammar, if requested on the command line */ - if( rpflag ){ - Reprint(&lem); - }else{ - /* Initialize the size for all follow and first sets */ - SetSize(lem.nterminal); - - /* Find the precedence for every production rule (that has one) */ - FindRulePrecedences(&lem); - - /* Compute the lambda-nonterminals and the first-sets for every - ** nonterminal */ - FindFirstSets(&lem); - - /* Compute all LR(0) states. Also record follow-set propagation - ** links so that the follow-set can be computed later */ - lem.nstate = 0; - FindStates(&lem); - lem.sorted = State_arrayof(); - - /* Tie up loose ends on the propagation links */ - FindLinks(&lem); - - /* Compute the follow set of every reducible configuration */ - FindFollowSets(&lem); - - /* Compute the action tables */ - FindActions(&lem); - - /* Compress the action tables */ - if( compress==0 ) CompressTables(&lem); - - /* Generate a report of the parser generated. (the "y.output" file) */ - if( !quiet ) ReportOutput(&lem); - - /* Generate the source code for the parser */ - ReportTable(&lem, mhflag); - - /* Produce a header file for use by the scanner. (This step is - ** omitted if the "-m" option is used because makeheaders will - ** generate the file for us.) */ - if( !mhflag ) ReportHeader(&lem); - } - if( statistics ){ - printf("Parser statistics: %d terminals, %d nonterminals, %d rules\n", - lem.nterminal, lem.nsymbol - lem.nterminal, lem.nrule); - printf(" %d states, %d parser table entries, %d conflicts\n", - lem.nstate, lem.tablesize, lem.nconflict); - } - if( lem.nconflict ){ - fprintf(stderr,"%d parsing conflicts.\n",lem.nconflict); - } - exit(lem.errorcnt + lem.nconflict); - return (lem.errorcnt + lem.nconflict); -} -/******************** From the file "msort.c" *******************************/ -/* -** A generic merge-sort program. -** -** USAGE: -** Let "ptr" be a pointer to some structure which is at the head of -** a null-terminated list. Then to sort the list call: -** -** ptr = msort(ptr,&(ptr->next),cmpfnc); -** -** In the above, "cmpfnc" is a pointer to a function which compares -** two instances of the structure and returns an integer, as in -** strcmp. The second argument is a pointer to the pointer to the -** second element of the linked list. This address is used to compute -** the offset to the "next" field within the structure. The offset to -** the "next" field must be constant for all structures in the list. -** -** The function returns a new pointer which is the head of the list -** after sorting. -** -** ALGORITHM: -** Merge-sort. -*/ - -/* -** Return a pointer to the next structure in the linked list. -*/ -#define NEXT(A) (*(char**)(((size_t)A)+offset)) - -/* -** Inputs: -** a: A sorted, null-terminated linked list. (May be null). -** b: A sorted, null-terminated linked list. (May be null). -** cmp: A pointer to the comparison function. -** offset: Offset in the structure to the "next" field. -** -** Return Value: -** A pointer to the head of a sorted list containing the elements -** of both a and b. -** -** Side effects: -** The "next" pointers for elements in the lists a and b are -** changed. -*/ -static char *merge(a,b,cmp,offset) -char *a; -char *b; -int (*cmp)(); -int offset; -{ - char *ptr, *head; - - if( a==0 ){ - head = b; - }else if( b==0 ){ - head = a; - }else{ - if( (*cmp)(a,b)<0 ){ - ptr = a; - a = NEXT(a); - }else{ - ptr = b; - b = NEXT(b); - } - head = ptr; - while( a && b ){ - if( (*cmp)(a,b)<0 ){ - NEXT(ptr) = a; - ptr = a; - a = NEXT(a); - }else{ - NEXT(ptr) = b; - ptr = b; - b = NEXT(b); - } - } - if( a ) NEXT(ptr) = a; - else NEXT(ptr) = b; - } - return head; -} - -/* -** Inputs: -** list: Pointer to a singly-linked list of structures. -** next: Pointer to pointer to the second element of the list. -** cmp: A comparison function. -** -** Return Value: -** A pointer to the head of a sorted list containing the elements -** orginally in list. -** -** Side effects: -** The "next" pointers for elements in list are changed. -*/ -#define LISTSIZE 30 -char *msort(list,next,cmp) -char *list; -char **next; -int (*cmp)(); -{ - size_t offset; - char *ep; - char *set[LISTSIZE]; - int i; - offset = (size_t)next - (size_t)list; - for(i=0; istate = WAITING_FOR_DECL_KEYWORD; - }else if( islower(x[0]) ){ - psp->lhs = Symbol_new(x); - psp->nrhs = 0; - psp->lhsalias = 0; - psp->state = WAITING_FOR_ARROW; - }else if( x[0]=='{' ){ - if( psp->prevrule==0 ){ - ErrorMsg(psp->filename,psp->tokenlineno, -"There is not prior rule opon which to attach the code \ -fragment which begins on this line."); - psp->errorcnt++; - }else if( psp->prevrule->code!=0 ){ - ErrorMsg(psp->filename,psp->tokenlineno, -"Code fragment beginning on this line is not the first \ -to follow the previous rule."); - psp->errorcnt++; - }else{ - psp->prevrule->line = psp->tokenlineno; - psp->prevrule->code = &x[1]; - } - }else if( x[0]=='[' ){ - psp->state = PRECEDENCE_MARK_1; - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "Token \"%s\" should be either \"%%\" or a nonterminal name.", - x); - psp->errorcnt++; - } - break; - case PRECEDENCE_MARK_1: - if( !isupper(x[0]) ){ - ErrorMsg(psp->filename,psp->tokenlineno, - "The precedence symbol must be a terminal."); - psp->errorcnt++; - }else if( psp->prevrule==0 ){ - ErrorMsg(psp->filename,psp->tokenlineno, - "There is no prior rule to assign precedence \"[%s]\".",x); - psp->errorcnt++; - }else if( psp->prevrule->precsym!=0 ){ - ErrorMsg(psp->filename,psp->tokenlineno, -"Precedence mark on this line is not the first \ -to follow the previous rule."); - psp->errorcnt++; - }else{ - psp->prevrule->precsym = Symbol_new(x); - } - psp->state = PRECEDENCE_MARK_2; - break; - case PRECEDENCE_MARK_2: - if( x[0]!=']' ){ - ErrorMsg(psp->filename,psp->tokenlineno, - "Missing \"]\" on precedence mark."); - psp->errorcnt++; - } - psp->state = WAITING_FOR_DECL_OR_RULE; - break; - case WAITING_FOR_ARROW: - if( x[0]==':' && x[1]==':' && x[2]=='=' ){ - psp->state = IN_RHS; - }else if( x[0]=='(' ){ - psp->state = LHS_ALIAS_1; - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "Expected to see a \":\" following the LHS symbol \"%s\".", - psp->lhs->name); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case LHS_ALIAS_1: - if( isalpha(x[0]) ){ - psp->lhsalias = x; - psp->state = LHS_ALIAS_2; - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "\"%s\" is not a valid alias for the LHS \"%s\"\n", - x,psp->lhs->name); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case LHS_ALIAS_2: - if( x[0]==')' ){ - psp->state = LHS_ALIAS_3; - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "Missing \")\" following LHS alias name \"%s\".",psp->lhsalias); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case LHS_ALIAS_3: - if( x[0]==':' && x[1]==':' && x[2]=='=' ){ - psp->state = IN_RHS; - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "Missing \"->\" following: \"%s(%s)\".", - psp->lhs->name,psp->lhsalias); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case IN_RHS: - if( x[0]=='.' ){ - struct rule *rp; - rp = (struct rule *)malloc( sizeof(struct rule) + - sizeof(struct symbol*)*psp->nrhs + sizeof(char*)*psp->nrhs ); - if( rp==0 ){ - ErrorMsg(psp->filename,psp->tokenlineno, - "Can't allocate enough memory for this rule."); - psp->errorcnt++; - psp->prevrule = 0; - }else{ - int i; - rp->ruleline = psp->tokenlineno; - rp->rhs = (struct symbol**)&rp[1]; - rp->rhsalias = (char**)&(rp->rhs[psp->nrhs]); - for(i=0; inrhs; i++){ - rp->rhs[i] = psp->rhs[i]; - rp->rhsalias[i] = psp->alias[i]; - } - rp->lhs = psp->lhs; - rp->lhsalias = psp->lhsalias; - rp->nrhs = psp->nrhs; - rp->code = 0; - rp->precsym = 0; - rp->index = psp->gp->nrule++; - rp->nextlhs = rp->lhs->rule; - rp->lhs->rule = rp; - rp->next = 0; - if( psp->firstrule==0 ){ - psp->firstrule = psp->lastrule = rp; - }else{ - psp->lastrule->next = rp; - psp->lastrule = rp; - } - psp->prevrule = rp; - } - psp->state = WAITING_FOR_DECL_OR_RULE; - }else if( isalpha(x[0]) ){ - if( psp->nrhs>=MAXRHS ){ - ErrorMsg(psp->filename,psp->tokenlineno, - "Too many symbol on RHS or rule beginning at \"%s\".", - x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - }else{ - psp->rhs[psp->nrhs] = Symbol_new(x); - psp->alias[psp->nrhs] = 0; - psp->nrhs++; - } - }else if( x[0]=='(' && psp->nrhs>0 ){ - psp->state = RHS_ALIAS_1; - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "Illegal character on RHS of rule: \"%s\".",x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case RHS_ALIAS_1: - if( isalpha(x[0]) ){ - psp->alias[psp->nrhs-1] = x; - psp->state = RHS_ALIAS_2; - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "\"%s\" is not a valid alias for the RHS symbol \"%s\"\n", - x,psp->rhs[psp->nrhs-1]->name); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case RHS_ALIAS_2: - if( x[0]==')' ){ - psp->state = IN_RHS; - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "Missing \")\" following LHS alias name \"%s\".",psp->lhsalias); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case WAITING_FOR_DECL_KEYWORD: - if( isalpha(x[0]) ){ - psp->declkeyword = x; - psp->declargslot = 0; - psp->decllnslot = 0; - psp->state = WAITING_FOR_DECL_ARG; - if( strcmp(x,"name")==0 ){ - psp->declargslot = &(psp->gp->name); - }else if( strcmp(x,"include")==0 ){ - psp->declargslot = &(psp->gp->include); - psp->decllnslot = &psp->gp->includeln; - }else if( strcmp(x,"code")==0 ){ - psp->declargslot = &(psp->gp->extracode); - psp->decllnslot = &psp->gp->extracodeln; - }else if( strcmp(x,"token_destructor")==0 ){ - psp->declargslot = &psp->gp->tokendest; - psp->decllnslot = &psp->gp->tokendestln; - }else if( strcmp(x,"default_destructor")==0 ){ - psp->declargslot = &psp->gp->vardest; - psp->decllnslot = &psp->gp->vardestln; - }else if( strcmp(x,"token_prefix")==0 ){ - psp->declargslot = &psp->gp->tokenprefix; - }else if( strcmp(x,"syntax_error")==0 ){ - psp->declargslot = &(psp->gp->error); - psp->decllnslot = &psp->gp->errorln; - }else if( strcmp(x,"parse_accept")==0 ){ - psp->declargslot = &(psp->gp->accept); - psp->decllnslot = &psp->gp->acceptln; - }else if( strcmp(x,"parse_failure")==0 ){ - psp->declargslot = &(psp->gp->failure); - psp->decllnslot = &psp->gp->failureln; - }else if( strcmp(x,"stack_overflow")==0 ){ - psp->declargslot = &(psp->gp->overflow); - psp->decllnslot = &psp->gp->overflowln; - }else if( strcmp(x,"extra_argument")==0 ){ - psp->declargslot = &(psp->gp->arg); - }else if( strcmp(x,"token_type")==0 ){ - psp->declargslot = &(psp->gp->tokentype); - }else if( strcmp(x,"default_type")==0 ){ - psp->declargslot = &(psp->gp->vartype); - }else if( strcmp(x,"stack_size")==0 ){ - psp->declargslot = &(psp->gp->stacksize); - }else if( strcmp(x,"start_symbol")==0 ){ - psp->declargslot = &(psp->gp->start); - }else if( strcmp(x,"left")==0 ){ - psp->preccounter++; - psp->declassoc = LEFT; - psp->state = WAITING_FOR_PRECEDENCE_SYMBOL; - }else if( strcmp(x,"right")==0 ){ - psp->preccounter++; - psp->declassoc = RIGHT; - psp->state = WAITING_FOR_PRECEDENCE_SYMBOL; - }else if( strcmp(x,"nonassoc")==0 ){ - psp->preccounter++; - psp->declassoc = NONE; - psp->state = WAITING_FOR_PRECEDENCE_SYMBOL; - }else if( strcmp(x,"destructor")==0 ){ - psp->state = WAITING_FOR_DESTRUCTOR_SYMBOL; - }else if( strcmp(x,"type")==0 ){ - psp->state = WAITING_FOR_DATATYPE_SYMBOL; - }else if( strcmp(x,"fallback")==0 ){ - psp->fallback = 0; - psp->state = WAITING_FOR_FALLBACK_ID; - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "Unknown declaration keyword: \"%%%s\".",x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "Illegal declaration keyword: \"%s\".",x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } - break; - case WAITING_FOR_DESTRUCTOR_SYMBOL: - if( !isalpha(x[0]) ){ - ErrorMsg(psp->filename,psp->tokenlineno, - "Symbol name missing after %destructor keyword"); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - }else{ - struct symbol *sp = Symbol_new(x); - psp->declargslot = &sp->destructor; - psp->decllnslot = &sp->destructorln; - psp->state = WAITING_FOR_DECL_ARG; - } - break; - case WAITING_FOR_DATATYPE_SYMBOL: - if( !isalpha(x[0]) ){ - ErrorMsg(psp->filename,psp->tokenlineno, - "Symbol name missing after %destructor keyword"); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - }else{ - struct symbol *sp = Symbol_new(x); - psp->declargslot = &sp->datatype; - psp->decllnslot = 0; - psp->state = WAITING_FOR_DECL_ARG; - } - break; - case WAITING_FOR_PRECEDENCE_SYMBOL: - if( x[0]=='.' ){ - psp->state = WAITING_FOR_DECL_OR_RULE; - }else if( isupper(x[0]) ){ - struct symbol *sp; - sp = Symbol_new(x); - if( sp->prec>=0 ){ - ErrorMsg(psp->filename,psp->tokenlineno, - "Symbol \"%s\" has already be given a precedence.",x); - psp->errorcnt++; - }else{ - sp->prec = psp->preccounter; - sp->assoc = psp->declassoc; - } - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "Can't assign a precedence to \"%s\".",x); - psp->errorcnt++; - } - break; - case WAITING_FOR_DECL_ARG: - if( (x[0]=='{' || x[0]=='\"' || isalnum(x[0])) ){ - if( *(psp->declargslot)!=0 ){ - ErrorMsg(psp->filename,psp->tokenlineno, - "The argument \"%s\" to declaration \"%%%s\" is not the first.", - x[0]=='\"' ? &x[1] : x,psp->declkeyword); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - }else{ - *(psp->declargslot) = (x[0]=='\"' || x[0]=='{') ? &x[1] : x; - if( psp->decllnslot ) *psp->decllnslot = psp->tokenlineno; - psp->state = WAITING_FOR_DECL_OR_RULE; - } - }else{ - ErrorMsg(psp->filename,psp->tokenlineno, - "Illegal argument to %%%s: %s",psp->declkeyword,x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } - break; - case WAITING_FOR_FALLBACK_ID: - if( x[0]=='.' ){ - psp->state = WAITING_FOR_DECL_OR_RULE; - }else if( !isupper(x[0]) ){ - ErrorMsg(psp->filename, psp->tokenlineno, - "%%fallback argument \"%s\" should be a token", x); - psp->errorcnt++; - }else{ - struct symbol *sp = Symbol_new(x); - if( psp->fallback==0 ){ - psp->fallback = sp; - }else if( sp->fallback ){ - ErrorMsg(psp->filename, psp->tokenlineno, - "More than one fallback assigned to token %s", x); - psp->errorcnt++; - }else{ - sp->fallback = psp->fallback; - psp->gp->has_fallback = 1; - } - } - break; - case RESYNC_AFTER_RULE_ERROR: -/* if( x[0]=='.' ) psp->state = WAITING_FOR_DECL_OR_RULE; -** break; */ - case RESYNC_AFTER_DECL_ERROR: - if( x[0]=='.' ) psp->state = WAITING_FOR_DECL_OR_RULE; - if( x[0]=='%' ) psp->state = WAITING_FOR_DECL_KEYWORD; - break; - } -} - -/* Run the proprocessor over the input file text. The global variables -** azDefine[0] through azDefine[nDefine-1] contains the names of all defined -** macros. This routine looks for "%ifdef" and "%ifndef" and "%endif" and -** comments them out. Text in between is also commented out as appropriate. -*/ -static void preprocess_input(char *z){ - int i, j, k, n; - int exclude = 0; - int start = 1; - int lineno = 1; - int start_lineno = 1; - for(i=0; z[i]; i++){ - if( z[i]=='\n' ) lineno++; - if( z[i]!='%' || (i>0 && z[i-1]!='\n') ) continue; - if( strncmp(&z[i],"%endif",6)==0 && isspace(z[i+6]) ){ - if( exclude ){ - exclude--; - if( exclude==0 ){ - for(j=start; jfilename; - ps.errorcnt = 0; - ps.state = INITIALIZE; - - /* Begin by reading the input file */ - fp = fopen(ps.filename,"rb"); - if( fp==0 ){ - ErrorMsg(ps.filename,0,"Can't open this file for reading."); - gp->errorcnt++; - return; - } - fseek(fp,0,2); - filesize = ftell(fp); - rewind(fp); - filebuf = (char *)malloc( filesize+1 ); - if( filebuf==0 ){ - ErrorMsg(ps.filename,0,"Can't allocate %d of memory to hold this file.", - filesize+1); - gp->errorcnt++; - return; - } - if( fread(filebuf,1,filesize,fp)!=filesize ){ - ErrorMsg(ps.filename,0,"Can't read in all %d bytes of this file.", - filesize); - free(filebuf); - gp->errorcnt++; - return; - } - fclose(fp); - filebuf[filesize] = 0; - - /* Make an initial pass through the file to handle %ifdef and %ifndef */ - preprocess_input(filebuf); - - /* Now scan the text of the input file */ - lineno = 1; - for(cp=filebuf; (c= *cp)!=0; ){ - if( c=='\n' ) lineno++; /* Keep track of the line number */ - if( isspace(c) ){ cp++; continue; } /* Skip all white space */ - if( c=='/' && cp[1]=='/' ){ /* Skip C++ style comments */ - cp+=2; - while( (c= *cp)!=0 && c!='\n' ) cp++; - continue; - } - if( c=='/' && cp[1]=='*' ){ /* Skip C style comments */ - cp+=2; - while( (c= *cp)!=0 && (c!='/' || cp[-1]!='*') ){ - if( c=='\n' ) lineno++; - cp++; - } - if( c ) cp++; - continue; - } - ps.tokenstart = cp; /* Mark the beginning of the token */ - ps.tokenlineno = lineno; /* Linenumber on which token begins */ - if( c=='\"' ){ /* String literals */ - cp++; - while( (c= *cp)!=0 && c!='\"' ){ - if( c=='\n' ) lineno++; - cp++; - } - if( c==0 ){ - ErrorMsg(ps.filename,startline, -"String starting on this line is not terminated before the end of the file."); - ps.errorcnt++; - nextcp = cp; - }else{ - nextcp = cp+1; - } - }else if( c=='{' ){ /* A block of C code */ - int level; - cp++; - for(level=1; (c= *cp)!=0 && (level>1 || c!='}'); cp++){ - if( c=='\n' ) lineno++; - else if( c=='{' ) level++; - else if( c=='}' ) level--; - else if( c=='/' && cp[1]=='*' ){ /* Skip comments */ - int prevc; - cp = &cp[2]; - prevc = 0; - while( (c= *cp)!=0 && (c!='/' || prevc!='*') ){ - if( c=='\n' ) lineno++; - prevc = c; - cp++; - } - }else if( c=='/' && cp[1]=='/' ){ /* Skip C++ style comments too */ - cp = &cp[2]; - while( (c= *cp)!=0 && c!='\n' ) cp++; - if( c ) lineno++; - }else if( c=='\'' || c=='\"' ){ /* String a character literals */ - int startchar, prevc; - startchar = c; - prevc = 0; - for(cp++; (c= *cp)!=0 && (c!=startchar || prevc=='\\'); cp++){ - if( c=='\n' ) lineno++; - if( prevc=='\\' ) prevc = 0; - else prevc = c; - } - } - } - if( c==0 ){ - ErrorMsg(ps.filename,ps.tokenlineno, -"C code starting on this line is not terminated before the end of the file."); - ps.errorcnt++; - nextcp = cp; - }else{ - nextcp = cp+1; - } - }else if( isalnum(c) ){ /* Identifiers */ - while( (c= *cp)!=0 && (isalnum(c) || c=='_') ) cp++; - nextcp = cp; - }else if( c==':' && cp[1]==':' && cp[2]=='=' ){ /* The operator "::=" */ - cp += 3; - nextcp = cp; - }else{ /* All other (one character) operators */ - cp++; - nextcp = cp; - } - c = *cp; - *cp = 0; /* Null terminate the token */ - parseonetoken(&ps); /* Parse the token */ - *cp = c; /* Restore the buffer */ - cp = nextcp; - } - free(filebuf); /* Release the buffer after parsing */ - gp->rule = ps.firstrule; - gp->errorcnt = ps.errorcnt; -} -/*************************** From the file "plink.c" *********************/ -/* -** Routines processing configuration follow-set propagation links -** in the LEMON parser generator. -*/ -static struct plink *plink_freelist = 0; - -/* Allocate a new plink */ -struct plink *Plink_new(){ - struct plink *new; - - if( plink_freelist==0 ){ - int i; - int amt = 100; - plink_freelist = (struct plink *)malloc( sizeof(struct plink)*amt ); - if( plink_freelist==0 ){ - fprintf(stderr, - "Unable to allocate memory for a new follow-set propagation link.\n"); - exit(1); - } - for(i=0; inext; - return new; -} - -/* Add a plink to a plink list */ -void Plink_add(plpp,cfp) -struct plink **plpp; -struct config *cfp; -{ - struct plink *new; - new = Plink_new(); - new->next = *plpp; - *plpp = new; - new->cfp = cfp; -} - -/* Transfer every plink on the list "from" to the list "to" */ -void Plink_copy(to,from) -struct plink **to; -struct plink *from; -{ - struct plink *nextpl; - while( from ){ - nextpl = from->next; - from->next = *to; - *to = from; - from = nextpl; - } -} - -/* Delete every plink on the list */ -void Plink_delete(plp) -struct plink *plp; -{ - struct plink *nextpl; - - while( plp ){ - nextpl = plp->next; - plp->next = plink_freelist; - plink_freelist = plp; - plp = nextpl; - } -} -/*********************** From the file "report.c" **************************/ -/* -** Procedures for generating reports and tables in the LEMON parser generator. -*/ - -/* Generate a filename with the given suffix. Space to hold the -** name comes from malloc() and must be freed by the calling -** function. -*/ -PRIVATE char *file_makename(lemp,suffix) -struct lemon *lemp; -char *suffix; -{ - char *name; - char *cp; - - name = malloc( strlen(lemp->filename) + strlen(suffix) + 5 ); - if( name==0 ){ - fprintf(stderr,"Can't allocate space for a filename.\n"); - exit(1); - } - strcpy(name,lemp->filename); - cp = strrchr(name,'.'); - if( cp ) *cp = 0; - strcat(name,suffix); - return name; -} - -/* Open a file with a name based on the name of the input file, -** but with a different (specified) suffix, and return a pointer -** to the stream */ -PRIVATE FILE *file_open(lemp,suffix,mode) -struct lemon *lemp; -char *suffix; -char *mode; -{ - FILE *fp; - - if( lemp->outname ) free(lemp->outname); - lemp->outname = file_makename(lemp, suffix); - fp = fopen(lemp->outname,mode); - if( fp==0 && *mode=='w' ){ - fprintf(stderr,"Can't open file \"%s\".\n",lemp->outname); - lemp->errorcnt++; - return 0; - } - return fp; -} - -/* Duplicate the input file without comments and without actions -** on rules */ -void Reprint(lemp) -struct lemon *lemp; -{ - struct rule *rp; - struct symbol *sp; - int i, j, maxlen, len, ncolumns, skip; - printf("// Reprint of input file \"%s\".\n// Symbols:\n",lemp->filename); - maxlen = 10; - for(i=0; insymbol; i++){ - sp = lemp->symbols[i]; - len = (int)strlen(sp->name); - if( len>maxlen ) maxlen = len; - } - ncolumns = 76/(maxlen+5); - if( ncolumns<1 ) ncolumns = 1; - skip = (lemp->nsymbol + ncolumns - 1)/ncolumns; - for(i=0; insymbol; j+=skip){ - sp = lemp->symbols[j]; - assert( sp->index==j ); - printf(" %3d %-*.*s",j,maxlen,maxlen,sp->name); - } - printf("\n"); - } - for(rp=lemp->rule; rp; rp=rp->next){ - printf("%s",rp->lhs->name); -/* if( rp->lhsalias ) printf("(%s)",rp->lhsalias); */ - printf(" ::="); - for(i=0; inrhs; i++){ - printf(" %s",rp->rhs[i]->name); -/* if( rp->rhsalias[i] ) printf("(%s)",rp->rhsalias[i]); */ - } - printf("."); - if( rp->precsym ) printf(" [%s]",rp->precsym->name); -/* if( rp->code ) printf("\n %s",rp->code); */ - printf("\n"); - } -} - -void ConfigPrint(fp,cfp) -FILE *fp; -struct config *cfp; -{ - struct rule *rp; - int i; - rp = cfp->rp; - fprintf(fp,"%s ::=",rp->lhs->name); - for(i=0; i<=rp->nrhs; i++){ - if( i==cfp->dot ) fprintf(fp," *"); - if( i==rp->nrhs ) break; - fprintf(fp," %s",rp->rhs[i]->name); - } -} - -/* #define TEST */ -#ifdef TEST -/* Print a set */ -PRIVATE void SetPrint(out,set,lemp) -FILE *out; -char *set; -struct lemon *lemp; -{ - int i; - char *spacer; - spacer = ""; - fprintf(out,"%12s[",""); - for(i=0; interminal; i++){ - if( SetFind(set,i) ){ - fprintf(out,"%s%s",spacer,lemp->symbols[i]->name); - spacer = " "; - } - } - fprintf(out,"]\n"); -} - -/* Print a plink chain */ -PRIVATE void PlinkPrint(out,plp,tag) -FILE *out; -struct plink *plp; -char *tag; -{ - while( plp ){ - fprintf(out,"%12s%s (state %2d) ","",tag,plp->cfp->stp->index); - ConfigPrint(out,plp->cfp); - fprintf(out,"\n"); - plp = plp->next; - } -} -#endif - -/* Print an action to the given file descriptor. Return FALSE if -** nothing was actually printed. -*/ -int PrintAction(struct action *ap, FILE *fp, int indent){ - int result = 1; - switch( ap->type ){ - case SHIFT: - fprintf(fp,"%*s shift %d",indent,ap->sp->name,ap->x.stp->index); - break; - case REDUCE: - fprintf(fp,"%*s reduce %d",indent,ap->sp->name,ap->x.rp->index); - break; - case ACCEPT: - fprintf(fp,"%*s accept",indent,ap->sp->name); - break; - case ERROR: - fprintf(fp,"%*s error",indent,ap->sp->name); - break; - case CONFLICT: - fprintf(fp,"%*s reduce %-3d ** Parsing conflict **", - indent,ap->sp->name,ap->x.rp->index); - break; - case SH_RESOLVED: - case RD_RESOLVED: - case NOT_USED: - result = 0; - break; - } - return result; -} - -/* Generate the "y.output" log file */ -void ReportOutput(lemp) -struct lemon *lemp; -{ - int i; - struct state *stp; - struct config *cfp; - struct action *ap; - FILE *fp; - - fp = file_open(lemp,".out","wb"); - if( fp==0 ) return; - fprintf(fp," \b"); - for(i=0; instate; i++){ - stp = lemp->sorted[i]; - fprintf(fp,"State %d:\n",stp->index); - if( lemp->basisflag ) cfp=stp->bp; - else cfp=stp->cfp; - while( cfp ){ - char buf[20]; - if( cfp->dot==cfp->rp->nrhs ){ - sprintf(buf,"(%d)",cfp->rp->index); - fprintf(fp," %5s ",buf); - }else{ - fprintf(fp," "); - } - ConfigPrint(fp,cfp); - fprintf(fp,"\n"); -#ifdef TEST - SetPrint(fp,cfp->fws,lemp); - PlinkPrint(fp,cfp->fplp,"To "); - PlinkPrint(fp,cfp->bplp,"From"); -#endif - if( lemp->basisflag ) cfp=cfp->bp; - else cfp=cfp->next; - } - fprintf(fp,"\n"); - for(ap=stp->ap; ap; ap=ap->next){ - if( PrintAction(ap,fp,30) ) fprintf(fp,"\n"); - } - fprintf(fp,"\n"); - } - fclose(fp); - return; -} - -/* Search for the file "name" which is in the same directory as -** the exacutable */ -PRIVATE char *pathsearch(argv0,name,modemask) -char *argv0; -char *name; -int modemask; -{ - char *pathlist; - char *path,*cp; - char c; - extern int access(); - -#ifdef __WIN32__ - cp = strrchr(argv0,'\\'); -#else - cp = strrchr(argv0,'/'); -#endif - if( cp ){ - c = *cp; - *cp = 0; - path = (char *)malloc( strlen(argv0) + strlen(name) + 2 ); - if( path ) sprintf(path,"%s/%s",argv0,name); - *cp = c; - }else{ - extern char *getenv(); - pathlist = getenv("PATH"); - if( pathlist==0 ) pathlist = ".:/bin:/usr/bin"; - path = (char *)malloc( strlen(pathlist)+strlen(name)+2 ); - if( path!=0 ){ - while( *pathlist ){ - cp = strchr(pathlist,':'); - if( cp==0 ) cp = &pathlist[strlen(pathlist)]; - c = *cp; - *cp = 0; - sprintf(path,"%s/%s",pathlist,name); - *cp = c; - if( c==0 ) pathlist = ""; - else pathlist = &cp[1]; - if( access(path,modemask)==0 ) break; - } - } - } - return path; -} - -/* Given an action, compute the integer value for that action -** which is to be put in the action table of the generated machine. -** Return negative if no action should be generated. -*/ -PRIVATE int compute_action(lemp,ap) -struct lemon *lemp; -struct action *ap; -{ - int act; - switch( ap->type ){ - case SHIFT: act = ap->x.stp->index; break; - case REDUCE: act = ap->x.rp->index + lemp->nstate; break; - case ERROR: act = lemp->nstate + lemp->nrule; break; - case ACCEPT: act = lemp->nstate + lemp->nrule + 1; break; - default: act = -1; break; - } - return act; -} - -#define LINESIZE 1000 -/* The next cluster of routines are for reading the template file -** and writing the results to the generated parser */ -/* The first function transfers data from "in" to "out" until -** a line is seen which begins with "%%". The line number is -** tracked. -** -** if name!=0, then any word that begin with "Parse" is changed to -** begin with *name instead. -*/ -PRIVATE void tplt_xfer(name,in,out,lineno) -char *name; -FILE *in; -FILE *out; -int *lineno; -{ - int i, iStart; - char line[LINESIZE]; - while( fgets(line,LINESIZE,in) && (line[0]!='%' || line[1]!='%') ){ - (*lineno)++; - iStart = 0; - if( name ){ - for(i=0; line[i]; i++){ - if( line[i]=='P' && strncmp(&line[i],"Parse",5)==0 - && (i==0 || !isalpha(line[i-1])) - ){ - if( i>iStart ) fprintf(out,"%.*s",i-iStart,&line[iStart]); - fprintf(out,"%s",name); - i += 4; - iStart = i+1; - } - } - } - fprintf(out,"%s",&line[iStart]); - } -} - -/* The next function finds the template file and opens it, returning -** a pointer to the opened file. */ -PRIVATE FILE *tplt_open(lemp) -struct lemon *lemp; -{ - static char templatename[] = "lempar.c"; - char buf[1000]; - FILE *in; - char *tpltname; - char *cp; - - cp = strrchr(lemp->filename,'.'); - if( cp ){ - sprintf(buf,"%.*s.lt",(int)(cp-lemp->filename),lemp->filename); - }else{ - sprintf(buf,"%s.lt",lemp->filename); - } - if( access(buf,004)==0 ){ - tpltname = buf; - }else if( access(templatename,004)==0 ){ - tpltname = templatename; - }else{ - tpltname = pathsearch(lemp->argv0,templatename,0); - } - if( tpltname==0 ){ - fprintf(stderr,"Can't find the parser driver template file \"%s\".\n", - templatename); - lemp->errorcnt++; - return 0; - } - in = fopen(tpltname,"rb"); - if( in==0 ){ - fprintf(stderr,"Can't open the template file \"%s\".\n",templatename); - lemp->errorcnt++; - return 0; - } - return in; -} - -/* Print a #line directive line to the output file. */ -PRIVATE void tplt_linedir(out,lineno,filename) -FILE *out; -int lineno; -char *filename; -{ - fprintf(out,"#line %d \"",lineno); - while( *filename ){ - if( *filename == '\\' ) putc('\\',out); - putc(*filename,out); - filename++; - } - fprintf(out,"\"\n"); -} - -/* Print a string to the file and keep the linenumber up to date */ -PRIVATE void tplt_print(out,lemp,str,strln,lineno) -FILE *out; -struct lemon *lemp; -char *str; -int strln; -int *lineno; -{ - if( str==0 ) return; - tplt_linedir(out,strln,lemp->filename); - (*lineno)++; - while( *str ){ - if( *str=='\n' ) (*lineno)++; - putc(*str,out); - str++; - } - if( str[-1]!='\n' ){ - putc('\n',out); - (*lineno)++; - } - tplt_linedir(out,*lineno+2,lemp->outname); - (*lineno)+=2; - return; -} - -/* -** The following routine emits code for the destructor for the -** symbol sp -*/ -void emit_destructor_code(out,sp,lemp,lineno) -FILE *out; -struct symbol *sp; -struct lemon *lemp; -int *lineno; -{ - char *cp = 0; - - int linecnt = 0; - if( sp->type==TERMINAL ){ - cp = lemp->tokendest; - if( cp==0 ) return; - tplt_linedir(out,lemp->tokendestln,lemp->filename); - fprintf(out,"{"); - }else if( sp->destructor ){ - cp = sp->destructor; - tplt_linedir(out,sp->destructorln,lemp->filename); - fprintf(out,"{"); - }else if( lemp->vardest ){ - cp = lemp->vardest; - if( cp==0 ) return; - tplt_linedir(out,lemp->vardestln,lemp->filename); - fprintf(out,"{"); - }else{ - assert( 0 ); /* Cannot happen */ - } - for(; *cp; cp++){ - if( *cp=='$' && cp[1]=='$' ){ - fprintf(out,"(yypminor->yy%d)",sp->dtnum); - cp++; - continue; - } - if( *cp=='\n' ) linecnt++; - fputc(*cp,out); - } - (*lineno) += 3 + linecnt; - fprintf(out,"}\n"); - tplt_linedir(out,*lineno,lemp->outname); - return; -} - -/* -** Return TRUE (non-zero) if the given symbol has a destructor. -*/ -int has_destructor(sp, lemp) -struct symbol *sp; -struct lemon *lemp; -{ - int ret; - if( sp->type==TERMINAL ){ - ret = lemp->tokendest!=0; - }else{ - ret = lemp->vardest!=0 || sp->destructor!=0; - } - return ret; -} - -/* -** Append text to a dynamically allocated string. If zText is 0 then -** reset the string to be empty again. Always return the complete text -** of the string (which is overwritten with each call). -** -** n bytes of zText are stored. If n==0 then all of zText up to the first -** \000 terminator is stored. zText can contain up to two instances of -** %d. The values of p1 and p2 are written into the first and second -** %d. -** -** If n==-1, then the previous character is overwritten. -*/ -PRIVATE char *append_str(char *zText, int n, int p1, int p2){ - static char *z = 0; - static size_t alloced = 0; - static size_t used = 0; - int c; - char zInt[40]; - - if( zText==0 ){ - used = 0; - return z; - } - if( n<=0 ){ - if( n<0 ){ - used += n; - assert( used>=0 ); - } - n = (int)strlen(zText); - } - if( n+sizeof(zInt)*2+used >= alloced ){ - alloced = n + sizeof(zInt)*2 + used + 200; - z = realloc(z, alloced); - } - if( z==0 ) return ""; - while( n-- > 0 ){ - c = *(zText++); - if( c=='%' && zText[0]=='d' ){ - sprintf(zInt, "%d", p1); - p1 = p2; - strcpy(&z[used], zInt); - used += strlen(&z[used]); - zText++; - n--; - }else{ - z[used++] = c; - } - } - z[used] = 0; - return z; -} - -/* -** zCode is a string that is the action associated with a rule. Expand -** the symbols in this string so that the refer to elements of the parser -** stack. -*/ -PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){ - char *cp, *xp; - int i; - char lhsused = 0; /* True if the LHS element has been used */ - char used[MAXRHS]; /* True for each RHS element which is used */ - - for(i=0; inrhs; i++) used[i] = 0; - lhsused = 0; - - append_str(0,0,0,0); - for(cp=rp->code; *cp; cp++){ - if( isalpha(*cp) && (cp==rp->code || (!isalnum(cp[-1]) && cp[-1]!='_')) ){ - char saved; - for(xp= &cp[1]; isalnum(*xp) || *xp=='_'; xp++); - saved = *xp; - *xp = 0; - if( rp->lhsalias && strcmp(cp,rp->lhsalias)==0 ){ - append_str("yygotominor.yy%d",0,rp->lhs->dtnum,0); - cp = xp; - lhsused = 1; - }else{ - for(i=0; inrhs; i++){ - if( rp->rhsalias[i] && strcmp(cp,rp->rhsalias[i])==0 ){ - if( cp!=rp->code && cp[-1]=='@' ){ - /* If the argument is of the form @X then substituted - ** the token number of X, not the value of X */ - append_str("yymsp[%d].major",-1,i-rp->nrhs+1,0); - }else{ - append_str("yymsp[%d].minor.yy%d",0, - i-rp->nrhs+1,rp->rhs[i]->dtnum); - } - cp = xp; - used[i] = 1; - break; - } - } - } - *xp = saved; - } - append_str(cp, 1, 0, 0); - } /* End loop */ - - /* Check to make sure the LHS has been used */ - if( rp->lhsalias && !lhsused ){ - ErrorMsg(lemp->filename,rp->ruleline, - "Label \"%s\" for \"%s(%s)\" is never used.", - rp->lhsalias,rp->lhs->name,rp->lhsalias); - lemp->errorcnt++; - } - - /* Generate destructor code for RHS symbols which are not used in the - ** reduce code */ - for(i=0; inrhs; i++){ - if( rp->rhsalias[i] && !used[i] ){ - ErrorMsg(lemp->filename,rp->ruleline, - "Label %s for \"%s(%s)\" is never used.", - rp->rhsalias[i],rp->rhs[i]->name,rp->rhsalias[i]); - lemp->errorcnt++; - }else if( rp->rhsalias[i]==0 ){ - if( has_destructor(rp->rhs[i],lemp) ){ - append_str(" yy_destructor(%d,&yymsp[%d].minor);\n", 0, - rp->rhs[i]->index,i-rp->nrhs+1); - }else{ - /* No destructor defined for this term */ - } - } - } - cp = append_str(0,0,0,0); - rp->code = Strsafe(cp); -} - -/* -** Generate code which executes when the rule "rp" is reduced. Write -** the code to "out". Make sure lineno stays up-to-date. -*/ -PRIVATE void emit_code(out,rp,lemp,lineno) -FILE *out; -struct rule *rp; -struct lemon *lemp; -int *lineno; -{ - char *cp; - int linecnt = 0; - - /* Generate code to do the reduce action */ - if( rp->code ){ - tplt_linedir(out,rp->line,lemp->filename); - fprintf(out,"{%s",rp->code); - for(cp=rp->code; *cp; cp++){ - if( *cp=='\n' ) linecnt++; - } /* End loop */ - (*lineno) += 3 + linecnt; - fprintf(out,"}\n"); - tplt_linedir(out,*lineno,lemp->outname); - } /* End if( rp->code ) */ - - return; -} - -/* -** Print the definition of the union used for the parser's data stack. -** This union contains fields for every possible data type for tokens -** and nonterminals. In the process of computing and printing this -** union, also set the ".dtnum" field of every terminal and nonterminal -** symbol. -*/ -void print_stack_union(out,lemp,plineno,mhflag) -FILE *out; /* The output stream */ -struct lemon *lemp; /* The main info structure for this parser */ -int *plineno; /* Pointer to the line number */ -int mhflag; /* True if generating makeheaders output */ -{ - int lineno = *plineno; /* The line number of the output */ - char **types; /* A hash table of datatypes */ - int arraysize; /* Size of the "types" array */ - int maxdtlength; /* Maximum length of any ".datatype" field. */ - char *stddt; /* Standardized name for a datatype */ - int i,j; /* Loop counters */ - int hash; /* For hashing the name of a type */ - char *name; /* Name of the parser */ - - /* Allocate and initialize types[] and allocate stddt[] */ - arraysize = lemp->nsymbol * 2; - types = (char**)malloc( arraysize * sizeof(char*) ); - for(i=0; ivartype ){ - maxdtlength = (int)strlen(lemp->vartype); - } - for(i=0; insymbol; i++){ - int len; - struct symbol *sp = lemp->symbols[i]; - if( sp->datatype==0 ) continue; - len = (int)strlen(sp->datatype); - if( len>maxdtlength ) maxdtlength = len; - } - stddt = (char*)malloc( maxdtlength*2 + 1 ); - if( types==0 || stddt==0 ){ - fprintf(stderr,"Out of memory.\n"); - exit(1); - } - - /* Build a hash table of datatypes. The ".dtnum" field of each symbol - ** is filled in with the hash index plus 1. A ".dtnum" value of 0 is - ** used for terminal symbols. If there is no %default_type defined then - ** 0 is also used as the .dtnum value for nonterminals which do not specify - ** a datatype using the %type directive. - */ - for(i=0; insymbol; i++){ - struct symbol *sp = lemp->symbols[i]; - char *cp; - if( sp==lemp->errsym ){ - sp->dtnum = arraysize+1; - continue; - } - if( sp->type!=NONTERMINAL || (sp->datatype==0 && lemp->vartype==0) ){ - sp->dtnum = 0; - continue; - } - cp = sp->datatype; - if( cp==0 ) cp = lemp->vartype; - j = 0; - while( isspace(*cp) ) cp++; - while( *cp ) stddt[j++] = *cp++; - while( j>0 && isspace(stddt[j-1]) ) j--; - stddt[j] = 0; - hash = 0; - for(j=0; stddt[j]; j++){ - hash = hash*53 + stddt[j]; - } - hash = (hash & 0x7fffffff)%arraysize; - while( types[hash] ){ - if( strcmp(types[hash],stddt)==0 ){ - sp->dtnum = hash + 1; - break; - } - hash++; - if( hash>=arraysize ) hash = 0; - } - if( types[hash]==0 ){ - sp->dtnum = hash + 1; - types[hash] = (char*)malloc( strlen(stddt)+1 ); - if( types[hash]==0 ){ - fprintf(stderr,"Out of memory.\n"); - exit(1); - } - strcpy(types[hash],stddt); - } - } - - /* Print out the definition of YYTOKENTYPE and YYMINORTYPE */ - name = lemp->name ? lemp->name : "Parse"; - lineno = *plineno; - if( mhflag ){ fprintf(out,"#if INTERFACE\n"); lineno++; } - fprintf(out,"#define %sTOKENTYPE %s\n",name, - lemp->tokentype?lemp->tokentype:"void*"); lineno++; - if( mhflag ){ fprintf(out,"#endif\n"); lineno++; } - fprintf(out,"typedef union {\n"); lineno++; - fprintf(out," %sTOKENTYPE yy0;\n",name); lineno++; - for(i=0; ierrsym->dtnum); lineno++; - free(stddt); - free(types); - fprintf(out,"} YYMINORTYPE;\n"); lineno++; - *plineno = lineno; -} - -/* -** Return the name of a C datatype able to represent values between -** lwr and upr, inclusive. -*/ -static const char *minimum_size_type(int lwr, int upr){ - if( lwr>=0 ){ - if( upr<=255 ){ - return "unsigned char"; - }else if( upr<65535 ){ - return "unsigned short int"; - }else{ - return "unsigned int"; - } - }else if( lwr>=-127 && upr<=127 ){ - return "signed char"; - }else if( lwr>=-32767 && upr<32767 ){ - return "short"; - }else{ - return "int"; - } -} - -/* -** Each state contains a set of token transaction and a set of -** nonterminal transactions. Each of these sets makes an instance -** of the following structure. An array of these structures is used -** to order the creation of entries in the yy_action[] table. -*/ -struct axset { - struct state *stp; /* A pointer to a state */ - int isTkn; /* True to use tokens. False for non-terminals */ - int nAction; /* Number of actions */ -}; - -/* -** Compare to axset structures for sorting purposes -*/ -static int axset_compare(const void *a, const void *b){ - struct axset *p1 = (struct axset*)a; - struct axset *p2 = (struct axset*)b; - return p2->nAction - p1->nAction; -} - -/* Generate C source code for the parser */ -void ReportTable(lemp, mhflag) -struct lemon *lemp; -int mhflag; /* Output in makeheaders format if true */ -{ - FILE *out, *in; - char line[LINESIZE]; - int lineno; - struct state *stp; - struct action *ap; - struct rule *rp; - struct acttab *pActtab; - int i, j, n; - char *name; - int mnTknOfst, mxTknOfst; - int mnNtOfst, mxNtOfst; - struct axset *ax; - - in = tplt_open(lemp); - if( in==0 ) return; - out = file_open(lemp,".c","wb"); - if( out==0 ){ - fclose(in); - return; - } - lineno = 1; - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate the include code, if any */ - tplt_print(out,lemp,lemp->include,lemp->includeln,&lineno); - if( mhflag ){ - char *name = file_makename(lemp, ".h"); - fprintf(out,"#include \"%s\"\n", name); lineno++; - free(name); - } - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate #defines for all tokens */ - if( mhflag ){ - char *prefix; - fprintf(out,"#if INTERFACE\n"); lineno++; - if( lemp->tokenprefix ) prefix = lemp->tokenprefix; - else prefix = ""; - for(i=1; interminal; i++){ - fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i); - lineno++; - } - fprintf(out,"#endif\n"); lineno++; - } - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate the defines */ - fprintf(out,"#define YYCODETYPE %s\n", - minimum_size_type(0, lemp->nsymbol+5)); lineno++; - fprintf(out,"#define YYNOCODE %d\n",lemp->nsymbol+1); lineno++; - fprintf(out,"#define YYACTIONTYPE %s\n", - minimum_size_type(0, lemp->nstate+lemp->nrule+5)); lineno++; - print_stack_union(out,lemp,&lineno,mhflag); - if( lemp->stacksize ){ - if( atoi(lemp->stacksize)<=0 ){ - ErrorMsg(lemp->filename,0, -"Illegal stack size: [%s]. The stack size should be an integer constant.", - lemp->stacksize); - lemp->errorcnt++; - lemp->stacksize = "100"; - } - fprintf(out,"#define YYSTACKDEPTH %s\n",lemp->stacksize); lineno++; - }else{ - fprintf(out,"#define YYSTACKDEPTH 100\n"); lineno++; - } - if( mhflag ){ - fprintf(out,"#if INTERFACE\n"); lineno++; - } - name = lemp->name ? lemp->name : "Parse"; - if( lemp->arg && lemp->arg[0] ){ - int i; - i = (int)strlen(lemp->arg); - while( i>=1 && isspace(lemp->arg[i-1]) ) i--; - while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--; - fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg); lineno++; - fprintf(out,"#define %sARG_PDECL ,%s\n",name,lemp->arg); lineno++; - fprintf(out,"#define %sARG_FETCH %s = yypParser->%s\n", - name,lemp->arg,&lemp->arg[i]); lineno++; - fprintf(out,"#define %sARG_STORE yypParser->%s = %s\n", - name,&lemp->arg[i],&lemp->arg[i]); lineno++; - }else{ - fprintf(out,"#define %sARG_SDECL\n",name); lineno++; - fprintf(out,"#define %sARG_PDECL\n",name); lineno++; - fprintf(out,"#define %sARG_FETCH\n",name); lineno++; - fprintf(out,"#define %sARG_STORE\n",name); lineno++; - } - if( mhflag ){ - fprintf(out,"#endif\n"); lineno++; - } - fprintf(out,"#define YYNSTATE %d\n",lemp->nstate); lineno++; - fprintf(out,"#define YYNRULE %d\n",lemp->nrule); lineno++; - fprintf(out,"#define YYERRORSYMBOL %d\n",lemp->errsym->index); lineno++; - fprintf(out,"#define YYERRSYMDT yy%d\n",lemp->errsym->dtnum); lineno++; - if( lemp->has_fallback ){ - fprintf(out,"#define YYFALLBACK 1\n"); lineno++; - } - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate the action table and its associates: - ** - ** yy_action[] A single table containing all actions. - ** yy_lookahead[] A table containing the lookahead for each entry in - ** yy_action. Used to detect hash collisions. - ** yy_shift_ofst[] For each state, the offset into yy_action for - ** shifting terminals. - ** yy_reduce_ofst[] For each state, the offset into yy_action for - ** shifting non-terminals after a reduce. - ** yy_default[] Default action for each state. - */ - - /* Compute the actions on all states and count them up */ - ax = malloc( sizeof(ax[0])*lemp->nstate*2 ); - if( ax==0 ){ - fprintf(stderr,"malloc failed\n"); - exit(1); - } - for(i=0; instate; i++){ - stp = lemp->sorted[i]; - stp->nTknAct = stp->nNtAct = 0; - stp->iDflt = lemp->nstate + lemp->nrule; - stp->iTknOfst = NO_OFFSET; - stp->iNtOfst = NO_OFFSET; - for(ap=stp->ap; ap; ap=ap->next){ - if( compute_action(lemp,ap)>=0 ){ - if( ap->sp->indexnterminal ){ - stp->nTknAct++; - }else if( ap->sp->indexnsymbol ){ - stp->nNtAct++; - }else{ - stp->iDflt = compute_action(lemp, ap); - } - } - } - ax[i*2].stp = stp; - ax[i*2].isTkn = 1; - ax[i*2].nAction = stp->nTknAct; - ax[i*2+1].stp = stp; - ax[i*2+1].isTkn = 0; - ax[i*2+1].nAction = stp->nNtAct; - } - mxTknOfst = mnTknOfst = 0; - mxNtOfst = mnNtOfst = 0; - - /* Compute the action table. In order to try to keep the size of the - ** action table to a minimum, the heuristic of placing the largest action - ** sets first is used. - */ - qsort(ax, lemp->nstate*2, sizeof(ax[0]), axset_compare); - pActtab = acttab_alloc(); - for(i=0; instate*2 && ax[i].nAction>0; i++){ - stp = ax[i].stp; - if( ax[i].isTkn ){ - for(ap=stp->ap; ap; ap=ap->next){ - int action; - if( ap->sp->index>=lemp->nterminal ) continue; - action = compute_action(lemp, ap); - if( action<0 ) continue; - acttab_action(pActtab, ap->sp->index, action); - } - stp->iTknOfst = acttab_insert(pActtab); - if( stp->iTknOfstiTknOfst; - if( stp->iTknOfst>mxTknOfst ) mxTknOfst = stp->iTknOfst; - }else{ - for(ap=stp->ap; ap; ap=ap->next){ - int action; - if( ap->sp->indexnterminal ) continue; - if( ap->sp->index==lemp->nsymbol ) continue; - action = compute_action(lemp, ap); - if( action<0 ) continue; - acttab_action(pActtab, ap->sp->index, action); - } - stp->iNtOfst = acttab_insert(pActtab); - if( stp->iNtOfstiNtOfst; - if( stp->iNtOfst>mxNtOfst ) mxNtOfst = stp->iNtOfst; - } - } - free(ax); - - /* Output the yy_action table */ - fprintf(out,"static YYACTIONTYPE yy_action[] = {\n"); lineno++; - n = acttab_size(pActtab); - for(i=j=0; insymbol + lemp->nrule + 2; - if( j==0 ) fprintf(out," /* %5d */ ", i); - fprintf(out, " %4d,", action); - if( j==9 || i==n-1 ){ - fprintf(out, "\n"); lineno++; - j = 0; - }else{ - j++; - } - } - fprintf(out, "};\n"); lineno++; - - /* Output the yy_lookahead table */ - fprintf(out,"static YYCODETYPE yy_lookahead[] = {\n"); lineno++; - for(i=j=0; insymbol; - if( j==0 ) fprintf(out," /* %5d */ ", i); - fprintf(out, " %4d,", la); - if( j==9 || i==n-1 ){ - fprintf(out, "\n"); lineno++; - j = 0; - }else{ - j++; - } - } - fprintf(out, "};\n"); lineno++; - - /* Output the yy_shift_ofst[] table */ - fprintf(out, "#define YY_SHIFT_USE_DFLT (%d)\n", mnTknOfst-1); lineno++; - fprintf(out, "static %s yy_shift_ofst[] = {\n", - minimum_size_type(mnTknOfst-1, mxTknOfst)); lineno++; - n = lemp->nstate; - for(i=j=0; isorted[i]; - ofst = stp->iTknOfst; - if( ofst==NO_OFFSET ) ofst = mnTknOfst - 1; - if( j==0 ) fprintf(out," /* %5d */ ", i); - fprintf(out, " %4d,", ofst); - if( j==9 || i==n-1 ){ - fprintf(out, "\n"); lineno++; - j = 0; - }else{ - j++; - } - } - fprintf(out, "};\n"); lineno++; - - /* Output the yy_reduce_ofst[] table */ - fprintf(out, "#define YY_REDUCE_USE_DFLT (%d)\n", mnNtOfst-1); lineno++; - fprintf(out, "static %s yy_reduce_ofst[] = {\n", - minimum_size_type(mnNtOfst-1, mxNtOfst)); lineno++; - n = lemp->nstate; - for(i=j=0; isorted[i]; - ofst = stp->iNtOfst; - if( ofst==NO_OFFSET ) ofst = mnNtOfst - 1; - if( j==0 ) fprintf(out," /* %5d */ ", i); - fprintf(out, " %4d,", ofst); - if( j==9 || i==n-1 ){ - fprintf(out, "\n"); lineno++; - j = 0; - }else{ - j++; - } - } - fprintf(out, "};\n"); lineno++; - - /* Output the default action table */ - fprintf(out, "static YYACTIONTYPE yy_default[] = {\n"); lineno++; - n = lemp->nstate; - for(i=j=0; isorted[i]; - if( j==0 ) fprintf(out," /* %5d */ ", i); - fprintf(out, " %4d,", stp->iDflt); - if( j==9 || i==n-1 ){ - fprintf(out, "\n"); lineno++; - j = 0; - }else{ - j++; - } - } - fprintf(out, "};\n"); lineno++; - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate the table of fallback tokens. - */ - if( lemp->has_fallback ){ - for(i=0; interminal; i++){ - struct symbol *p = lemp->symbols[i]; - if( p->fallback==0 ){ - fprintf(out, " 0, /* %10s => nothing */\n", p->name); - }else{ - fprintf(out, " %3d, /* %10s => %s */\n", p->fallback->index, - p->name, p->fallback->name); - } - lineno++; - } - } - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate a table containing the symbolic name of every symbol - */ - for(i=0; insymbol; i++){ - sprintf(line,"\"%s\",",lemp->symbols[i]->name); - fprintf(out," %-15s",line); - if( (i&3)==3 ){ fprintf(out,"\n"); lineno++; } - } - if( (i&3)!=0 ){ fprintf(out,"\n"); lineno++; } - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate a table containing a text string that describes every - ** rule in the rule set of the grammer. This information is used - ** when tracing REDUCE actions. - */ - for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){ - assert( rp->index==i ); - fprintf(out," /* %3d */ \"%s ::=", i, rp->lhs->name); - for(j=0; jnrhs; j++) fprintf(out," %s",rp->rhs[j]->name); - fprintf(out,"\",\n"); lineno++; - } - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate code which executes every time a symbol is popped from - ** the stack while processing errors or while destroying the parser. - ** (In other words, generate the %destructor actions) - */ - if( lemp->tokendest ){ - for(i=0; insymbol; i++){ - struct symbol *sp = lemp->symbols[i]; - if( sp==0 || sp->type!=TERMINAL ) continue; - fprintf(out," case %d:\n",sp->index); lineno++; - } - for(i=0; insymbol && lemp->symbols[i]->type!=TERMINAL; i++); - if( insymbol ){ - emit_destructor_code(out,lemp->symbols[i],lemp,&lineno); - fprintf(out," break;\n"); lineno++; - } - } - for(i=0; insymbol; i++){ - struct symbol *sp = lemp->symbols[i]; - if( sp==0 || sp->type==TERMINAL || sp->destructor==0 ) continue; - fprintf(out," case %d:\n",sp->index); lineno++; - - /* Combine duplicate destructors into a single case */ - for(j=i+1; jnsymbol; j++){ - struct symbol *sp2 = lemp->symbols[j]; - if( sp2 && sp2->type!=TERMINAL && sp2->destructor - && sp2->dtnum==sp->dtnum - && strcmp(sp->destructor,sp2->destructor)==0 ){ - fprintf(out," case %d:\n",sp2->index); lineno++; - sp2->destructor = 0; - } - } - - emit_destructor_code(out,lemp->symbols[i],lemp,&lineno); - fprintf(out," break;\n"); lineno++; - } - if( lemp->vardest ){ - struct symbol *dflt_sp = 0; - for(i=0; insymbol; i++){ - struct symbol *sp = lemp->symbols[i]; - if( sp==0 || sp->type==TERMINAL || - sp->index<=0 || sp->destructor!=0 ) continue; - fprintf(out," case %d:\n",sp->index); lineno++; - dflt_sp = sp; - } - if( dflt_sp!=0 ){ - emit_destructor_code(out,dflt_sp,lemp,&lineno); - fprintf(out," break;\n"); lineno++; - } - } - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate code which executes whenever the parser stack overflows */ - tplt_print(out,lemp,lemp->overflow,lemp->overflowln,&lineno); - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate the table of rule information - ** - ** Note: This code depends on the fact that rules are number - ** sequentually beginning with 0. - */ - for(rp=lemp->rule; rp; rp=rp->next){ - fprintf(out," { %d, %d },\n",rp->lhs->index,rp->nrhs); lineno++; - } - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate code which execution during each REDUCE action */ - for(rp=lemp->rule; rp; rp=rp->next){ - if( rp->code ) translate_code(lemp, rp); - } - for(rp=lemp->rule; rp; rp=rp->next){ - struct rule *rp2; - if( rp->code==0 ) continue; - fprintf(out," case %d:\n",rp->index); lineno++; - for(rp2=rp->next; rp2; rp2=rp2->next){ - if( rp2->code==rp->code ){ - fprintf(out," case %d:\n",rp2->index); lineno++; - rp2->code = 0; - } - } - emit_code(out,rp,lemp,&lineno); - fprintf(out," break;\n"); lineno++; - } - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate code which executes if a parse fails */ - tplt_print(out,lemp,lemp->failure,lemp->failureln,&lineno); - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate code which executes when a syntax error occurs */ - tplt_print(out,lemp,lemp->error,lemp->errorln,&lineno); - tplt_xfer(lemp->name,in,out,&lineno); - - /* Generate code which executes when the parser accepts its input */ - tplt_print(out,lemp,lemp->accept,lemp->acceptln,&lineno); - tplt_xfer(lemp->name,in,out,&lineno); - - /* Append any addition code the user desires */ - tplt_print(out,lemp,lemp->extracode,lemp->extracodeln,&lineno); - - fclose(in); - fclose(out); - return; -} - -/* Generate a header file for the parser */ -void ReportHeader(lemp) -struct lemon *lemp; -{ - FILE *out, *in; - char *prefix; - char line[LINESIZE]; - char pattern[LINESIZE]; - int i; - - if( lemp->tokenprefix ) prefix = lemp->tokenprefix; - else prefix = ""; - in = file_open(lemp,".h","rb"); - if( in ){ - for(i=1; interminal && fgets(line,LINESIZE,in); i++){ - sprintf(pattern,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i); - if( strcmp(line,pattern) ) break; - } - fclose(in); - if( i==lemp->nterminal ){ - /* No change in the file. Don't rewrite it. */ - return; - } - } - out = file_open(lemp,".h","wb"); - if( out ){ - for(i=1; interminal; i++){ - fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i); - } - fclose(out); - } - return; -} - -/* Reduce the size of the action tables, if possible, by making use -** of defaults. -** -** In this version, we take the most frequent REDUCE action and make -** it the default. Only default a reduce if there are more than one. -*/ -void CompressTables(lemp) -struct lemon *lemp; -{ - struct state *stp; - struct action *ap, *ap2; - struct rule *rp, *rp2, *rbest; - int nbest, n; - int i; - - for(i=0; instate; i++){ - stp = lemp->sorted[i]; - nbest = 0; - rbest = 0; - - for(ap=stp->ap; ap; ap=ap->next){ - if( ap->type!=REDUCE ) continue; - rp = ap->x.rp; - if( rp==rbest ) continue; - n = 1; - for(ap2=ap->next; ap2; ap2=ap2->next){ - if( ap2->type!=REDUCE ) continue; - rp2 = ap2->x.rp; - if( rp2==rbest ) continue; - if( rp2==rp ) n++; - } - if( n>nbest ){ - nbest = n; - rbest = rp; - } - } - - /* Do not make a default if the number of rules to default - ** is not at least 2 */ - if( nbest<2 ) continue; - - - /* Combine matching REDUCE actions into a single default */ - for(ap=stp->ap; ap; ap=ap->next){ - if( ap->type==REDUCE && ap->x.rp==rbest ) break; - } - assert( ap ); - ap->sp = Symbol_new("{default}"); - for(ap=ap->next; ap; ap=ap->next){ - if( ap->type==REDUCE && ap->x.rp==rbest ) ap->type = NOT_USED; - } - stp->ap = Action_sort(stp->ap); - } -} - -/***************** From the file "set.c" ************************************/ -/* -** Set manipulation routines for the LEMON parser generator. -*/ - -static int size = 0; - -/* Set the set size */ -void SetSize(n) -int n; -{ - size = n+1; -} - -/* Allocate a new set */ -char *SetNew(){ - char *s; - int i; - s = (char*)malloc( size ); - if( s==0 ){ - extern void memory_error(); - memory_error(); - } - for(i=0; isize = 1024; - x1a->count = 0; - x1a->tbl = (x1node*)malloc( - (sizeof(x1node) + sizeof(x1node*))*1024 ); - if( x1a->tbl==0 ){ - free(x1a); - x1a = 0; - }else{ - int i; - x1a->ht = (x1node**)&(x1a->tbl[1024]); - for(i=0; i<1024; i++) x1a->ht[i] = 0; - } - } -} -/* Insert a new record into the array. Return TRUE if successful. -** Prior data with the same key is NOT overwritten */ -int Strsafe_insert(data) -char *data; -{ - x1node *np; - int h; - int ph; - - if( x1a==0 ) return 0; - ph = strhash(data); - h = ph & (x1a->size-1); - np = x1a->ht[h]; - while( np ){ - if( strcmp(np->data,data)==0 ){ - /* An existing entry with the same key is found. */ - /* Fail because overwrite is not allows. */ - return 0; - } - np = np->next; - } - if( x1a->count>=x1a->size ){ - /* Need to make the hash table bigger */ - int i,size; - struct s_x1 array; - array.size = size = x1a->size*2; - array.count = x1a->count; - array.tbl = (x1node*)malloc( - (sizeof(x1node) + sizeof(x1node*))*size ); - if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ - array.ht = (x1node**)&(array.tbl[size]); - for(i=0; icount; i++){ - x1node *oldnp, *newnp; - oldnp = &(x1a->tbl[i]); - h = strhash(oldnp->data) & (size-1); - newnp = &(array.tbl[i]); - if( array.ht[h] ) array.ht[h]->from = &(newnp->next); - newnp->next = array.ht[h]; - newnp->data = oldnp->data; - newnp->from = &(array.ht[h]); - array.ht[h] = newnp; - } - free(x1a->tbl); - *x1a = array; - } - /* Insert the new data */ - h = ph & (x1a->size-1); - np = &(x1a->tbl[x1a->count++]); - np->data = data; - if( x1a->ht[h] ) x1a->ht[h]->from = &(np->next); - np->next = x1a->ht[h]; - x1a->ht[h] = np; - np->from = &(x1a->ht[h]); - return 1; -} - -/* Return a pointer to data assigned to the given key. Return NULL -** if no such key. */ -char *Strsafe_find(key) -char *key; -{ - int h; - x1node *np; - - if( x1a==0 ) return 0; - h = strhash(key) & (x1a->size-1); - np = x1a->ht[h]; - while( np ){ - if( strcmp(np->data,key)==0 ) break; - np = np->next; - } - return np ? np->data : 0; -} - -/* Return a pointer to the (terminal or nonterminal) symbol "x". -** Create a new symbol if this is the first time "x" has been seen. -*/ -struct symbol *Symbol_new(x) -char *x; -{ - struct symbol *sp; - - sp = Symbol_find(x); - if( sp==0 ){ - sp = (struct symbol *)malloc( sizeof(struct symbol) ); - MemoryCheck(sp); - sp->name = Strsafe(x); - sp->type = isupper(*x) ? TERMINAL : NONTERMINAL; - sp->rule = 0; - sp->fallback = 0; - sp->prec = -1; - sp->assoc = UNK; - sp->firstset = 0; - sp->lambda = B_FALSE; - sp->destructor = 0; - sp->datatype = 0; - Symbol_insert(sp,sp->name); - } - return sp; -} - -/* Compare two symbols for working purposes -** -** Symbols that begin with upper case letters (terminals or tokens) -** must sort before symbols that begin with lower case letters -** (non-terminals). Other than that, the order does not matter. -** -** We find experimentally that leaving the symbols in their original -** order (the order they appeared in the grammar file) gives the -** smallest parser tables in SQLite. -*/ -int Symbolcmpp(struct symbol **a, struct symbol **b){ - int i1 = (**a).index + 10000000*((**a).name[0]>'Z'); - int i2 = (**b).index + 10000000*((**b).name[0]>'Z'); - return i1-i2; -} - -/* There is one instance of the following structure for each -** associative array of type "x2". -*/ -struct s_x2 { - int size; /* The number of available slots. */ - /* Must be a power of 2 greater than or */ - /* equal to 1 */ - int count; /* Number of currently slots filled */ - struct s_x2node *tbl; /* The data stored here */ - struct s_x2node **ht; /* Hash table for lookups */ -}; - -/* There is one instance of this structure for every data element -** in an associative array of type "x2". -*/ -typedef struct s_x2node { - struct symbol *data; /* The data */ - char *key; /* The key */ - struct s_x2node *next; /* Next entry with the same hash */ - struct s_x2node **from; /* Previous link */ -} x2node; - -/* There is only one instance of the array, which is the following */ -static struct s_x2 *x2a; - -/* Allocate a new associative array */ -void Symbol_init(){ - if( x2a ) return; - x2a = (struct s_x2*)malloc( sizeof(struct s_x2) ); - if( x2a ){ - x2a->size = 128; - x2a->count = 0; - x2a->tbl = (x2node*)malloc( - (sizeof(x2node) + sizeof(x2node*))*128 ); - if( x2a->tbl==0 ){ - free(x2a); - x2a = 0; - }else{ - int i; - x2a->ht = (x2node**)&(x2a->tbl[128]); - for(i=0; i<128; i++) x2a->ht[i] = 0; - } - } -} -/* Insert a new record into the array. Return TRUE if successful. -** Prior data with the same key is NOT overwritten */ -int Symbol_insert(data,key) -struct symbol *data; -char *key; -{ - x2node *np; - int h; - int ph; - - if( x2a==0 ) return 0; - ph = strhash(key); - h = ph & (x2a->size-1); - np = x2a->ht[h]; - while( np ){ - if( strcmp(np->key,key)==0 ){ - /* An existing entry with the same key is found. */ - /* Fail because overwrite is not allows. */ - return 0; - } - np = np->next; - } - if( x2a->count>=x2a->size ){ - /* Need to make the hash table bigger */ - int i,size; - struct s_x2 array; - array.size = size = x2a->size*2; - array.count = x2a->count; - array.tbl = (x2node*)malloc( - (sizeof(x2node) + sizeof(x2node*))*size ); - if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ - array.ht = (x2node**)&(array.tbl[size]); - for(i=0; icount; i++){ - x2node *oldnp, *newnp; - oldnp = &(x2a->tbl[i]); - h = strhash(oldnp->key) & (size-1); - newnp = &(array.tbl[i]); - if( array.ht[h] ) array.ht[h]->from = &(newnp->next); - newnp->next = array.ht[h]; - newnp->key = oldnp->key; - newnp->data = oldnp->data; - newnp->from = &(array.ht[h]); - array.ht[h] = newnp; - } - free(x2a->tbl); - *x2a = array; - } - /* Insert the new data */ - h = ph & (x2a->size-1); - np = &(x2a->tbl[x2a->count++]); - np->key = key; - np->data = data; - if( x2a->ht[h] ) x2a->ht[h]->from = &(np->next); - np->next = x2a->ht[h]; - x2a->ht[h] = np; - np->from = &(x2a->ht[h]); - return 1; -} - -/* Return a pointer to data assigned to the given key. Return NULL -** if no such key. */ -struct symbol *Symbol_find(key) -char *key; -{ - int h; - x2node *np; - - if( x2a==0 ) return 0; - h = strhash(key) & (x2a->size-1); - np = x2a->ht[h]; - while( np ){ - if( strcmp(np->key,key)==0 ) break; - np = np->next; - } - return np ? np->data : 0; -} - -/* Return the n-th data. Return NULL if n is out of range. */ -struct symbol *Symbol_Nth(n) -int n; -{ - struct symbol *data; - if( x2a && n>0 && n<=x2a->count ){ - data = x2a->tbl[n-1].data; - }else{ - data = 0; - } - return data; -} - -/* Return the size of the array */ -int Symbol_count() -{ - return x2a ? x2a->count : 0; -} - -/* Return an array of pointers to all data in the table. -** The array is obtained from malloc. Return NULL if memory allocation -** problems, or if the array is empty. */ -struct symbol **Symbol_arrayof() -{ - struct symbol **array; - int i,size; - if( x2a==0 ) return 0; - size = x2a->count; - array = (struct symbol **)malloc( sizeof(struct symbol *)*size ); - if( array ){ - for(i=0; itbl[i].data; - } - return array; -} - -/* Compare two configurations */ -int Configcmp(a,b) -struct config *a; -struct config *b; -{ - int x; - x = a->rp->index - b->rp->index; - if( x==0 ) x = a->dot - b->dot; - return x; -} - -/* Compare two states */ -PRIVATE int statecmp(a,b) -struct config *a; -struct config *b; -{ - int rc; - for(rc=0; rc==0 && a && b; a=a->bp, b=b->bp){ - rc = a->rp->index - b->rp->index; - if( rc==0 ) rc = a->dot - b->dot; - } - if( rc==0 ){ - if( a ) rc = 1; - if( b ) rc = -1; - } - return rc; -} - -/* Hash a state */ -PRIVATE int statehash(a) -struct config *a; -{ - int h=0; - while( a ){ - h = h*571 + a->rp->index*37 + a->dot; - a = a->bp; - } - return h; -} - -/* Allocate a new state structure */ -struct state *State_new() -{ - struct state *new; - new = (struct state *)malloc( sizeof(struct state) ); - MemoryCheck(new); - return new; -} - -/* There is one instance of the following structure for each -** associative array of type "x3". -*/ -struct s_x3 { - int size; /* The number of available slots. */ - /* Must be a power of 2 greater than or */ - /* equal to 1 */ - int count; /* Number of currently slots filled */ - struct s_x3node *tbl; /* The data stored here */ - struct s_x3node **ht; /* Hash table for lookups */ -}; - -/* There is one instance of this structure for every data element -** in an associative array of type "x3". -*/ -typedef struct s_x3node { - struct state *data; /* The data */ - struct config *key; /* The key */ - struct s_x3node *next; /* Next entry with the same hash */ - struct s_x3node **from; /* Previous link */ -} x3node; - -/* There is only one instance of the array, which is the following */ -static struct s_x3 *x3a; - -/* Allocate a new associative array */ -void State_init(){ - if( x3a ) return; - x3a = (struct s_x3*)malloc( sizeof(struct s_x3) ); - if( x3a ){ - x3a->size = 128; - x3a->count = 0; - x3a->tbl = (x3node*)malloc( - (sizeof(x3node) + sizeof(x3node*))*128 ); - if( x3a->tbl==0 ){ - free(x3a); - x3a = 0; - }else{ - int i; - x3a->ht = (x3node**)&(x3a->tbl[128]); - for(i=0; i<128; i++) x3a->ht[i] = 0; - } - } -} -/* Insert a new record into the array. Return TRUE if successful. -** Prior data with the same key is NOT overwritten */ -int State_insert(data,key) -struct state *data; -struct config *key; -{ - x3node *np; - int h; - int ph; - - if( x3a==0 ) return 0; - ph = statehash(key); - h = ph & (x3a->size-1); - np = x3a->ht[h]; - while( np ){ - if( statecmp(np->key,key)==0 ){ - /* An existing entry with the same key is found. */ - /* Fail because overwrite is not allows. */ - return 0; - } - np = np->next; - } - if( x3a->count>=x3a->size ){ - /* Need to make the hash table bigger */ - int i,size; - struct s_x3 array; - array.size = size = x3a->size*2; - array.count = x3a->count; - array.tbl = (x3node*)malloc( - (sizeof(x3node) + sizeof(x3node*))*size ); - if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ - array.ht = (x3node**)&(array.tbl[size]); - for(i=0; icount; i++){ - x3node *oldnp, *newnp; - oldnp = &(x3a->tbl[i]); - h = statehash(oldnp->key) & (size-1); - newnp = &(array.tbl[i]); - if( array.ht[h] ) array.ht[h]->from = &(newnp->next); - newnp->next = array.ht[h]; - newnp->key = oldnp->key; - newnp->data = oldnp->data; - newnp->from = &(array.ht[h]); - array.ht[h] = newnp; - } - free(x3a->tbl); - *x3a = array; - } - /* Insert the new data */ - h = ph & (x3a->size-1); - np = &(x3a->tbl[x3a->count++]); - np->key = key; - np->data = data; - if( x3a->ht[h] ) x3a->ht[h]->from = &(np->next); - np->next = x3a->ht[h]; - x3a->ht[h] = np; - np->from = &(x3a->ht[h]); - return 1; -} - -/* Return a pointer to data assigned to the given key. Return NULL -** if no such key. */ -struct state *State_find(key) -struct config *key; -{ - int h; - x3node *np; - - if( x3a==0 ) return 0; - h = statehash(key) & (x3a->size-1); - np = x3a->ht[h]; - while( np ){ - if( statecmp(np->key,key)==0 ) break; - np = np->next; - } - return np ? np->data : 0; -} - -/* Return an array of pointers to all data in the table. -** The array is obtained from malloc. Return NULL if memory allocation -** problems, or if the array is empty. */ -struct state **State_arrayof() -{ - struct state **array; - int i,size; - if( x3a==0 ) return 0; - size = x3a->count; - array = (struct state **)malloc( sizeof(struct state *)*size ); - if( array ){ - for(i=0; itbl[i].data; - } - return array; -} - -/* Hash a configuration */ -PRIVATE int confighash(a) -struct config *a; -{ - int h=0; - h = h*571 + a->rp->index*37 + a->dot; - return h; -} - -/* There is one instance of the following structure for each -** associative array of type "x4". -*/ -struct s_x4 { - int size; /* The number of available slots. */ - /* Must be a power of 2 greater than or */ - /* equal to 1 */ - int count; /* Number of currently slots filled */ - struct s_x4node *tbl; /* The data stored here */ - struct s_x4node **ht; /* Hash table for lookups */ -}; - -/* There is one instance of this structure for every data element -** in an associative array of type "x4". -*/ -typedef struct s_x4node { - struct config *data; /* The data */ - struct s_x4node *next; /* Next entry with the same hash */ - struct s_x4node **from; /* Previous link */ -} x4node; - -/* There is only one instance of the array, which is the following */ -static struct s_x4 *x4a; - -/* Allocate a new associative array */ -void Configtable_init(){ - if( x4a ) return; - x4a = (struct s_x4*)malloc( sizeof(struct s_x4) ); - if( x4a ){ - x4a->size = 64; - x4a->count = 0; - x4a->tbl = (x4node*)malloc( - (sizeof(x4node) + sizeof(x4node*))*64 ); - if( x4a->tbl==0 ){ - free(x4a); - x4a = 0; - }else{ - int i; - x4a->ht = (x4node**)&(x4a->tbl[64]); - for(i=0; i<64; i++) x4a->ht[i] = 0; - } - } -} -/* Insert a new record into the array. Return TRUE if successful. -** Prior data with the same key is NOT overwritten */ -int Configtable_insert(data) -struct config *data; -{ - x4node *np; - int h; - int ph; - - if( x4a==0 ) return 0; - ph = confighash(data); - h = ph & (x4a->size-1); - np = x4a->ht[h]; - while( np ){ - if( Configcmp(np->data,data)==0 ){ - /* An existing entry with the same key is found. */ - /* Fail because overwrite is not allows. */ - return 0; - } - np = np->next; - } - if( x4a->count>=x4a->size ){ - /* Need to make the hash table bigger */ - int i,size; - struct s_x4 array; - array.size = size = x4a->size*2; - array.count = x4a->count; - array.tbl = (x4node*)malloc( - (sizeof(x4node) + sizeof(x4node*))*size ); - if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ - array.ht = (x4node**)&(array.tbl[size]); - for(i=0; icount; i++){ - x4node *oldnp, *newnp; - oldnp = &(x4a->tbl[i]); - h = confighash(oldnp->data) & (size-1); - newnp = &(array.tbl[i]); - if( array.ht[h] ) array.ht[h]->from = &(newnp->next); - newnp->next = array.ht[h]; - newnp->data = oldnp->data; - newnp->from = &(array.ht[h]); - array.ht[h] = newnp; - } - free(x4a->tbl); - *x4a = array; - } - /* Insert the new data */ - h = ph & (x4a->size-1); - np = &(x4a->tbl[x4a->count++]); - np->data = data; - if( x4a->ht[h] ) x4a->ht[h]->from = &(np->next); - np->next = x4a->ht[h]; - x4a->ht[h] = np; - np->from = &(x4a->ht[h]); - return 1; -} - -/* Return a pointer to data assigned to the given key. Return NULL -** if no such key. */ -struct config *Configtable_find(key) -struct config *key; -{ - int h; - x4node *np; - - if( x4a==0 ) return 0; - h = confighash(key) & (x4a->size-1); - np = x4a->ht[h]; - while( np ){ - if( Configcmp(np->data,key)==0 ) break; - np = np->next; - } - return np ? np->data : 0; -} - -/* Remove all data from the table. Pass each data to the function "f" -** as it is removed. ("f" may be null to avoid this step.) */ -void Configtable_clear(f) -int(*f)(/* struct config * */); -{ - int i; - if( x4a==0 || x4a->count==0 ) return; - if( f ) for(i=0; icount; i++) (*f)(x4a->tbl[i].data); - for(i=0; isize; i++) x4a->ht[i] = 0; - x4a->count = 0; - return; -} +/* +** This file contains all sources (including headers) to the LEMON +** LALR(1) parser generator. The sources have been combined into a +** single file to make it easy to include LEMON in the source tree +** and Makefile of another program. +** +** The author of this program disclaims copyright. +*/ +#include +#include +#include +#include +#include + +#ifndef __WIN32__ +# if defined(_WIN32) || defined(WIN32) +# define __WIN32__ +# endif +#endif + +/* #define PRIVATE static */ +#define PRIVATE + +#ifdef TEST +#define MAXRHS 5 /* Set low to exercise exception code */ +#else +#define MAXRHS 1000 +#endif + +char *msort(); + +/******** From the file "action.h" *************************************/ +struct action *Action_new(); +struct action *Action_sort(); + +/********* From the file "assert.h" ************************************/ +void myassert(); +#ifndef NDEBUG +# define assert(X) if(!(X))myassert(__FILE__,__LINE__) +#else +# define assert(X) +#endif + +/********** From the file "build.h" ************************************/ +void FindRulePrecedences(); +void FindFirstSets(); +void FindStates(); +void FindLinks(); +void FindFollowSets(); +void FindActions(); + +/********* From the file "configlist.h" *********************************/ +void Configlist_init(/* void */); +struct config *Configlist_add(/* struct rule *, int */); +struct config *Configlist_addbasis(/* struct rule *, int */); +void Configlist_closure(/* void */); +void Configlist_sort(/* void */); +void Configlist_sortbasis(/* void */); +struct config *Configlist_return(/* void */); +struct config *Configlist_basis(/* void */); +void Configlist_eat(/* struct config * */); +void Configlist_reset(/* void */); + +/********* From the file "error.h" ***************************************/ +void ErrorMsg(const char *, int,const char *, ...); + +/****** From the file "option.h" ******************************************/ +struct s_options { + enum { OPT_FLAG=1, OPT_INT, OPT_DBL, OPT_STR, + OPT_FFLAG, OPT_FINT, OPT_FDBL, OPT_FSTR} type; + char *label; + char *arg; + char *message; +}; +int OptInit(/* char**,struct s_options*,FILE* */); +int OptNArgs(/* void */); +char *OptArg(/* int */); +void OptErr(/* int */); +void OptPrint(/* void */); + +/******** From the file "parse.h" *****************************************/ +void Parse(/* struct lemon *lemp */); + +/********* From the file "plink.h" ***************************************/ +struct plink *Plink_new(/* void */); +void Plink_add(/* struct plink **, struct config * */); +void Plink_copy(/* struct plink **, struct plink * */); +void Plink_delete(/* struct plink * */); + +/********** From the file "report.h" *************************************/ +void Reprint(/* struct lemon * */); +void ReportOutput(/* struct lemon * */); +void ReportTable(/* struct lemon * */); +void ReportHeader(/* struct lemon * */); +void CompressTables(/* struct lemon * */); +void ResortStates(/* struct lemon * */); + +/********** From the file "set.h" ****************************************/ +void SetSize(/* int N */); /* All sets will be of size N */ +char *SetNew(/* void */); /* A new set for element 0..N */ +void SetFree(/* char* */); /* Deallocate a set */ + +int SetAdd(/* char*,int */); /* Add element to a set */ +int SetUnion(/* char *A,char *B */); /* A <- A U B, thru element N */ + +#define SetFind(X,Y) (X[Y]) /* True if Y is in set X */ + +/********** From the file "struct.h" *************************************/ +/* +** Principal data structures for the LEMON parser generator. +*/ + +typedef enum {B_FALSE=0, B_TRUE} Boolean; + +/* Symbols (terminals and nonterminals) of the grammar are stored +** in the following: */ +struct symbol { + char *name; /* Name of the symbol */ + int index; /* Index number for this symbol */ + enum { + TERMINAL, + NONTERMINAL, + MULTITERMINAL + } type; /* Symbols are all either TERMINALS or NTs */ + struct rule *rule; /* Linked list of rules of this (if an NT) */ + struct symbol *fallback; /* fallback token in case this token doesn't parse */ + int prec; /* Precedence if defined (-1 otherwise) */ + enum e_assoc { + LEFT, + RIGHT, + NONE, + UNK + } assoc; /* Associativity if predecence is defined */ + char *firstset; /* First-set for all rules of this symbol */ + Boolean lambda; /* True if NT and can generate an empty string */ + char *destructor; /* Code which executes whenever this symbol is + ** popped from the stack during error processing */ + int destructorln; /* Line number of destructor code */ + char *datatype; /* The data type of information held by this + ** object. Only used if type==NONTERMINAL */ + int dtnum; /* The data type number. In the parser, the value + ** stack is a union. The .yy%d element of this + ** union is the correct data type for this object */ + /* The following fields are used by MULTITERMINALs only */ + int nsubsym; /* Number of constituent symbols in the MULTI */ + struct symbol **subsym; /* Array of constituent symbols */ +}; + +/* Each production rule in the grammar is stored in the following +** structure. */ +struct rule { + struct symbol *lhs; /* Left-hand side of the rule */ + char *lhsalias; /* Alias for the LHS (NULL if none) */ + int ruleline; /* Line number for the rule */ + int nrhs; /* Number of RHS symbols */ + struct symbol **rhs; /* The RHS symbols */ + char **rhsalias; /* An alias for each RHS symbol (NULL if none) */ + int line; /* Line number at which code begins */ + char *code; /* The code executed when this rule is reduced */ + struct symbol *precsym; /* Precedence symbol for this rule */ + int index; /* An index number for this rule */ + Boolean canReduce; /* True if this rule is ever reduced */ + struct rule *nextlhs; /* Next rule with the same LHS */ + struct rule *next; /* Next rule in the global list */ +}; + +/* A configuration is a production rule of the grammar together with +** a mark (dot) showing how much of that rule has been processed so far. +** Configurations also contain a follow-set which is a list of terminal +** symbols which are allowed to immediately follow the end of the rule. +** Every configuration is recorded as an instance of the following: */ +struct config { + struct rule *rp; /* The rule upon which the configuration is based */ + int dot; /* The parse point */ + char *fws; /* Follow-set for this configuration only */ + struct plink *fplp; /* Follow-set forward propagation links */ + struct plink *bplp; /* Follow-set backwards propagation links */ + struct state *stp; /* Pointer to state which contains this */ + enum { + COMPLETE, /* The status is used during followset and */ + INCOMPLETE /* shift computations */ + } status; + struct config *next; /* Next configuration in the state */ + struct config *bp; /* The next basis configuration */ +}; + +/* Every shift or reduce operation is stored as one of the following */ +struct action { + struct symbol *sp; /* The look-ahead symbol */ + enum e_action { + SHIFT, + ACCEPT, + REDUCE, + ERROR, + CONFLICT, /* Was a reduce, but part of a conflict */ + SH_RESOLVED, /* Was a shift. Precedence resolved conflict */ + RD_RESOLVED, /* Was reduce. Precedence resolved conflict */ + NOT_USED /* Deleted by compression */ + } type; + union { + struct state *stp; /* The new state, if a shift */ + struct rule *rp; /* The rule, if a reduce */ + } x; + struct action *next; /* Next action for this state */ + struct action *collide; /* Next action with the same hash */ +}; + +/* Each state of the generated parser's finite state machine +** is encoded as an instance of the following structure. */ +struct state { + struct config *bp; /* The basis configurations for this state */ + struct config *cfp; /* All configurations in this set */ + int statenum; /* Sequencial number for this state */ + struct action *ap; /* Array of actions for this state */ + int nTknAct, nNtAct; /* Number of actions on terminals and nonterminals */ + int iTknOfst, iNtOfst; /* yy_action[] offset for terminals and nonterms */ + int iDflt; /* Default action */ +}; +#define NO_OFFSET (-2147483647) + +/* A followset propagation link indicates that the contents of one +** configuration followset should be propagated to another whenever +** the first changes. */ +struct plink { + struct config *cfp; /* The configuration to which linked */ + struct plink *next; /* The next propagate link */ +}; + +/* The state vector for the entire parser generator is recorded as +** follows. (LEMON uses no global variables and makes little use of +** static variables. Fields in the following structure can be thought +** of as begin global variables in the program.) */ +struct lemon { + struct state **sorted; /* Table of states sorted by state number */ + struct rule *rule; /* List of all rules */ + int nstate; /* Number of states */ + int nrule; /* Number of rules */ + int nsymbol; /* Number of terminal and nonterminal symbols */ + int nterminal; /* Number of terminal symbols */ + struct symbol **symbols; /* Sorted array of pointers to symbols */ + int errorcnt; /* Number of errors */ + struct symbol *errsym; /* The error symbol */ + char *name; /* Name of the generated parser */ + char *arg; /* Declaration of the 3th argument to parser */ + char *tokentype; /* Type of terminal symbols in the parser stack */ + char *vartype; /* The default type of non-terminal symbols */ + char *start; /* Name of the start symbol for the grammar */ + char *stacksize; /* Size of the parser stack */ + char *include; /* Code to put at the start of the C file */ + int includeln; /* Line number for start of include code */ + char *error; /* Code to execute when an error is seen */ + int errorln; /* Line number for start of error code */ + char *overflow; /* Code to execute on a stack overflow */ + int overflowln; /* Line number for start of overflow code */ + char *failure; /* Code to execute on parser failure */ + int failureln; /* Line number for start of failure code */ + char *accept; /* Code to execute when the parser excepts */ + int acceptln; /* Line number for the start of accept code */ + char *extracode; /* Code appended to the generated file */ + int extracodeln; /* Line number for the start of the extra code */ + char *tokendest; /* Code to execute to destroy token data */ + int tokendestln; /* Line number for token destroyer code */ + char *vardest; /* Code for the default non-terminal destructor */ + int vardestln; /* Line number for default non-term destructor code*/ + char *filename; /* Name of the input file */ + char *outname; /* Name of the current output file */ + char *tokenprefix; /* A prefix added to token names in the .h file */ + int nconflict; /* Number of parsing conflicts */ + int tablesize; /* Size of the parse tables */ + int basisflag; /* Print only basis configurations */ + int has_fallback; /* True if any %fallback is seen in the grammer */ + char *argv0; /* Name of the program */ +}; + +#define MemoryCheck(X) if((X)==0){ \ + extern void memory_error(); \ + memory_error(); \ +} + +/**************** From the file "table.h" *********************************/ +/* +** All code in this file has been automatically generated +** from a specification in the file +** "table.q" +** by the associative array code building program "aagen". +** Do not edit this file! Instead, edit the specification +** file, then rerun aagen. +*/ +/* +** Code for processing tables in the LEMON parser generator. +*/ + +/* Routines for handling a strings */ + +char *Strsafe(); + +void Strsafe_init(/* void */); +int Strsafe_insert(/* char * */); +char *Strsafe_find(/* char * */); + +/* Routines for handling symbols of the grammar */ + +struct symbol *Symbol_new(); +int Symbolcmpp(/* struct symbol **, struct symbol ** */); +void Symbol_init(/* void */); +int Symbol_insert(/* struct symbol *, char * */); +struct symbol *Symbol_find(/* char * */); +struct symbol *Symbol_Nth(/* int */); +int Symbol_count(/* */); +struct symbol **Symbol_arrayof(/* */); + +/* Routines to manage the state table */ + +int Configcmp(/* struct config *, struct config * */); +struct state *State_new(); +void State_init(/* void */); +int State_insert(/* struct state *, struct config * */); +struct state *State_find(/* struct config * */); +struct state **State_arrayof(/* */); + +/* Routines used for efficiency in Configlist_add */ + +void Configtable_init(/* void */); +int Configtable_insert(/* struct config * */); +struct config *Configtable_find(/* struct config * */); +void Configtable_clear(/* int(*)(struct config *) */); +/****************** From the file "action.c" *******************************/ +/* +** Routines processing parser actions in the LEMON parser generator. +*/ + +/* Allocate a new parser action */ +struct action *Action_new(){ + static struct action *freelist = 0; + struct action *new; + + if( freelist==0 ){ + int i; + int amt = 100; + freelist = (struct action *)malloc( sizeof(struct action)*amt ); + if( freelist==0 ){ + fprintf(stderr,"Unable to allocate memory for a new parser action."); + exit(1); + } + for(i=0; inext; + return new; +} + +/* Compare two actions */ +static int actioncmp(ap1,ap2) +struct action *ap1; +struct action *ap2; +{ + int rc; + rc = ap1->sp->index - ap2->sp->index; + if( rc==0 ) rc = (int)ap1->type - (int)ap2->type; + if( rc==0 ){ + assert( ap1->type==REDUCE || ap1->type==RD_RESOLVED || ap1->type==CONFLICT); + assert( ap2->type==REDUCE || ap2->type==RD_RESOLVED || ap2->type==CONFLICT); + rc = ap1->x.rp->index - ap2->x.rp->index; + } + return rc; +} + +/* Sort parser actions */ +struct action *Action_sort(ap) +struct action *ap; +{ + ap = (struct action *)msort((char *)ap,(char **)&ap->next,actioncmp); + return ap; +} + +void Action_add(app,type,sp,arg) +struct action **app; +enum e_action type; +struct symbol *sp; +char *arg; +{ + struct action *new; + new = Action_new(); + new->next = *app; + *app = new; + new->type = type; + new->sp = sp; + if( type==SHIFT ){ + new->x.stp = (struct state *)arg; + }else{ + new->x.rp = (struct rule *)arg; + } +} +/********************** New code to implement the "acttab" module ***********/ +/* +** This module implements routines use to construct the yy_action[] table. +*/ + +/* +** The state of the yy_action table under construction is an instance of +** the following structure +*/ +typedef struct acttab acttab; +struct acttab { + int nAction; /* Number of used slots in aAction[] */ + int nActionAlloc; /* Slots allocated for aAction[] */ + struct { + int lookahead; /* Value of the lookahead token */ + int action; /* Action to take on the given lookahead */ + } *aAction, /* The yy_action[] table under construction */ + *aLookahead; /* A single new transaction set */ + int mnLookahead; /* Minimum aLookahead[].lookahead */ + int mnAction; /* Action associated with mnLookahead */ + int mxLookahead; /* Maximum aLookahead[].lookahead */ + int nLookahead; /* Used slots in aLookahead[] */ + int nLookaheadAlloc; /* Slots allocated in aLookahead[] */ +}; + +/* Return the number of entries in the yy_action table */ +#define acttab_size(X) ((X)->nAction) + +/* The value for the N-th entry in yy_action */ +#define acttab_yyaction(X,N) ((X)->aAction[N].action) + +/* The value for the N-th entry in yy_lookahead */ +#define acttab_yylookahead(X,N) ((X)->aAction[N].lookahead) + +/* Free all memory associated with the given acttab */ +void acttab_free(acttab *p){ + free( p->aAction ); + free( p->aLookahead ); + free( p ); +} + +/* Allocate a new acttab structure */ +acttab *acttab_alloc(void){ + acttab *p = malloc( sizeof(*p) ); + if( p==0 ){ + fprintf(stderr,"Unable to allocate memory for a new acttab."); + exit(1); + } + memset(p, 0, sizeof(*p)); + return p; +} + +/* Add a new action to the current transaction set +*/ +void acttab_action(acttab *p, int lookahead, int action){ + if( p->nLookahead>=p->nLookaheadAlloc ){ + p->nLookaheadAlloc += 25; + p->aLookahead = realloc( p->aLookahead, + sizeof(p->aLookahead[0])*p->nLookaheadAlloc ); + if( p->aLookahead==0 ){ + fprintf(stderr,"malloc failed\n"); + exit(1); + } + } + if( p->nLookahead==0 ){ + p->mxLookahead = lookahead; + p->mnLookahead = lookahead; + p->mnAction = action; + }else{ + if( p->mxLookaheadmxLookahead = lookahead; + if( p->mnLookahead>lookahead ){ + p->mnLookahead = lookahead; + p->mnAction = action; + } + } + p->aLookahead[p->nLookahead].lookahead = lookahead; + p->aLookahead[p->nLookahead].action = action; + p->nLookahead++; +} + +/* +** Add the transaction set built up with prior calls to acttab_action() +** into the current action table. Then reset the transaction set back +** to an empty set in preparation for a new round of acttab_action() calls. +** +** Return the offset into the action table of the new transaction. +*/ +int acttab_insert(acttab *p){ + int i, j, k, n; + assert( p->nLookahead>0 ); + + /* Make sure we have enough space to hold the expanded action table + ** in the worst case. The worst case occurs if the transaction set + ** must be appended to the current action table + */ + n = p->mxLookahead + 1; + if( p->nAction + n >= p->nActionAlloc ){ + int oldAlloc = p->nActionAlloc; + p->nActionAlloc = p->nAction + n + p->nActionAlloc + 20; + p->aAction = realloc( p->aAction, + sizeof(p->aAction[0])*p->nActionAlloc); + if( p->aAction==0 ){ + fprintf(stderr,"malloc failed\n"); + exit(1); + } + for(i=oldAlloc; inActionAlloc; i++){ + p->aAction[i].lookahead = -1; + p->aAction[i].action = -1; + } + } + + /* Scan the existing action table looking for an offset where we can + ** insert the current transaction set. Fall out of the loop when that + ** offset is found. In the worst case, we fall out of the loop when + ** i reaches p->nAction, which means we append the new transaction set. + ** + ** i is the index in p->aAction[] where p->mnLookahead is inserted. + */ + for(i=0; inAction+p->mnLookahead; i++){ + if( p->aAction[i].lookahead<0 ){ + for(j=0; jnLookahead; j++){ + k = p->aLookahead[j].lookahead - p->mnLookahead + i; + if( k<0 ) break; + if( p->aAction[k].lookahead>=0 ) break; + } + if( jnLookahead ) continue; + for(j=0; jnAction; j++){ + if( p->aAction[j].lookahead==j+p->mnLookahead-i ) break; + } + if( j==p->nAction ){ + break; /* Fits in empty slots */ + } + }else if( p->aAction[i].lookahead==p->mnLookahead ){ + if( p->aAction[i].action!=p->mnAction ) continue; + for(j=0; jnLookahead; j++){ + k = p->aLookahead[j].lookahead - p->mnLookahead + i; + if( k<0 || k>=p->nAction ) break; + if( p->aLookahead[j].lookahead!=p->aAction[k].lookahead ) break; + if( p->aLookahead[j].action!=p->aAction[k].action ) break; + } + if( jnLookahead ) continue; + n = 0; + for(j=0; jnAction; j++){ + if( p->aAction[j].lookahead<0 ) continue; + if( p->aAction[j].lookahead==j+p->mnLookahead-i ) n++; + } + if( n==p->nLookahead ){ + break; /* Same as a prior transaction set */ + } + } + } + /* Insert transaction set at index i. */ + for(j=0; jnLookahead; j++){ + k = p->aLookahead[j].lookahead - p->mnLookahead + i; + p->aAction[k] = p->aLookahead[j]; + if( k>=p->nAction ) p->nAction = k+1; + } + p->nLookahead = 0; + + /* Return the offset that is added to the lookahead in order to get the + ** index into yy_action of the action */ + return i - p->mnLookahead; +} + +/********************** From the file "assert.c" ****************************/ +/* +** A more efficient way of handling assertions. +*/ +void myassert(file,line) +char *file; +int line; +{ + fprintf(stderr,"Assertion failed on line %d of file \"%s\"\n",line,file); + exit(1); +} +/********************** From the file "build.c" *****************************/ +/* +** Routines to construction the finite state machine for the LEMON +** parser generator. +*/ + +/* Find a precedence symbol of every rule in the grammar. +** +** Those rules which have a precedence symbol coded in the input +** grammar using the "[symbol]" construct will already have the +** rp->precsym field filled. Other rules take as their precedence +** symbol the first RHS symbol with a defined precedence. If there +** are not RHS symbols with a defined precedence, the precedence +** symbol field is left blank. +*/ +void FindRulePrecedences(xp) +struct lemon *xp; +{ + struct rule *rp; + for(rp=xp->rule; rp; rp=rp->next){ + if( rp->precsym==0 ){ + int i, j; + for(i=0; inrhs && rp->precsym==0; i++){ + struct symbol *sp = rp->rhs[i]; + if( sp->type==MULTITERMINAL ){ + for(j=0; jnsubsym; j++){ + if( sp->subsym[j]->prec>=0 ){ + rp->precsym = sp->subsym[j]; + break; + } + } + }else if( sp->prec>=0 ){ + rp->precsym = rp->rhs[i]; + } + } + } + } + return; +} + +/* Find all nonterminals which will generate the empty string. +** Then go back and compute the first sets of every nonterminal. +** The first set is the set of all terminal symbols which can begin +** a string generated by that nonterminal. +*/ +void FindFirstSets(lemp) +struct lemon *lemp; +{ + int i, j; + struct rule *rp; + int progress; + + for(i=0; insymbol; i++){ + lemp->symbols[i]->lambda = B_FALSE; + } + for(i=lemp->nterminal; insymbol; i++){ + lemp->symbols[i]->firstset = SetNew(); + } + + /* First compute all lambdas */ + do{ + progress = 0; + for(rp=lemp->rule; rp; rp=rp->next){ + if( rp->lhs->lambda ) continue; + for(i=0; inrhs; i++){ + struct symbol *sp = rp->rhs[i]; + if( sp->type!=TERMINAL || sp->lambda==B_FALSE ) break; + } + if( i==rp->nrhs ){ + rp->lhs->lambda = B_TRUE; + progress = 1; + } + } + }while( progress ); + + /* Now compute all first sets */ + do{ + struct symbol *s1, *s2; + progress = 0; + for(rp=lemp->rule; rp; rp=rp->next){ + s1 = rp->lhs; + for(i=0; inrhs; i++){ + s2 = rp->rhs[i]; + if( s2->type==TERMINAL ){ + progress += SetAdd(s1->firstset,s2->index); + break; + }else if( s2->type==MULTITERMINAL ){ + for(j=0; jnsubsym; j++){ + progress += SetAdd(s1->firstset,s2->subsym[j]->index); + } + break; + }else if( s1==s2 ){ + if( s1->lambda==B_FALSE ) break; + }else{ + progress += SetUnion(s1->firstset,s2->firstset); + if( s2->lambda==B_FALSE ) break; + } + } + } + }while( progress ); + return; +} + +/* Compute all LR(0) states for the grammar. Links +** are added to between some states so that the LR(1) follow sets +** can be computed later. +*/ +PRIVATE struct state *getstate(/* struct lemon * */); /* forward reference */ +void FindStates(lemp) +struct lemon *lemp; +{ + struct symbol *sp; + struct rule *rp; + + Configlist_init(); + + /* Find the start symbol */ + if( lemp->start ){ + sp = Symbol_find(lemp->start); + if( sp==0 ){ + ErrorMsg(lemp->filename,0, +"The specified start symbol \"%s\" is not \ +in a nonterminal of the grammar. \"%s\" will be used as the start \ +symbol instead.",lemp->start,lemp->rule->lhs->name); + lemp->errorcnt++; + sp = lemp->rule->lhs; + } + }else{ + sp = lemp->rule->lhs; + } + + /* Make sure the start symbol doesn't occur on the right-hand side of + ** any rule. Report an error if it does. (YACC would generate a new + ** start symbol in this case.) */ + for(rp=lemp->rule; rp; rp=rp->next){ + int i; + for(i=0; inrhs; i++){ + if( rp->rhs[i]==sp ){ /* FIX ME: Deal with multiterminals */ + ErrorMsg(lemp->filename,0, +"The start symbol \"%s\" occurs on the \ +right-hand side of a rule. This will result in a parser which \ +does not work properly.",sp->name); + lemp->errorcnt++; + } + } + } + + /* The basis configuration set for the first state + ** is all rules which have the start symbol as their + ** left-hand side */ + for(rp=sp->rule; rp; rp=rp->nextlhs){ + struct config *newcfp; + newcfp = Configlist_addbasis(rp,0); + SetAdd(newcfp->fws,0); + } + + /* Compute the first state. All other states will be + ** computed automatically during the computation of the first one. + ** The returned pointer to the first state is not used. */ + (void)getstate(lemp); + return; +} + +/* Return a pointer to a state which is described by the configuration +** list which has been built from calls to Configlist_add. +*/ +PRIVATE void buildshifts(/* struct lemon *, struct state * */); /* Forwd ref */ +PRIVATE struct state *getstate(lemp) +struct lemon *lemp; +{ + struct config *cfp, *bp; + struct state *stp; + + /* Extract the sorted basis of the new state. The basis was constructed + ** by prior calls to "Configlist_addbasis()". */ + Configlist_sortbasis(); + bp = Configlist_basis(); + + /* Get a state with the same basis */ + stp = State_find(bp); + if( stp ){ + /* A state with the same basis already exists! Copy all the follow-set + ** propagation links from the state under construction into the + ** preexisting state, then return a pointer to the preexisting state */ + struct config *x, *y; + for(x=bp, y=stp->bp; x && y; x=x->bp, y=y->bp){ + Plink_copy(&y->bplp,x->bplp); + Plink_delete(x->fplp); + x->fplp = x->bplp = 0; + } + cfp = Configlist_return(); + Configlist_eat(cfp); + }else{ + /* This really is a new state. Construct all the details */ + Configlist_closure(lemp); /* Compute the configuration closure */ + Configlist_sort(); /* Sort the configuration closure */ + cfp = Configlist_return(); /* Get a pointer to the config list */ + stp = State_new(); /* A new state structure */ + MemoryCheck(stp); + stp->bp = bp; /* Remember the configuration basis */ + stp->cfp = cfp; /* Remember the configuration closure */ + stp->statenum = lemp->nstate++; /* Every state gets a sequence number */ + stp->ap = 0; /* No actions, yet. */ + State_insert(stp,stp->bp); /* Add to the state table */ + buildshifts(lemp,stp); /* Recursively compute successor states */ + } + return stp; +} + +/* +** Return true if two symbols are the same. +*/ +int same_symbol(a,b) +struct symbol *a; +struct symbol *b; +{ + int i; + if( a==b ) return 1; + if( a->type!=MULTITERMINAL ) return 0; + if( b->type!=MULTITERMINAL ) return 0; + if( a->nsubsym!=b->nsubsym ) return 0; + for(i=0; insubsym; i++){ + if( a->subsym[i]!=b->subsym[i] ) return 0; + } + return 1; +} + +/* Construct all successor states to the given state. A "successor" +** state is any state which can be reached by a shift action. +*/ +PRIVATE void buildshifts(lemp,stp) +struct lemon *lemp; +struct state *stp; /* The state from which successors are computed */ +{ + struct config *cfp; /* For looping thru the config closure of "stp" */ + struct config *bcfp; /* For the inner loop on config closure of "stp" */ + struct config *new; /* */ + struct symbol *sp; /* Symbol following the dot in configuration "cfp" */ + struct symbol *bsp; /* Symbol following the dot in configuration "bcfp" */ + struct state *newstp; /* A pointer to a successor state */ + + /* Each configuration becomes complete after it contibutes to a successor + ** state. Initially, all configurations are incomplete */ + for(cfp=stp->cfp; cfp; cfp=cfp->next) cfp->status = INCOMPLETE; + + /* Loop through all configurations of the state "stp" */ + for(cfp=stp->cfp; cfp; cfp=cfp->next){ + if( cfp->status==COMPLETE ) continue; /* Already used by inner loop */ + if( cfp->dot>=cfp->rp->nrhs ) continue; /* Can't shift this config */ + Configlist_reset(); /* Reset the new config set */ + sp = cfp->rp->rhs[cfp->dot]; /* Symbol after the dot */ + + /* For every configuration in the state "stp" which has the symbol "sp" + ** following its dot, add the same configuration to the basis set under + ** construction but with the dot shifted one symbol to the right. */ + for(bcfp=cfp; bcfp; bcfp=bcfp->next){ + if( bcfp->status==COMPLETE ) continue; /* Already used */ + if( bcfp->dot>=bcfp->rp->nrhs ) continue; /* Can't shift this one */ + bsp = bcfp->rp->rhs[bcfp->dot]; /* Get symbol after dot */ + if( !same_symbol(bsp,sp) ) continue; /* Must be same as for "cfp" */ + bcfp->status = COMPLETE; /* Mark this config as used */ + new = Configlist_addbasis(bcfp->rp,bcfp->dot+1); + Plink_add(&new->bplp,bcfp); + } + + /* Get a pointer to the state described by the basis configuration set + ** constructed in the preceding loop */ + newstp = getstate(lemp); + + /* The state "newstp" is reached from the state "stp" by a shift action + ** on the symbol "sp" */ + if( sp->type==MULTITERMINAL ){ + int i; + for(i=0; insubsym; i++){ + Action_add(&stp->ap,SHIFT,sp->subsym[i],(char*)newstp); + } + }else{ + Action_add(&stp->ap,SHIFT,sp,(char *)newstp); + } + } +} + +/* +** Construct the propagation links +*/ +void FindLinks(lemp) +struct lemon *lemp; +{ + int i; + struct config *cfp, *other; + struct state *stp; + struct plink *plp; + + /* Housekeeping detail: + ** Add to every propagate link a pointer back to the state to + ** which the link is attached. */ + for(i=0; instate; i++){ + stp = lemp->sorted[i]; + for(cfp=stp->cfp; cfp; cfp=cfp->next){ + cfp->stp = stp; + } + } + + /* Convert all backlinks into forward links. Only the forward + ** links are used in the follow-set computation. */ + for(i=0; instate; i++){ + stp = lemp->sorted[i]; + for(cfp=stp->cfp; cfp; cfp=cfp->next){ + for(plp=cfp->bplp; plp; plp=plp->next){ + other = plp->cfp; + Plink_add(&other->fplp,cfp); + } + } + } +} + +/* Compute all followsets. +** +** A followset is the set of all symbols which can come immediately +** after a configuration. +*/ +void FindFollowSets(lemp) +struct lemon *lemp; +{ + int i; + struct config *cfp; + struct plink *plp; + int progress; + int change; + + for(i=0; instate; i++){ + for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){ + cfp->status = INCOMPLETE; + } + } + + do{ + progress = 0; + for(i=0; instate; i++){ + for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){ + if( cfp->status==COMPLETE ) continue; + for(plp=cfp->fplp; plp; plp=plp->next){ + change = SetUnion(plp->cfp->fws,cfp->fws); + if( change ){ + plp->cfp->status = INCOMPLETE; + progress = 1; + } + } + cfp->status = COMPLETE; + } + } + }while( progress ); +} + +static int resolve_conflict(); + +/* Compute the reduce actions, and resolve conflicts. +*/ +void FindActions(lemp) +struct lemon *lemp; +{ + int i,j; + struct config *cfp; + struct state *stp; + struct symbol *sp; + struct rule *rp; + + /* Add all of the reduce actions + ** A reduce action is added for each element of the followset of + ** a configuration which has its dot at the extreme right. + */ + for(i=0; instate; i++){ /* Loop over all states */ + stp = lemp->sorted[i]; + for(cfp=stp->cfp; cfp; cfp=cfp->next){ /* Loop over all configurations */ + if( cfp->rp->nrhs==cfp->dot ){ /* Is dot at extreme right? */ + for(j=0; jnterminal; j++){ + if( SetFind(cfp->fws,j) ){ + /* Add a reduce action to the state "stp" which will reduce by the + ** rule "cfp->rp" if the lookahead symbol is "lemp->symbols[j]" */ + Action_add(&stp->ap,REDUCE,lemp->symbols[j],(char *)cfp->rp); + } + } + } + } + } + + /* Add the accepting token */ + if( lemp->start ){ + sp = Symbol_find(lemp->start); + if( sp==0 ) sp = lemp->rule->lhs; + }else{ + sp = lemp->rule->lhs; + } + /* Add to the first state (which is always the starting state of the + ** finite state machine) an action to ACCEPT if the lookahead is the + ** start nonterminal. */ + Action_add(&lemp->sorted[0]->ap,ACCEPT,sp,0); + + /* Resolve conflicts */ + for(i=0; instate; i++){ + struct action *ap, *nap; + struct state *stp; + stp = lemp->sorted[i]; + assert( stp->ap ); + stp->ap = Action_sort(stp->ap); + for(ap=stp->ap; ap && ap->next; ap=ap->next){ + for(nap=ap->next; nap && nap->sp==ap->sp; nap=nap->next){ + /* The two actions "ap" and "nap" have the same lookahead. + ** Figure out which one should be used */ + lemp->nconflict += resolve_conflict(ap,nap,lemp->errsym); + } + } + } + + /* Report an error for each rule that can never be reduced. */ + for(rp=lemp->rule; rp; rp=rp->next) rp->canReduce = B_FALSE; + for(i=0; instate; i++){ + struct action *ap; + for(ap=lemp->sorted[i]->ap; ap; ap=ap->next){ + if( ap->type==REDUCE ) ap->x.rp->canReduce = B_TRUE; + } + } + for(rp=lemp->rule; rp; rp=rp->next){ + if( rp->canReduce ) continue; + ErrorMsg(lemp->filename,rp->ruleline,"This rule can not be reduced.\n"); + lemp->errorcnt++; + } +} + +/* Resolve a conflict between the two given actions. If the +** conflict can't be resolve, return non-zero. +** +** NO LONGER TRUE: +** To resolve a conflict, first look to see if either action +** is on an error rule. In that case, take the action which +** is not associated with the error rule. If neither or both +** actions are associated with an error rule, then try to +** use precedence to resolve the conflict. +** +** If either action is a SHIFT, then it must be apx. This +** function won't work if apx->type==REDUCE and apy->type==SHIFT. +*/ +static int resolve_conflict(apx,apy,errsym) +struct action *apx; +struct action *apy; +struct symbol *errsym; /* The error symbol (if defined. NULL otherwise) */ +{ + struct symbol *spx, *spy; + int errcnt = 0; + assert( apx->sp==apy->sp ); /* Otherwise there would be no conflict */ + if( apx->type==SHIFT && apy->type==REDUCE ){ + spx = apx->sp; + spy = apy->x.rp->precsym; + if( spy==0 || spx->prec<0 || spy->prec<0 ){ + /* Not enough precedence information. */ + apy->type = CONFLICT; + errcnt++; + }else if( spx->prec>spy->prec ){ /* Lower precedence wins */ + apy->type = RD_RESOLVED; + }else if( spx->precprec ){ + apx->type = SH_RESOLVED; + }else if( spx->prec==spy->prec && spx->assoc==RIGHT ){ /* Use operator */ + apy->type = RD_RESOLVED; /* associativity */ + }else if( spx->prec==spy->prec && spx->assoc==LEFT ){ /* to break tie */ + apx->type = SH_RESOLVED; + }else{ + assert( spx->prec==spy->prec && spx->assoc==NONE ); + apy->type = CONFLICT; + errcnt++; + } + }else if( apx->type==REDUCE && apy->type==REDUCE ){ + spx = apx->x.rp->precsym; + spy = apy->x.rp->precsym; + if( spx==0 || spy==0 || spx->prec<0 || + spy->prec<0 || spx->prec==spy->prec ){ + apy->type = CONFLICT; + errcnt++; + }else if( spx->prec>spy->prec ){ + apy->type = RD_RESOLVED; + }else if( spx->precprec ){ + apx->type = RD_RESOLVED; + } + }else{ + assert( + apx->type==SH_RESOLVED || + apx->type==RD_RESOLVED || + apx->type==CONFLICT || + apy->type==SH_RESOLVED || + apy->type==RD_RESOLVED || + apy->type==CONFLICT + ); + /* The REDUCE/SHIFT case cannot happen because SHIFTs come before + ** REDUCEs on the list. If we reach this point it must be because + ** the parser conflict had already been resolved. */ + } + return errcnt; +} +/********************* From the file "configlist.c" *************************/ +/* +** Routines to processing a configuration list and building a state +** in the LEMON parser generator. +*/ + +static struct config *freelist = 0; /* List of free configurations */ +static struct config *current = 0; /* Top of list of configurations */ +static struct config **currentend = 0; /* Last on list of configs */ +static struct config *basis = 0; /* Top of list of basis configs */ +static struct config **basisend = 0; /* End of list of basis configs */ + +/* Return a pointer to a new configuration */ +PRIVATE struct config *newconfig(){ + struct config *new; + if( freelist==0 ){ + int i; + int amt = 3; + freelist = (struct config *)malloc( sizeof(struct config)*amt ); + if( freelist==0 ){ + fprintf(stderr,"Unable to allocate memory for a new configuration."); + exit(1); + } + for(i=0; inext; + return new; +} + +/* The configuration "old" is no longer used */ +PRIVATE void deleteconfig(old) +struct config *old; +{ + old->next = freelist; + freelist = old; +} + +/* Initialized the configuration list builder */ +void Configlist_init(){ + current = 0; + currentend = ¤t; + basis = 0; + basisend = &basis; + Configtable_init(); + return; +} + +/* Initialized the configuration list builder */ +void Configlist_reset(){ + current = 0; + currentend = ¤t; + basis = 0; + basisend = &basis; + Configtable_clear(0); + return; +} + +/* Add another configuration to the configuration list */ +struct config *Configlist_add(rp,dot) +struct rule *rp; /* The rule */ +int dot; /* Index into the RHS of the rule where the dot goes */ +{ + struct config *cfp, model; + + assert( currentend!=0 ); + model.rp = rp; + model.dot = dot; + cfp = Configtable_find(&model); + if( cfp==0 ){ + cfp = newconfig(); + cfp->rp = rp; + cfp->dot = dot; + cfp->fws = SetNew(); + cfp->stp = 0; + cfp->fplp = cfp->bplp = 0; + cfp->next = 0; + cfp->bp = 0; + *currentend = cfp; + currentend = &cfp->next; + Configtable_insert(cfp); + } + return cfp; +} + +/* Add a basis configuration to the configuration list */ +struct config *Configlist_addbasis(rp,dot) +struct rule *rp; +int dot; +{ + struct config *cfp, model; + + assert( basisend!=0 ); + assert( currentend!=0 ); + model.rp = rp; + model.dot = dot; + cfp = Configtable_find(&model); + if( cfp==0 ){ + cfp = newconfig(); + cfp->rp = rp; + cfp->dot = dot; + cfp->fws = SetNew(); + cfp->stp = 0; + cfp->fplp = cfp->bplp = 0; + cfp->next = 0; + cfp->bp = 0; + *currentend = cfp; + currentend = &cfp->next; + *basisend = cfp; + basisend = &cfp->bp; + Configtable_insert(cfp); + } + return cfp; +} + +/* Compute the closure of the configuration list */ +void Configlist_closure(lemp) +struct lemon *lemp; +{ + struct config *cfp, *newcfp; + struct rule *rp, *newrp; + struct symbol *sp, *xsp; + int i, dot; + + assert( currentend!=0 ); + for(cfp=current; cfp; cfp=cfp->next){ + rp = cfp->rp; + dot = cfp->dot; + if( dot>=rp->nrhs ) continue; + sp = rp->rhs[dot]; + if( sp->type==NONTERMINAL ){ + if( sp->rule==0 && sp!=lemp->errsym ){ + ErrorMsg(lemp->filename,rp->line,"Nonterminal \"%s\" has no rules.", + sp->name); + lemp->errorcnt++; + } + for(newrp=sp->rule; newrp; newrp=newrp->nextlhs){ + newcfp = Configlist_add(newrp,0); + for(i=dot+1; inrhs; i++){ + xsp = rp->rhs[i]; + if( xsp->type==TERMINAL ){ + SetAdd(newcfp->fws,xsp->index); + break; + }else if( xsp->type==MULTITERMINAL ){ + int k; + for(k=0; knsubsym; k++){ + SetAdd(newcfp->fws, xsp->subsym[k]->index); + } + break; + }else{ + SetUnion(newcfp->fws,xsp->firstset); + if( xsp->lambda==B_FALSE ) break; + } + } + if( i==rp->nrhs ) Plink_add(&cfp->fplp,newcfp); + } + } + } + return; +} + +/* Sort the configuration list */ +void Configlist_sort(){ + current = (struct config *)msort((char *)current,(char **)&(current->next),Configcmp); + currentend = 0; + return; +} + +/* Sort the basis configuration list */ +void Configlist_sortbasis(){ + basis = (struct config *)msort((char *)current,(char **)&(current->bp),Configcmp); + basisend = 0; + return; +} + +/* Return a pointer to the head of the configuration list and +** reset the list */ +struct config *Configlist_return(){ + struct config *old; + old = current; + current = 0; + currentend = 0; + return old; +} + +/* Return a pointer to the head of the configuration list and +** reset the list */ +struct config *Configlist_basis(){ + struct config *old; + old = basis; + basis = 0; + basisend = 0; + return old; +} + +/* Free all elements of the given configuration list */ +void Configlist_eat(cfp) +struct config *cfp; +{ + struct config *nextcfp; + for(; cfp; cfp=nextcfp){ + nextcfp = cfp->next; + assert( cfp->fplp==0 ); + assert( cfp->bplp==0 ); + if( cfp->fws ) SetFree(cfp->fws); + deleteconfig(cfp); + } + return; +} +/***************** From the file "error.c" *********************************/ +/* +** Code for printing error message. +*/ + +/* Find a good place to break "msg" so that its length is at least "min" +** but no more than "max". Make the point as close to max as possible. +*/ +static int findbreak(msg,min,max) +char *msg; +int min; +int max; +{ + int i,spot; + char c; + for(i=spot=min; i<=max; i++){ + c = msg[i]; + if( c=='\t' ) msg[i] = ' '; + if( c=='\n' ){ msg[i] = ' '; spot = i; break; } + if( c==0 ){ spot = i; break; } + if( c=='-' && i0 ){ + sprintf(prefix,"%.*s(%d) : error : ",PREFIXLIMIT-10,filename,lineno); + }else{ + sprintf(prefix,"%.*s : error : ",PREFIXLIMIT-10,filename); + } +#else + if( lineno>0 ){ + sprintf(prefix,"%.*s:%d: ",PREFIXLIMIT-10,filename,lineno); + }else{ + sprintf(prefix,"%.*s: ",PREFIXLIMIT-10,filename); + } +#endif + prefixsize = strlen(prefix); + availablewidth = LINEWIDTH - prefixsize; + + /* Generate the error message */ + vsprintf(errmsg,format,ap); + va_end(ap); + errmsgsize = strlen(errmsg); + /* Remove trailing '\n's from the error message. */ + while( errmsgsize>0 && errmsg[errmsgsize-1]=='\n' ){ + errmsg[--errmsgsize] = 0; + } + + /* Print the error message */ + base = 0; + while( errmsg[base]!=0 ){ + end = restart = findbreak(&errmsg[base],0,availablewidth); + restart += base; + while( errmsg[restart]==' ' ) restart++; + fprintf(stdout,"%s%.*s\n",prefix,end,&errmsg[base]); + base = restart; + } +} +/**************** From the file "main.c" ************************************/ +/* +** Main program file for the LEMON parser generator. +*/ + +/* Report an out-of-memory condition and abort. This function +** is used mostly by the "MemoryCheck" macro in struct.h +*/ +void memory_error(){ + fprintf(stderr,"Out of memory. Aborting...\n"); + exit(1); +} + +static int nDefine = 0; /* Number of -D options on the command line */ +static char **azDefine = 0; /* Name of the -D macros */ + +/* This routine is called with the argument to each -D command-line option. +** Add the macro defined to the azDefine array. +*/ +static void handle_D_option(char *z){ + char **paz; + nDefine++; + azDefine = realloc(azDefine, sizeof(azDefine[0])*nDefine); + if( azDefine==0 ){ + fprintf(stderr,"out of memory\n"); + exit(1); + } + paz = &azDefine[nDefine-1]; + *paz = malloc( strlen(z)+1 ); + if( *paz==0 ){ + fprintf(stderr,"out of memory\n"); + exit(1); + } + strcpy(*paz, z); + for(z=*paz; *z && *z!='='; z++){} + *z = 0; +} + + +/* The main program. Parse the command line and do it... */ +int main(argc,argv) +int argc; +char **argv; +{ + static int version = 0; + static int rpflag = 0; + static int basisflag = 0; + static int compress = 0; + static int quiet = 0; + static int statistics = 0; + static int mhflag = 0; + static struct s_options options[] = { + {OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."}, + {OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."}, + {OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."}, + {OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."}, + {OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file"}, + {OPT_FLAG, "q", (char*)&quiet, "(Quiet) Don't print the report file."}, + {OPT_FLAG, "s", (char*)&statistics, + "Print parser stats to standard output."}, + {OPT_FLAG, "x", (char*)&version, "Print the version number."}, + {OPT_FLAG,0,0,0} + }; + int i; + struct lemon lem; + + OptInit(argv,options,stderr); + if( version ){ + printf("Lemon version 1.0\n"); + exit(0); + } + if( OptNArgs()!=1 ){ + fprintf(stderr,"Exactly one filename argument is required.\n"); + exit(1); + } + lem.errorcnt = 0; + + /* Initialize the machine */ + Strsafe_init(); + Symbol_init(); + State_init(); + lem.argv0 = argv[0]; + lem.filename = OptArg(0); + lem.basisflag = basisflag; + lem.has_fallback = 0; + lem.nconflict = 0; + lem.name = lem.include = lem.arg = lem.tokentype = lem.start = 0; + lem.vartype = 0; + lem.stacksize = 0; + lem.error = lem.overflow = lem.failure = lem.accept = lem.tokendest = + lem.tokenprefix = lem.outname = lem.extracode = 0; + lem.vardest = 0; + lem.tablesize = 0; + Symbol_new("$"); + lem.errsym = Symbol_new("error"); + + /* Parse the input file */ + Parse(&lem); + if( lem.errorcnt ) exit(lem.errorcnt); + if( lem.rule==0 ){ + fprintf(stderr,"Empty grammar.\n"); + exit(1); + } + + /* Count and index the symbols of the grammar */ + lem.nsymbol = Symbol_count(); + Symbol_new("{default}"); + lem.symbols = Symbol_arrayof(); + for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i; + qsort(lem.symbols,lem.nsymbol+1,sizeof(struct symbol*), + (int(*)(const void*, const void*))Symbolcmpp); + for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i; + for(i=1; isupper(lem.symbols[i]->name[0]); i++); + lem.nterminal = i; + + /* Generate a reprint of the grammar, if requested on the command line */ + if( rpflag ){ + Reprint(&lem); + }else{ + /* Initialize the size for all follow and first sets */ + SetSize(lem.nterminal); + + /* Find the precedence for every production rule (that has one) */ + FindRulePrecedences(&lem); + + /* Compute the lambda-nonterminals and the first-sets for every + ** nonterminal */ + FindFirstSets(&lem); + + /* Compute all LR(0) states. Also record follow-set propagation + ** links so that the follow-set can be computed later */ + lem.nstate = 0; + FindStates(&lem); + lem.sorted = State_arrayof(); + + /* Tie up loose ends on the propagation links */ + FindLinks(&lem); + + /* Compute the follow set of every reducible configuration */ + FindFollowSets(&lem); + + /* Compute the action tables */ + FindActions(&lem); + + /* Compress the action tables */ + if( compress==0 ) CompressTables(&lem); + + /* Reorder and renumber the states so that states with fewer choices + ** occur at the end. */ + ResortStates(&lem); + + /* Generate a report of the parser generated. (the "y.output" file) */ + if( !quiet ) ReportOutput(&lem); + + /* Generate the source code for the parser */ + ReportTable(&lem, mhflag); + + /* Produce a header file for use by the scanner. (This step is + ** omitted if the "-m" option is used because makeheaders will + ** generate the file for us.) */ + if( !mhflag ) ReportHeader(&lem); + } + if( statistics ){ + printf("Parser statistics: %d terminals, %d nonterminals, %d rules\n", + lem.nterminal, lem.nsymbol - lem.nterminal, lem.nrule); + printf(" %d states, %d parser table entries, %d conflicts\n", + lem.nstate, lem.tablesize, lem.nconflict); + } + if( lem.nconflict ){ + fprintf(stderr,"%d parsing conflicts.\n",lem.nconflict); + } + exit(lem.errorcnt + lem.nconflict); + return (lem.errorcnt + lem.nconflict); +} +/******************** From the file "msort.c" *******************************/ +/* +** A generic merge-sort program. +** +** USAGE: +** Let "ptr" be a pointer to some structure which is at the head of +** a null-terminated list. Then to sort the list call: +** +** ptr = msort(ptr,&(ptr->next),cmpfnc); +** +** In the above, "cmpfnc" is a pointer to a function which compares +** two instances of the structure and returns an integer, as in +** strcmp. The second argument is a pointer to the pointer to the +** second element of the linked list. This address is used to compute +** the offset to the "next" field within the structure. The offset to +** the "next" field must be constant for all structures in the list. +** +** The function returns a new pointer which is the head of the list +** after sorting. +** +** ALGORITHM: +** Merge-sort. +*/ + +/* +** Return a pointer to the next structure in the linked list. +*/ +#define NEXT(A) (*(char**)(((unsigned long)A)+offset)) + +/* +** Inputs: +** a: A sorted, null-terminated linked list. (May be null). +** b: A sorted, null-terminated linked list. (May be null). +** cmp: A pointer to the comparison function. +** offset: Offset in the structure to the "next" field. +** +** Return Value: +** A pointer to the head of a sorted list containing the elements +** of both a and b. +** +** Side effects: +** The "next" pointers for elements in the lists a and b are +** changed. +*/ +static char *merge(a,b,cmp,offset) +char *a; +char *b; +int (*cmp)(); +int offset; +{ + char *ptr, *head; + + if( a==0 ){ + head = b; + }else if( b==0 ){ + head = a; + }else{ + if( (*cmp)(a,b)<0 ){ + ptr = a; + a = NEXT(a); + }else{ + ptr = b; + b = NEXT(b); + } + head = ptr; + while( a && b ){ + if( (*cmp)(a,b)<0 ){ + NEXT(ptr) = a; + ptr = a; + a = NEXT(a); + }else{ + NEXT(ptr) = b; + ptr = b; + b = NEXT(b); + } + } + if( a ) NEXT(ptr) = a; + else NEXT(ptr) = b; + } + return head; +} + +/* +** Inputs: +** list: Pointer to a singly-linked list of structures. +** next: Pointer to pointer to the second element of the list. +** cmp: A comparison function. +** +** Return Value: +** A pointer to the head of a sorted list containing the elements +** orginally in list. +** +** Side effects: +** The "next" pointers for elements in list are changed. +*/ +#define LISTSIZE 30 +char *msort(list,next,cmp) +char *list; +char **next; +int (*cmp)(); +{ + unsigned long offset; + char *ep; + char *set[LISTSIZE]; + int i; + offset = (unsigned long)next - (unsigned long)list; + for(i=0; istate = WAITING_FOR_DECL_KEYWORD; + }else if( islower(x[0]) ){ + psp->lhs = Symbol_new(x); + psp->nrhs = 0; + psp->lhsalias = 0; + psp->state = WAITING_FOR_ARROW; + }else if( x[0]=='{' ){ + if( psp->prevrule==0 ){ + ErrorMsg(psp->filename,psp->tokenlineno, +"There is not prior rule opon which to attach the code \ +fragment which begins on this line."); + psp->errorcnt++; + }else if( psp->prevrule->code!=0 ){ + ErrorMsg(psp->filename,psp->tokenlineno, +"Code fragment beginning on this line is not the first \ +to follow the previous rule."); + psp->errorcnt++; + }else{ + psp->prevrule->line = psp->tokenlineno; + psp->prevrule->code = &x[1]; + } + }else if( x[0]=='[' ){ + psp->state = PRECEDENCE_MARK_1; + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "Token \"%s\" should be either \"%%\" or a nonterminal name.", + x); + psp->errorcnt++; + } + break; + case PRECEDENCE_MARK_1: + if( !isupper(x[0]) ){ + ErrorMsg(psp->filename,psp->tokenlineno, + "The precedence symbol must be a terminal."); + psp->errorcnt++; + }else if( psp->prevrule==0 ){ + ErrorMsg(psp->filename,psp->tokenlineno, + "There is no prior rule to assign precedence \"[%s]\".",x); + psp->errorcnt++; + }else if( psp->prevrule->precsym!=0 ){ + ErrorMsg(psp->filename,psp->tokenlineno, +"Precedence mark on this line is not the first \ +to follow the previous rule."); + psp->errorcnt++; + }else{ + psp->prevrule->precsym = Symbol_new(x); + } + psp->state = PRECEDENCE_MARK_2; + break; + case PRECEDENCE_MARK_2: + if( x[0]!=']' ){ + ErrorMsg(psp->filename,psp->tokenlineno, + "Missing \"]\" on precedence mark."); + psp->errorcnt++; + } + psp->state = WAITING_FOR_DECL_OR_RULE; + break; + case WAITING_FOR_ARROW: + if( x[0]==':' && x[1]==':' && x[2]=='=' ){ + psp->state = IN_RHS; + }else if( x[0]=='(' ){ + psp->state = LHS_ALIAS_1; + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "Expected to see a \":\" following the LHS symbol \"%s\".", + psp->lhs->name); + psp->errorcnt++; + psp->state = RESYNC_AFTER_RULE_ERROR; + } + break; + case LHS_ALIAS_1: + if( isalpha(x[0]) ){ + psp->lhsalias = x; + psp->state = LHS_ALIAS_2; + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "\"%s\" is not a valid alias for the LHS \"%s\"\n", + x,psp->lhs->name); + psp->errorcnt++; + psp->state = RESYNC_AFTER_RULE_ERROR; + } + break; + case LHS_ALIAS_2: + if( x[0]==')' ){ + psp->state = LHS_ALIAS_3; + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "Missing \")\" following LHS alias name \"%s\".",psp->lhsalias); + psp->errorcnt++; + psp->state = RESYNC_AFTER_RULE_ERROR; + } + break; + case LHS_ALIAS_3: + if( x[0]==':' && x[1]==':' && x[2]=='=' ){ + psp->state = IN_RHS; + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "Missing \"->\" following: \"%s(%s)\".", + psp->lhs->name,psp->lhsalias); + psp->errorcnt++; + psp->state = RESYNC_AFTER_RULE_ERROR; + } + break; + case IN_RHS: + if( x[0]=='.' ){ + struct rule *rp; + rp = (struct rule *)malloc( sizeof(struct rule) + + sizeof(struct symbol*)*psp->nrhs + sizeof(char*)*psp->nrhs ); + if( rp==0 ){ + ErrorMsg(psp->filename,psp->tokenlineno, + "Can't allocate enough memory for this rule."); + psp->errorcnt++; + psp->prevrule = 0; + }else{ + int i; + rp->ruleline = psp->tokenlineno; + rp->rhs = (struct symbol**)&rp[1]; + rp->rhsalias = (char**)&(rp->rhs[psp->nrhs]); + for(i=0; inrhs; i++){ + rp->rhs[i] = psp->rhs[i]; + rp->rhsalias[i] = psp->alias[i]; + } + rp->lhs = psp->lhs; + rp->lhsalias = psp->lhsalias; + rp->nrhs = psp->nrhs; + rp->code = 0; + rp->precsym = 0; + rp->index = psp->gp->nrule++; + rp->nextlhs = rp->lhs->rule; + rp->lhs->rule = rp; + rp->next = 0; + if( psp->firstrule==0 ){ + psp->firstrule = psp->lastrule = rp; + }else{ + psp->lastrule->next = rp; + psp->lastrule = rp; + } + psp->prevrule = rp; + } + psp->state = WAITING_FOR_DECL_OR_RULE; + }else if( isalpha(x[0]) ){ + if( psp->nrhs>=MAXRHS ){ + ErrorMsg(psp->filename,psp->tokenlineno, + "Too many symbols on RHS or rule beginning at \"%s\".", + x); + psp->errorcnt++; + psp->state = RESYNC_AFTER_RULE_ERROR; + }else{ + psp->rhs[psp->nrhs] = Symbol_new(x); + psp->alias[psp->nrhs] = 0; + psp->nrhs++; + } + }else if( (x[0]=='|' || x[0]=='/') && psp->nrhs>0 ){ + struct symbol *msp = psp->rhs[psp->nrhs-1]; + if( msp->type!=MULTITERMINAL ){ + struct symbol *origsp = msp; + msp = malloc(sizeof(*msp)); + memset(msp, 0, sizeof(*msp)); + msp->type = MULTITERMINAL; + msp->nsubsym = 1; + msp->subsym = malloc(sizeof(struct symbol*)); + msp->subsym[0] = origsp; + msp->name = origsp->name; + psp->rhs[psp->nrhs-1] = msp; + } + msp->nsubsym++; + msp->subsym = realloc(msp->subsym, sizeof(struct symbol*)*msp->nsubsym); + msp->subsym[msp->nsubsym-1] = Symbol_new(&x[1]); + if( islower(x[1]) || islower(msp->subsym[0]->name[0]) ){ + ErrorMsg(psp->filename,psp->tokenlineno, + "Cannot form a compound containing a non-terminal"); + psp->errorcnt++; + } + }else if( x[0]=='(' && psp->nrhs>0 ){ + psp->state = RHS_ALIAS_1; + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "Illegal character on RHS of rule: \"%s\".",x); + psp->errorcnt++; + psp->state = RESYNC_AFTER_RULE_ERROR; + } + break; + case RHS_ALIAS_1: + if( isalpha(x[0]) ){ + psp->alias[psp->nrhs-1] = x; + psp->state = RHS_ALIAS_2; + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "\"%s\" is not a valid alias for the RHS symbol \"%s\"\n", + x,psp->rhs[psp->nrhs-1]->name); + psp->errorcnt++; + psp->state = RESYNC_AFTER_RULE_ERROR; + } + break; + case RHS_ALIAS_2: + if( x[0]==')' ){ + psp->state = IN_RHS; + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "Missing \")\" following LHS alias name \"%s\".",psp->lhsalias); + psp->errorcnt++; + psp->state = RESYNC_AFTER_RULE_ERROR; + } + break; + case WAITING_FOR_DECL_KEYWORD: + if( isalpha(x[0]) ){ + psp->declkeyword = x; + psp->declargslot = 0; + psp->decllnslot = 0; + psp->state = WAITING_FOR_DECL_ARG; + if( strcmp(x,"name")==0 ){ + psp->declargslot = &(psp->gp->name); + }else if( strcmp(x,"include")==0 ){ + psp->declargslot = &(psp->gp->include); + psp->decllnslot = &psp->gp->includeln; + }else if( strcmp(x,"code")==0 ){ + psp->declargslot = &(psp->gp->extracode); + psp->decllnslot = &psp->gp->extracodeln; + }else if( strcmp(x,"token_destructor")==0 ){ + psp->declargslot = &psp->gp->tokendest; + psp->decllnslot = &psp->gp->tokendestln; + }else if( strcmp(x,"default_destructor")==0 ){ + psp->declargslot = &psp->gp->vardest; + psp->decllnslot = &psp->gp->vardestln; + }else if( strcmp(x,"token_prefix")==0 ){ + psp->declargslot = &psp->gp->tokenprefix; + }else if( strcmp(x,"syntax_error")==0 ){ + psp->declargslot = &(psp->gp->error); + psp->decllnslot = &psp->gp->errorln; + }else if( strcmp(x,"parse_accept")==0 ){ + psp->declargslot = &(psp->gp->accept); + psp->decllnslot = &psp->gp->acceptln; + }else if( strcmp(x,"parse_failure")==0 ){ + psp->declargslot = &(psp->gp->failure); + psp->decllnslot = &psp->gp->failureln; + }else if( strcmp(x,"stack_overflow")==0 ){ + psp->declargslot = &(psp->gp->overflow); + psp->decllnslot = &psp->gp->overflowln; + }else if( strcmp(x,"extra_argument")==0 ){ + psp->declargslot = &(psp->gp->arg); + }else if( strcmp(x,"token_type")==0 ){ + psp->declargslot = &(psp->gp->tokentype); + }else if( strcmp(x,"default_type")==0 ){ + psp->declargslot = &(psp->gp->vartype); + }else if( strcmp(x,"stack_size")==0 ){ + psp->declargslot = &(psp->gp->stacksize); + }else if( strcmp(x,"start_symbol")==0 ){ + psp->declargslot = &(psp->gp->start); + }else if( strcmp(x,"left")==0 ){ + psp->preccounter++; + psp->declassoc = LEFT; + psp->state = WAITING_FOR_PRECEDENCE_SYMBOL; + }else if( strcmp(x,"right")==0 ){ + psp->preccounter++; + psp->declassoc = RIGHT; + psp->state = WAITING_FOR_PRECEDENCE_SYMBOL; + }else if( strcmp(x,"nonassoc")==0 ){ + psp->preccounter++; + psp->declassoc = NONE; + psp->state = WAITING_FOR_PRECEDENCE_SYMBOL; + }else if( strcmp(x,"destructor")==0 ){ + psp->state = WAITING_FOR_DESTRUCTOR_SYMBOL; + }else if( strcmp(x,"type")==0 ){ + psp->state = WAITING_FOR_DATATYPE_SYMBOL; + }else if( strcmp(x,"fallback")==0 ){ + psp->fallback = 0; + psp->state = WAITING_FOR_FALLBACK_ID; + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "Unknown declaration keyword: \"%%%s\".",x); + psp->errorcnt++; + psp->state = RESYNC_AFTER_DECL_ERROR; + } + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "Illegal declaration keyword: \"%s\".",x); + psp->errorcnt++; + psp->state = RESYNC_AFTER_DECL_ERROR; + } + break; + case WAITING_FOR_DESTRUCTOR_SYMBOL: + if( !isalpha(x[0]) ){ + ErrorMsg(psp->filename,psp->tokenlineno, + "Symbol name missing after %destructor keyword"); + psp->errorcnt++; + psp->state = RESYNC_AFTER_DECL_ERROR; + }else{ + struct symbol *sp = Symbol_new(x); + psp->declargslot = &sp->destructor; + psp->decllnslot = &sp->destructorln; + psp->state = WAITING_FOR_DECL_ARG; + } + break; + case WAITING_FOR_DATATYPE_SYMBOL: + if( !isalpha(x[0]) ){ + ErrorMsg(psp->filename,psp->tokenlineno, + "Symbol name missing after %destructor keyword"); + psp->errorcnt++; + psp->state = RESYNC_AFTER_DECL_ERROR; + }else{ + struct symbol *sp = Symbol_new(x); + psp->declargslot = &sp->datatype; + psp->decllnslot = 0; + psp->state = WAITING_FOR_DECL_ARG; + } + break; + case WAITING_FOR_PRECEDENCE_SYMBOL: + if( x[0]=='.' ){ + psp->state = WAITING_FOR_DECL_OR_RULE; + }else if( isupper(x[0]) ){ + struct symbol *sp; + sp = Symbol_new(x); + if( sp->prec>=0 ){ + ErrorMsg(psp->filename,psp->tokenlineno, + "Symbol \"%s\" has already be given a precedence.",x); + psp->errorcnt++; + }else{ + sp->prec = psp->preccounter; + sp->assoc = psp->declassoc; + } + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "Can't assign a precedence to \"%s\".",x); + psp->errorcnt++; + } + break; + case WAITING_FOR_DECL_ARG: + if( (x[0]=='{' || x[0]=='\"' || isalnum(x[0])) ){ + if( *(psp->declargslot)!=0 ){ + ErrorMsg(psp->filename,psp->tokenlineno, + "The argument \"%s\" to declaration \"%%%s\" is not the first.", + x[0]=='\"' ? &x[1] : x,psp->declkeyword); + psp->errorcnt++; + psp->state = RESYNC_AFTER_DECL_ERROR; + }else{ + *(psp->declargslot) = (x[0]=='\"' || x[0]=='{') ? &x[1] : x; + if( psp->decllnslot ) *psp->decllnslot = psp->tokenlineno; + psp->state = WAITING_FOR_DECL_OR_RULE; + } + }else{ + ErrorMsg(psp->filename,psp->tokenlineno, + "Illegal argument to %%%s: %s",psp->declkeyword,x); + psp->errorcnt++; + psp->state = RESYNC_AFTER_DECL_ERROR; + } + break; + case WAITING_FOR_FALLBACK_ID: + if( x[0]=='.' ){ + psp->state = WAITING_FOR_DECL_OR_RULE; + }else if( !isupper(x[0]) ){ + ErrorMsg(psp->filename, psp->tokenlineno, + "%%fallback argument \"%s\" should be a token", x); + psp->errorcnt++; + }else{ + struct symbol *sp = Symbol_new(x); + if( psp->fallback==0 ){ + psp->fallback = sp; + }else if( sp->fallback ){ + ErrorMsg(psp->filename, psp->tokenlineno, + "More than one fallback assigned to token %s", x); + psp->errorcnt++; + }else{ + sp->fallback = psp->fallback; + psp->gp->has_fallback = 1; + } + } + break; + case RESYNC_AFTER_RULE_ERROR: +/* if( x[0]=='.' ) psp->state = WAITING_FOR_DECL_OR_RULE; +** break; */ + case RESYNC_AFTER_DECL_ERROR: + if( x[0]=='.' ) psp->state = WAITING_FOR_DECL_OR_RULE; + if( x[0]=='%' ) psp->state = WAITING_FOR_DECL_KEYWORD; + break; + } +} + +/* Run the proprocessor over the input file text. The global variables +** azDefine[0] through azDefine[nDefine-1] contains the names of all defined +** macros. This routine looks for "%ifdef" and "%ifndef" and "%endif" and +** comments them out. Text in between is also commented out as appropriate. +*/ +static void preprocess_input(char *z){ + int i, j, k, n; + int exclude = 0; + int start = 1; + int lineno = 1; + int start_lineno = 1; + for(i=0; z[i]; i++){ + if( z[i]=='\n' ) lineno++; + if( z[i]!='%' || (i>0 && z[i-1]!='\n') ) continue; + if( strncmp(&z[i],"%endif",6)==0 && isspace(z[i+6]) ){ + if( exclude ){ + exclude--; + if( exclude==0 ){ + for(j=start; jfilename; + ps.errorcnt = 0; + ps.state = INITIALIZE; + + /* Begin by reading the input file */ + fp = fopen(ps.filename,"rb"); + if( fp==0 ){ + ErrorMsg(ps.filename,0,"Can't open this file for reading."); + gp->errorcnt++; + return; + } + fseek(fp,0,2); + filesize = ftell(fp); + rewind(fp); + filebuf = (char *)malloc( filesize+1 ); + if( filebuf==0 ){ + ErrorMsg(ps.filename,0,"Can't allocate %d of memory to hold this file.", + filesize+1); + gp->errorcnt++; + return; + } + if( fread(filebuf,1,filesize,fp)!=filesize ){ + ErrorMsg(ps.filename,0,"Can't read in all %d bytes of this file.", + filesize); + free(filebuf); + gp->errorcnt++; + return; + } + fclose(fp); + filebuf[filesize] = 0; + + /* Make an initial pass through the file to handle %ifdef and %ifndef */ + preprocess_input(filebuf); + + /* Now scan the text of the input file */ + lineno = 1; + for(cp=filebuf; (c= *cp)!=0; ){ + if( c=='\n' ) lineno++; /* Keep track of the line number */ + if( isspace(c) ){ cp++; continue; } /* Skip all white space */ + if( c=='/' && cp[1]=='/' ){ /* Skip C++ style comments */ + cp+=2; + while( (c= *cp)!=0 && c!='\n' ) cp++; + continue; + } + if( c=='/' && cp[1]=='*' ){ /* Skip C style comments */ + cp+=2; + while( (c= *cp)!=0 && (c!='/' || cp[-1]!='*') ){ + if( c=='\n' ) lineno++; + cp++; + } + if( c ) cp++; + continue; + } + ps.tokenstart = cp; /* Mark the beginning of the token */ + ps.tokenlineno = lineno; /* Linenumber on which token begins */ + if( c=='\"' ){ /* String literals */ + cp++; + while( (c= *cp)!=0 && c!='\"' ){ + if( c=='\n' ) lineno++; + cp++; + } + if( c==0 ){ + ErrorMsg(ps.filename,startline, +"String starting on this line is not terminated before the end of the file."); + ps.errorcnt++; + nextcp = cp; + }else{ + nextcp = cp+1; + } + }else if( c=='{' ){ /* A block of C code */ + int level; + cp++; + for(level=1; (c= *cp)!=0 && (level>1 || c!='}'); cp++){ + if( c=='\n' ) lineno++; + else if( c=='{' ) level++; + else if( c=='}' ) level--; + else if( c=='/' && cp[1]=='*' ){ /* Skip comments */ + int prevc; + cp = &cp[2]; + prevc = 0; + while( (c= *cp)!=0 && (c!='/' || prevc!='*') ){ + if( c=='\n' ) lineno++; + prevc = c; + cp++; + } + }else if( c=='/' && cp[1]=='/' ){ /* Skip C++ style comments too */ + cp = &cp[2]; + while( (c= *cp)!=0 && c!='\n' ) cp++; + if( c ) lineno++; + }else if( c=='\'' || c=='\"' ){ /* String a character literals */ + int startchar, prevc; + startchar = c; + prevc = 0; + for(cp++; (c= *cp)!=0 && (c!=startchar || prevc=='\\'); cp++){ + if( c=='\n' ) lineno++; + if( prevc=='\\' ) prevc = 0; + else prevc = c; + } + } + } + if( c==0 ){ + ErrorMsg(ps.filename,ps.tokenlineno, +"C code starting on this line is not terminated before the end of the file."); + ps.errorcnt++; + nextcp = cp; + }else{ + nextcp = cp+1; + } + }else if( isalnum(c) ){ /* Identifiers */ + while( (c= *cp)!=0 && (isalnum(c) || c=='_') ) cp++; + nextcp = cp; + }else if( c==':' && cp[1]==':' && cp[2]=='=' ){ /* The operator "::=" */ + cp += 3; + nextcp = cp; + }else if( (c=='/' || c=='|') && isalpha(cp[1]) ){ + cp += 2; + while( (c = *cp)!=0 && (isalnum(c) || c=='_') ) cp++; + nextcp = cp; + }else{ /* All other (one character) operators */ + cp++; + nextcp = cp; + } + c = *cp; + *cp = 0; /* Null terminate the token */ + parseonetoken(&ps); /* Parse the token */ + *cp = c; /* Restore the buffer */ + cp = nextcp; + } + free(filebuf); /* Release the buffer after parsing */ + gp->rule = ps.firstrule; + gp->errorcnt = ps.errorcnt; +} +/*************************** From the file "plink.c" *********************/ +/* +** Routines processing configuration follow-set propagation links +** in the LEMON parser generator. +*/ +static struct plink *plink_freelist = 0; + +/* Allocate a new plink */ +struct plink *Plink_new(){ + struct plink *new; + + if( plink_freelist==0 ){ + int i; + int amt = 100; + plink_freelist = (struct plink *)malloc( sizeof(struct plink)*amt ); + if( plink_freelist==0 ){ + fprintf(stderr, + "Unable to allocate memory for a new follow-set propagation link.\n"); + exit(1); + } + for(i=0; inext; + return new; +} + +/* Add a plink to a plink list */ +void Plink_add(plpp,cfp) +struct plink **plpp; +struct config *cfp; +{ + struct plink *new; + new = Plink_new(); + new->next = *plpp; + *plpp = new; + new->cfp = cfp; +} + +/* Transfer every plink on the list "from" to the list "to" */ +void Plink_copy(to,from) +struct plink **to; +struct plink *from; +{ + struct plink *nextpl; + while( from ){ + nextpl = from->next; + from->next = *to; + *to = from; + from = nextpl; + } +} + +/* Delete every plink on the list */ +void Plink_delete(plp) +struct plink *plp; +{ + struct plink *nextpl; + + while( plp ){ + nextpl = plp->next; + plp->next = plink_freelist; + plink_freelist = plp; + plp = nextpl; + } +} +/*********************** From the file "report.c" **************************/ +/* +** Procedures for generating reports and tables in the LEMON parser generator. +*/ + +/* Generate a filename with the given suffix. Space to hold the +** name comes from malloc() and must be freed by the calling +** function. +*/ +PRIVATE char *file_makename(lemp,suffix) +struct lemon *lemp; +char *suffix; +{ + char *name; + char *cp; + + name = malloc( strlen(lemp->filename) + strlen(suffix) + 5 ); + if( name==0 ){ + fprintf(stderr,"Can't allocate space for a filename.\n"); + exit(1); + } + strcpy(name,lemp->filename); + cp = strrchr(name,'.'); + if( cp ) *cp = 0; + strcat(name,suffix); + return name; +} + +/* Open a file with a name based on the name of the input file, +** but with a different (specified) suffix, and return a pointer +** to the stream */ +PRIVATE FILE *file_open(lemp,suffix,mode) +struct lemon *lemp; +char *suffix; +char *mode; +{ + FILE *fp; + + if( lemp->outname ) free(lemp->outname); + lemp->outname = file_makename(lemp, suffix); + fp = fopen(lemp->outname,mode); + if( fp==0 && *mode=='w' ){ + fprintf(stderr,"Can't open file \"%s\".\n",lemp->outname); + lemp->errorcnt++; + return 0; + } + return fp; +} + +/* Duplicate the input file without comments and without actions +** on rules */ +void Reprint(lemp) +struct lemon *lemp; +{ + struct rule *rp; + struct symbol *sp; + int i, j, maxlen, len, ncolumns, skip; + printf("// Reprint of input file \"%s\".\n// Symbols:\n",lemp->filename); + maxlen = 10; + for(i=0; insymbol; i++){ + sp = lemp->symbols[i]; + len = strlen(sp->name); + if( len>maxlen ) maxlen = len; + } + ncolumns = 76/(maxlen+5); + if( ncolumns<1 ) ncolumns = 1; + skip = (lemp->nsymbol + ncolumns - 1)/ncolumns; + for(i=0; insymbol; j+=skip){ + sp = lemp->symbols[j]; + assert( sp->index==j ); + printf(" %3d %-*.*s",j,maxlen,maxlen,sp->name); + } + printf("\n"); + } + for(rp=lemp->rule; rp; rp=rp->next){ + printf("%s",rp->lhs->name); + /* if( rp->lhsalias ) printf("(%s)",rp->lhsalias); */ + printf(" ::="); + for(i=0; inrhs; i++){ + sp = rp->rhs[i]; + printf(" %s", sp->name); + if( sp->type==MULTITERMINAL ){ + for(j=1; jnsubsym; j++){ + printf("|%s", sp->subsym[j]->name); + } + } + /* if( rp->rhsalias[i] ) printf("(%s)",rp->rhsalias[i]); */ + } + printf("."); + if( rp->precsym ) printf(" [%s]",rp->precsym->name); + /* if( rp->code ) printf("\n %s",rp->code); */ + printf("\n"); + } +} + +void ConfigPrint(fp,cfp) +FILE *fp; +struct config *cfp; +{ + struct rule *rp; + struct symbol *sp; + int i, j; + rp = cfp->rp; + fprintf(fp,"%s ::=",rp->lhs->name); + for(i=0; i<=rp->nrhs; i++){ + if( i==cfp->dot ) fprintf(fp," *"); + if( i==rp->nrhs ) break; + sp = rp->rhs[i]; + fprintf(fp," %s", sp->name); + if( sp->type==MULTITERMINAL ){ + for(j=1; jnsubsym; j++){ + fprintf(fp,"|%s",sp->subsym[j]->name); + } + } + } +} + +/* #define TEST */ +#if 0 +/* Print a set */ +PRIVATE void SetPrint(out,set,lemp) +FILE *out; +char *set; +struct lemon *lemp; +{ + int i; + char *spacer; + spacer = ""; + fprintf(out,"%12s[",""); + for(i=0; interminal; i++){ + if( SetFind(set,i) ){ + fprintf(out,"%s%s",spacer,lemp->symbols[i]->name); + spacer = " "; + } + } + fprintf(out,"]\n"); +} + +/* Print a plink chain */ +PRIVATE void PlinkPrint(out,plp,tag) +FILE *out; +struct plink *plp; +char *tag; +{ + while( plp ){ + fprintf(out,"%12s%s (state %2d) ","",tag,plp->cfp->stp->statenum); + ConfigPrint(out,plp->cfp); + fprintf(out,"\n"); + plp = plp->next; + } +} +#endif + +/* Print an action to the given file descriptor. Return FALSE if +** nothing was actually printed. +*/ +int PrintAction(struct action *ap, FILE *fp, int indent){ + int result = 1; + switch( ap->type ){ + case SHIFT: + fprintf(fp,"%*s shift %d",indent,ap->sp->name,ap->x.stp->statenum); + break; + case REDUCE: + fprintf(fp,"%*s reduce %d",indent,ap->sp->name,ap->x.rp->index); + break; + case ACCEPT: + fprintf(fp,"%*s accept",indent,ap->sp->name); + break; + case ERROR: + fprintf(fp,"%*s error",indent,ap->sp->name); + break; + case CONFLICT: + fprintf(fp,"%*s reduce %-3d ** Parsing conflict **", + indent,ap->sp->name,ap->x.rp->index); + break; + case SH_RESOLVED: + case RD_RESOLVED: + case NOT_USED: + result = 0; + break; + } + return result; +} + +/* Generate the "y.output" log file */ +void ReportOutput(lemp) +struct lemon *lemp; +{ + int i; + struct state *stp; + struct config *cfp; + struct action *ap; + FILE *fp; + + fp = file_open(lemp,".out","wb"); + if( fp==0 ) return; + fprintf(fp," \b"); + for(i=0; instate; i++){ + stp = lemp->sorted[i]; + fprintf(fp,"State %d:\n",stp->statenum); + if( lemp->basisflag ) cfp=stp->bp; + else cfp=stp->cfp; + while( cfp ){ + char buf[20]; + if( cfp->dot==cfp->rp->nrhs ){ + sprintf(buf,"(%d)",cfp->rp->index); + fprintf(fp," %5s ",buf); + }else{ + fprintf(fp," "); + } + ConfigPrint(fp,cfp); + fprintf(fp,"\n"); +#if 0 + SetPrint(fp,cfp->fws,lemp); + PlinkPrint(fp,cfp->fplp,"To "); + PlinkPrint(fp,cfp->bplp,"From"); +#endif + if( lemp->basisflag ) cfp=cfp->bp; + else cfp=cfp->next; + } + fprintf(fp,"\n"); + for(ap=stp->ap; ap; ap=ap->next){ + if( PrintAction(ap,fp,30) ) fprintf(fp,"\n"); + } + fprintf(fp,"\n"); + } + fclose(fp); + return; +} + +/* Search for the file "name" which is in the same directory as +** the exacutable */ +PRIVATE char *pathsearch(argv0,name,modemask) +char *argv0; +char *name; +int modemask; +{ + char *pathlist; + char *path,*cp; + char c; + extern int access(); + +#ifdef __WIN32__ + for (cp = argv0 + strlen(argv0); cp-- > argv0; ) + { + if( *cp == '\\' || *cp == '/' ) + break; + } +#else + cp = strrchr(argv0,'/'); +#endif + if( cp ){ + c = *cp; + *cp = 0; + path = (char *)malloc( strlen(argv0) + strlen(name) + 2 ); + if( path ) sprintf(path,"%s/%s",argv0,name); + *cp = c; + }else{ + extern char *getenv(); + pathlist = getenv("PATH"); + if( pathlist==0 ) pathlist = ".:/bin:/usr/bin"; + path = (char *)malloc( strlen(pathlist)+strlen(name)+2 ); + if( path!=0 ){ + while( *pathlist ){ + cp = strchr(pathlist,':'); + if( cp==0 ) cp = &pathlist[strlen(pathlist)]; + c = *cp; + *cp = 0; + sprintf(path,"%s/%s",pathlist,name); + *cp = c; + if( c==0 ) pathlist = ""; + else pathlist = &cp[1]; + if( access(path,modemask)==0 ) break; + } + } + } + return path; +} + +/* Given an action, compute the integer value for that action +** which is to be put in the action table of the generated machine. +** Return negative if no action should be generated. +*/ +PRIVATE int compute_action(lemp,ap) +struct lemon *lemp; +struct action *ap; +{ + int act; + switch( ap->type ){ + case SHIFT: act = ap->x.stp->statenum; break; + case REDUCE: act = ap->x.rp->index + lemp->nstate; break; + case ERROR: act = lemp->nstate + lemp->nrule; break; + case ACCEPT: act = lemp->nstate + lemp->nrule + 1; break; + default: act = -1; break; + } + return act; +} + +#define LINESIZE 1000 +/* The next cluster of routines are for reading the template file +** and writing the results to the generated parser */ +/* The first function transfers data from "in" to "out" until +** a line is seen which begins with "%%". The line number is +** tracked. +** +** if name!=0, then any word that begin with "Parse" is changed to +** begin with *name instead. +*/ +PRIVATE void tplt_xfer(name,in,out,lineno) +char *name; +FILE *in; +FILE *out; +int *lineno; +{ + int i, iStart; + char line[LINESIZE]; + while( fgets(line,LINESIZE,in) && (line[0]!='%' || line[1]!='%') ){ + (*lineno)++; + iStart = 0; + if( name ){ + for(i=0; line[i]; i++){ + if( line[i]=='P' && strncmp(&line[i],"Parse",5)==0 + && (i==0 || !isalpha(line[i-1])) + ){ + if( i>iStart ) fprintf(out,"%.*s",i-iStart,&line[iStart]); + fprintf(out,"%s",name); + i += 4; + iStart = i+1; + } + } + } + fprintf(out,"%s",&line[iStart]); + } +} + +/* The next function finds the template file and opens it, returning +** a pointer to the opened file. */ +PRIVATE FILE *tplt_open(lemp) +struct lemon *lemp; +{ + static char templatename[] = "lempar.c"; + char buf[1000]; + FILE *in; + char *tpltname; + char *cp; + + cp = strrchr(lemp->filename,'.'); + if( cp ){ + sprintf(buf,"%.*s.lt",(int)(cp-lemp->filename),lemp->filename); + }else{ + sprintf(buf,"%s.lt",lemp->filename); + } + if( access(buf,004)==0 ){ + tpltname = buf; + }else if( access(templatename,004)==0 ){ + tpltname = templatename; + }else{ + tpltname = pathsearch(lemp->argv0,templatename,0); + } + if( tpltname==0 ){ + fprintf(stderr,"Can't find the parser driver template file \"%s\".\n", + templatename); + lemp->errorcnt++; + return 0; + } + in = fopen(tpltname,"rb"); + if( in==0 ){ + fprintf(stderr,"Can't open the template file \"%s\".\n",templatename); + lemp->errorcnt++; + return 0; + } + return in; +} + +/* Print a #line directive line to the output file. */ +PRIVATE void tplt_linedir(out,lineno,filename) +FILE *out; +int lineno; +char *filename; +{ + fprintf(out,"#line %d \"",lineno); + while( *filename ){ + if( *filename == '\\' ) putc('\\',out); + putc(*filename,out); + filename++; + } + fprintf(out,"\"\n"); +} + +/* Print a string to the file and keep the linenumber up to date */ +PRIVATE void tplt_print(out,lemp,str,strln,lineno) +FILE *out; +struct lemon *lemp; +char *str; +int strln; +int *lineno; +{ + if( str==0 ) return; + tplt_linedir(out,strln,lemp->filename); + (*lineno)++; + while( *str ){ + if( *str=='\n' ) (*lineno)++; + putc(*str,out); + str++; + } + if( str[-1]!='\n' ){ + putc('\n',out); + (*lineno)++; + } + tplt_linedir(out,*lineno+2,lemp->outname); + (*lineno)+=2; + return; +} + +/* +** The following routine emits code for the destructor for the +** symbol sp +*/ +void emit_destructor_code(out,sp,lemp,lineno) +FILE *out; +struct symbol *sp; +struct lemon *lemp; +int *lineno; +{ + char *cp = 0; + + int linecnt = 0; + if( sp->type==TERMINAL ){ + cp = lemp->tokendest; + if( cp==0 ) return; + tplt_linedir(out,lemp->tokendestln,lemp->filename); + fprintf(out,"{"); + }else if( sp->destructor ){ + cp = sp->destructor; + tplt_linedir(out,sp->destructorln,lemp->filename); + fprintf(out,"{"); + }else if( lemp->vardest ){ + cp = lemp->vardest; + if( cp==0 ) return; + tplt_linedir(out,lemp->vardestln,lemp->filename); + fprintf(out,"{"); + }else{ + assert( 0 ); /* Cannot happen */ + } + for(; *cp; cp++){ + if( *cp=='$' && cp[1]=='$' ){ + fprintf(out,"(yypminor->yy%d)",sp->dtnum); + cp++; + continue; + } + if( *cp=='\n' ) linecnt++; + fputc(*cp,out); + } + (*lineno) += 3 + linecnt; + fprintf(out,"}\n"); + tplt_linedir(out,*lineno,lemp->outname); + return; +} + +/* +** Return TRUE (non-zero) if the given symbol has a destructor. +*/ +int has_destructor(sp, lemp) +struct symbol *sp; +struct lemon *lemp; +{ + int ret; + if( sp->type==TERMINAL ){ + ret = lemp->tokendest!=0; + }else{ + ret = lemp->vardest!=0 || sp->destructor!=0; + } + return ret; +} + +/* +** Append text to a dynamically allocated string. If zText is 0 then +** reset the string to be empty again. Always return the complete text +** of the string (which is overwritten with each call). +** +** n bytes of zText are stored. If n==0 then all of zText up to the first +** \000 terminator is stored. zText can contain up to two instances of +** %d. The values of p1 and p2 are written into the first and second +** %d. +** +** If n==-1, then the previous character is overwritten. +*/ +PRIVATE char *append_str(char *zText, int n, int p1, int p2, int bNoSubst){ + static char *z = 0; + static int alloced = 0; + static int used = 0; + int c; + char zInt[40]; + + if( zText==0 ){ + used = 0; + return z; + } + if( n<=0 ){ + if( n<0 ){ + used += n; + assert( used>=0 ); + } + n = strlen(zText); + } + if( n+sizeof(zInt)*2+used >= (size_t)alloced ){ + alloced = n + sizeof(zInt)*2 + used + 200; + z = realloc(z, alloced); + } + if( z==0 ) return ""; + while( n-- > 0 ){ + c = *(zText++); + if( !bNoSubst && c=='%' && zText[0]=='d' ){ + sprintf(zInt, "%d", p1); + p1 = p2; + strcpy(&z[used], zInt); + used += strlen(&z[used]); + zText++; + n--; + }else{ + z[used++] = c; + } + } + z[used] = 0; + return z; +} + +/* +** zCode is a string that is the action associated with a rule. Expand +** the symbols in this string so that the refer to elements of the parser +** stack. +*/ +PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){ + char *cp, *xp; + int i; + char lhsused = 0; /* True if the LHS element has been used */ + char used[MAXRHS]; /* True for each RHS element which is used */ + + for(i=0; inrhs; i++) used[i] = 0; + lhsused = 0; + + append_str(0,0,0,0,0); + for(cp=rp->code; *cp; cp++){ + if( isalpha(*cp) && (cp==rp->code || (!isalnum(cp[-1]) && cp[-1]!='_')) ){ + char saved; + for(xp= &cp[1]; isalnum(*xp) || *xp=='_'; xp++); + saved = *xp; + *xp = 0; + if( rp->lhsalias && strcmp(cp,rp->lhsalias)==0 ){ + append_str("yygotominor.yy%d",0,rp->lhs->dtnum,0,0); + cp = xp; + lhsused = 1; + }else{ + for(i=0; inrhs; i++){ + if( rp->rhsalias[i] && strcmp(cp,rp->rhsalias[i])==0 ){ + if( cp!=rp->code && cp[-1]=='@' ){ + /* If the argument is of the form @X then substituted + ** the token number of X, not the value of X */ + append_str("yymsp[%d].major",-1,i-rp->nrhs+1,0,0); + }else{ + struct symbol *sp = rp->rhs[i]; + int dtnum; + if( sp->type==MULTITERMINAL ){ + dtnum = sp->subsym[0]->dtnum; + }else{ + dtnum = sp->dtnum; + } + append_str("yymsp[%d].minor.yy%d",0,i-rp->nrhs+1, dtnum,0); + } + cp = xp; + used[i] = 1; + break; + } + } + } + *xp = saved; + } + append_str(cp, 1, 0, 0, 1); + } /* End loop */ + + /* Check to make sure the LHS has been used */ + if( rp->lhsalias && !lhsused ){ + ErrorMsg(lemp->filename,rp->ruleline, + "Label \"%s\" for \"%s(%s)\" is never used.", + rp->lhsalias,rp->lhs->name,rp->lhsalias); + lemp->errorcnt++; + } + + /* Generate destructor code for RHS symbols which are not used in the + ** reduce code */ + for(i=0; inrhs; i++){ + if( rp->rhsalias[i] && !used[i] ){ + ErrorMsg(lemp->filename,rp->ruleline, + "Label %s for \"%s(%s)\" is never used.", + rp->rhsalias[i],rp->rhs[i]->name,rp->rhsalias[i]); + lemp->errorcnt++; + }else if( rp->rhsalias[i]==0 ){ + if( has_destructor(rp->rhs[i],lemp) ){ + append_str(" yy_destructor(%d,&yymsp[%d].minor);\n", 0, + rp->rhs[i]->index,i-rp->nrhs+1,0); + }else{ + /* No destructor defined for this term */ + } + } + } + cp = append_str(0,0,0,0,0); + rp->code = Strsafe(cp); +} + +/* +** Generate code which executes when the rule "rp" is reduced. Write +** the code to "out". Make sure lineno stays up-to-date. +*/ +PRIVATE void emit_code(out,rp,lemp,lineno) +FILE *out; +struct rule *rp; +struct lemon *lemp; +int *lineno; +{ + char *cp; + int linecnt = 0; + + /* Generate code to do the reduce action */ + if( rp->code ){ + tplt_linedir(out,rp->line,lemp->filename); + fprintf(out,"{%s",rp->code); + for(cp=rp->code; *cp; cp++){ + if( *cp=='\n' ) linecnt++; + } /* End loop */ + (*lineno) += 3 + linecnt; + fprintf(out,"}\n"); + tplt_linedir(out,*lineno,lemp->outname); + } /* End if( rp->code ) */ + + return; +} + +/* +** Print the definition of the union used for the parser's data stack. +** This union contains fields for every possible data type for tokens +** and nonterminals. In the process of computing and printing this +** union, also set the ".dtnum" field of every terminal and nonterminal +** symbol. +*/ +void print_stack_union(out,lemp,plineno,mhflag) +FILE *out; /* The output stream */ +struct lemon *lemp; /* The main info structure for this parser */ +int *plineno; /* Pointer to the line number */ +int mhflag; /* True if generating makeheaders output */ +{ + int lineno = *plineno; /* The line number of the output */ + char **types; /* A hash table of datatypes */ + int arraysize; /* Size of the "types" array */ + int maxdtlength; /* Maximum length of any ".datatype" field. */ + char *stddt; /* Standardized name for a datatype */ + int i,j; /* Loop counters */ + int hash; /* For hashing the name of a type */ + char *name; /* Name of the parser */ + + /* Allocate and initialize types[] and allocate stddt[] */ + arraysize = lemp->nsymbol * 2; + types = (char**)malloc( arraysize * sizeof(char*) ); + for(i=0; ivartype ){ + maxdtlength = strlen(lemp->vartype); + } + for(i=0; insymbol; i++){ + int len; + struct symbol *sp = lemp->symbols[i]; + if( sp->datatype==0 ) continue; + len = strlen(sp->datatype); + if( len>maxdtlength ) maxdtlength = len; + } + stddt = (char*)malloc( maxdtlength*2 + 1 ); + if( types==0 || stddt==0 ){ + fprintf(stderr,"Out of memory.\n"); + exit(1); + } + + /* Build a hash table of datatypes. The ".dtnum" field of each symbol + ** is filled in with the hash index plus 1. A ".dtnum" value of 0 is + ** used for terminal symbols. If there is no %default_type defined then + ** 0 is also used as the .dtnum value for nonterminals which do not specify + ** a datatype using the %type directive. + */ + for(i=0; insymbol; i++){ + struct symbol *sp = lemp->symbols[i]; + char *cp; + if( sp==lemp->errsym ){ + sp->dtnum = arraysize+1; + continue; + } + if( sp->type!=NONTERMINAL || (sp->datatype==0 && lemp->vartype==0) ){ + sp->dtnum = 0; + continue; + } + cp = sp->datatype; + if( cp==0 ) cp = lemp->vartype; + j = 0; + while( isspace(*cp) ) cp++; + while( *cp ) stddt[j++] = *cp++; + while( j>0 && isspace(stddt[j-1]) ) j--; + stddt[j] = 0; + hash = 0; + for(j=0; stddt[j]; j++){ + hash = hash*53 + stddt[j]; + } + hash = (hash & 0x7fffffff)%arraysize; + while( types[hash] ){ + if( strcmp(types[hash],stddt)==0 ){ + sp->dtnum = hash + 1; + break; + } + hash++; + if( hash>=arraysize ) hash = 0; + } + if( types[hash]==0 ){ + sp->dtnum = hash + 1; + types[hash] = (char*)malloc( strlen(stddt)+1 ); + if( types[hash]==0 ){ + fprintf(stderr,"Out of memory.\n"); + exit(1); + } + strcpy(types[hash],stddt); + } + } + + /* Print out the definition of YYTOKENTYPE and YYMINORTYPE */ + name = lemp->name ? lemp->name : "Parse"; + lineno = *plineno; + if( mhflag ){ fprintf(out,"#if INTERFACE\n"); lineno++; } + fprintf(out,"#define %sTOKENTYPE %s\n",name, + lemp->tokentype?lemp->tokentype:"void*"); lineno++; + if( mhflag ){ fprintf(out,"#endif\n"); lineno++; } + fprintf(out,"typedef union {\n"); lineno++; + fprintf(out," %sTOKENTYPE yy0;\n",name); lineno++; + for(i=0; ierrsym->dtnum); lineno++; + free(stddt); + free(types); + fprintf(out,"} YYMINORTYPE;\n"); lineno++; + *plineno = lineno; +} + +/* +** Return the name of a C datatype able to represent values between +** lwr and upr, inclusive. +*/ +static const char *minimum_size_type(int lwr, int upr){ + if( lwr>=0 ){ + if( upr<=255 ){ + return "unsigned char"; + }else if( upr<65535 ){ + return "unsigned short int"; + }else{ + return "unsigned int"; + } + }else if( lwr>=-127 && upr<=127 ){ + return "signed char"; + }else if( lwr>=-32767 && upr<32767 ){ + return "short"; + }else{ + return "int"; + } +} + +/* +** Each state contains a set of token transaction and a set of +** nonterminal transactions. Each of these sets makes an instance +** of the following structure. An array of these structures is used +** to order the creation of entries in the yy_action[] table. +*/ +struct axset { + struct state *stp; /* A pointer to a state */ + int isTkn; /* True to use tokens. False for non-terminals */ + int nAction; /* Number of actions */ +}; + +/* +** Compare to axset structures for sorting purposes +*/ +static int axset_compare(const void *a, const void *b){ + struct axset *p1 = (struct axset*)a; + struct axset *p2 = (struct axset*)b; + return p2->nAction - p1->nAction; +} + +/* Generate C source code for the parser */ +void ReportTable(lemp, mhflag) +struct lemon *lemp; +int mhflag; /* Output in makeheaders format if true */ +{ + FILE *out, *in; + char line[LINESIZE]; + int lineno; + struct state *stp; + struct action *ap; + struct rule *rp; + struct acttab *pActtab; + int i, j, n; + char *name; + int mnTknOfst, mxTknOfst; + int mnNtOfst, mxNtOfst; + struct axset *ax; + + in = tplt_open(lemp); + if( in==0 ) return; + out = file_open(lemp,".c","wb"); + if( out==0 ){ + fclose(in); + return; + } + lineno = 1; + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate the include code, if any */ + tplt_print(out,lemp,lemp->include,lemp->includeln,&lineno); + if( mhflag ){ + char *name = file_makename(lemp, ".h"); + fprintf(out,"#include \"%s\"\n", name); lineno++; + free(name); + } + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate #defines for all tokens */ + if( mhflag ){ + char *prefix; + fprintf(out,"#if INTERFACE\n"); lineno++; + if( lemp->tokenprefix ) prefix = lemp->tokenprefix; + else prefix = ""; + for(i=1; interminal; i++){ + fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i); + lineno++; + } + fprintf(out,"#endif\n"); lineno++; + } + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate the defines */ + fprintf(out,"#define YYCODETYPE %s\n", + minimum_size_type(0, lemp->nsymbol+5)); lineno++; + fprintf(out,"#define YYNOCODE %d\n",lemp->nsymbol+1); lineno++; + fprintf(out,"#define YYACTIONTYPE %s\n", + minimum_size_type(0, lemp->nstate+lemp->nrule+5)); lineno++; + print_stack_union(out,lemp,&lineno,mhflag); + if( lemp->stacksize ){ + if( atoi(lemp->stacksize)<=0 ){ + ErrorMsg(lemp->filename,0, +"Illegal stack size: [%s]. The stack size should be an integer constant.", + lemp->stacksize); + lemp->errorcnt++; + lemp->stacksize = "100"; + } + fprintf(out,"#define YYSTACKDEPTH %s\n",lemp->stacksize); lineno++; + }else{ + fprintf(out,"#define YYSTACKDEPTH 100\n"); lineno++; + } + if( mhflag ){ + fprintf(out,"#if INTERFACE\n"); lineno++; + } + name = lemp->name ? lemp->name : "Parse"; + if( lemp->arg && lemp->arg[0] ){ + int i; + i = strlen(lemp->arg); + while( i>=1 && isspace(lemp->arg[i-1]) ) i--; + while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--; + fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg); lineno++; + fprintf(out,"#define %sARG_PDECL ,%s\n",name,lemp->arg); lineno++; + fprintf(out,"#define %sARG_FETCH %s = yypParser->%s\n", + name,lemp->arg,&lemp->arg[i]); lineno++; + fprintf(out,"#define %sARG_STORE yypParser->%s = %s\n", + name,&lemp->arg[i],&lemp->arg[i]); lineno++; + }else{ + fprintf(out,"#define %sARG_SDECL\n",name); lineno++; + fprintf(out,"#define %sARG_PDECL\n",name); lineno++; + fprintf(out,"#define %sARG_FETCH\n",name); lineno++; + fprintf(out,"#define %sARG_STORE\n",name); lineno++; + } + if( mhflag ){ + fprintf(out,"#endif\n"); lineno++; + } + fprintf(out,"#define YYNSTATE %d\n",lemp->nstate); lineno++; + fprintf(out,"#define YYNRULE %d\n",lemp->nrule); lineno++; + fprintf(out,"#define YYERRORSYMBOL %d\n",lemp->errsym->index); lineno++; + fprintf(out,"#define YYERRSYMDT yy%d\n",lemp->errsym->dtnum); lineno++; + if( lemp->has_fallback ){ + fprintf(out,"#define YYFALLBACK 1\n"); lineno++; + } + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate the action table and its associates: + ** + ** yy_action[] A single table containing all actions. + ** yy_lookahead[] A table containing the lookahead for each entry in + ** yy_action. Used to detect hash collisions. + ** yy_shift_ofst[] For each state, the offset into yy_action for + ** shifting terminals. + ** yy_reduce_ofst[] For each state, the offset into yy_action for + ** shifting non-terminals after a reduce. + ** yy_default[] Default action for each state. + */ + + /* Compute the actions on all states and count them up */ + ax = malloc( sizeof(ax[0])*lemp->nstate*2 ); + if( ax==0 ){ + fprintf(stderr,"malloc failed\n"); + exit(1); + } + for(i=0; instate; i++){ + stp = lemp->sorted[i]; + ax[i*2].stp = stp; + ax[i*2].isTkn = 1; + ax[i*2].nAction = stp->nTknAct; + ax[i*2+1].stp = stp; + ax[i*2+1].isTkn = 0; + ax[i*2+1].nAction = stp->nNtAct; + } + mxTknOfst = mnTknOfst = 0; + mxNtOfst = mnNtOfst = 0; + + /* Compute the action table. In order to try to keep the size of the + ** action table to a minimum, the heuristic of placing the largest action + ** sets first is used. + */ + qsort(ax, lemp->nstate*2, sizeof(ax[0]), axset_compare); + pActtab = acttab_alloc(); + for(i=0; instate*2 && ax[i].nAction>0; i++){ + stp = ax[i].stp; + if( ax[i].isTkn ){ + for(ap=stp->ap; ap; ap=ap->next){ + int action; + if( ap->sp->index>=lemp->nterminal ) continue; + action = compute_action(lemp, ap); + if( action<0 ) continue; + acttab_action(pActtab, ap->sp->index, action); + } + stp->iTknOfst = acttab_insert(pActtab); + if( stp->iTknOfstiTknOfst; + if( stp->iTknOfst>mxTknOfst ) mxTknOfst = stp->iTknOfst; + }else{ + for(ap=stp->ap; ap; ap=ap->next){ + int action; + if( ap->sp->indexnterminal ) continue; + if( ap->sp->index==lemp->nsymbol ) continue; + action = compute_action(lemp, ap); + if( action<0 ) continue; + acttab_action(pActtab, ap->sp->index, action); + } + stp->iNtOfst = acttab_insert(pActtab); + if( stp->iNtOfstiNtOfst; + if( stp->iNtOfst>mxNtOfst ) mxNtOfst = stp->iNtOfst; + } + } + free(ax); + + /* Output the yy_action table */ + fprintf(out,"static const YYACTIONTYPE yy_action[] = {\n"); lineno++; + n = acttab_size(pActtab); + for(i=j=0; insymbol + lemp->nrule + 2; + if( j==0 ) fprintf(out," /* %5d */ ", i); + fprintf(out, " %4d,", action); + if( j==9 || i==n-1 ){ + fprintf(out, "\n"); lineno++; + j = 0; + }else{ + j++; + } + } + fprintf(out, "};\n"); lineno++; + + /* Output the yy_lookahead table */ + fprintf(out,"static const YYCODETYPE yy_lookahead[] = {\n"); lineno++; + for(i=j=0; insymbol; + if( j==0 ) fprintf(out," /* %5d */ ", i); + fprintf(out, " %4d,", la); + if( j==9 || i==n-1 ){ + fprintf(out, "\n"); lineno++; + j = 0; + }else{ + j++; + } + } + fprintf(out, "};\n"); lineno++; + + /* Output the yy_shift_ofst[] table */ + fprintf(out, "#define YY_SHIFT_USE_DFLT (%d)\n", mnTknOfst-1); lineno++; + n = lemp->nstate; + while( n>0 && lemp->sorted[n-1]->iTknOfst==NO_OFFSET ) n--; + fprintf(out, "#define YY_SHIFT_MAX %d\n", n-1); lineno++; + fprintf(out, "static const %s yy_shift_ofst[] = {\n", + minimum_size_type(mnTknOfst-1, mxTknOfst)); lineno++; + for(i=j=0; isorted[i]; + ofst = stp->iTknOfst; + if( ofst==NO_OFFSET ) ofst = mnTknOfst - 1; + if( j==0 ) fprintf(out," /* %5d */ ", i); + fprintf(out, " %4d,", ofst); + if( j==9 || i==n-1 ){ + fprintf(out, "\n"); lineno++; + j = 0; + }else{ + j++; + } + } + fprintf(out, "};\n"); lineno++; + + /* Output the yy_reduce_ofst[] table */ + fprintf(out, "#define YY_REDUCE_USE_DFLT (%d)\n", mnNtOfst-1); lineno++; + n = lemp->nstate; + while( n>0 && lemp->sorted[n-1]->iNtOfst==NO_OFFSET ) n--; + fprintf(out, "#define YY_REDUCE_MAX %d\n", n-1); lineno++; + fprintf(out, "static const %s yy_reduce_ofst[] = {\n", + minimum_size_type(mnNtOfst-1, mxNtOfst)); lineno++; + for(i=j=0; isorted[i]; + ofst = stp->iNtOfst; + if( ofst==NO_OFFSET ) ofst = mnNtOfst - 1; + if( j==0 ) fprintf(out," /* %5d */ ", i); + fprintf(out, " %4d,", ofst); + if( j==9 || i==n-1 ){ + fprintf(out, "\n"); lineno++; + j = 0; + }else{ + j++; + } + } + fprintf(out, "};\n"); lineno++; + + /* Output the default action table */ + fprintf(out, "static const YYACTIONTYPE yy_default[] = {\n"); lineno++; + n = lemp->nstate; + for(i=j=0; isorted[i]; + if( j==0 ) fprintf(out," /* %5d */ ", i); + fprintf(out, " %4d,", stp->iDflt); + if( j==9 || i==n-1 ){ + fprintf(out, "\n"); lineno++; + j = 0; + }else{ + j++; + } + } + fprintf(out, "};\n"); lineno++; + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate the table of fallback tokens. + */ + if( lemp->has_fallback ){ + for(i=0; interminal; i++){ + struct symbol *p = lemp->symbols[i]; + if( p->fallback==0 ){ + fprintf(out, " 0, /* %10s => nothing */\n", p->name); + }else{ + fprintf(out, " %3d, /* %10s => %s */\n", p->fallback->index, + p->name, p->fallback->name); + } + lineno++; + } + } + tplt_xfer(lemp->name, in, out, &lineno); + + /* Generate a table containing the symbolic name of every symbol + */ + for(i=0; insymbol; i++){ + sprintf(line,"\"%s\",",lemp->symbols[i]->name); + fprintf(out," %-15s",line); + if( (i&3)==3 ){ fprintf(out,"\n"); lineno++; } + } + if( (i&3)!=0 ){ fprintf(out,"\n"); lineno++; } + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate a table containing a text string that describes every + ** rule in the rule set of the grammer. This information is used + ** when tracing REDUCE actions. + */ + for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){ + assert( rp->index==i ); + fprintf(out," /* %3d */ \"%s ::=", i, rp->lhs->name); + for(j=0; jnrhs; j++){ + struct symbol *sp = rp->rhs[j]; + fprintf(out," %s", sp->name); + if( sp->type==MULTITERMINAL ){ + int k; + for(k=1; knsubsym; k++){ + fprintf(out,"|%s",sp->subsym[k]->name); + } + } + } + fprintf(out,"\",\n"); lineno++; + } + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate code which executes every time a symbol is popped from + ** the stack while processing errors or while destroying the parser. + ** (In other words, generate the %destructor actions) + */ + if( lemp->tokendest ){ + for(i=0; insymbol; i++){ + struct symbol *sp = lemp->symbols[i]; + if( sp==0 || sp->type!=TERMINAL ) continue; + fprintf(out," case %d:\n",sp->index); lineno++; + } + for(i=0; insymbol && lemp->symbols[i]->type!=TERMINAL; i++); + if( insymbol ){ + emit_destructor_code(out,lemp->symbols[i],lemp,&lineno); + fprintf(out," break;\n"); lineno++; + } + } + if( lemp->vardest ){ + struct symbol *dflt_sp = 0; + for(i=0; insymbol; i++){ + struct symbol *sp = lemp->symbols[i]; + if( sp==0 || sp->type==TERMINAL || + sp->index<=0 || sp->destructor!=0 ) continue; + fprintf(out," case %d:\n",sp->index); lineno++; + dflt_sp = sp; + } + if( dflt_sp!=0 ){ + emit_destructor_code(out,dflt_sp,lemp,&lineno); + fprintf(out," break;\n"); lineno++; + } + } + for(i=0; insymbol; i++){ + struct symbol *sp = lemp->symbols[i]; + if( sp==0 || sp->type==TERMINAL || sp->destructor==0 ) continue; + fprintf(out," case %d:\n",sp->index); lineno++; + + /* Combine duplicate destructors into a single case */ + for(j=i+1; jnsymbol; j++){ + struct symbol *sp2 = lemp->symbols[j]; + if( sp2 && sp2->type!=TERMINAL && sp2->destructor + && sp2->dtnum==sp->dtnum + && strcmp(sp->destructor,sp2->destructor)==0 ){ + fprintf(out," case %d:\n",sp2->index); lineno++; + sp2->destructor = 0; + } + } + + emit_destructor_code(out,lemp->symbols[i],lemp,&lineno); + fprintf(out," break;\n"); lineno++; + } + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate code which executes whenever the parser stack overflows */ + tplt_print(out,lemp,lemp->overflow,lemp->overflowln,&lineno); + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate the table of rule information + ** + ** Note: This code depends on the fact that rules are number + ** sequentually beginning with 0. + */ + for(rp=lemp->rule; rp; rp=rp->next){ + fprintf(out," { %d, %d },\n",rp->lhs->index,rp->nrhs); lineno++; + } + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate code which executes during each REDUCE action */ + for(rp=lemp->rule; rp; rp=rp->next){ + if( rp->code ) translate_code(lemp, rp); + } + for(rp=lemp->rule; rp; rp=rp->next){ + struct rule *rp2; + if( rp->code==0 ) continue; + fprintf(out," case %d:\n",rp->index); lineno++; + for(rp2=rp->next; rp2; rp2=rp2->next){ + if( rp2->code==rp->code ){ + fprintf(out," case %d:\n",rp2->index); lineno++; + rp2->code = 0; + } + } + emit_code(out,rp,lemp,&lineno); + fprintf(out," break;\n"); lineno++; + } + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate code which executes if a parse fails */ + tplt_print(out,lemp,lemp->failure,lemp->failureln,&lineno); + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate code which executes when a syntax error occurs */ + tplt_print(out,lemp,lemp->error,lemp->errorln,&lineno); + tplt_xfer(lemp->name,in,out,&lineno); + + /* Generate code which executes when the parser accepts its input */ + tplt_print(out,lemp,lemp->accept,lemp->acceptln,&lineno); + tplt_xfer(lemp->name,in,out,&lineno); + + /* Append any addition code the user desires */ + tplt_print(out,lemp,lemp->extracode,lemp->extracodeln,&lineno); + + fclose(in); + fclose(out); + return; +} + +/* Generate a header file for the parser */ +void ReportHeader(lemp) +struct lemon *lemp; +{ + FILE *out, *in; + char *prefix; + char line[LINESIZE]; + char pattern[LINESIZE]; + int i; + + if( lemp->tokenprefix ) prefix = lemp->tokenprefix; + else prefix = ""; + in = file_open(lemp,".h","rb"); + if( in ){ + for(i=1; interminal && fgets(line,LINESIZE,in); i++){ + sprintf(pattern,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i); + if( strcmp(line,pattern) ) break; + } + fclose(in); + if( i==lemp->nterminal ){ + /* No change in the file. Don't rewrite it. */ + return; + } + } + out = file_open(lemp,".h","wb"); + if( out ){ + for(i=1; interminal; i++){ + fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i); + } + fclose(out); + } + return; +} + +/* Reduce the size of the action tables, if possible, by making use +** of defaults. +** +** In this version, we take the most frequent REDUCE action and make +** it the default. +*/ +void CompressTables(lemp) +struct lemon *lemp; +{ + struct state *stp; + struct action *ap, *ap2; + struct rule *rp, *rp2, *rbest; + int nbest, n; + int i; + + for(i=0; instate; i++){ + stp = lemp->sorted[i]; + nbest = 0; + rbest = 0; + + for(ap=stp->ap; ap; ap=ap->next){ + if( ap->type!=REDUCE ) continue; + rp = ap->x.rp; + if( rp==rbest ) continue; + n = 1; + for(ap2=ap->next; ap2; ap2=ap2->next){ + if( ap2->type!=REDUCE ) continue; + rp2 = ap2->x.rp; + if( rp2==rbest ) continue; + if( rp2==rp ) n++; + } + if( n>nbest ){ + nbest = n; + rbest = rp; + } + } + + /* Do not make a default if the number of rules to default + ** is not at least 1 */ + if( nbest<1 ) continue; + + + /* Combine matching REDUCE actions into a single default */ + for(ap=stp->ap; ap; ap=ap->next){ + if( ap->type==REDUCE && ap->x.rp==rbest ) break; + } + assert( ap ); + ap->sp = Symbol_new("{default}"); + for(ap=ap->next; ap; ap=ap->next){ + if( ap->type==REDUCE && ap->x.rp==rbest ) ap->type = NOT_USED; + } + stp->ap = Action_sort(stp->ap); + } +} + + +/* +** Compare two states for sorting purposes. The smaller state is the +** one with the most non-terminal actions. If they have the same number +** of non-terminal actions, then the smaller is the one with the most +** token actions. +*/ +static int stateResortCompare(const void *a, const void *b){ + const struct state *pA = *(const struct state**)a; + const struct state *pB = *(const struct state**)b; + int n; + + n = pB->nNtAct - pA->nNtAct; + if( n==0 ){ + n = pB->nTknAct - pA->nTknAct; + } + return n; +} + + +/* +** Renumber and resort states so that states with fewer choices +** occur at the end. Except, keep state 0 as the first state. +*/ +void ResortStates(lemp) +struct lemon *lemp; +{ + int i; + struct state *stp; + struct action *ap; + + for(i=0; instate; i++){ + stp = lemp->sorted[i]; + stp->nTknAct = stp->nNtAct = 0; + stp->iDflt = lemp->nstate + lemp->nrule; + stp->iTknOfst = NO_OFFSET; + stp->iNtOfst = NO_OFFSET; + for(ap=stp->ap; ap; ap=ap->next){ + if( compute_action(lemp,ap)>=0 ){ + if( ap->sp->indexnterminal ){ + stp->nTknAct++; + }else if( ap->sp->indexnsymbol ){ + stp->nNtAct++; + }else{ + stp->iDflt = compute_action(lemp, ap); + } + } + } + } + qsort(&lemp->sorted[1], lemp->nstate-1, sizeof(lemp->sorted[0]), + stateResortCompare); + for(i=0; instate; i++){ + lemp->sorted[i]->statenum = i; + } +} + + +/***************** From the file "set.c" ************************************/ +/* +** Set manipulation routines for the LEMON parser generator. +*/ + +static int size = 0; + +/* Set the set size */ +void SetSize(n) +int n; +{ + size = n+1; +} + +/* Allocate a new set */ +char *SetNew(){ + char *s; + int i; + s = (char*)malloc( size ); + if( s==0 ){ + extern void memory_error(); + memory_error(); + } + for(i=0; isize = 1024; + x1a->count = 0; + x1a->tbl = (x1node*)malloc( + (sizeof(x1node) + sizeof(x1node*))*1024 ); + if( x1a->tbl==0 ){ + free(x1a); + x1a = 0; + }else{ + int i; + x1a->ht = (x1node**)&(x1a->tbl[1024]); + for(i=0; i<1024; i++) x1a->ht[i] = 0; + } + } +} +/* Insert a new record into the array. Return TRUE if successful. +** Prior data with the same key is NOT overwritten */ +int Strsafe_insert(data) +char *data; +{ + x1node *np; + int h; + int ph; + + if( x1a==0 ) return 0; + ph = strhash(data); + h = ph & (x1a->size-1); + np = x1a->ht[h]; + while( np ){ + if( strcmp(np->data,data)==0 ){ + /* An existing entry with the same key is found. */ + /* Fail because overwrite is not allows. */ + return 0; + } + np = np->next; + } + if( x1a->count>=x1a->size ){ + /* Need to make the hash table bigger */ + int i,size; + struct s_x1 array; + array.size = size = x1a->size*2; + array.count = x1a->count; + array.tbl = (x1node*)malloc( + (sizeof(x1node) + sizeof(x1node*))*size ); + if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ + array.ht = (x1node**)&(array.tbl[size]); + for(i=0; icount; i++){ + x1node *oldnp, *newnp; + oldnp = &(x1a->tbl[i]); + h = strhash(oldnp->data) & (size-1); + newnp = &(array.tbl[i]); + if( array.ht[h] ) array.ht[h]->from = &(newnp->next); + newnp->next = array.ht[h]; + newnp->data = oldnp->data; + newnp->from = &(array.ht[h]); + array.ht[h] = newnp; + } + free(x1a->tbl); + *x1a = array; + } + /* Insert the new data */ + h = ph & (x1a->size-1); + np = &(x1a->tbl[x1a->count++]); + np->data = data; + if( x1a->ht[h] ) x1a->ht[h]->from = &(np->next); + np->next = x1a->ht[h]; + x1a->ht[h] = np; + np->from = &(x1a->ht[h]); + return 1; +} + +/* Return a pointer to data assigned to the given key. Return NULL +** if no such key. */ +char *Strsafe_find(key) +char *key; +{ + int h; + x1node *np; + + if( x1a==0 ) return 0; + h = strhash(key) & (x1a->size-1); + np = x1a->ht[h]; + while( np ){ + if( strcmp(np->data,key)==0 ) break; + np = np->next; + } + return np ? np->data : 0; +} + +/* Return a pointer to the (terminal or nonterminal) symbol "x". +** Create a new symbol if this is the first time "x" has been seen. +*/ +struct symbol *Symbol_new(x) +char *x; +{ + struct symbol *sp; + + sp = Symbol_find(x); + if( sp==0 ){ + sp = (struct symbol *)malloc( sizeof(struct symbol) ); + MemoryCheck(sp); + sp->name = Strsafe(x); + sp->type = isupper(*x) ? TERMINAL : NONTERMINAL; + sp->rule = 0; + sp->fallback = 0; + sp->prec = -1; + sp->assoc = UNK; + sp->firstset = 0; + sp->lambda = B_FALSE; + sp->destructor = 0; + sp->datatype = 0; + Symbol_insert(sp,sp->name); + } + return sp; +} + +/* Compare two symbols for working purposes +** +** Symbols that begin with upper case letters (terminals or tokens) +** must sort before symbols that begin with lower case letters +** (non-terminals). Other than that, the order does not matter. +** +** We find experimentally that leaving the symbols in their original +** order (the order they appeared in the grammar file) gives the +** smallest parser tables in SQLite. +*/ +int Symbolcmpp(struct symbol **a, struct symbol **b){ + int i1 = (**a).index + 10000000*((**a).name[0]>'Z'); + int i2 = (**b).index + 10000000*((**b).name[0]>'Z'); + return i1-i2; +} + +/* There is one instance of the following structure for each +** associative array of type "x2". +*/ +struct s_x2 { + int size; /* The number of available slots. */ + /* Must be a power of 2 greater than or */ + /* equal to 1 */ + int count; /* Number of currently slots filled */ + struct s_x2node *tbl; /* The data stored here */ + struct s_x2node **ht; /* Hash table for lookups */ +}; + +/* There is one instance of this structure for every data element +** in an associative array of type "x2". +*/ +typedef struct s_x2node { + struct symbol *data; /* The data */ + char *key; /* The key */ + struct s_x2node *next; /* Next entry with the same hash */ + struct s_x2node **from; /* Previous link */ +} x2node; + +/* There is only one instance of the array, which is the following */ +static struct s_x2 *x2a; + +/* Allocate a new associative array */ +void Symbol_init(){ + if( x2a ) return; + x2a = (struct s_x2*)malloc( sizeof(struct s_x2) ); + if( x2a ){ + x2a->size = 128; + x2a->count = 0; + x2a->tbl = (x2node*)malloc( + (sizeof(x2node) + sizeof(x2node*))*128 ); + if( x2a->tbl==0 ){ + free(x2a); + x2a = 0; + }else{ + int i; + x2a->ht = (x2node**)&(x2a->tbl[128]); + for(i=0; i<128; i++) x2a->ht[i] = 0; + } + } +} +/* Insert a new record into the array. Return TRUE if successful. +** Prior data with the same key is NOT overwritten */ +int Symbol_insert(data,key) +struct symbol *data; +char *key; +{ + x2node *np; + int h; + int ph; + + if( x2a==0 ) return 0; + ph = strhash(key); + h = ph & (x2a->size-1); + np = x2a->ht[h]; + while( np ){ + if( strcmp(np->key,key)==0 ){ + /* An existing entry with the same key is found. */ + /* Fail because overwrite is not allows. */ + return 0; + } + np = np->next; + } + if( x2a->count>=x2a->size ){ + /* Need to make the hash table bigger */ + int i,size; + struct s_x2 array; + array.size = size = x2a->size*2; + array.count = x2a->count; + array.tbl = (x2node*)malloc( + (sizeof(x2node) + sizeof(x2node*))*size ); + if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ + array.ht = (x2node**)&(array.tbl[size]); + for(i=0; icount; i++){ + x2node *oldnp, *newnp; + oldnp = &(x2a->tbl[i]); + h = strhash(oldnp->key) & (size-1); + newnp = &(array.tbl[i]); + if( array.ht[h] ) array.ht[h]->from = &(newnp->next); + newnp->next = array.ht[h]; + newnp->key = oldnp->key; + newnp->data = oldnp->data; + newnp->from = &(array.ht[h]); + array.ht[h] = newnp; + } + free(x2a->tbl); + *x2a = array; + } + /* Insert the new data */ + h = ph & (x2a->size-1); + np = &(x2a->tbl[x2a->count++]); + np->key = key; + np->data = data; + if( x2a->ht[h] ) x2a->ht[h]->from = &(np->next); + np->next = x2a->ht[h]; + x2a->ht[h] = np; + np->from = &(x2a->ht[h]); + return 1; +} + +/* Return a pointer to data assigned to the given key. Return NULL +** if no such key. */ +struct symbol *Symbol_find(key) +char *key; +{ + int h; + x2node *np; + + if( x2a==0 ) return 0; + h = strhash(key) & (x2a->size-1); + np = x2a->ht[h]; + while( np ){ + if( strcmp(np->key,key)==0 ) break; + np = np->next; + } + return np ? np->data : 0; +} + +/* Return the n-th data. Return NULL if n is out of range. */ +struct symbol *Symbol_Nth(n) +int n; +{ + struct symbol *data; + if( x2a && n>0 && n<=x2a->count ){ + data = x2a->tbl[n-1].data; + }else{ + data = 0; + } + return data; +} + +/* Return the size of the array */ +int Symbol_count() +{ + return x2a ? x2a->count : 0; +} + +/* Return an array of pointers to all data in the table. +** The array is obtained from malloc. Return NULL if memory allocation +** problems, or if the array is empty. */ +struct symbol **Symbol_arrayof() +{ + struct symbol **array; + int i,size; + if( x2a==0 ) return 0; + size = x2a->count; + array = (struct symbol **)malloc( sizeof(struct symbol *)*size ); + if( array ){ + for(i=0; itbl[i].data; + } + return array; +} + +/* Compare two configurations */ +int Configcmp(a,b) +struct config *a; +struct config *b; +{ + int x; + x = a->rp->index - b->rp->index; + if( x==0 ) x = a->dot - b->dot; + return x; +} + +/* Compare two states */ +PRIVATE int statecmp(a,b) +struct config *a; +struct config *b; +{ + int rc; + for(rc=0; rc==0 && a && b; a=a->bp, b=b->bp){ + rc = a->rp->index - b->rp->index; + if( rc==0 ) rc = a->dot - b->dot; + } + if( rc==0 ){ + if( a ) rc = 1; + if( b ) rc = -1; + } + return rc; +} + +/* Hash a state */ +PRIVATE int statehash(a) +struct config *a; +{ + int h=0; + while( a ){ + h = h*571 + a->rp->index*37 + a->dot; + a = a->bp; + } + return h; +} + +/* Allocate a new state structure */ +struct state *State_new() +{ + struct state *new; + new = (struct state *)malloc( sizeof(struct state) ); + MemoryCheck(new); + return new; +} + +/* There is one instance of the following structure for each +** associative array of type "x3". +*/ +struct s_x3 { + int size; /* The number of available slots. */ + /* Must be a power of 2 greater than or */ + /* equal to 1 */ + int count; /* Number of currently slots filled */ + struct s_x3node *tbl; /* The data stored here */ + struct s_x3node **ht; /* Hash table for lookups */ +}; + +/* There is one instance of this structure for every data element +** in an associative array of type "x3". +*/ +typedef struct s_x3node { + struct state *data; /* The data */ + struct config *key; /* The key */ + struct s_x3node *next; /* Next entry with the same hash */ + struct s_x3node **from; /* Previous link */ +} x3node; + +/* There is only one instance of the array, which is the following */ +static struct s_x3 *x3a; + +/* Allocate a new associative array */ +void State_init(){ + if( x3a ) return; + x3a = (struct s_x3*)malloc( sizeof(struct s_x3) ); + if( x3a ){ + x3a->size = 128; + x3a->count = 0; + x3a->tbl = (x3node*)malloc( + (sizeof(x3node) + sizeof(x3node*))*128 ); + if( x3a->tbl==0 ){ + free(x3a); + x3a = 0; + }else{ + int i; + x3a->ht = (x3node**)&(x3a->tbl[128]); + for(i=0; i<128; i++) x3a->ht[i] = 0; + } + } +} +/* Insert a new record into the array. Return TRUE if successful. +** Prior data with the same key is NOT overwritten */ +int State_insert(data,key) +struct state *data; +struct config *key; +{ + x3node *np; + int h; + int ph; + + if( x3a==0 ) return 0; + ph = statehash(key); + h = ph & (x3a->size-1); + np = x3a->ht[h]; + while( np ){ + if( statecmp(np->key,key)==0 ){ + /* An existing entry with the same key is found. */ + /* Fail because overwrite is not allows. */ + return 0; + } + np = np->next; + } + if( x3a->count>=x3a->size ){ + /* Need to make the hash table bigger */ + int i,size; + struct s_x3 array; + array.size = size = x3a->size*2; + array.count = x3a->count; + array.tbl = (x3node*)malloc( + (sizeof(x3node) + sizeof(x3node*))*size ); + if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ + array.ht = (x3node**)&(array.tbl[size]); + for(i=0; icount; i++){ + x3node *oldnp, *newnp; + oldnp = &(x3a->tbl[i]); + h = statehash(oldnp->key) & (size-1); + newnp = &(array.tbl[i]); + if( array.ht[h] ) array.ht[h]->from = &(newnp->next); + newnp->next = array.ht[h]; + newnp->key = oldnp->key; + newnp->data = oldnp->data; + newnp->from = &(array.ht[h]); + array.ht[h] = newnp; + } + free(x3a->tbl); + *x3a = array; + } + /* Insert the new data */ + h = ph & (x3a->size-1); + np = &(x3a->tbl[x3a->count++]); + np->key = key; + np->data = data; + if( x3a->ht[h] ) x3a->ht[h]->from = &(np->next); + np->next = x3a->ht[h]; + x3a->ht[h] = np; + np->from = &(x3a->ht[h]); + return 1; +} + +/* Return a pointer to data assigned to the given key. Return NULL +** if no such key. */ +struct state *State_find(key) +struct config *key; +{ + int h; + x3node *np; + + if( x3a==0 ) return 0; + h = statehash(key) & (x3a->size-1); + np = x3a->ht[h]; + while( np ){ + if( statecmp(np->key,key)==0 ) break; + np = np->next; + } + return np ? np->data : 0; +} + +/* Return an array of pointers to all data in the table. +** The array is obtained from malloc. Return NULL if memory allocation +** problems, or if the array is empty. */ +struct state **State_arrayof() +{ + struct state **array; + int i,size; + if( x3a==0 ) return 0; + size = x3a->count; + array = (struct state **)malloc( sizeof(struct state *)*size ); + if( array ){ + for(i=0; itbl[i].data; + } + return array; +} + +/* Hash a configuration */ +PRIVATE int confighash(a) +struct config *a; +{ + int h=0; + h = h*571 + a->rp->index*37 + a->dot; + return h; +} + +/* There is one instance of the following structure for each +** associative array of type "x4". +*/ +struct s_x4 { + int size; /* The number of available slots. */ + /* Must be a power of 2 greater than or */ + /* equal to 1 */ + int count; /* Number of currently slots filled */ + struct s_x4node *tbl; /* The data stored here */ + struct s_x4node **ht; /* Hash table for lookups */ +}; + +/* There is one instance of this structure for every data element +** in an associative array of type "x4". +*/ +typedef struct s_x4node { + struct config *data; /* The data */ + struct s_x4node *next; /* Next entry with the same hash */ + struct s_x4node **from; /* Previous link */ +} x4node; + +/* There is only one instance of the array, which is the following */ +static struct s_x4 *x4a; + +/* Allocate a new associative array */ +void Configtable_init(){ + if( x4a ) return; + x4a = (struct s_x4*)malloc( sizeof(struct s_x4) ); + if( x4a ){ + x4a->size = 64; + x4a->count = 0; + x4a->tbl = (x4node*)malloc( + (sizeof(x4node) + sizeof(x4node*))*64 ); + if( x4a->tbl==0 ){ + free(x4a); + x4a = 0; + }else{ + int i; + x4a->ht = (x4node**)&(x4a->tbl[64]); + for(i=0; i<64; i++) x4a->ht[i] = 0; + } + } +} +/* Insert a new record into the array. Return TRUE if successful. +** Prior data with the same key is NOT overwritten */ +int Configtable_insert(data) +struct config *data; +{ + x4node *np; + int h; + int ph; + + if( x4a==0 ) return 0; + ph = confighash(data); + h = ph & (x4a->size-1); + np = x4a->ht[h]; + while( np ){ + if( Configcmp(np->data,data)==0 ){ + /* An existing entry with the same key is found. */ + /* Fail because overwrite is not allows. */ + return 0; + } + np = np->next; + } + if( x4a->count>=x4a->size ){ + /* Need to make the hash table bigger */ + int i,size; + struct s_x4 array; + array.size = size = x4a->size*2; + array.count = x4a->count; + array.tbl = (x4node*)malloc( + (sizeof(x4node) + sizeof(x4node*))*size ); + if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ + array.ht = (x4node**)&(array.tbl[size]); + for(i=0; icount; i++){ + x4node *oldnp, *newnp; + oldnp = &(x4a->tbl[i]); + h = confighash(oldnp->data) & (size-1); + newnp = &(array.tbl[i]); + if( array.ht[h] ) array.ht[h]->from = &(newnp->next); + newnp->next = array.ht[h]; + newnp->data = oldnp->data; + newnp->from = &(array.ht[h]); + array.ht[h] = newnp; + } + free(x4a->tbl); + *x4a = array; + } + /* Insert the new data */ + h = ph & (x4a->size-1); + np = &(x4a->tbl[x4a->count++]); + np->data = data; + if( x4a->ht[h] ) x4a->ht[h]->from = &(np->next); + np->next = x4a->ht[h]; + x4a->ht[h] = np; + np->from = &(x4a->ht[h]); + return 1; +} + +/* Return a pointer to data assigned to the given key. Return NULL +** if no such key. */ +struct config *Configtable_find(key) +struct config *key; +{ + int h; + x4node *np; + + if( x4a==0 ) return 0; + h = confighash(key) & (x4a->size-1); + np = x4a->ht[h]; + while( np ){ + if( Configcmp(np->data,key)==0 ) break; + np = np->next; + } + return np ? np->data : 0; +} + +/* Remove all data from the table. Pass each data to the function "f" +** as it is removed. ("f" may be null to avoid this step.) */ +void Configtable_clear(f) +int(*f)(/* struct config * */); +{ + int i; + if( x4a==0 || x4a->count==0 ) return; + if( f ) for(i=0; icount; i++) (*f)(x4a->tbl[i].data); + for(i=0; isize; i++) x4a->ht[i] = 0; + x4a->count = 0; + return; +} diff --git a/tools/lemon/lemon.vcproj b/tools/lemon/lemon.vcproj index caae99ddf..137b9d7b0 100644 --- a/tools/lemon/lemon.vcproj +++ b/tools/lemon/lemon.vcproj @@ -43,15 +43,16 @@ /> - - - - - - - - -
- - - - - - - - - - - @@ -268,6 +186,89 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/tools/lemon/lempar.c b/tools/lemon/lempar.c index ee1edbfa7..f379544c1 100644 --- a/tools/lemon/lempar.c +++ b/tools/lemon/lempar.c @@ -4,6 +4,9 @@ /* First off, code is include which follows the "include" declaration ** in the input file. */ #include +#ifndef NDEBUG +#include +#endif %% /* Next is all token values, in a form suitable for use by makeheaders. ** This section will be null unless lemon is run with the -m switch. @@ -191,7 +194,7 @@ void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ #ifndef NDEBUG /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ -static const char *yyTokenName[] = { +static const char *const yyTokenName[] = { %% }; #endif /* NDEBUG */ @@ -199,7 +202,7 @@ static const char *yyTokenName[] = { #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. */ -static const char *yyRuleName[] = { +static const char *const yyRuleName[] = { %% }; #endif /* NDEBUG */ @@ -326,9 +329,7 @@ static int yy_find_shift_action( int i; int stateno = pParser->yystack[pParser->yyidx].stateno; - /* if( pParser->yyidx<0 ) return YY_NO_ACTION; */ - i = yy_shift_ofst[stateno]; - if( i==YY_SHIFT_USE_DFLT ){ + if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){ return yy_default[stateno]; } if( iLookAhead==YYNOCODE ){ @@ -364,14 +365,14 @@ static int yy_find_shift_action( ** return YY_NO_ACTION. */ static int yy_find_reduce_action( - yyParser *pParser, /* The parser */ + int stateno, /* Current state number */ int iLookAhead /* The look-ahead token */ ){ int i; - int stateno = pParser->yystack[pParser->yyidx].stateno; + /* int stateno = pParser->yystack[pParser->yyidx].stateno; */ - i = yy_reduce_ofst[stateno]; - if( i==YY_REDUCE_USE_DFLT ){ + if( stateno>YY_REDUCE_MAX || + (i = yy_reduce_ofst[stateno])==YY_REDUCE_USE_DFLT ){ return yy_default[stateno]; } if( iLookAhead==YYNOCODE ){ @@ -430,7 +431,7 @@ static void yy_shift( /* The following table contains information about every rule that ** is used during the reduce. */ -static struct { +static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ unsigned char nrhs; /* Number of right-hand side symbols in the rule */ } yyRuleInfo[] = { @@ -462,6 +463,18 @@ static void yy_reduce( } #endif /* NDEBUG */ +#ifndef NDEBUG + /* Silence complaints from purify about yygotominor being uninitialized + ** in some cases when it is copied into the stack after the following + ** switch. yygotominor is uninitialized when a rule reduces that does + ** not set the value of its left-hand side nonterminal. Leaving the + ** value of the nonterminal uninitialized is utterly harmless as long + ** as the value is never used. So really the only thing this code + ** accomplishes is to quieten purify. + */ + memset(&yygotominor, 0, sizeof(yygotominor)); +#endif + switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example ** follows: @@ -476,9 +489,24 @@ static void yy_reduce( yygoto = yyRuleInfo[yyruleno].lhs; yysize = yyRuleInfo[yyruleno].nrhs; yypParser->yyidx -= yysize; - yyact = yy_find_reduce_action(yypParser,yygoto); + yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto); if( yyact < YYNSTATE ){ - yy_shift(yypParser,yyact,yygoto,&yygotominor); +#ifdef NDEBUG + /* If we are not debugging and the reduce action popped at least + ** one element off the stack, then we can push the new element back + ** onto the stack here, and skip the stack overflow test in yy_shift(). + ** That gives a significant speed improvement. */ + if( yysize ){ + yypParser->yyidx++; + yymsp -= yysize-1; + yymsp->stateno = yyact; + yymsp->major = yygoto; + yymsp->minor = yygotominor; + }else +#endif + { + yy_shift(yypParser,yyact,yygoto,&yygotominor); + } }else if( yyact == YYNSTATE + YYNRULE + 1 ){ yy_accept(yypParser); } @@ -570,7 +598,7 @@ void Parse( /* (re)initialize the parser, if necessary */ yypParser = (yyParser*)yyp; if( yypParser->yyidx<0 ){ - if( yymajor==0 ) return; + /* if( yymajor==0 ) return; // not sure why this was here... */ yypParser->yyidx = 0; yypParser->yyerrcnt = -1; yypParser->yystack[0].stateno = 0; @@ -642,7 +670,9 @@ void Parse( while( yypParser->yyidx >= 0 && yymx != YYERRORSYMBOL && - (yyact = yy_find_shift_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE + (yyact = yy_find_reduce_action( + yypParser->yystack[yypParser->yyidx].stateno, + YYERRORSYMBOL)) >= YYNSTATE ){ yy_pop_parser_stack(yypParser); } diff --git a/tools/re2c/CHANGELOG b/tools/re2c/CHANGELOG new file mode 100644 index 000000000..e1a95b05e --- /dev/null +++ b/tools/re2c/CHANGELOG @@ -0,0 +1,141 @@ +Version 0.10.3 (2006-05-14) +--------------------------- +- Fixed issue with -wb and -ws. +- Added -g switch to support gcc's computed goto's. +- Changed to use nested if's instead of "switch(yyaccept)" in -s mode. + +Version 0.10.2 (2006-05-01) +--------------------------- +- Changed to generate YYMARKER only when needed or in single pass mode. +- Added -1 switch to force single pass generation and make two pass the default. +- Fixed -i switch. +- Added configuration 'yyfill:enable' to allow suppression of YYFILL() blocks. +- Added tutorial like lessons to re2c. +- Added /*!ignore!re2c */ to support documenting of re2c source. +- Fixed issue with multiline re2c comments (/*!max:re2c ... */ and alike). +- Fixed generation of YYDEBUG() when using -d switch. +- Added /*!getstate:re2c */ which triggers generation of the YYGETSTATE() block. +- Added configuration 'state:abort'. +- Changed to not generate yyNext unless configuration 'state:nextlabel' is used. +- Changed to not generate yyaccept code unless needed. +- Changed to use if- instead of switch-expression when yyaccpt has only one case. +- Added docu, examples and tests to .src.zip package (0.10.1 zip was repackaged). +- Fixed #1479044 incorrect code generated when using -b. +- Fixed #1472770 re2c creates an infinite loop. +- Fixed #1454253 Piece of code saving a backtracking point not generated. +- Fixed #1463639 Missing forward declaration. +- Implemented #1187127 savable state support for multiple re2c blocks. + +Version 0.10.1 (2006-02-28) +--------------------------- +- Added support for Solaris and native SUN compiler. +- Applied #1438160 expose YYCTXMARKER. + +Version 0.10.0 (2006-02-18) +--------------------------- +- Added make target zip to create windows source packages as zip files. +- Added re2c:startlabel configuration. +- Fixed code generation to not generate unreachable code for initial state. +- Added support for c/c++ compatible \u and \U unicode notation. +- Added ability to control indendation. +- Made scanner error out in case an ambiguous /* is found. +- Fixed indendation of generated code. +- Added support for DOS line endings. +- Added experimental unicode support. +- Added config_w32.h to build out of the box on windows (using msvc 2002+). +- Added Microsoft Visual C .NET 2005 build files. +- Applied #1411087 variable length trailing context. +- Applied #1408326 do not generate goto next state. +- Applied #1408282 CharSet initialization fix. +- Applied #1408278 readsome with MSVC. +- Applied #1307467 Unicode patch for 0.9.7. + +Version 0.9.12 (2005-12-28) +--------------------------- +- Fixed bug #1390174 re2c cannot accept {0,}. + +Version 0.9.11 (2005-12-18) +--------------------------- +- Fixed #1313083 -e (EBCDIC cross compile) broken. +- Fixed #1297658 underestimation of n in YYFILL(n). +- Applied #1339483 Avoid rebuilds of re2c when running subtargets. +- Implemented #1335305 symbol table reimplementation, just slightly modifed. + +Version 0.9.10 (2005-09-04) +--------------------------- +- Added -i switch to avoid generating #line information. +- Fixed bug #1251653 re2c generate some invalid #line on WIN32. + +Version 0.9.9 (2005-07-21) +-------------------------- +- Implemented #1232777 negated char classes '[^...]' and the dot operator '.'. +- Added hexadecimal character definitions. +- Added consistency check for octal character definitions. + +Version 0.9.8 (2005-06-26) +-------------------------- +- Fixed code generation for -b switch. +- Added Microsoft Visual C .NET build files. + +Version 0.9.7 (2005-04-30) +-------------------------- +- Applied #1181535 storable state patch. +- Added -d flag which outputs a debugable parser. +- Fixed generation of '#line' directives (according to ISO-C99). +- Fixed bug #1187785 Re2c fails to generate valid code. +- Fixed bug #1187452 unused variable `yyaccept'. + +Version 0.9.6 (2005-04-14) +-------------------------- +- Fixed build with gcc >= 3.4. + +Version 0.9.5 (2005-04-08) +-------------------------- +- Added /*!max:re2c */ which emits a '#define YYMAXFILL \n' line + This allows to define buffers of the minimum required length. Occurence + must follow '/*re2c */ and cannot preceed it. +- Changed re2c to two pass generation to output warning free code. +- Fixed bug #1163046 re2c hangs when processing valid re-file. +- Fixed bug #1022799 re2c scanner has buffering bug. + +Version 0.9.4 (2005-03-12) +-------------------------- +- Added --vernum support. +- Fixed bug #1054496 incorrect code generated with -b option. +- Fixed bug #1012748 re2c does not emit last line if '\n' missing. +- Fixed bug #999104 --output=output option does not work as documented. +- Fixed bug #999103 Invalid options prefixed with two dashes cause program crash. + +Version 0.9.3 (2004-05-26) +-------------------------- +- Fixes one small possible bug in the generated output. ych instead of yych is + output in certain circumstances + +Version 0.9.2 (2004-05-26) +-------------------------- +- Added -o option to specify the output file which also will set the #line + directives to something useful. +- Print version to cout instead cerr. +- Added -h and -- style options. +- Moved development to http://sourceforge.net/projects/re2c . +- Fixed bug #960144 minor cosmetic problem. +- Fixed bug #953181 cannot compile with. +- Fixed bug #939277 Windows support. +- Fixed bug #914462 automake build patch +- Fixed bug #891940 braced quantifiers: {\d+(,|,\d+)?} style. +- Fixed bug #869298 Add case insensitive string literals. +- Fixed bug #869297 Input buffer overrun. + +Version 0.9.1 (2003-12-13) +-------------------------- +- Removed rcs comments in source files. + +Version 0.9 +----------- +- Redistribution based on version 0.5. +- Added parentheses to assignment expressions in 'if' statements. +- Rearranged class members to match initialization order. +- Substr fix. +- Use array delete [] when necessary. +- Other minor fixes for subduing compiler warnings. + diff --git a/tools/re2c/Makefile.am b/tools/re2c/Makefile.am deleted file mode 100644 index 14a19138a..000000000 --- a/tools/re2c/Makefile.am +++ /dev/null @@ -1,47 +0,0 @@ -# $Id: Makefile.am,v 1.15 2004/05/26 23:59:15 nuffer Exp $ - -bin_PROGRAMS = re2c -re2c_SOURCES = code.cc dfa.cc main.cc parser.cc actions.cc scanner.re substr.cc\ - translate.cc scanner.cc mbo_getopt.cc \ - basics.h dfa.h globals.h ins.h parser.h re.h scanner.h \ - substr.h token.h mbo_getopt.h -BUILT_SOURCES = parser.cc scanner.cc - -man_MANS = re2c.1 - -#CXXFLAGS = -O2 -Wall -I. -Wno-unused -Wno-parentheses -Wno-deprecated -YFLAGS = -d - -RE2C = re2c -RE2CFLAGS = -s - -CLEANFILES = parser.cc y.tab.c y.tab.h parser.cc re2c.1 .version - -DISTCLEANFILES = makerpm re2c.spec README scanner.cc re2c$(EXEEXT) - -EXTRA_DIST = $(man_MANS) README parser.y scanner.re makerpm.in re2c.spec.in \ - README.in y.tab.h \ - examples/basemmap.c examples/c.re examples/cmmap.re \ - examples/cnokw.re examples/cunroll.re examples/modula.re \ - examples/sample.re examples/simple.re examples/rexx/README \ - examples/rexx/rexx.l examples/rexx/scanio.c doc/loplas.ps \ - doc/sample.bib - -rpm-files: $(bin_PROGRAMS) $(EXTRA_DIST) - -parser.cc: $(top_srcdir)/parser.y - $(YACC) $(YFLAGS) $< - mv -f y.tab.c $(top_srcdir)/parser.cc - if cmp -s y.tab.h $(top_srcdir)/y.tab.h; then :; else mv -f y.tab.h $(top_srcdir)/y.tab.h; fi - -scanner.cc: $(top_srcdir)/scanner.re - @if test -x ./re2c$(EXEEXT); then \ - echo "re2c $(RE2CFLAGS) -o $@ $<"; \ - ./re2c $(RE2CFLAGS) -o $@ $< && cp $@ $(top_srcdir)/bootstrap/; \ - else \ - echo "cp -f $(top_srcdir)/bootstrap/$@ $@"; \ - cp -f $(top_srcdir)/bootstrap/$@ $@; \ - fi - -.version: - echo $(PACKAGE_VERSION) > .version diff --git a/tools/re2c/Makefile.in b/tools/re2c/Makefile.in deleted file mode 100644 index 09e1c4b13..000000000 --- a/tools/re2c/Makefile.in +++ /dev/null @@ -1,472 +0,0 @@ -# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999, 2001 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. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -# $Id: Makefile.am,v 1.15 2004/05/26 23:59:15 nuffer Exp $ - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = . - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -CC = @CC@ -CXX = @CXX@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -VERSION = @VERSION@ -YACC = @YACC@ - -bin_PROGRAMS = re2c -re2c_SOURCES = code.cc dfa.cc main.cc parser.cc actions.cc scanner.re substr.cc translate.cc scanner.cc mbo_getopt.cc basics.h dfa.h globals.h ins.h parser.h re.h scanner.h substr.h token.h mbo_getopt.h - -BUILT_SOURCES = parser.cc scanner.cc - -man_MANS = re2c.1 - -#CXXFLAGS = -O2 -Wall -I. -Wno-unused -Wno-parentheses -Wno-deprecated -YFLAGS = -d - -RE2C = re2c -RE2CFLAGS = -s - -CLEANFILES = parser.cc y.tab.c y.tab.h parser.cc re2c.1 .version - -DISTCLEANFILES = makerpm re2c.spec README scanner.cc re2c$(EXEEXT) - -EXTRA_DIST = $(man_MANS) README parser.y scanner.re makerpm.in re2c.spec.in README.in y.tab.h examples/basemmap.c examples/c.re examples/cmmap.re examples/cnokw.re examples/cunroll.re examples/modula.re examples/sample.re examples/simple.re examples/rexx/README examples/rexx/rexx.l examples/rexx/scanio.c doc/loplas.ps doc/sample.bib - -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = config.h -CONFIG_CLEAN_FILES = README makerpm re2c.1 re2c.spec -PROGRAMS = $(bin_PROGRAMS) - - -DEFS = @DEFS@ -I. -I$(srcdir) -I. -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -re2c_OBJECTS = code.o dfa.o main.o parser.o actions.o substr.o \ -translate.o scanner.o mbo_getopt.o -re2c_LDADD = $(LDADD) -re2c_DEPENDENCIES = -re2c_LDFLAGS = -CXXFLAGS = @CXXFLAGS@ -CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -CXXLD = $(CXX) -CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ -CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -man1dir = $(mandir)/man1 -MANS = $(man_MANS) - -NROFF = nroff -DIST_COMMON = README ./stamp-h.in Makefile.am Makefile.in README.in \ -aclocal.m4 config.h.in configure configure.in install-sh makerpm.in \ -missing mkinstalldirs re2c.1.in re2c.spec.in - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = gtar -GZIP_ENV = --best -SOURCES = $(re2c_SOURCES) -OBJECTS = $(re2c_OBJECTS) - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .cc .o .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status - -$(ACLOCAL_M4): configure.in - cd $(srcdir) && $(ACLOCAL) - -config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - $(SHELL) ./config.status --recheck -$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) - cd $(srcdir) && $(AUTOCONF) - -config.h: stamp-h - @if test ! -f $@; then \ - rm -f stamp-h; \ - $(MAKE) stamp-h; \ - else :; fi -stamp-h: $(srcdir)/config.h.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES= CONFIG_HEADERS=config.h \ - $(SHELL) ./config.status - @echo timestamp > stamp-h 2> /dev/null -$(srcdir)/config.h.in: $(srcdir)/stamp-h.in - @if test ! -f $@; then \ - rm -f $(srcdir)/stamp-h.in; \ - $(MAKE) $(srcdir)/stamp-h.in; \ - else :; fi -$(srcdir)/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOHEADER) - @echo timestamp > $(srcdir)/stamp-h.in 2> /dev/null - -mostlyclean-hdr: - -clean-hdr: - -distclean-hdr: - -rm -f config.h - -maintainer-clean-hdr: -README: $(top_builddir)/config.status README.in - cd $(top_builddir) && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status -makerpm: $(top_builddir)/config.status makerpm.in - cd $(top_builddir) && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status -re2c.1: $(top_builddir)/config.status re2c.1.in - cd $(top_builddir) && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status -re2c.spec: $(top_builddir)/config.status re2c.spec.in - cd $(top_builddir) && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status - -mostlyclean-binPROGRAMS: - -clean-binPROGRAMS: - -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) - -distclean-binPROGRAMS: - -maintainer-clean-binPROGRAMS: - -install-binPROGRAMS: $(bin_PROGRAMS) - @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(bindir) - @list='$(bin_PROGRAMS)'; for p in $$list; do \ - if test -f $$p; then \ - echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \ - $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ - else :; fi; \ - done - -uninstall-binPROGRAMS: - @$(NORMAL_UNINSTALL) - list='$(bin_PROGRAMS)'; for p in $$list; do \ - rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ - done - -.c.o: - $(COMPILE) -c $< - -.s.o: - $(COMPILE) -c $< - -.S.o: - $(COMPILE) -c $< - -mostlyclean-compile: - -rm -f *.o core *.core - -clean-compile: - -distclean-compile: - -rm -f *.tab.c - -maintainer-clean-compile: - -re2c: $(re2c_OBJECTS) $(re2c_DEPENDENCIES) - @rm -f re2c - $(CXXLINK) $(re2c_LDFLAGS) $(re2c_OBJECTS) $(re2c_LDADD) $(LIBS) -.cc.o: - $(CXXCOMPILE) -c $< - -install-man1: - $(mkinstalldirs) $(DESTDIR)$(man1dir) - @list='$(man1_MANS)'; \ - l2='$(man_MANS)'; for i in $$l2; do \ - case "$$i" in \ - *.1*) list="$$list $$i" ;; \ - esac; \ - done; \ - for i in $$list; do \ - if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \ - else file=$$i; fi; \ - ext=`echo $$i | sed -e 's/^.*\\.//'`; \ - inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ - inst=`echo $$inst | sed '$(transform)'`.$$ext; \ - echo " $(INSTALL_DATA) $$file $(DESTDIR)$(man1dir)/$$inst"; \ - $(INSTALL_DATA) $$file $(DESTDIR)$(man1dir)/$$inst; \ - done - -uninstall-man1: - @list='$(man1_MANS)'; \ - l2='$(man_MANS)'; for i in $$l2; do \ - case "$$i" in \ - *.1*) list="$$list $$i" ;; \ - esac; \ - done; \ - for i in $$list; do \ - ext=`echo $$i | sed -e 's/^.*\\.//'`; \ - inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ - inst=`echo $$inst | sed '$(transform)'`.$$ext; \ - echo " rm -f $(DESTDIR)$(man1dir)/$$inst"; \ - rm -f $(DESTDIR)$(man1dir)/$$inst; \ - done -install-man: $(MANS) - @$(NORMAL_INSTALL) - $(MAKE) $(AM_MAKEFLAGS) install-man1 -uninstall-man: - @$(NORMAL_UNINSTALL) - $(MAKE) $(AM_MAKEFLAGS) uninstall-man1 - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)config.h.in$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags config.h.in $$unique $(LISP) -o $$here/TAGS) - -mostlyclean-tags: - -clean-tags: - -distclean-tags: - -rm -f TAGS ID - -maintainer-clean-tags: - -distdir = $(PACKAGE)-$(VERSION) -top_distdir = $(distdir) - -# This target untars the dist file and tries a VPATH configuration. Then -# it guarantees that the distribution is self-contained by making another -# tarfile. -distcheck: dist - -rm -rf $(distdir) - GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz - mkdir $(distdir)/=build - mkdir $(distdir)/=inst - dc_install_base=`cd $(distdir)/=inst && pwd`; \ - cd $(distdir)/=build \ - && ../configure --srcdir=.. --prefix=$$dc_install_base \ - && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ - && $(MAKE) $(AM_MAKEFLAGS) check \ - && $(MAKE) $(AM_MAKEFLAGS) install \ - && $(MAKE) $(AM_MAKEFLAGS) installcheck \ - && $(MAKE) $(AM_MAKEFLAGS) dist - -rm -rf $(distdir) - @banner="$(distdir).tar.gz is ready for distribution"; \ - dashes=`echo "$$banner" | sed s/./=/g`; \ - echo "$$dashes"; \ - echo "$$banner"; \ - echo "$$dashes" -dist: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -dist-all: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -distdir: $(DISTFILES) - -rm -rf $(distdir) - mkdir $(distdir) - -chmod 777 $(distdir) - $(mkinstalldirs) $(distdir)/doc $(distdir)/examples \ - $(distdir)/examples/rexx - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done -actions.o: actions.cc globals.h basics.h config.h parser.h scanner.h \ - token.h substr.h re.h ins.h dfa.h -code.o: code.cc substr.h basics.h config.h globals.h dfa.h re.h token.h \ - ins.h parser.h scanner.h -dfa.o: dfa.cc globals.h basics.h config.h substr.h dfa.h re.h token.h \ - ins.h -main.o: main.cc config.h globals.h basics.h parser.h scanner.h token.h \ - substr.h re.h ins.h dfa.h mbo_getopt.h -mbo_getopt.o: mbo_getopt.cc mbo_getopt.h -parser.o: parser.cc config.h globals.h basics.h parser.h scanner.h \ - token.h substr.h re.h ins.h -scanner.o: scanner.cc scanner.h token.h substr.h basics.h config.h \ - parser.h re.h ins.h y.tab.h -substr.o: substr.cc substr.h basics.h config.h globals.h -translate.o: translate.cc globals.h basics.h config.h - -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -all-recursive-am: config.h - $(MAKE) $(AM_MAKEFLAGS) all-recursive - -install-exec-am: install-binPROGRAMS -install-exec: install-exec-am - -install-data-am: install-man -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: uninstall-binPROGRAMS uninstall-man -uninstall: uninstall-am -all-am: Makefile $(PROGRAMS) $(MANS) config.h -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man1 - - -mostlyclean-generic: - -clean-generic: - -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) - -maintainer-clean-generic: - -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) -mostlyclean-am: mostlyclean-hdr mostlyclean-binPROGRAMS \ - mostlyclean-compile mostlyclean-tags \ - mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-hdr clean-binPROGRAMS clean-compile clean-tags \ - clean-generic mostlyclean-am - -clean: clean-am - -distclean-am: distclean-hdr distclean-binPROGRAMS distclean-compile \ - distclean-tags distclean-generic clean-am - -distclean: distclean-am - -rm -f config.status - -maintainer-clean-am: maintainer-clean-hdr maintainer-clean-binPROGRAMS \ - maintainer-clean-compile maintainer-clean-tags \ - maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -rm -f config.status - -.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \ -mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \ -maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \ -mostlyclean-compile distclean-compile clean-compile \ -maintainer-clean-compile install-man1 uninstall-man1 install-man \ -uninstall-man tags mostlyclean-tags distclean-tags clean-tags \ -maintainer-clean-tags distdir info-am info dvi-am dvi check check-am \ -installcheck-am installcheck all-recursive-am install-exec-am \ -install-exec install-data-am install-data install-am install \ -uninstall-am uninstall all-redirect all-am all installdirs \ -mostlyclean-generic distclean-generic clean-generic \ -maintainer-clean-generic clean mostlyclean distclean maintainer-clean - - -rpm-files: $(bin_PROGRAMS) $(EXTRA_DIST) - -parser.cc: $(top_srcdir)/parser.y - $(YACC) $(YFLAGS) $< - mv -f y.tab.c $(top_srcdir)/parser.cc - if cmp -s y.tab.h $(top_srcdir)/y.tab.h; then :; else mv -f y.tab.h $(top_srcdir)/y.tab.h; fi - -scanner.cc: $(top_srcdir)/scanner.re - @if test -x ./re2c$(EXEEXT); then \ - echo "re2c $(RE2CFLAGS) -o $@ $<"; \ - ./re2c $(RE2CFLAGS) -o $@ $< && cp $@ $(top_srcdir)/bootstrap/; \ - else \ - echo "cp -f $(top_srcdir)/bootstrap/$@ $@"; \ - cp -f $(top_srcdir)/bootstrap/$@ $@; \ - fi - -.version: - echo $(PACKAGE_VERSION) > .version - -# 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. -.NOEXPORT: diff --git a/tools/re2c/README b/tools/re2c/README index 8155382a2..918dff725 100644 --- a/tools/re2c/README +++ b/tools/re2c/README @@ -1,4 +1,4 @@ -re2c Version 0.9.3 +re2c Version 0.10.3 ------------------ Originally written by Peter Bumbulis (peter@csg.uwaterloo.ca) @@ -12,41 +12,59 @@ The re2c distribution can be found at: http://sourceforge.net/projects/re2c/ -This distribution is a cleaned up version of the 0.5 release. Several -bugs were fixed as well as code cleanup for warning free compilation. -It has been developed and tested with egcs 1.0.2 and gcc 2.7.2.3, 2.96 -and 3.3.1 on Linux x86. You can compile your own version with other gcc -version if you have yacc or any working bison version (tested up to bison -1.875). +re2c has been developed and tested with gcc 3.3 to 4.0.2, Microsoft and Intel +compilers on various platforms. Building re2c requires autoconf 2.57 and bison +(tested with 1.875 and later). Under windows you don't need autoconf or bison +and can use the pregenerated files. You can build this software by simply typing the following commands: - ./autogen.sh ./configure make The above version will be based on the pregenerated scanner.cc file. If you want to build that file yourself (recommended when installing re2c) you need the following steps: - ./autogen.sh ./configure make rm -f scanner.cc make install Or you can create a rpm package and install it by the following commands: + ./configure + make rpm + rpm -Uhv /re2c-0.10.3-1.rpm + +If you want to build from CVS then the first thing you should do is +regenerating all build files using the following command: + ./autogen.sh +and then continue with one of the above described build methods. Or if you +need to generate RPM packages for cvs builds use these commands: ./autogen.sh ./configure ./makerpm - rpm -Uhv /re2c-0.9.3-.rpm + rpm -Uhv /re2c-0.10.3-.rpm Here should be a number like 1. And must equal the directory where the makerpm step has written the generated rpm to. +If you are on a debian system you can use the tool 'alien' to convert rpms +to debian packages. + +When building with native SUN compilers you need to set the following compiler +flags: CXXFLAGS='-g -compat5 -library=stlport4'. + +If you want to build re2c on a windows system you can either use cygwin and one +of the methods described above or use Microsoft Visual C .NET 2002 or later +with the solution files provided (re2c.sln for 2002/2003 and re2c-2005.sln for +version 2005). re2c cannot be built with Microsoft Visual C 6.0 or earlier. + re2c is a great tool for writing fast and flexible lexers. It has served many people well for many years. re2c is on the order of 2-3 times faster than a flex based scanner, and its input model is much more flexible. +For an introduction to re2c refer to the lessons sub directory. + Peter's original version 0.5 ANNOUNCE and README follows. -- @@ -70,12 +88,11 @@ buffer as illustrated below. Given the following source #define NULL ((char*) 0) - char *scan(char *p){ - char *q; + char *scan(char *p) + { #define YYCTYPE char #define YYCURSOR p #define YYLIMIT p - #define YYMARKER q #define YYFILL(n) /*!re2c [0-9]+ {return YYCURSOR;} @@ -88,19 +105,16 @@ re2c will generate /* Generated by re2c on Sat Apr 16 11:40:58 1994 */ #line 1 "simple.re" #define NULL ((char*) 0) - char *scan(char *p){ - char *q; + char *scan(char *p) + { #define YYCTYPE char #define YYCURSOR p #define YYLIMIT p - #define YYMARKER q #define YYFILL(n) { YYCTYPE yych; unsigned int yyaccept; - goto yy0; - yy1: ++YYCURSOR; - yy0: + if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; if(yych <= '/') goto yy4; @@ -108,11 +122,11 @@ re2c will generate yy2: yych = *++YYCURSOR; goto yy7; yy3: - #line 10 + #line 9 {return YYCURSOR;} yy4: yych = *++YYCURSOR; yy5: - #line 11 + #line 10 {return NULL;} yy6: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -121,7 +135,7 @@ re2c will generate if(yych <= '9') goto yy6; goto yy3; } - #line 12 + #line 11 } diff --git a/tools/re2c/README.in b/tools/re2c/README.in deleted file mode 100644 index 7bb32bb23..000000000 --- a/tools/re2c/README.in +++ /dev/null @@ -1,165 +0,0 @@ -re2c Version @PACKAGE_VERSION@ ------------------- - -Originally written by Peter Bumbulis (peter@csg.uwaterloo.ca) - -Currently maintained by: - Dan Nuffer - Marcus Boerger - Hartmut Kaiser - -The re2c distribution can be found at: - - http://sourceforge.net/projects/re2c/ - -This distribution is a cleaned up version of the 0.5 release. Several -bugs were fixed as well as code cleanup for warning free compilation. -It has been developed and tested with egcs 1.0.2 and gcc 2.7.2.3, 2.96 -and 3.3.1 on Linux x86. You can compile your own version with other gcc -version if you have yacc or any working bison version (tested up to bison -1.875). - -You can build this software by simply typing the following commands: - ./autogen.sh - ./configure - make - -The above version will be based on the pregenerated scanner.cc file. -If you want to build that file yourself (recommended when installing -re2c) you need the following steps: - ./autogen.sh - ./configure - make - rm -f scanner.cc - make install - -Or you can create a rpm package and install it by the following commands: - ./autogen.sh - ./configure - ./makerpm - rpm -Uhv /re2c-@PACKAGE_VERSION@-.rpm - -Here should be a number like 1. And must equal -the directory where the makerpm step has written the generated rpm to. - -re2c is a great tool for writing fast and flexible lexers. It has -served many people well for many years. re2c is on the order of 2-3 -times faster than a flex based scanner, and its input model is much -more flexible. - -Peter's original version 0.5 ANNOUNCE and README follows. - --- - -re2c is a tool for generating C-based recognizers from regular -expressions. re2c-based scanners are efficient: for programming -languages, given similar specifications, an re2c-based scanner is -typically almost twice as fast as a flex-based scanner with little or no -increase in size (possibly a decrease on cisc architectures). Indeed, -re2c-based scanners are quite competitive with hand-crafted ones. - -Unlike flex, re2c does not generate complete scanners: the user must -supply some interface code. While this code is not bulky (about 50-100 -lines for a flex-like scanner; see the man page and examples in the -distribution) careful coding is required for efficiency (and -correctness). One advantage of this arrangement is that the generated -code is not tied to any particular input model. For example, re2c -generated code can be used to scan data from a null-byte terminated -buffer as illustrated below. - -Given the following source - - #define NULL ((char*) 0) - char *scan(char *p){ - char *q; - #define YYCTYPE char - #define YYCURSOR p - #define YYLIMIT p - #define YYMARKER q - #define YYFILL(n) - /*!re2c - [0-9]+ {return YYCURSOR;} - [\000-\377] {return NULL;} - */ - } - -re2c will generate - - /* Generated by re2c on Sat Apr 16 11:40:58 1994 */ - #line 1 "simple.re" - #define NULL ((char*) 0) - char *scan(char *p){ - char *q; - #define YYCTYPE char - #define YYCURSOR p - #define YYLIMIT p - #define YYMARKER q - #define YYFILL(n) - { - YYCTYPE yych; - unsigned int yyaccept; - goto yy0; - yy1: ++YYCURSOR; - yy0: - if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if(yych <= '/') goto yy4; - if(yych >= ':') goto yy4; - yy2: yych = *++YYCURSOR; - goto yy7; - yy3: - #line 10 - {return YYCURSOR;} - yy4: yych = *++YYCURSOR; - yy5: - #line 11 - {return NULL;} - yy6: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - yy7: if(yych <= '/') goto yy3; - if(yych <= '9') goto yy6; - goto yy3; - } - #line 12 - - } - -Note that most compilers will perform dead-code elimination to remove -all YYCURSOR, YYLIMIT comparisions. - -re2c was developed for a particular project (constructing a fast REXX -scanner of all things!) and so while it has some rough edges, it should -be quite usable. More information about re2c can be found in the -(admittedly skimpy) man page; the algorithms and heuristics used are -described in an upcoming LOPLAS article (included in the distribution). -Probably the best way to find out more about re2c is to try the supplied -examples. re2c is written in C++, and is currently being developed -under Linux using gcc 2.5.8. - -Peter - --- - -re2c is distributed with no warranty whatever. The code is certain to -contain errors. Neither the author nor any contributor takes -responsibility for any consequences of its use. - -re2c is in the public domain. The data structures and algorithms used -in re2c are all either taken from documents available to the general -public or are inventions of the author. Programs generated by re2c may -be distributed freely. re2c itself may be distributed freely, in source -or binary, unchanged or modified. Distributors may charge whatever fees -they can obtain for re2c. - -If you do make use of re2c, or incorporate it into a larger project an -acknowledgement somewhere (documentation, research report, etc.) would -be appreciated. - -Please send bug reports and feedback (including suggestions for -improving the distribution) to - - peter@csg.uwaterloo.ca - -Include a small example and the banner from parser.y with bug reports. - diff --git a/tools/re2c/aclocal.m4 b/tools/re2c/aclocal.m4 deleted file mode 100644 index 964b7acd7..000000000 --- a/tools/re2c/aclocal.m4 +++ /dev/null @@ -1,157 +0,0 @@ -dnl aclocal.m4 generated automatically by aclocal 1.4-p6 - -dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl This program is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without -dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A -dnl PARTICULAR PURPOSE. - -# Do all the work for Automake. This macro actually does too much -- -# some checks are only needed if your package does certain things. -# But this isn't really a big deal. - -# serial 1 - -dnl Usage: -dnl AM_INIT_AUTOMAKE(package,version, [no-define]) - -AC_DEFUN([AM_INIT_AUTOMAKE], -[AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl -AC_REQUIRE([AC_PROG_INSTALL]) -PACKAGE=[$1] -AC_SUBST(PACKAGE) -VERSION=[$2] -AC_SUBST(VERSION) -dnl test to see if srcdir already configured -if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then - AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) -fi -ifelse([$3],, -AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) -AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])) -AC_REQUIRE([AM_SANITY_CHECK]) -AC_REQUIRE([AC_ARG_PROGRAM]) -dnl FIXME This is truly gross. -missing_dir=`cd $ac_aux_dir && pwd` -AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}, $missing_dir) -AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) -AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}, $missing_dir) -AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) -AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir) -AC_REQUIRE([AC_PROG_MAKE_SET])]) - -# Copyright 2002 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# 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 - -# AM_AUTOMAKE_VERSION(VERSION) -# ---------------------------- -# Automake X.Y traces this macro to ensure aclocal.m4 has been -# generated from the m4 files accompanying Automake X.Y. -AC_DEFUN([AM_AUTOMAKE_VERSION],[am__api_version="1.4"]) - -# AM_SET_CURRENT_AUTOMAKE_VERSION -# ------------------------------- -# Call AM_AUTOMAKE_VERSION so it can be traced. -# This function is AC_REQUIREd by AC_INIT_AUTOMAKE. -AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], - [AM_AUTOMAKE_VERSION([1.4-p6])]) - -# -# Check to make sure that the build environment is sane. -# - -AC_DEFUN([AM_SANITY_CHECK], -[AC_MSG_CHECKING([whether build environment is sane]) -# Just in case -sleep 1 -echo timestamp > conftestfile -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` - if test "[$]*" = "X"; then - # -L didn't work. - set X `ls -t $srcdir/configure conftestfile` - fi - if test "[$]*" != "X $srcdir/configure conftestfile" \ - && test "[$]*" != "X conftestfile $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken -alias in your environment]) - fi - - test "[$]2" = conftestfile - ) -then - # Ok. - : -else - AC_MSG_ERROR([newly created file is older than distributed files! -Check your system clock]) -fi -rm -f conftest* -AC_MSG_RESULT(yes)]) - -dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY) -dnl The program must properly implement --version. -AC_DEFUN([AM_MISSING_PROG], -[AC_MSG_CHECKING(for working $2) -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if ($2 --version) < /dev/null > /dev/null 2>&1; then - $1=$2 - AC_MSG_RESULT(found) -else - $1="$3/missing $2" - AC_MSG_RESULT(missing) -fi -AC_SUBST($1)]) - -# Like AC_CONFIG_HEADER, but automatically create stamp file. - -AC_DEFUN([AM_CONFIG_HEADER], -[AC_PREREQ([2.12]) -AC_CONFIG_HEADER([$1]) -dnl When config.status generates a header, we must update the stamp-h file. -dnl This file resides in the same directory as the config header -dnl that is generated. We must strip everything past the first ":", -dnl and everything past the last "/". -AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl -ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>, -<>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>, -<>; do - case " <<$>>CONFIG_HEADERS " in - *" <<$>>am_file "*<<)>> - echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx - ;; - esac - am_indx=`expr "<<$>>am_indx" + 1` -done<<>>dnl>>) -changequote([,]))]) - diff --git a/tools/re2c/actions.cc b/tools/re2c/actions.cc index 7a596396d..f9fd327f3 100644 --- a/tools/re2c/actions.cc +++ b/tools/re2c/actions.cc @@ -1,568 +1,1046 @@ -/* $Id: actions.cc,v 1.5 2004/05/13 02:58:17 nuffer Exp $ */ +/* $Id: actions.cc,v 1.35 2006/02/25 12:57:50 helly Exp $ */ #include #include #include #include +#include #include "globals.h" #include "parser.h" #include "dfa.h" -Symbol *Symbol::first = NULL; +namespace re2c +{ -Symbol::Symbol(const SubStr &str) : next(first), name(str), re(NULL) { - first = this; +void Symbol::ClearTable() +{ + symbol_table.clear(); } -Symbol *Symbol::find(const SubStr &str){ - for(Symbol *sym = first; sym; sym = sym->next) - if(sym->name == str) return sym; - return new Symbol(str); -} +Symbol::SymbolTable Symbol::symbol_table; -void showIns(std::ostream &o, const Ins &i, const Ins &base){ - o.width(3); - o << &i - &base << ": "; - switch(i.i.tag){ - case CHAR: { - o << "match "; - for(const Ins *j = &(&i)[1]; j < (Ins*) i.i.link; ++j) - prtCh(o, (const uchar)j->c.value); - break; - } case GOTO: - o << "goto " << ((Ins*) i.i.link - &base); - break; - case FORK: - o << "fork " << ((Ins*) i.i.link - &base); - break; - case CTXT: - o << "term " << ((RuleOp*) i.i.link)->accept; - break; - case TERM: - o << "term " << ((RuleOp*) i.i.link)->accept; - break; - } - o << "\n"; -} +Symbol *Symbol::find(const SubStr &str) +{ + const std::string ss(str.to_string()); + SymbolTable::const_iterator it = symbol_table.find(ss); -uint RegExp::fixedLength(){ - return ~0; -} - -char *NullOp::type = "NullOp"; - -void NullOp::calcSize(Char*){ - size = 0; -} - -uint NullOp::fixedLength(){ - return 0; -} - -void NullOp::compile(Char*, Ins*){ - ; -} - -void NullOp::split(CharSet&){ - ; -} - -std::ostream& operator<<(std::ostream &o, const Range &r){ - if((r.ub - r.lb) == 1){ - prtCh(o, r.lb); - } else { - prtCh(o, r.lb); o << "-"; prtCh(o, r.ub-1); - } - return o << r.next; -} - -Range *doUnion(Range *r1, Range *r2){ - Range *r, **rP = &r; - for(;;){ - Range *s; - if(r1->lb <= r2->lb){ - s = new Range(*r1); - } else { - s = new Range(*r2); + if (it == symbol_table.end()) + { + return (*symbol_table.insert(SymbolTable::value_type(ss, new Symbol(str))).first).second; } - *rP = s; - rP = &s->next; - for(;;){ - if(r1->lb <= r2->lb){ - if(r1->lb > s->ub) - break; - if(r1->ub > s->ub) - s->ub = r1->ub; - if(!(r1 = r1->next)){ - uint ub = 0; - for(; r2 && r2->lb <= s->ub; r2 = r2->next) - ub = r2->ub; - if(ub > s->ub) - s->ub = ub; - *rP = r2; - return r; + + return (*it).second; +} + +void showIns(std::ostream &o, const Ins &i, const Ins &base) +{ + o.width(3); + o << &i - &base << ": "; + + switch (i.i.tag) + { + + case CHAR: + { + o << "match "; + + for (const Ins *j = &(&i)[1]; j < (Ins*) i.i.link; ++j) + prtCh(o, j->c.value); + + break; } - } else { - if(r2->lb > s->ub) - break; - if(r2->ub > s->ub) - s->ub = r2->ub; - if(!(r2 = r2->next)){ - uint ub = 0; - for(; r1 && r1->lb <= s->ub; r1 = r1->next) - ub = r1->ub; - if(ub > s->ub) - s->ub = ub; - *rP = r1; - return r; - } - } + + case GOTO: + o << "goto " << ((Ins*) i.i.link - &base); + break; + + case FORK: + o << "fork " << ((Ins*) i.i.link - &base); + break; + + case CTXT: + o << "ctxt"; + break; + + case TERM: + o << "term " << ((RuleOp*) i.i.link)->accept; + break; } - } - *rP = NULL; - return r; + + o << "\n"; } -Range *doDiff(Range *r1, Range *r2){ - Range *r, *s, **rP = &r; - for(; r1; r1 = r1->next){ - uint lb = r1->lb; - for(; r2 && r2->ub <= r1->lb; r2 = r2->next); - for(; r2 && r2->lb < r1->ub; r2 = r2->next){ - if(lb < r2->lb){ - *rP = s = new Range(lb, r2->lb); - rP = &s->next; - } - if((lb = r2->ub) >= r1->ub) - goto noMore; - } - *rP = s = new Range(lb, r1->ub); - rP = &s->next; - noMore:; - } - *rP = NULL; - return r; -} - -MatchOp *merge(MatchOp *m1, MatchOp *m2){ - if(!m1) - return m2; - if(!m2) - return m1; - return new MatchOp(doUnion(m1->match, m2->match)); -} - -char *MatchOp::type = "MatchOp"; - -void MatchOp::display(std::ostream &o) const{ - o << match; -} - -void MatchOp::calcSize(Char *rep){ - size = 1; - for(Range *r = match; r; r = r->next) - for(uint c = r->lb; c < r->ub; ++c) - if(rep[c] == c) - ++size; -} - -uint MatchOp::fixedLength(){ - return 1; -} - -void MatchOp::compile(Char *rep, Ins *i){ - i->i.tag = CHAR; - i->i.link = &i[size]; - Ins *j = &i[1]; - uint bump = size; - for(Range *r = match; r; r = r->next){ - for(uint c = r->lb; c < r->ub; ++c){ - if(rep[c] == c){ - j->c.value = c; - j->c.bump = --bump; - j++; - } - } - } -} - -void MatchOp::split(CharSet &s){ - for(Range *r = match; r; r = r->next){ - for(uint c = r->lb; c < r->ub; ++c){ - CharPtn *x = s.rep[c], *a = x->nxt; - if(!a){ - if(x->card == 1) - continue; - x->nxt = a = s.freeHead; - if(!(s.freeHead = s.freeHead->nxt)) - s.freeTail = &s.freeHead; - a->nxt = NULL; - x->fix = s.fix; - s.fix = x; - } - if(--(x->card) == 0){ - *s.freeTail = x; - *(s.freeTail = &x->nxt) = NULL; - } - s.rep[c] = a; - ++(a->card); - } - } - for(; s.fix; s.fix = s.fix->fix) - if(s.fix->card) - s.fix->nxt = NULL; -} - -RegExp *mkDiff(RegExp *e1, RegExp *e2){ - MatchOp *m1, *m2; - if(!(m1 = (MatchOp*) e1->isA(MatchOp::type))) - return NULL; - if(!(m2 = (MatchOp*) e2->isA(MatchOp::type))) - return NULL; - Range *r = doDiff(m1->match, m2->match); - return r? (RegExp*) new MatchOp(r) : (RegExp*) new NullOp; -} - -RegExp *doAlt(RegExp *e1, RegExp *e2){ - if(!e1) - return e2; - if(!e2) - return e1; - return new AltOp(e1, e2); -} - -RegExp *mkAlt(RegExp *e1, RegExp *e2){ - AltOp *a; - MatchOp *m1, *m2; - if((a = (AltOp*) e1->isA(AltOp::type))){ - if((m1 = (MatchOp*) a->exp1->isA(MatchOp::type))) - e1 = a->exp2; - } else if((m1 = (MatchOp*) e1->isA(MatchOp::type))){ - e1 = NULL; - } - if((a = (AltOp*) e2->isA(AltOp::type))){ - if((m2 = (MatchOp*) a->exp1->isA(MatchOp::type))) - e2 = a->exp2; - } else if((m2 = (MatchOp*) e2->isA(MatchOp::type))){ - e2 = NULL; - } - return doAlt(merge(m1, m2), doAlt(e1, e2)); -} - -char *AltOp::type = "AltOp"; - -void AltOp::calcSize(Char *rep){ - exp1->calcSize(rep); - exp2->calcSize(rep); - size = exp1->size + exp2->size + 2; -} - -uint AltOp::fixedLength(){ - uint l1 = exp1->fixedLength(); - uint l2 = exp1->fixedLength(); - if(l1 != l2 || l1 == ~0u) +uint RegExp::fixedLength() +{ return ~0; - return l1; } -void AltOp::compile(Char *rep, Ins *i){ - i->i.tag = FORK; - Ins *j = &i[exp1->size + 1]; - i->i.link = &j[1]; - exp1->compile(rep, &i[1]); - j->i.tag = GOTO; - j->i.link = &j[exp2->size + 1]; - exp2->compile(rep, &j[1]); +const char *NullOp::type = "NullOp"; + +void NullOp::calcSize(Char*) +{ + size = 0; } -void AltOp::split(CharSet &s){ - exp1->split(s); - exp2->split(s); +uint NullOp::fixedLength() +{ + return 0; } -char *CatOp::type = "CatOp"; - -void CatOp::calcSize(Char *rep){ - exp1->calcSize(rep); - exp2->calcSize(rep); - size = exp1->size + exp2->size; +void NullOp::compile(Char*, Ins*) +{ + ; } -uint CatOp::fixedLength(){ - uint l1, l2; - if((l1 = exp1->fixedLength()) != ~0u ) - if((l2 = exp2->fixedLength()) != ~0u) - return l1+l2; - return ~0; +void NullOp::split(CharSet&) +{ + ; } -void CatOp::compile(Char *rep, Ins *i){ - exp1->compile(rep, &i[0]); - exp2->compile(rep, &i[exp1->size]); +std::ostream& operator<<(std::ostream &o, const Range &r) +{ + if ((r.ub - r.lb) == 1) + { + prtCh(o, r.lb); + } + else + { + prtCh(o, r.lb); + o << "-"; + prtCh(o, r.ub - 1); + } + + return o << r.next; } -void CatOp::split(CharSet &s){ - exp1->split(s); - exp2->split(s); +Range *doUnion(Range *r1, Range *r2) +{ + Range *r, **rP = &r; + + for (;;) + { + Range *s; + + if (r1->lb <= r2->lb) + { + s = new Range(*r1); + } + else + { + s = new Range(*r2); + } + + *rP = s; + rP = &s->next; + + for (;;) + { + if (r1->lb <= r2->lb) + { + if (r1->lb > s->ub) + break; + + if (r1->ub > s->ub) + s->ub = r1->ub; + + if (!(r1 = r1->next)) + { + uint ub = 0; + + for (; r2 && r2->lb <= s->ub; r2 = r2->next) + ub = r2->ub; + + if (ub > s->ub) + s->ub = ub; + + *rP = r2; + + return r; + } + } + else + { + if (r2->lb > s->ub) + break; + + if (r2->ub > s->ub) + s->ub = r2->ub; + + if (!(r2 = r2->next)) + { + uint ub = 0; + + for (; r1 && r1->lb <= s->ub; r1 = r1->next) + ub = r1->ub; + + if (ub > s->ub) + s->ub = ub; + + *rP = r1; + + return r; + } + } + } + } + + *rP = NULL; + return r; } -char *CloseOp::type = "CloseOp"; +Range *doDiff(Range *r1, Range *r2) +{ + Range *r, *s, **rP = &r; -void CloseOp::calcSize(Char *rep){ - exp->calcSize(rep); - size = exp->size + 1; + for (; r1; r1 = r1->next) + { + uint lb = r1->lb; + + for (; r2 && r2->ub <= r1->lb; r2 = r2->next) + + ; + for (; r2 && r2->lb < r1->ub; r2 = r2->next) + { + if (lb < r2->lb) + { + *rP = s = new Range(lb, r2->lb); + rP = &s->next; + } + + if ((lb = r2->ub) >= r1->ub) + goto noMore; + } + + *rP = s = new Range(lb, r1->ub); + rP = &s->next; + +noMore: + ; + } + + *rP = NULL; + return r; } -void CloseOp::compile(Char *rep, Ins *i){ - exp->compile(rep, &i[0]); - i += exp->size; - i->i.tag = FORK; - i->i.link = i - exp->size; +MatchOp *merge(MatchOp *m1, MatchOp *m2) +{ + if (!m1) + return m2; + + if (!m2) + return m1; + + return new MatchOp(doUnion(m1->match, m2->match)); } -void CloseOp::split(CharSet &s){ - exp->split(s); +const char *MatchOp::type = "MatchOp"; + +void MatchOp::display(std::ostream &o) const +{ + o << match; } -char *CloseVOp::type = "CloseVOp"; +void MatchOp::calcSize(Char *rep) +{ + size = 1; -void CloseVOp::calcSize(Char *rep){ - exp->calcSize(rep); - if(max >= 0) - size = (exp->size * min) + ((1 + exp->size) * (max - min)); - else - size = (exp->size * min) + 1; + for (Range *r = match; r; r = r->next) + for (uint c = r->lb; c < r->ub; ++c) + if (rep[c] == c) + ++size; } -void CloseVOp::compile(Char *rep, Ins *i){ - Ins *jumppoint; - int st = 0; - jumppoint = i + ((1 + exp->size) * (max - min)); - for(st = min; st < max; st++) { - i->i.tag = FORK; - i->i.link = jumppoint; - i+=1; - exp->compile(rep, &i[0]); - i += exp->size; - } - for(st = 0; st < min; st++) { - exp->compile(rep, &i[0]); - i += exp->size; - if(max < 0 && st == 0) { - i->i.tag = FORK; - i->i.link = i - exp->size; - i++; - } - } +uint MatchOp::fixedLength() +{ + return 1; } -void CloseVOp::split(CharSet &s){ - exp->split(s); +void MatchOp::compile(Char *rep, Ins *i) +{ + i->i.tag = CHAR; + i->i.link = &i[size]; + Ins *j = &i[1]; + uint bump = size; + + for (Range *r = match; r; r = r->next) + { + for (uint c = r->lb; c < r->ub; ++c) + { + if (rep[c] == c) + { + j->c.value = c; + j->c.bump = --bump; + j++; + } + } + } +} + +void MatchOp::split(CharSet &s) +{ + for (Range *r = match; r; r = r->next) + { + for (uint c = r->lb; c < r->ub; ++c) + { + CharPtn *x = s.rep[c], *a = x->nxt; + + if (!a) + { + if (x->card == 1) + continue; + + x->nxt = a = s.freeHead; + + if (!(s.freeHead = s.freeHead->nxt)) + s.freeTail = &s.freeHead; + + a->nxt = NULL; + + x->fix = s.fix; + + s.fix = x; + } + + if (--(x->card) == 0) + { + *s.freeTail = x; + *(s.freeTail = &x->nxt) = NULL; + } + + s.rep[c] = a; + ++(a->card); + } + } + + for (; s.fix; s.fix = s.fix->fix) + if (s.fix->card) + s.fix->nxt = NULL; +} + +RegExp * mkDiff(RegExp *e1, RegExp *e2) +{ + MatchOp *m1, *m2; + + if (!(m1 = (MatchOp*) e1->isA(MatchOp::type))) + return NULL; + + if (!(m2 = (MatchOp*) e2->isA(MatchOp::type))) + return NULL; + + Range *r = doDiff(m1->match, m2->match); + + return r ? (RegExp*) new MatchOp(r) : (RegExp*) new NullOp; +} + +RegExp *doAlt(RegExp *e1, RegExp *e2) +{ + if (!e1) + return e2; + + if (!e2) + return e1; + + return new AltOp(e1, e2); +} + +RegExp *mkAlt(RegExp *e1, RegExp *e2) +{ + AltOp *a; + MatchOp *m1, *m2; + + if ((a = (AltOp*) e1->isA(AltOp::type))) + { + if ((m1 = (MatchOp*) a->exp1->isA(MatchOp::type))) + e1 = a->exp2; + } + else if ((m1 = (MatchOp*) e1->isA(MatchOp::type))) + { + e1 = NULL; + } + + if ((a = (AltOp*) e2->isA(AltOp::type))) + { + if ((m2 = (MatchOp*) a->exp1->isA(MatchOp::type))) + e2 = a->exp2; + } + else if ((m2 = (MatchOp*) e2->isA(MatchOp::type))) + { + e2 = NULL; + } + + return doAlt(merge(m1, m2), doAlt(e1, e2)); +} + +const char *AltOp::type = "AltOp"; + +void AltOp::calcSize(Char *rep) +{ + exp1->calcSize(rep); + exp2->calcSize(rep); + size = exp1->size + exp2->size + 2; +} + +uint AltOp::fixedLength() +{ + uint l1 = exp1->fixedLength(); + uint l2 = exp1->fixedLength(); + + if (l1 != l2 || l1 == ~0u) + return ~0; + + return l1; +} + +void AltOp::compile(Char *rep, Ins *i) +{ + i->i.tag = FORK; + Ins *j = &i[exp1->size + 1]; + i->i.link = &j[1]; + exp1->compile(rep, &i[1]); + j->i.tag = GOTO; + j->i.link = &j[exp2->size + 1]; + exp2->compile(rep, &j[1]); +} + +void AltOp::split(CharSet &s) +{ + exp1->split(s); + exp2->split(s); +} + +const char *CatOp::type = "CatOp"; + +void CatOp::calcSize(Char *rep) +{ + exp1->calcSize(rep); + exp2->calcSize(rep); + size = exp1->size + exp2->size; +} + +uint CatOp::fixedLength() +{ + uint l1, l2; + + if ((l1 = exp1->fixedLength()) != ~0u ) + if ((l2 = exp2->fixedLength()) != ~0u) + return l1 + l2; + + return ~0u; +} + +void CatOp::compile(Char *rep, Ins *i) +{ + exp1->compile(rep, &i[0]); + exp2->compile(rep, &i[exp1->size]); +} + +void CatOp::split(CharSet &s) +{ + exp1->split(s); + exp2->split(s); +} + +const char *CloseOp::type = "CloseOp"; + +void CloseOp::calcSize(Char *rep) +{ + exp->calcSize(rep); + size = exp->size + 1; +} + +void CloseOp::compile(Char *rep, Ins *i) +{ + exp->compile(rep, &i[0]); + i += exp->size; + i->i.tag = FORK; + i->i.link = i - exp->size; +} + +void CloseOp::split(CharSet &s) +{ + exp->split(s); +} + +const char *CloseVOp::type = "CloseVOp"; + +void CloseVOp::calcSize(Char *rep) +{ + exp->calcSize(rep); + + if (max >= 0) + { + size = (exp->size * min) + ((1 + exp->size) * (max - min)); + } + else + { + size = (exp->size * min) + 1; + } +} + +void CloseVOp::compile(Char *rep, Ins *i) +{ + Ins *jumppoint; + int st; + jumppoint = i + ((1 + exp->size) * (max - min)); + + for (st = min; st < max; st++) + { + i->i.tag = FORK; + i->i.link = jumppoint; + i++; + exp->compile(rep, &i[0]); + i += exp->size; + } + + for (st = 0; st < min; st++) + { + exp->compile(rep, &i[0]); + i += exp->size; + + if (max < 0 && st == 0) + { + i->i.tag = FORK; + i->i.link = i - exp->size; + i++; + } + } +} + +void CloseVOp::split(CharSet &s) +{ + exp->split(s); } RegExp *expr(Scanner &); -uchar unescape(SubStr &s){ - s.len--; - uchar c; - if((c = *s.str++) != '\\' || s.len == 0) - return xlat[c]; - s.len--; - switch(c = *s.str++){ - case 'n': - return xlat['\n']; - case 't': - return xlat['\t']; - case 'v': - return xlat['\v']; - case 'b': - return xlat['\b']; - case 'r': - return xlat['\r']; - case 'f': - return xlat['\f']; - case 'a': - return xlat['\a']; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': { - uchar v = c - '0'; - for(; s.len != 0 && '0' <= (c = *s.str) && c <= '7'; s.len--, s.str++) - v = v*8 + (c - '0'); - return v; - } default: - return xlat[c]; - } -} +uint Scanner::unescape(SubStr &s) const +{ + static const char * hex = "0123456789abcdef"; + static const char * oct = "01234567"; -Range *getRange(SubStr &s){ - uchar lb = unescape(s), ub; - if(s.len < 2 || *s.str != '-'){ - ub = lb; - } else { - s.len--; s.str++; - ub = unescape(s); - if(ub < lb){ - uchar tmp; - tmp = lb; lb = ub; ub = tmp; + s.len--; + uint c; + + if ((c = *s.str++) != '\\' || s.len == 0) + { + return xlat(c); + } + + s.len--; + + switch (c = *s.str++) + { + case 'n': return xlat('\n'); + case 't': return xlat('\t'); + case 'v': return xlat('\v'); + case 'b': return xlat('\b'); + case 'r': return xlat('\r'); + case 'f': return xlat('\f'); + case 'a': return xlat('\a'); + + case 'x': + { + if (s.len < 2) + { + fatal(s.ofs()+s.len, "Illegal hexadecimal character code, two hexadecimal digits are required"); + return ~0; + } + + const char *p1 = strchr(hex, tolower(s.str[0])); + const char *p2 = strchr(hex, tolower(s.str[1])); + + if (!p1 || !p2) + { + fatal(s.ofs()+(p1?1:0), "Illegal hexadecimal character code"); + return ~0; + } + else + { + s.len -= 2; + s.str += 2; + + uint v = (uint)((p1 - hex) << 4) + + (uint)((p2 - hex)); + + return v; + } + } + + case 'U': + { + if (s.len < 8) + { + fatal(s.ofs()+s.len, "Illegal unicode character, eight hexadecimal digits are required"); + return ~0; + } + + uint l = 0; + + if (s.str[0] == '0') + { + l++; + if (s.str[1] == '0') + { + l++; + if (s.str[2] == '0') + { + l++; + if (s.str[3] == '0') + { + l++; + } + } + } + } + + if (l != 4) + { + fatal(s.ofs()+l, "Illegal unicode character, eight hexadecimal digits are required"); + } + + s.len -= 4; + s.str += 4; + + // no break; + } + case 'X': + case 'u': + { + if (s.len < 4) + { + fatal(s.ofs()+s.len, + c == 'X' + ? "Illegal hexadecimal character code, four hexadecimal digits are required" + : "Illegal unicode character, four hexadecimal digits are required"); + return ~0; + } + + const char *p1 = strchr(hex, tolower(s.str[0])); + const char *p2 = strchr(hex, tolower(s.str[1])); + const char *p3 = strchr(hex, tolower(s.str[2])); + const char *p4 = strchr(hex, tolower(s.str[3])); + + if (!p1 || !p2 || !p3 || !p4) + { + fatal(s.ofs()+(p1?1:0)+(p2?1:0)+(p3?1:0), + c == 'X' + ? "Illegal hexadecimal character code, non hexxdecimal digit found" + : "Illegal unicode character, non hexadecimal digit found"); + return ~0; + } + else + { + s.len -= 4; + s.str += 4; + + uint v = (uint)((p1 - hex) << 12) + + (uint)((p2 - hex) << 8) + + (uint)((p3 - hex) << 4) + + (uint)((p4 - hex)); + + if (v >= nRealChars) + { + fatal(s.ofs(), + c == 'X' + ? "Illegal hexadecimal character code, out of range" + : "Illegal unicode character, out of range"); + } + + return v; + } + } + + case '4': + case '5': + case '6': + case '7': + { + fatal(s.ofs()-1, "Illegal octal character code, first digit must be 0 thru 3"); + return ~0; + } + + case '0': + case '1': + case '2': + case '3': + { + if (s.len < 2) + { + fatal(s.ofs()+s.len, "Illegal octal character code, three octal digits are required"); + return ~0; + } + + const char *p0 = strchr(oct, c); + const char *p1 = strchr(oct, s.str[0]); + const char *p2 = strchr(oct, s.str[1]); + + if (!p0 || !p1 || !p2) + { + fatal(s.ofs()+(p1?1:0), "Illegal octal character code, non octal digit found"); + return ~0; + } + else + { + s.len -= 2; + s.str += 2; + + uint v = (uint)((p0 - oct) << 6) + (uint)((p1 - oct) << 3) + (uint)(p2 - oct); + + return v; + } + } + + default: + return xlat(c); } - } - return new Range(lb, ub+1); } -RegExp *matchChar(uint c){ - return new MatchOp(new Range(c, c+1)); +std::string& Scanner::unescape(SubStr& str_in, std::string& str_out) const +{ + str_out.clear(); + + while(str_in.len) + { + uint c = unescape(str_in); + + if (c > 0xFF) + { + fatal(str_in.ofs(), "Illegal character"); + } + + str_out += static_cast(c); + } + + return str_out; } -RegExp *strToRE(SubStr s){ - s.len -= 2; s.str += 1; - if(s.len == 0) - return new NullOp; - RegExp *re = matchChar(unescape(s)); - while(s.len > 0) - re = new CatOp(re, matchChar(unescape(s))); - return re; +Range * Scanner::getRange(SubStr &s) const +{ + uint lb = unescape(s), ub, xlb, xub, c; + + if (s.len < 2 || *s.str != '-') + { + ub = lb; + } + else + { + s.len--; + s.str++; + ub = unescape(s); + + if (ub < lb) + { + uint tmp = lb; + lb = ub; + ub = tmp; + } + + xlb = xlat(lb); + xub = xlat(ub); + + for(c = lb; c <= ub; c++) + { + if (!(xlb <= xlat(c) && xlat(c) <= ub)) + { + /* range doesn't work */ + Range * r = new Range(xlb, xlb + 1); + for (c = lb + 1; c <= ub; c++) + { + r = doUnion(r, new Range(xlat(c), xlat(c) + 1)); + } + return r; + } + } + + lb = xlb; + ub = xub; + } + + return new Range(lb, ub + 1); } -RegExp *strToCaseInsensitiveRE(SubStr s){ - s.len -= 2; s.str += 1; - if(s.len == 0) - return new NullOp; - uchar c = unescape(s); +RegExp * Scanner::matchChar(uint c) const +{ + return new MatchOp(new Range(c, c + 1)); +} + +RegExp * Scanner::strToRE(SubStr s) const +{ + s.len -= 2; + s.str += 1; + + if (s.len == 0) + return new NullOp; + + RegExp *re = matchChar(unescape(s)); + + while (s.len > 0) + re = new CatOp(re, matchChar(unescape(s))); + + return re; +} + +RegExp * Scanner::strToCaseInsensitiveRE(SubStr s) const +{ + s.len -= 2; + s.str += 1; + + if (s.len == 0) + return new NullOp; + + uint c = unescape(s); + RegExp *re, *reL, *reU; - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { - reL = matchChar(tolower(c)); - reU = matchChar(toupper(c)); - re = mkAlt(reL, reU); - } else { - re = matchChar(c); + + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) + { + reL = matchChar(xlat(tolower(c))); + reU = matchChar(xlat(toupper(c))); + re = mkAlt(reL, reU); } - while(s.len > 0) { - uchar c = unescape(s); - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { - reL = matchChar(tolower(c)); - reU = matchChar(toupper(c)); + else + { + re = matchChar(c); + } + + while (s.len > 0) + { + uint c = unescape(s); + + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) + { + reL = matchChar(xlat(tolower(c))); + reU = matchChar(xlat(toupper(c))); re = new CatOp(re, mkAlt(reL, reU)); - } else { + } + else + { re = new CatOp(re, matchChar(c)); } } - return re; + + return re; } -RegExp *ranToRE(SubStr s){ - s.len -= 2; s.str += 1; - if(s.len == 0) - return new NullOp; - Range *r = getRange(s); - while(s.len > 0) - r = doUnion(r, getRange(s)); - return new MatchOp(r); +RegExp * Scanner::ranToRE(SubStr s) const +{ + s.len -= 2; + s.str += 1; + + if (s.len == 0) + return new NullOp; + + Range *r = getRange(s); + + while (s.len > 0) + r = doUnion(r, getRange(s)); + + return new MatchOp(r); } -char *RuleOp::type = "RuleOp"; +RegExp * Scanner::invToRE(SubStr s) const +{ + s.len--; + s.str++; + + RegExp * any = ranToRE(SubStr(wFlag ? "[\\X0000-\\XFFFF]" : "[\\000-\\377]")); + + if (s.len <= 2) + { + return any; + } + + RegExp * ran = ranToRE(s); + RegExp * inv = mkDiff(any, ran); + + delete ran; + delete any; + + return inv; +} + +RegExp * Scanner::mkDot() const +{ + RegExp * any = ranToRE(SubStr(wFlag ? "[\\X0000-\\XFFFF]" : "[\\000-\\377]")); + RegExp * ran = matchChar(xlat('\n')); + RegExp * inv = mkDiff(any, ran); + + delete ran; + delete any; + + return inv; +} + +const char *RuleOp::type = "RuleOp"; RuleOp::RuleOp(RegExp *e, RegExp *c, Token *t, uint a) - : exp(e), ctx(c), ins(NULL), accept(a), code(t) { - ; + : exp(e) + , ctx(c) + , ins(NULL) + , accept(a) + , code(t) + , line(0) +{ + ; } -void RuleOp::calcSize(Char *rep){ - exp->calcSize(rep); - ctx->calcSize(rep); - size = exp->size + ctx->size + 1; +void RuleOp::calcSize(Char *rep) +{ + exp->calcSize(rep); + ctx->calcSize(rep); + size = exp->size + (ctx->size ? ctx->size + 2 : 1); } -void RuleOp::compile(Char *rep, Ins *i){ - ins = i; - exp->compile(rep, &i[0]); - i += exp->size; - ctx->compile(rep, &i[0]); - i += ctx->size; - i->i.tag = TERM; - i->i.link = this; +void RuleOp::compile(Char *rep, Ins *i) +{ + ins = i; + exp->compile(rep, &i[0]); + i += exp->size; + if (ctx->size) + { + i->i.tag = CTXT; + i->i.link = &i[1]; + i++; + ctx->compile(rep, &i[0]); + i += ctx->size; + } + i->i.tag = TERM; + i->i.link = this; } -void RuleOp::split(CharSet &s){ - exp->split(s); - ctx->split(s); +void RuleOp::split(CharSet &s) +{ + exp->split(s); + ctx->split(s); } -extern void printSpan(std::ostream&, uint, uint); +void optimize(Ins *i) +{ + while (!isMarked(i)) + { + mark(i); -void optimize(Ins *i){ - while(!isMarked(i)){ - mark(i); - if(i->i.tag == CHAR){ - i = (Ins*) i->i.link; - } else if(i->i.tag == GOTO || i->i.tag == FORK){ - Ins *target = (Ins*) i->i.link; - optimize(target); - if(target->i.tag == GOTO) - i->i.link = target->i.link == target? i : target; - if(i->i.tag == FORK){ - Ins *follow = (Ins*) &i[1]; - optimize(follow); - if(follow->i.tag == GOTO && follow->i.link == follow){ - i->i.tag = GOTO; - } else if(i->i.link == i){ - i->i.tag = GOTO; - i->i.link = follow; + if (i->i.tag == CHAR) + { + i = (Ins*) i->i.link; } + else if (i->i.tag == GOTO || i->i.tag == FORK) + { + Ins *target = (Ins*) i->i.link; + optimize(target); + + if (target->i.tag == GOTO) + i->i.link = target->i.link == target ? i : target; + + if (i->i.tag == FORK) + { + Ins *follow = (Ins*) & i[1]; + optimize(follow); + + if (follow->i.tag == GOTO && follow->i.link == follow) + { + i->i.tag = GOTO; + } + else if (i->i.link == i) + { + i->i.tag = GOTO; + i->i.link = follow; + } + } + + return ; + } + else + { + ++i; + } + } +} + +void genCode(std::ostream& o, RegExp *re) +{ + genCode(o, 0, re); +} + +CharSet::CharSet() + : fix(0) + , freeHead(0) + , freeTail(0) + , rep(new CharPtr[nRealChars]) + , ptn(new CharPtn[nRealChars]) +{ + for (uint j = 0; j < nRealChars; ++j) + { + rep[j] = &ptn[0]; + ptn[j].nxt = &ptn[j + 1]; /* wrong for j=nRealChars but will be corrected below */ + ptn[j].card = 0; + } + + freeHead = &ptn[1]; + *(freeTail = &ptn[nRealChars - 1].nxt) = NULL; + ptn[0].card = nRealChars; + ptn[0].nxt = NULL; +} + +CharSet::~CharSet() +{ + delete[] rep; + delete[] ptn; +} + +void genCode(std::ostream& o, uint ind, RegExp *re) +{ + CharSet cs; + uint j; + + re->split(cs); + /* + for(uint k = 0; k < nChars;){ + for(j = k; ++k < nRealChars && cs.rep[k] == cs.rep[j];); + printSpan(cerr, j, k); + cerr << "\t" << cs.rep[j] - &cs.ptn[0] << endl; } - return; - } else { - ++i; + */ + Char *rep = new Char[nRealChars]; + + for (j = 0; j < nRealChars; ++j) + { + if (!cs.rep[j]->nxt) + cs.rep[j]->nxt = &cs.ptn[j]; + + rep[j] = (Char) (cs.rep[j]->nxt - &cs.ptn[0]); } - } + + re->calcSize(rep); + Ins *ins = new Ins[re->size + 1]; + memset(ins, 0, (re->size + 1)*sizeof(Ins)); + re->compile(rep, ins); + Ins *eoi = &ins[re->size]; + eoi->i.tag = GOTO; + eoi->i.link = eoi; + + optimize(ins); + + for (j = 0; j < re->size;) + { + unmark(&ins[j]); + + if (ins[j].i.tag == CHAR) + { + j = (Ins*) ins[j].i.link - ins; + } + else + { + j++; + } + } + + DFA *dfa = new DFA(ins, re->size, 0, nRealChars, rep); + dfa->emit(o, ind); + delete dfa; + delete [] ins; + delete [] rep; } -void genCode(std::ostream& o, RegExp *re){ - CharSet cs; - uint j; - memset(&cs, 0, sizeof(cs)); - for(j = 0; j < nChars; ++j){ - cs.rep[j] = &cs.ptn[0]; - cs.ptn[j].nxt = &cs.ptn[j+1]; - } - cs.freeHead = &cs.ptn[1]; - *(cs.freeTail = &cs.ptn[nChars-1].nxt) = NULL; - cs.ptn[0].card = nChars; - cs.ptn[0].nxt = NULL; - re->split(cs); -/* - for(uint k = 0; k < nChars;){ - for(j = k; ++k < nChars && cs.rep[k] == cs.rep[j];); - printSpan(cerr, j, k); - cerr << "\t" << cs.rep[j] - &cs.ptn[0] << endl; - } -*/ - Char rep[nChars]; - for(j = 0; j < nChars; ++j){ - if(!cs.rep[j]->nxt) - cs.rep[j]->nxt = &cs.ptn[j]; - rep[j] = (Char) (cs.rep[j]->nxt - &cs.ptn[0]); - } +} // end namespace re2c - re->calcSize(rep); - Ins *ins = new Ins[re->size+1]; - memset(ins, 0, (re->size+1)*sizeof(Ins)); - re->compile(rep, ins); - Ins *eoi = &ins[re->size]; - eoi->i.tag = GOTO; - eoi->i.link = eoi; - - optimize(ins); - for(j = 0; j < re->size;){ - unmark(&ins[j]); - if(ins[j].i.tag == CHAR){ - j = (Ins*) ins[j].i.link - ins; - } else { - j++; - } - } - - DFA *dfa = new DFA(ins, re->size, 0, 256, rep); - dfa->emit(o); - delete dfa; - delete [] ins; -} diff --git a/tools/re2c/basics.h b/tools/re2c/basics.h index 7771f210e..009adda18 100644 --- a/tools/re2c/basics.h +++ b/tools/re2c/basics.h @@ -1,13 +1,16 @@ -/* $Id: basics.h,v 1.3 2004/03/13 13:40:37 helly Exp $ */ +/* $Id: basics.h,v 1.6 2005/12/29 14:32:09 helly Exp $ */ #ifndef _basics_h #define _basics_h #ifdef HAVE_CONFIG_H #include "config.h" -#elif _WIN32 -#include "configwin.h" +#elif defined(_WIN32) +#include "config_w32.h" #endif +namespace re2c +{ + #if SIZEOF_CHAR == 1 typedef unsigned char byte; #elif SIZEOF_SHORT == 1 @@ -44,20 +47,11 @@ typedef unsigned long dword; typedef unsigned long dword; #endif -#ifndef HAVE_UINT -typedef unsigned int uint; -#endif +typedef unsigned int uint; +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned long ulong; -#ifndef HAVE_UCHAR -typedef unsigned char uchar; -#endif - -#ifndef HAVE_USHORT -typedef unsigned short ushort; -#endif - -#ifndef HAVE_ULONG -typedef unsigned long ulong; -#endif +} // end namespace re2c #endif diff --git a/tools/re2c/code.cc b/tools/re2c/code.cc index 2a14557eb..227682745 100644 --- a/tools/re2c/code.cc +++ b/tools/re2c/code.cc @@ -1,4 +1,4 @@ -/* $Id: code.cc,v 1.10 2004/05/27 00:02:01 nuffer Exp $ */ +/* $Id: code.cc,v 1.74 2006/05/14 13:38:26 helly Exp $ */ #include #include #include @@ -8,606 +8,1054 @@ #include "globals.h" #include "dfa.h" #include "parser.h" +#include "code.h" + +namespace re2c +{ // there must be at least one span in list; all spans must cover // same range +std::string indent(uint ind) +{ + std::string str; + + while (ind-- > 0) + { + str += indString; + } + return str; +} + +static std::string space(uint this_label) +{ + int nl = next_label > 9999 ? 4 : next_label > 999 ? 3 : next_label > 99 ? 2 : next_label > 9 ? 1 : 0; + int tl = this_label > 9999 ? 4 : this_label > 999 ? 3 : this_label > 99 ? 2 : this_label > 9 ? 1 : 0; + + return std::string(std::max(1, nl - tl + 1), ' '); +} + void Go::compact() { // arrange so that adjacent spans have different targets uint i = 0; - for(uint j = 1; j < nSpans; ++j) + + for (uint j = 1; j < nSpans; ++j) { - if(span[j].to != span[i].to) + if (span[j].to != span[i].to) { - ++i; span[i].to = span[j].to; + ++i; + span[i].to = span[j].to; } + span[i].ub = span[j].ub; } + nSpans = i + 1; } -void Go::unmap(Go *base, State *x) +void Go::unmap(Go *base, const State *x) { Span *s = span, *b = base->span, *e = &b[base->nSpans]; uint lb = 0; s->ub = 0; s->to = NULL; - for(; b != e; ++b) + + for (; b != e; ++b) { - if(b->to == x) + if (b->to == x) { - if((s->ub - lb) > 1) + if ((s->ub - lb) > 1) { s->ub = b->ub; } - } else { - if(b->to != s->to) + } + else + { + if (b->to != s->to) { - if(s->ub) + if (s->ub) { - lb = s->ub; ++s; + lb = s->ub; + ++s; } + s->to = b->to; } + s->ub = b->ub; } } - s->ub = e[-1].ub; ++s; + + s->ub = e[ -1].ub; + ++s; nSpans = s - span; } -void doGen(Go *g, State *s, uchar *bm, uchar m) +void doGen(const Go *g, const State *s, uint *bm, uint f, uint m) { Span *b = g->span, *e = &b[g->nSpans]; uint lb = 0; - for(; b < e; ++b) + + for (; b < e; ++b) { - if(b->to == s) + if (b->to == s) { - for(; lb < b->ub; ++lb) + for (; lb < b->ub && lb < 256; ++lb) { - bm[lb] |= m; + bm[lb-f] |= m; } } + lb = b->ub; } } -void prt(std::ostream& o, Go *g, State *s) +void prt(std::ostream& o, const Go *g, const State *s) { Span *b = g->span, *e = &b[g->nSpans]; uint lb = 0; - for(; b < e; ++b) + + for (; b < e; ++b) { - if(b->to == s) + if (b->to == s) { printSpan(o, lb, b->ub); } + lb = b->ub; } } -bool matches(Go *g1, State *s1, Go *g2, State *s2) +bool matches(const Go *g1, const State *s1, const Go *g2, const State *s2) { Span *b1 = g1->span, *e1 = &b1[g1->nSpans]; uint lb1 = 0; Span *b2 = g2->span, *e2 = &b2[g2->nSpans]; uint lb2 = 0; - for(;;) + + for (;;) { - for(; b1 < e1 && b1->to != s1; ++b1) + for (; b1 < e1 && b1->to != s1; ++b1) { lb1 = b1->ub; } - for(; b2 < e2 && b2->to != s2; ++b2) + + for (; b2 < e2 && b2->to != s2; ++b2) { lb2 = b2->ub; } - if(b1 == e1) + + if (b1 == e1) { return b2 == e2; } - if(b2 == e2){ - return false; - } - if(lb1 != lb2 || b1->ub != b2->ub) + + if (b2 == e2) { return false; } - ++b1; ++b2; + + if (lb1 != lb2 || b1->ub != b2->ub) + { + return false; + } + + ++b1; + ++b2; } } -class BitMap { -public: - static BitMap *first; - Go *go; - State *on; - BitMap *next; - uint i; - uchar m; - public: - static BitMap *find(Go*, State*); - static BitMap *find(State*); - static void gen(std::ostream&, uint, uint); - static void stats(); - BitMap(Go*, State*); -}; - BitMap *BitMap::first = NULL; -BitMap::BitMap(Go *g, State *x) : go(g), on(x), next(first) +BitMap::BitMap(const Go *g, const State *x) + : go(g) + , on(x) + , next(first) + , i(0) + , m(0) { first = this; } -BitMap *BitMap::find(Go *g, State *x) +BitMap::~BitMap() { - for(BitMap *b = first; b; b = b->next) + if (next) { - if(matches(b->go, b->on, g, x)) - { - return b; - } - } - return new BitMap(g, x); + delete next; + } } -BitMap *BitMap::find(State *x) +const BitMap *BitMap::find(const Go *g, const State *x) { - for(BitMap *b = first; b; b = b->next) - { - if(b->on == x) + for (const BitMap *b = first; b; b = b->next) + { + if (matches(b->go, b->on, g, x)) { - return b; - } - } - return NULL; + return b; + } + } + + return new BitMap(g, x); } -void BitMap::gen(std::ostream &o, uint lb, uint ub) +const BitMap *BitMap::find(const State *x) +{ + for (const BitMap *b = first; b; b = b->next) + { + if (b->on == x) + { + return b; + } + } + + return NULL; +} + +void BitMap::gen(std::ostream &o, uint ind, uint lb, uint ub) { BitMap *b = first; - if(b) + + if (b && bLastPass) { - o << "\tstatic unsigned char yybm[] = {"; - uint n = ub - lb; - uchar *bm = new uchar[n]; - memset(bm, 0, n); - for(uint i = 0; b; i += n) + o << indent(ind) << "static unsigned char yybm[] = {"; + + uint c = 1, n = ub - lb; + + while((b = const_cast(b->next)) != NULL) { + ++c; + } + b = first; + + uint *bm = new uint[n]; + + for (uint i = 0, t = 1; b; i += n, t += 8) { - for(uchar m = 0x80; b && m; b = b->next, m >>= 1) + memset(bm, 0, n * sizeof(uint)); + + for (uint m = 0x80; b && m; m >>= 1) { - b->i = i; b->m = m; - doGen(b->go, b->on, bm-lb, m); + b->i = i; + b->m = m; + doGen(b->go, b->on, bm, lb, m); + b = const_cast(b->next); } - for(uint j = 0; j < n; ++j) + + if (c > 8) { - if(j%8 == 0) + o << "\n" << indent(ind+1) << "/* table " << t << " .. " << std::min(c, t+7) << ": " << i << " */"; + } + + for (uint j = 0; j < n; ++j) + { + if (j % 8 == 0) { - o << "\n\t"; ++oline; + o << "\n" << indent(ind+1); } - o << std::setw(3) << (uint) bm[j] << ", "; + + if (yybmHexTable) + { + prtHex(o, bm[j], false); + } + else + { + o << std::setw(3) << (uint)bm[j]; + } + o << ", "; } } - o << "\n\t};\n"; - oline += 2; + + o << "\n" << indent(ind) << "};\n"; + /* stats(); */ + + delete[] bm; } } void BitMap::stats() { uint n = 0; - for(BitMap *b = first; b; b = b->next) + + for (const BitMap *b = first; b; b = b->next) { - prt(std::cerr, b->go, b->on); std::cerr << std::endl; + prt(std::cerr, b->go, b->on); + std::cerr << std::endl; ++n; } + std::cerr << n << " bitmaps\n"; first = NULL; } -void genGoTo(std::ostream &o, State *from, State *to, bool & readCh) +void genGoTo(std::ostream &o, uint ind, const State *from, const State *to, bool & readCh) { if (readCh && from->label + 1 != to->label) { - o << "\tyych = *YYCURSOR;\n"; + o << indent(ind) << "yych = *YYCURSOR;\n"; readCh = false; } - o << "\tgoto yy" << to->label << ";\n"; - ++oline; + + o << indent(ind) << "goto yy" << to->label << ";\n"; + vUsedLabels.insert(to->label); } -void genIf(std::ostream &o, char *cmp, uint v, bool &readCh) +void genIf(std::ostream &o, uint ind, const char *cmp, uint v, bool &readCh) { if (readCh) { - o << "\tif((yych = *YYCURSOR) "; + o << indent(ind) << "if((yych = *YYCURSOR) "; readCh = false; } else { - o << "\tif(yych "; + o << indent(ind) << "if(yych "; } - o << cmp << " '"; - prtCh(o, v); - o << "')"; + + o << cmp << " "; + prtChOrHex(o, v); + o << ") "; } -void indent(std::ostream &o, uint i) +static void need(std::ostream &o, uint ind, uint n, bool & readCh, bool bSetMarker) { - while(i-- > 0) - { - o << "\t"; - } -} + uint fillIndex = next_fill_index; -static void need(std::ostream &o, uint n, bool & readCh) -{ - if(n == 1) + if (fFlag) { - o << "\tif(YYLIMIT == YYCURSOR) YYFILL(1);\n"; - ++oline; + next_fill_index++; + o << indent(ind) << "YYSETSTATE(" << fillIndex << ");\n"; + } + + if (bUseYYFill) + { + if (n == 1) + { + o << indent(ind) << "if(YYLIMIT == YYCURSOR) YYFILL(1);\n"; + } + else + { + o << indent(ind) << "if((YYLIMIT - YYCURSOR) < " << n << ") YYFILL(" << n << ");\n"; + } + } + + if (fFlag) + { + o << "yyFillLabel" << fillIndex << ":\n"; + } + + if (bSetMarker) + { + o << indent(ind) << "yych = *(YYMARKER = YYCURSOR);\n"; } else { - o << "\tif((YYLIMIT - YYCURSOR) < " << n << ") YYFILL(" << n << ");\n"; - ++oline; + o << indent(ind) << "yych = *YYCURSOR;\n"; } - o << "\tyych = *YYCURSOR;\n"; readCh = false; - ++oline; } -void Match::emit(std::ostream &o, bool &readCh) +void Match::emit(std::ostream &o, uint ind, bool &readCh) const { if (state->link) { - o << "\t++YYCURSOR;\n"; + o << indent(ind) << "++YYCURSOR;\n"; } else if (!readAhead()) { /* do not read next char if match */ - o << "\t++YYCURSOR;\n"; + o << indent(ind) << "++YYCURSOR;\n"; readCh = true; } else { - o << "\tyych = *++YYCURSOR;\n"; + o << indent(ind) << "yych = *++YYCURSOR;\n"; readCh = false; } - ++oline; - if(state->link) + + if (state->link) { - ++oline; - need(o, state->depth, readCh); + need(o, ind, state->depth, readCh, false); } } -void Enter::emit(std::ostream &o, bool &readCh) +void Enter::emit(std::ostream &o, uint ind, bool &readCh) const { - if(state->link){ - o << "\t++YYCURSOR;\n"; - o << "yy" << label << ":\n"; - oline += 2; - need(o, state->depth, readCh); - } else { - /* we shouldn't need 'rule-following' protection here */ - o << "\tyych = *++YYCURSOR;\n"; - o << "yy" << label << ":\n"; - oline += 2; - readCh = false; - } -} - -void Save::emit(std::ostream &o, bool &readCh) -{ - o << "\tyyaccept = " << selector << ";\n"; - ++oline; - if(state->link){ - o << "\tYYMARKER = ++YYCURSOR;\n"; - ++oline; - need(o, state->depth, readCh); - } else { - o << "\tyych = *(YYMARKER = ++YYCURSOR);\n"; - ++oline; - readCh = false; - } -} - -Move::Move(State *s) : Action(s) { - ; -} - -void Move::emit(std::ostream &o, bool &readCh){ - ; -} - -Accept::Accept(State *x, uint n, uint *s, State **r) - : Action(x), nRules(n), saves(s), rules(r){ - ; -} - -void Accept::emit(std::ostream &o, bool &readCh) -{ - bool first = true; - for(uint i = 0; i < nRules; ++i) - if(saves[i] != ~0u) + if (state->link) { - if(first) + o << indent(ind) << "++YYCURSOR;\n"; + if (vUsedLabels.count(label)) { - first = false; - o << "\tYYCURSOR = YYMARKER;\n"; - o << "\tswitch(yyaccept){\n"; - oline += 2; + o << "yy" << label << ":\n"; } - o << "\tcase " << saves[i] << ":"; - genGoTo(o, state, rules[i], readCh); - } - if(!first) - { - o << "\t}\n"; - ++oline; - } -} - -Rule::Rule(State *s, RuleOp *r) : Action(s), rule(r) { - ; -} - -void Rule::emit(std::ostream &o, bool &readCh) -{ - uint back = rule->ctx->fixedLength(); - if(back != ~0u && back > 0u) { - o << "\tYYCURSOR -= " << back << ";"; - } - o << "\n"; - ++oline; - line_source(rule->code->line, o); - o << rule->code->text; - // not sure if we need this or not. oline += std::count(rule->code->text, rule->code->text + ::strlen(rule->code->text), '\n'); - o << "\n"; - ++oline; - o << "#line " << ++oline << " \"" << outputFileName << "\"\n"; - // o << "\n#line " << rule->code->line - // << "\n\t" << rule->code->text << "\n"; -} - -void doLinear(std::ostream &o, uint i, Span *s, uint n, State *from, State *next, bool &readCh) -{ - for(;;) - { - State *bg = s[0].to; - while(n >= 3 && s[2].to == bg && (s[1].ub - s[0].ub) == 1) - { - if(s[1].to == next && n == 3) - { - indent(o, i); genIf(o, "!=", s[0].ub, readCh); genGoTo(o, from, bg, readCh); - indent(o, i); genGoTo(o, from, next, readCh); - return; - } - else - { - indent(o, i); genIf(o, "==", s[0].ub, readCh); genGoTo(o, from, s[1].to, readCh); - } - n -= 2; s += 2; - } - if(n == 1) - { -// if(bg != next){ - indent(o, i); genGoTo(o, from, s[0].to, readCh); -// } - return; - } - else if(n == 2 && bg == next) - { - indent(o, i); genIf(o, ">=", s[0].ub, readCh); genGoTo(o, from, s[1].to, readCh); - indent(o, i); genGoTo(o, from, next, readCh); - return; - } - else - { - indent(o, i); genIf(o, "<=", s[0].ub - 1, readCh); genGoTo(o, from, bg, readCh); - n -= 1; s += 1; - } - } - indent(o, i); genGoTo(o, from, next, readCh); -} - -void Go::genLinear(std::ostream &o, State *from, State *next, bool &readCh) -{ - doLinear(o, 0, span, nSpans, from, next, readCh); -} - -void genCases(std::ostream &o, uint lb, Span *s) -{ - if(lb < s->ub) - { - for(;;) - { - o << "\tcase '"; prtCh(o, lb); o << "':"; - if(++lb == s->ub) - { - break; - } - o << "\n"; - ++oline; - } - } -} - -void Go::genSwitch(std::ostream &o, State *from, State *next, bool &readCh) -{ - if(nSpans <= 2){ - genLinear(o, from, next, readCh); + need(o, ind, state->depth, readCh, false); } else { - State *def = span[nSpans-1].to; - Span **sP = new Span*[nSpans-1], **r, **s, **t; - - t = &sP[0]; - for(uint i = 0; i < nSpans; ++i) + /* we shouldn't need 'rule-following' protection here */ + o << indent(ind) << "yych = *++YYCURSOR;\n"; + if (vUsedLabels.count(label)) { - if(span[i].to != def) + o << "yy" << label << ":\n"; + } + readCh = false; + } +} + +void Initial::emit(std::ostream &o, uint ind, bool &readCh) const +{ + if (!startLabelName.empty()) + { + o << startLabelName << ":\n"; + } + + if (vUsedLabels.count(1)) + { + if (state->link) + { + o << indent(ind) << "++YYCURSOR;\n"; + } + else + { + o << indent(ind) << "yych = *++YYCURSOR;\n"; + } + } + + if (vUsedLabels.count(label)) + { + o << "yy" << label << ":\n"; + } + else if (!label) + { + o << "\n"; + } + + if (dFlag) + { + o << indent(ind) << "YYDEBUG(" << label << ", *YYCURSOR);\n"; + } + + if (state->link) + { + need(o, ind, state->depth, readCh, setMarker && bUsedYYMarker); + } + else + { + if (setMarker && bUsedYYMarker) + { + o << indent(ind) << "YYMARKER = YYCURSOR;\n"; + } + readCh = false; + } +} + +void Save::emit(std::ostream &o, uint ind, bool &readCh) const +{ + if (bUsedYYAccept) + { + o << indent(ind) << "yyaccept = " << selector << ";\n"; + } + + if (state->link) + { + if (bUsedYYMarker) + { + o << indent(ind) << "YYMARKER = ++YYCURSOR;\n"; + } + need(o, ind, state->depth, readCh, false); + } + else + { + if (bUsedYYMarker) + { + o << indent(ind) << "yych = *(YYMARKER = ++YYCURSOR);\n"; + } + else + { + o << indent(ind) << "yych = *++YYCURSOR;\n"; + } + readCh = false; + } +} + +Move::Move(State *s) : Action(s) +{ + ; +} + +void Move::emit(std::ostream &, uint, bool &) const +{ + ; +} + +Accept::Accept(State *x, uint n, uint *s, State **r) + : Action(x), nRules(n), saves(s), rules(r) +{ + ; +} + +void Accept::genRuleMap() +{ + for (uint i = 0; i < nRules; ++i) + { + if (saves[i] != ~0u) + { + mapRules[saves[i]] = rules[i]; + } + } +} + +void Accept::emitBinary(std::ostream &o, uint ind, uint l, uint r, bool &readCh) const +{ + if (l < r) + { + uint m = (l + r) >> 1; + + o << indent(ind) << "if(yyaccept <= " << m << ") {\n"; + emitBinary(o, ++ind, l, m, readCh); + o << indent(--ind) << "} else {\n"; + emitBinary(o, ++ind, m + 1, r, readCh); + o << indent(--ind) << "}\n"; + } + else + { + genGoTo(o, ind, state, mapRules.find(l)->second, readCh); + } +} + +void Accept::emit(std::ostream &o, uint ind, bool &readCh) const +{ + if (mapRules.size() > 0) + { + bUsedYYMarker = true; + o << indent(ind) << "YYCURSOR = YYMARKER;\n"; + + if (readCh) // shouldn't be necessary, but might become at some point + { + o << indent(ind) << "yych = *YYCURSOR;\n"; + readCh = false; + } + + if (mapRules.size() > 1) + { + bUsedYYAccept = true; + + if (gFlag && mapRules.size() >= cGotoThreshold) + { + o << indent(ind++) << "{\n"; + o << indent(ind++) << "static void *yytarget[" << mapRules.size() << "] = {\n"; + for (RuleMap::const_iterator it = mapRules.begin(); it != mapRules.end(); ++it) + { + o << indent(ind) << "&&yy" << it->second->label << ",\n"; + vUsedLabels.insert(it->second->label); + } + o << indent(--ind) << "};\n"; + o << indent(ind) << "goto *yytarget[yyaccept];\n"; + o << indent(--ind) << "}\n"; + } + else if (sFlag) + { + emitBinary(o, ind, 0, mapRules.size() - 1, readCh); + } + else + { + o << indent(ind) << "switch(yyaccept) {\n"; + + for (RuleMap::const_iterator it = mapRules.begin(); it != mapRules.end(); ++it) + { + o << indent(ind) << "case " << it->first << ": \t"; + genGoTo(o, 0, state, it->second, readCh); + } + + o << indent(ind) << "}\n"; + } + } + else + { + // no need to write if statement here since there is only case 0. + genGoTo(o, ind, state, mapRules.find(0)->second, readCh); + } + } +} + +Rule::Rule(State *s, RuleOp *r) : Action(s), rule(r) +{ + ; +} + +void Rule::emit(std::ostream &o, uint ind, bool &) const +{ + uint back = rule->ctx->fixedLength(); + + if (back != 0u) + { + o << indent(ind) << "YYCURSOR = YYCTXMARKER;\n"; + } + + RuleLine rl(*rule); + + o << file_info(sourceFileInfo, &rl); + o << indent(ind); + o << rule->code->text; + o << "\n"; + o << outputFileInfo; +} + +void doLinear(std::ostream &o, uint ind, Span *s, uint n, const State *from, const State *next, bool &readCh, uint mask) +{ + for (;;) + { + State *bg = s[0].to; + + while (n >= 3 && s[2].to == bg && (s[1].ub - s[0].ub) == 1) + { + if (s[1].to == next && n == 3) + { + if (!mask || (s[0].ub > 0x00FF)) + { + genIf(o, ind, "!=", s[0].ub, readCh); + genGoTo(o, 0, from, bg, readCh); + } + if (next->label != from->label + 1) + { + genGoTo(o, ind, from, next, readCh); + } + return ; + } + else + { + if (!mask || (s[0].ub > 0x00FF)) + { + genIf(o, ind, "==", s[0].ub, readCh); + genGoTo(o, 0, from, s[1].to, readCh); + } + } + + n -= 2; + s += 2; + } + + if (n == 1) + { + // if(bg != next){ + if (s[0].to->label != from->label + 1) + { + genGoTo(o, ind, from, s[0].to, readCh); + } + // } + return ; + } + else if (n == 2 && bg == next) + { + if (!mask || (s[0].ub > 0x00FF)) + { + genIf(o, ind, ">=", s[0].ub, readCh); + genGoTo(o, 0, from, s[1].to, readCh); + } + if (next->label != from->label + 1) + { + genGoTo(o, ind, from, next, readCh); + } + return ; + } + else + { + if (!mask || ((s[0].ub - 1) > 0x00FF)) + { + genIf(o, ind, "<=", s[0].ub - 1, readCh); + genGoTo(o, 0, from, bg, readCh); + } + n -= 1; + s += 1; + } + } + + if (next->label != from->label + 1) + { + genGoTo(o, ind, from, next, readCh); + } +} + +void Go::genLinear(std::ostream &o, uint ind, const State *from, const State *next, bool &readCh, uint mask) const +{ + doLinear(o, ind, span, nSpans, from, next, readCh, mask); +} + +bool genCases(std::ostream &o, uint ind, uint lb, Span *s, bool &newLine, uint mask) +{ + bool used = false; + + if (!newLine) + { + o << "\n"; + } + newLine = true; + if (lb < s->ub) + { + for (;;) + { + if (!mask || lb > 0x00FF) + { + o << indent(ind) << "case "; + prtChOrHex(o, lb); + o << ":"; + newLine = false; + used = true; + } + + if (++lb == s->ub) + { + break; + } + + o << "\n"; + newLine = true; + } + } + return used; +} + +void Go::genSwitch(std::ostream &o, uint ind, const State *from, const State *next, bool &readCh, uint mask) const +{ + bool newLine = true; + + if ((mask ? wSpans : nSpans) <= 2) + { + genLinear(o, ind, from, next, readCh, mask); + } + else + { + State *def = span[nSpans - 1].to; + Span **sP = new Span * [nSpans - 1], **r, **s, **t; + + t = &sP[0]; + + for (uint i = 0; i < nSpans; ++i) + { + if (span[i].to != def) { *(t++) = &span[i]; } } - + + if (dFlag) + { + o << indent(ind) << "YYDEBUG(-1, yych);\n"; + } + if (readCh) { - o << "\tswitch((yych = *YYCURSOR)) {\n"; - readCh =false; + o << indent(ind) << "switch((yych = *YYCURSOR)) {\n"; + readCh = false; } else { - o << "\tswitch(yych){\n"; + o << indent(ind) << "switch(yych){\n"; } - ++oline; - while(t != &sP[0]) + + while (t != &sP[0]) { + bool used = false; + r = s = &sP[0]; - if(*s == &span[0]) - genCases(o, 0, *s); - else - genCases(o, (*s)[-1].ub, *s); - State *to = (*s)->to; - while(++s < t) + + if (*s == &span[0]) { - if((*s)->to == to) + used |= genCases(o, ind, 0, *s, newLine, mask); + } + else + { + used |= genCases(o, ind, (*s)[ -1].ub, *s, newLine, mask); + } + + State *to = (*s)->to; + + while (++s < t) + { + if ((*s)->to == to) { - genCases(o, (*s)[-1].ub, *s); + used |= genCases(o, ind, (*s)[ -1].ub, *s, newLine, mask); } else { *(r++) = *s; } } - genGoTo(o, from, to, readCh); + + if (used) + { + genGoTo(o, newLine ? ind+1 : 1, from, to, readCh); + newLine = true; + } t = r; } - o << "\tdefault:"; - genGoTo(o, from, def, readCh); - o << "\t}\n"; - ++oline; - + + o << indent(ind) << "default:"; + genGoTo(o, 1, from, def, readCh); + o << indent(ind) << "}\n"; + delete [] sP; } } -void doBinary(std::ostream &o, uint i, Span *s, uint n, State *from, State *next, bool &readCh) +void doBinary(std::ostream &o, uint ind, Span *s, uint n, const State *from, const State *next, bool &readCh, uint mask) { - if(n <= 4) + if (n <= 4) { - doLinear(o, i, s, n, from, next, readCh); + doLinear(o, ind, s, n, from, next, readCh, mask); } else { - uint h = n/2; - indent(o, i); genIf(o, "<=", s[h-1].ub - 1, readCh); o << "{\n"; - ++oline; - doBinary(o, i+1, &s[0], h, from, next, readCh); - indent(o, i); o << "\t} else {\n"; - ++oline; - doBinary(o, i+1, &s[h], n - h, from, next, readCh); - indent(o, i); o << "\t}\n"; - ++oline; + uint h = n / 2; + + genIf(o, ind, "<=", s[h - 1].ub - 1, readCh); + o << "{\n"; + doBinary(o, ind+1, &s[0], h, from, next, readCh, mask); + o << indent(ind) << "} else {\n"; + doBinary(o, ind+1, &s[h], n - h, from, next, readCh, mask); + o << indent(ind) << "}\n"; } } -void Go::genBinary(std::ostream &o, State *from, State *next, bool &readCh) +void Go::genBinary(std::ostream &o, uint ind, const State *from, const State *next, bool &readCh, uint mask) const { - doBinary(o, 0, span, nSpans, from, next, readCh); -} - -void Go::genBase(std::ostream &o, State *from, State *next, bool &readCh) -{ - if(nSpans == 0) + if (mask) { - return; - } - if(!sFlag) - { - genSwitch(o, from, next, readCh); - return; - } - if(nSpans > 8) - { - Span *bot = &span[0], *top = &span[nSpans-1]; - uint util; - if(bot[0].to == top[0].to) + Span * sc = new Span[wSpans]; + + for (uint i = 0, j = 0; i < nSpans; i++) { - util = (top[-1].ub - bot[0].ub)/(nSpans - 2); + if (span[i].ub > 0xFF) + { + sc[j++] = span[i]; + } + } + + doBinary(o, ind, sc, wSpans, from, next, readCh, mask); + + delete[] sc; + } + else + { + doBinary(o, ind, span, nSpans, from, next, readCh, mask); + } +} + +void Go::genBase(std::ostream &o, uint ind, const State *from, const State *next, bool &readCh, uint mask) const +{ + if ((mask ? wSpans : nSpans) == 0) + { + return ; + } + + if (!sFlag) + { + genSwitch(o, ind, from, next, readCh, mask); + return ; + } + + if ((mask ? wSpans : nSpans) > 8) + { + Span *bot = &span[0], *top = &span[nSpans - 1]; + uint util; + + if (bot[0].to == top[0].to) + { + util = (top[ -1].ub - bot[0].ub) / (nSpans - 2); } else { - if(bot[0].ub > (top[0].ub - top[-1].ub)) + if (bot[0].ub > (top[0].ub - top[ -1].ub)) { - util = (top[0].ub - bot[0].ub)/(nSpans - 1); + util = (top[0].ub - bot[0].ub) / (nSpans - 1); } else { - util = top[-1].ub/(nSpans - 1); + util = top[ -1].ub / (nSpans - 1); } } - if(util <= 2) + + if (util <= 2) { - genSwitch(o, from, next, readCh); - return; + genSwitch(o, ind, from, next, readCh, mask); + return ; } } - if(nSpans > 5) + + if ((mask ? wSpans : nSpans) > 5) { - genBinary(o, from, next, readCh); + genBinary(o, ind, from, next, readCh, mask); } else { - genLinear(o, from, next, readCh); + genLinear(o, ind, from, next, readCh, mask); } } -void Go::genGoto(std::ostream &o, State *from, State *next, bool &readCh) +void Go::genCpGoto(std::ostream &o, uint ind, const State *from, const State *next, bool &readCh) const { - if(bFlag) + const char * sYych = readCh ? "(yych = *YYCURSOR)" : "yych"; + + readCh = false; + if (wFlag) { - for(uint i = 0; i < nSpans; ++i) + o << indent(ind) << "if(" << sYych <<" & 0xFF00) {\n"; + genBase(o, ind+1, from, next, readCh, 1); + o << indent(ind++) << "} else {\n"; + sYych = "yych"; + } + else + { + o << indent(ind++) << "{\n"; + } + o << indent(ind++) << "static void *yytarget[256] = {\n"; + o << indent(ind); + + uint ch = 0; + for (uint i = 0; i < lSpans; ++i) + { + vUsedLabels.insert(span[i].to->label); + for(; ch < span[i].ub; ++ch) + { + o << "&&yy" << span[i].to->label; + if (ch == 255) + { + o << "\n"; + i = lSpans; + break; + } + else if (ch % 8 == 7) + { + o << ",\n" << indent(ind); + } + else + { + o << "," << space(span[i].to->label); + } + } + } + o << indent(--ind) << "};\n"; + o << indent(ind) << "goto *yytarget[" << sYych << "];\n"; + o << indent(--ind) << "}\n"; +} + +void Go::genGoto(std::ostream &o, uint ind, const State *from, const State *next, bool &readCh) +{ + if ((gFlag || wFlag) && wSpans == ~0u) + { + uint nBitmaps = 0; + std::set vTargets; + wSpans = 0; + lSpans = 1; + dSpans = 0; + for (uint i = 0; i < nSpans; ++i) + { + if (span[i].ub > 0xFF) + { + wSpans++; + } + if (span[i].ub < 0x100 || !wFlag) + { + lSpans++; + + State *to = span[i].to; + + if (to && to->isBase) + { + const BitMap *b = BitMap::find(to); + const char * sYych; + + if (b && matches(b->go, b->on, this, to)) + { + nBitmaps++; + } + else + { + dSpans++; + vTargets.insert(to->label); + } + } + else + { + dSpans++; + vTargets.insert(to->label); + } + } + } + lTargets = vTargets.size() >> nBitmaps; + } + + if (gFlag && (lTargets >= cGotoThreshold || dSpans >= cGotoThreshold)) + { + genCpGoto(o, ind, from, next, readCh); + return; + } + else if (bFlag) + { + for (uint i = 0; i < nSpans; ++i) { State *to = span[i].to; - if(to && to->isBase) + + if (to && to->isBase) { - BitMap *b = BitMap::find(to); - if(b && matches(b->go, b->on, this, to)) + const BitMap *b = BitMap::find(to); + const char * sYych; + + if (b && matches(b->go, b->on, this, to)) { Go go; go.span = new Span[nSpans]; go.unmap(this, to); - o << "\tif(yybm[" << b->i << "+"; - if (readCh) + sYych = readCh ? "(yych = *YYCURSOR)" : "yych"; + readCh = false; + if (wFlag) { - o << "(yych = *YYCURSOR)"; + o << indent(ind) << "if(" << sYych << " & 0xFF00) {\n"; + sYych = "yych"; + genBase(o, ind+1, from, next, readCh, 1); + o << indent(ind) << "} else "; } else { - o << "yych"; + o << indent(ind); } - o << "] & " << (uint) b->m << ")"; - genGoTo(o, from, to, readCh); - go.genBase(o, from, next, readCh); + o << "if(yybm[" << b->i << "+" << sYych << "] & "; + if (yybmHexTable) + { + prtHex(o, b->m, false); + } + else + { + o << (uint) b->m; + } + o << ") {\n"; + genGoTo(o, ind+1, from, to, readCh); + o << indent(ind) << "}\n"; + go.genBase(o, ind, from, next, readCh, 0); delete [] go.span; - return; + return ; } } } } - genBase(o, from, next, readCh); + + genBase(o, ind, from, next, readCh, 0); } -void State::emit(std::ostream &o, bool &readCh){ - o << "yy" << label << ":"; -/* o << "\nfprintf(stderr, \"<" << label << ">\");\n";*/ - action->emit(o, readCh); +void State::emit(std::ostream &o, uint ind, bool &readCh) const +{ + if (vUsedLabels.count(label)) + { + o << "yy" << label << ":\n"; + } + if (dFlag && !action->isInitial()) + { + o << indent(ind) << "YYDEBUG(" << label << ", *YYCURSOR);\n"; + } + if (isPreCtxt) + { + o << indent(ind) << "YYCTXMARKER = YYCURSOR + 1;\n"; + } + action->emit(o, ind, readCh); } uint merge(Span *x0, State *fg, State *bg) @@ -616,29 +1064,40 @@ uint merge(Span *x0, State *fg, State *bg) uint nf = fg->go.nSpans, nb = bg->go.nSpans; State *prev = NULL, *to; // NB: we assume both spans are for same range - for(;;) + + for (;;) { - if(f->ub == b->ub) + if (f->ub == b->ub) { - to = f->to == b->to? bg : f->to; - if(to == prev){ + to = f->to == b->to ? bg : f->to; + + if (to == prev) + { --x; } else { x->to = prev = to; } + x->ub = f->ub; - ++x; ++f; --nf; ++b; --nb; - if(nf == 0 && nb == 0) + ++x; + ++f; + --nf; + ++b; + --nb; + + if (nf == 0 && nb == 0) { return x - x0; } } - while(f->ub < b->ub) + + while (f->ub < b->ub) { - to = f->to == b->to? bg : f->to; - if(to == prev) + to = f->to == b->to ? bg : f->to; + + if (to == prev) { --x; } @@ -646,13 +1105,18 @@ uint merge(Span *x0, State *fg, State *bg) { x->to = prev = to; } + x->ub = f->ub; - ++x; ++f; --nf; + ++x; + ++f; + --nf; } - while(b->ub < f->ub) + + while (b->ub < f->ub) { - to = b->to == f->to? bg : f->to; - if(to == prev) + to = b->to == f->to ? bg : f->to; + + if (to == prev) { --x; } @@ -660,28 +1124,51 @@ uint merge(Span *x0, State *fg, State *bg) { x->to = prev = to; } + x->ub = b->ub; - ++x; ++b; --nb; + ++x; + ++b; + --nb; } } } const uint cInfinity = ~0; -class SCC { +class SCC +{ + public: State **top, **stk; + public: SCC(uint); ~SCC(); void traverse(State*); + +#ifdef PEDANTIC +private: + SCC(const SCC& oth) + : top(oth.top) + , stk(oth.stk) + { + } + SCC& operator = (const SCC& oth) + { + new(this) SCC(oth); + return *this; + } +#endif }; -SCC::SCC(uint size){ - top = stk = new State*[size]; +SCC::SCC(uint size) + : top(new State * [size]) + , stk(top) +{ } -SCC::~SCC(){ +SCC::~SCC() +{ delete [] stk; } @@ -690,90 +1177,141 @@ void SCC::traverse(State *x) *top = x; uint k = ++top - stk; x->depth = k; - for(uint i = 0; i < x->go.nSpans; ++i) + + for (uint i = 0; i < x->go.nSpans; ++i) { State *y = x->go.span[i].to; - if(y) + + if (y) { - if(y->depth == 0) + if (y->depth == 0) { traverse(y); } - if(y->depth < x->depth) + + if (y->depth < x->depth) { x->depth = y->depth; } } } - if(x->depth == k) + + if (x->depth == k) { do { (*--top)->depth = cInfinity; (*top)->link = x; - } while(*top != x); + } + while (*top != x); } } +static bool state_is_in_non_trivial_SCC(const State* s) +{ + + // does not link to self + if (s->link != s) + { + return true; + } + + // or exists i: (s->go.spans[i].to->link == s) + // + // Note: (s->go.spans[i].to == s) is allowed, corresponds to s + // looping back to itself. + // + for (uint i = 0; i < s->go.nSpans; ++i) + { + const State* t = s->go.span[i].to; + + if (t && t->link == s) + { + return true; + } + } + // otherwise no + return false; +} + uint maxDist(State *s) { + if (s->depth != cInfinity) + { + // Already calculated, just return result. + return s->depth; + } uint mm = 0; - for(uint i = 0; i < s->go.nSpans; ++i) + + for (uint i = 0; i < s->go.nSpans; ++i) { State *t = s->go.span[i].to; - if(t) + + if (t) { uint m = 1; - if(!t->link) + + if (!t->link) // marked as non-key state { - m += maxDist(t); + if (t->depth == cInfinity) + { + t->depth = maxDist(t); + } + m += t->depth; } - if(m > mm) + + if (m > mm) { mm = m; } } } + + s->depth = mm; return mm; } void calcDepth(State *head) { - State *t; - for(State *s = head; s; s = s->next) + State* s; + + // mark non-key states by s->link = NULL ; + for (s = head; s; s = s->next) { - if(s->link == s){ - for(uint i = 0; i < s->go.nSpans; ++i) - { - t = s->go.span[i].to; - if(t && t->link == s) - { - goto inSCC; - } - } - s->link = NULL; - }else + if (s != head && !state_is_in_non_trivial_SCC(s)) { - inSCC: - s->depth = maxDist(s); + s->link = NULL; } + //else: key state, leave alone + } + + for (s = head; s; s = s->next) + { + s->depth = cInfinity; + } + + // calculate max number of transitions before guarantied to reach + // a key state. + for (s = head; s; s = s->next) + { + maxDist(s); } } - + void DFA::findSCCs() { SCC scc(nStates); State *s; - for(s = head; s; s = s->next) + for (s = head; s; s = s->next) { s->depth = 0; s->link = NULL; } - for(s = head; s; s = s->next) + for (s = head; s; s = s->next) { - if(!s->depth) + if (!s->depth) { scc.traverse(s); } @@ -797,20 +1335,58 @@ void DFA::split(State *s) s->go.span[0].to = move; } -void DFA::emit(std::ostream &o) +void DFA::findBaseState() +{ + Span *span = new Span[ubChar - lbChar]; + + for (State *s = head; s; s = s->next) + { + if (!s->link) + { + for (uint i = 0; i < s->go.nSpans; ++i) + { + State *to = s->go.span[i].to; + + if (to && to->isBase) + { + to = to->go.span[0].to; + uint nSpans = merge(span, s, to); + + if (nSpans < s->go.nSpans) + { + delete [] s->go.span; + s->go.nSpans = nSpans; + s->go.span = new Span[nSpans]; + memcpy(s->go.span, span, nSpans*sizeof(Span)); + } + + break; + } + } + } + } + + delete [] span; +} + +void DFA::emit(std::ostream &o, uint ind) { - static uint label = 0; State *s; - uint i; + uint i, bitmap_brace = 0; findSCCs(); head->link = head; - head->depth = maxDist(head); uint nRules = 0; - for(s = head; s; s = s->next) + + for (s = head; s; s = s->next) { - if(s->rule && s->rule->accept >= nRules) + s->depth = maxDist(s); + if (maxFill < s->depth) + { + maxFill = s->depth; + } + if (s->rule && s->rule->accept >= nRules) { nRules = s->rule->accept + 1; } @@ -821,77 +1397,99 @@ void DFA::emit(std::ostream &o) memset(saves, ~0, (nRules)*sizeof(*saves)); // mark backtracking points - for(s = head; s; s = s->next) + bool bSaveOnHead = false; + + for (s = head; s; s = s->next) { - RuleOp *ignore = NULL; - if(s->rule) + if (s->rule) { - for(i = 0; i < s->go.nSpans; ++i) + for (i = 0; i < s->go.nSpans; ++i) { - if(s->go.span[i].to && !s->go.span[i].to->rule){ + if (s->go.span[i].to && !s->go.span[i].to->rule) + { delete s->action; - if(saves[s->rule->accept] == ~0u) + + if (saves[s->rule->accept] == ~0u) { saves[s->rule->accept] = nSaves++; } - (void) new Save(s, saves[s->rule->accept]); - continue; + + bSaveOnHead |= s == head; + (void) new Save(s, saves[s->rule->accept]); // sets s->action } } - ignore = s->rule; } } // insert actions - State **rules = new State*[nRules]; + State **rules = new State * [nRules]; + memset(rules, 0, (nRules)*sizeof(*rules)); + State *accept = NULL; - for(s = head; s; s = s->next) + Accept *accfixup = NULL; + + for (s = head; s; s = s->next) { - State *ow; - if(!s->rule) + State * ow; + + if (!s->rule) { ow = accept; } else { - if(!rules[s->rule->accept]) + if (!rules[s->rule->accept]) { State *n = new State; (void) new Rule(n, s->rule); rules[s->rule->accept] = n; addState(&s->next, n); } + ow = rules[s->rule->accept]; } - for(i = 0; i < s->go.nSpans; ++i) - if(!s->go.span[i].to) + + for (i = 0; i < s->go.nSpans; ++i) { - if(!ow) + if (!s->go.span[i].to) { - ow = accept = new State; - (void) new Accept(accept, nRules, saves, rules); - addState(&s->next, accept); + if (!ow) + { + ow = accept = new State; + accfixup = new Accept(accept, nRules, saves, rules); + addState(&s->next, accept); + } + + s->go.span[i].to = ow; } - s->go.span[i].to = ow; } } + + if (accfixup) + { + accfixup->genRuleMap(); + } // split ``base'' states into two parts - for(s = head; s; s = s->next) + for (s = head; s; s = s->next) { s->isBase = false; - if(s->link) + + if (s->link) { - for(i = 0; i < s->go.nSpans; ++i) + for (i = 0; i < s->go.nSpans; ++i) { - if(s->go.span[i].to == s){ + if (s->go.span[i].to == s) + { s->isBase = true; split(s); - if(bFlag) + + if (bFlag) { BitMap::find(&s->next->go, s); } + s = s->next; break; } @@ -900,65 +1498,226 @@ void DFA::emit(std::ostream &o) } // find ``base'' state, if possible - Span *span = new Span[ubChar - lbChar]; - for(s = head; s; s = s->next) - { - if(!s->link) - { - for(i = 0; i < s->go.nSpans; ++i) - { - State *to = s->go.span[i].to; - if(to && to->isBase) - { - to = to->go.span[0].to; - uint nSpans = merge(span, s, to); - if(nSpans < s->go.nSpans) - { - delete [] s->go.span; - s->go.nSpans = nSpans; - s->go.span = new Span[nSpans]; - memcpy(s->go.span, span, nSpans*sizeof(Span)); - } - break; - } - } - } - } - delete [] span; + findBaseState(); delete head->action; - ++oline; - o << "\n#line " << ++oline << " \"" << outputFileName << "\"\n"; - o << "{\n\tYYCTYPE yych;\n\tunsigned int yyaccept;\n"; - oline += 3; - - - if(bFlag) + if (bFlag) { - BitMap::gen(o, lbChar, ubChar); + o << indent(ind++) << "{\n"; + bitmap_brace = 1; + BitMap::gen(o, ind, lbChar, ubChar <= 256 ? ubChar : 256); } - o << "\tgoto yy" << label << ";\n"; - ++oline; - (void) new Enter(head, label++); + bUsedYYAccept = false; + + uint start_label = next_label; - for(s = head; s; s = s->next) + (void) new Initial(head, next_label++, bSaveOnHead); + + if (bUseStartLabel) { - s->label = label++; + if (startLabelName.empty()) + { + vUsedLabels.insert(start_label); + } } - for(s = head; s; s = s->next) + for (s = head; s; s = s->next) + { + s->label = next_label++; + } + + // Save 'next_fill_index' and compute information about code generation + // while writing to null device. + uint save_fill_index = next_fill_index; + null_stream null_dev; + + for (s = head; s; s = s->next) { bool readCh = false; - s->emit(o, readCh); - s->go.genGoto(o, s, s->next, readCh); + s->emit(null_dev, ind, readCh); + s->go.genGoto(null_dev, ind, s, s->next, readCh); } - o << "}\n"; - ++oline; + if (last_fill_index < next_fill_index) + { + last_fill_index = next_fill_index; + } + next_fill_index = save_fill_index; - BitMap::first = NULL; + // Generate prolog + o << "\n" << outputFileInfo; + o << indent(ind++) << "{\n"; + + if (!fFlag) + { + o << indent(ind) << "YYCTYPE yych;\n"; + if (bUsedYYAccept) + { + o << indent(ind) << "unsigned int yyaccept = 0;\n"; + } + } + else + { + o << "\n"; + } + + genGetState(o, ind, start_label); + + if (vUsedLabels.count(1)) + { + vUsedLabels.insert(0); + o << indent(ind) << "goto yy0;\n"; + } + + // Generate code + for (s = head; s; s = s->next) + { + bool readCh = false; + s->emit(o, ind, readCh); + s->go.genGoto(o, ind, s, s->next, readCh); + } + + // Generate epilog + o << indent(--ind) << "}\n"; + if (bitmap_brace) + { + o << indent(--ind) << "}\n"; + } + + // Cleanup + if (BitMap::first) + { + delete BitMap::first; + BitMap::first = NULL; + } delete [] saves; delete [] rules; + + bUseStartLabel = false; } + +void genGetState(std::ostream &o, uint& ind, uint start_label) +{ + if (fFlag && !bWroteGetState) + { + vUsedLabels.insert(start_label); + o << indent(ind) << "switch(YYGETSTATE())\n"; + o << indent(ind) << "{\n"; + if (bUseStateAbort) + { + o << indent(ind) << "default: abort();\n"; + o << indent(ind) << "case -1: goto yy" << start_label << ";\n"; + } + else + { + o << indent(ind) << "default: goto yy" << start_label << ";\n"; + } + + for (size_t i=0; iget_line() << " \"" << li.fname << "\"\n"; + } + return o; +} + +uint Scanner::get_line() const +{ + return cline; +} + +void Scanner::config(const Str& cfg, int num) +{ + if (cfg.to_string() == "indent:top") + { + if (num < 0) + { + fatal("configuration 'indent:top' must be a positive integer"); + } + topIndent = num; + } + else if (cfg.to_string() == "yybm:hex") + { + yybmHexTable = num != 0; + } + else if (cfg.to_string() == "startlabel") + { + bUseStartLabel = num != 0; + startLabelName = ""; + } + else if (cfg.to_string() == "state:abort") + { + bUseStateAbort = num != 0; + } + else if (cfg.to_string() == "state:nextlabel") + { + bUseStateNext = num != 0; + } + else if (cfg.to_string() == "yyfill:enable") + { + bUseYYFill = num != 0; + } + else if (cfg.to_string() == "cgoto:threshold") + { + cGotoThreshold = num; + } + else + { + fatal("unrecognized configuration name or illegal integer value"); + } +} + +void Scanner::config(const Str& cfg, const Str& val) +{ + if (cfg.to_string() == "indent:string") + { + if (val.len >= 2 && val.str[0] == val.str[val.len-1] + && (val.str[0] == '"' || val.str[0] == '\'')) + { + SubStr tmp(val.str + 1, val.len - 2); + unescape(tmp, indString); + } + else + { + indString = val.to_string(); + } + return; + } + else if (cfg.to_string() == "startlabel") + { + if (val.len >= 2 && val.str[0] == val.str[val.len-1] + && (val.str[0] == '"' || val.str[0] == '\'')) + { + SubStr tmp(val.str + 1, val.len - 2); + unescape(tmp, startLabelName); + } + else + { + startLabelName = val.to_string(); + } + bUseStartLabel = !startLabelName.empty(); + } + else + { + fatal("unrecognized configuration name or illegal string value"); + } +} + +} // end namespace re2c diff --git a/tools/re2c/code.h b/tools/re2c/code.h new file mode 100644 index 000000000..5f2e55123 --- /dev/null +++ b/tools/re2c/code.h @@ -0,0 +1,53 @@ +/* $Id: code.h,v 1.7 2006/01/21 15:51:02 helly Exp $ */ +#ifndef _code_h +#define _code_h + +#include "re.h" +#include "dfa.h" + +namespace re2c +{ + +class BitMap +{ +public: + static BitMap *first; + + const Go *go; + const State *on; + const BitMap *next; + uint i; + uint m; + +public: + static const BitMap *find(const Go*, const State*); + static const BitMap *find(const State*); + static void gen(std::ostream&, uint ind, uint, uint); + static void stats(); + BitMap(const Go*, const State*); + ~BitMap(); + +#if PEDANTIC + BitMap(const BitMap& oth) + : go(oth.go) + , on(oth.on) + , next(oth.next) + , i(oth.i) + , m(oth.m) + { + } + BitMap& operator = (const BitMap& oth) + { + new(this) BitMap(oth); + return *this; + } +#endif +}; + +#ifdef _MSC_VER +# pragma warning(disable: 4355) /* 'this' : used in base member initializer list */ +#endif + +} // end namespace re2c + +#endif diff --git a/tools/re2c/config.h.in b/tools/re2c/config.h.in deleted file mode 100644 index 0d6253fe5..000000000 --- a/tools/re2c/config.h.in +++ /dev/null @@ -1,118 +0,0 @@ -/* config.h.in. Generated from configure.in by autoheader. */ - -/* Define to 1 if you have the `getpagesize' function. */ -#undef HAVE_GETPAGESIZE - -/* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define to 1 if your system has a GNU libc compatible `malloc' function, and - to 0 otherwise. */ -#undef HAVE_MALLOC - -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define to 1 if you have the `memset' function. */ -#undef HAVE_MEMSET - -/* Define to 1 if you have a working `mmap' system call. */ -#undef HAVE_MMAP - -/* Define to 1 if you have the `munmap' function. */ -#undef HAVE_MUNMAP - -/* Define to 1 if stdbool.h conforms to C99. */ -#undef HAVE_STDBOOL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the `strdup' function. */ -#undef HAVE_STRDUP - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have uchar type definition */ -#undef HAVE_UCHAR - -/* Define to 1 if you have uint type definition */ -#undef HAVE_UINT - -/* Define to 1 if you have ulong type definition */ -#undef HAVE_ULONG - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Define to 1 if you have ushort type definition */ -#undef HAVE_USHORT - -/* Define to 1 if the system has the type `_Bool'. */ -#undef HAVE__BOOL - -/* Name of package */ -#undef PACKAGE - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - -/* The size of a `char', as computed by sizeof. */ -#undef SIZEOF_CHAR - -/* The size of a `int', as computed by sizeof. */ -#undef SIZEOF_INT - -/* The size of a `long', as computed by sizeof. */ -#undef SIZEOF_LONG - -/* The size of a `short', as computed by sizeof. */ -#undef SIZEOF_SHORT - -/* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Version number of package */ -#undef VERSION - -/* Define to empty if `const' does not conform to ANSI C. */ -#undef const - -/* Define as `__inline' if that's what the C compiler calls it, or to nothing - if it is not supported. */ -#undef inline - -/* Define to rpl_malloc if the replacement function should be used. */ -#undef malloc - -/* Define to `unsigned' if does not define. */ -#undef size_t - -/* Define to empty if the keyword `volatile' does not work. Warning: valid - code using `volatile' can become incorrect without. Disable with care. */ -#undef volatile diff --git a/tools/re2c/configwin.h b/tools/re2c/config_w32.h similarity index 74% rename from tools/re2c/configwin.h rename to tools/re2c/config_w32.h index d8cd70339..28f8eeee2 100644 --- a/tools/re2c/configwin.h +++ b/tools/re2c/config_w32.h @@ -1,15 +1,16 @@ +/* config.h. Generated by configure. */ /* config.h.in. Generated from configure.in by autoheader. */ /* Define to 1 if you have the `getpagesize' function. */ -#undef HAVE_GETPAGESIZE +#define HAVE_GETPAGESIZE 1 /* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H +#define HAVE_INTTYPES_H 1 /* Define to 1 if your system has a GNU libc compatible `malloc' function, and to 0 otherwise. */ -#undef HAVE_MALLOC -#include +#define HAVE_MALLOC 1 + /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 @@ -17,16 +18,16 @@ #define HAVE_MEMSET 1 /* Define to 1 if you have a working `mmap' system call. */ -#undef HAVE_MMAP +/* #undef HAVE_MMAP */ /* Define to 1 if you have the `munmap' function. */ -#undef HAVE_MUNMAP +#define HAVE_MUNMAP 1 /* Define to 1 if stdbool.h conforms to C99. */ -#undef HAVE_STDBOOL_H +#define HAVE_STDBOOL_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H +#define HAVE_STDINT_H 1 /* Define to 1 if you have the header file. */ #define HAVE_STDLIB_H 1 @@ -35,7 +36,7 @@ #define HAVE_STRDUP 1 /* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H +#define HAVE_STRINGS_H 1 /* Define to 1 if you have the header file. */ #define HAVE_STRING_H 1 @@ -46,41 +47,29 @@ /* Define to 1 if you have the header file. */ #define HAVE_SYS_TYPES_H 1 -/* Define to 1 if you have uchar type definition */ -#undef HAVE_UCHAR - -/* Define to 1 if you have uint type definition */ -#undef HAVE_UINT - -/* Define to 1 if you have ulong type definition */ -#undef HAVE_ULONG - /* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Define to 1 if you have ushort type definition */ -#undef HAVE_USHORT +#define HAVE_UNISTD_H 1 /* Define to 1 if the system has the type `_Bool'. */ -#undef HAVE__BOOL +#define HAVE__BOOL 1 /* Name of package */ -#undef PACKAGE +#define PACKAGE "re2c" /* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT +#define PACKAGE_BUGREPORT "re2c-general@lists.sourceforge.net" /* Define to the full name of this package. */ #define PACKAGE_NAME "re2c" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "re2c 0.9.3" +#define PACKAGE_STRING "re2c 0.10.3" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "re2c" /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.9.3" +#define PACKAGE_VERSION "0.10.3" /* The size of a `char', as computed by sizeof. */ #define SIZEOF_CHAR 1 @@ -98,21 +87,23 @@ #define STDC_HEADERS 1 /* Version number of package */ -#define VERSION "0.9.3" +#define VERSION "0.10.3" /* Define to empty if `const' does not conform to ANSI C. */ -//#undef const +/* #undef const */ -/* Define as `__inline' if that's what the C compiler calls it, or to nothing - if it is not supported. */ -//#undef inline +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif /* Define to rpl_malloc if the replacement function should be used. */ -//#undef malloc +/* #undef malloc */ /* Define to `unsigned' if does not define. */ -//#undef size_t +/* #undef size_t */ /* Define to empty if the keyword `volatile' does not work. Warning: valid code using `volatile' can become incorrect without. Disable with care. */ -//#undef volatile +/* #undef volatile */ diff --git a/tools/re2c/configure b/tools/re2c/configure deleted file mode 100644 index 275b208a4..000000000 --- a/tools/re2c/configure +++ /dev/null @@ -1,7415 +0,0 @@ -#! /bin/sh -# Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.57 for Makefile.am 0.9.3. -# -# Report bugs to . -# -# Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002 -# Free Software Foundation, Inc. -# This configure script is free software; the Free Software Foundation -# gives unlimited permission to copy, distribute and modify it. -## --------------------- ## -## M4sh Initialization. ## -## --------------------- ## - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi - -# Support unset when possible. -if (FOO=FOO; unset FOO) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - - -# Work around bugs in pre-3.0 UWIN ksh. -$as_unset ENV MAIL MAILPATH -PS1='$ ' -PS2='> ' -PS4='+ ' - -# NLS nuisances. -for as_var in \ - LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ - LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ - LC_TELEPHONE LC_TIME -do - if (set +x; test -n "`(eval $as_var=C; export $as_var) 2>&1`"); then - eval $as_var=C; export $as_var - else - $as_unset $as_var - fi -done - -# Required to use basename. -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then - as_basename=basename -else - as_basename=false -fi - - -# Name of the executable. -as_me=`$as_basename "$0" || -$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)$' \| \ - . : '\(.\)' 2>/dev/null || -echo X/"$0" | - sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; } - /^X\/\(\/\/\)$/{ s//\1/; q; } - /^X\/\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - - -# PATH needs CR, and LINENO needs CR and PATH. -# Avoid depending upon Character Ranges. -as_cr_letters='abcdefghijklmnopqrstuvwxyz' -as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -as_cr_Letters=$as_cr_letters$as_cr_LETTERS -as_cr_digits='0123456789' -as_cr_alnum=$as_cr_Letters$as_cr_digits - -# The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then - echo "#! /bin/sh" >conf$$.sh - echo "exit 0" >>conf$$.sh - chmod +x conf$$.sh - if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then - PATH_SEPARATOR=';' - else - PATH_SEPARATOR=: - fi - rm -f conf$$.sh -fi - - - as_lineno_1=$LINENO - as_lineno_2=$LINENO - as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x$as_lineno_3" = "x$as_lineno_2" || { - # Find who we are. Look in the path if we contain no path at all - # relative or not. - case $0 in - *[\\/]* ) as_myself=$0 ;; - *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break -done - - ;; - esac - # We did not find ourselves, most probably we were run as `sh COMMAND' - # in which case we are not to be found in the path. - if test "x$as_myself" = x; then - as_myself=$0 - fi - if test ! -f "$as_myself"; then - { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2 - { (exit 1); exit 1; }; } - fi - case $CONFIG_SHELL in - '') - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for as_base in sh bash ksh sh5; do - case $as_dir in - /*) - if ("$as_dir/$as_base" -c ' - as_lineno_1=$LINENO - as_lineno_2=$LINENO - as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x$as_lineno_3" = "x$as_lineno_2" ') 2>/dev/null; then - $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; } - $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; } - CONFIG_SHELL=$as_dir/$as_base - export CONFIG_SHELL - exec "$CONFIG_SHELL" "$0" ${1+"$@"} - fi;; - esac - done -done -;; - esac - - # Create $as_me.lineno as a copy of $as_myself, but with $LINENO - # uniformly replaced by the line number. The first 'sed' inserts a - # line-number line before each line; the second 'sed' does the real - # work. The second script uses 'N' to pair each line-number line - # with the numbered line, and appends trailing '-' during - # substitution so that $LINENO is not a special case at line end. - # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the - # second 'sed' script. Blame Lee E. McMahon for sed's syntax. :-) - sed '=' <$as_myself | - sed ' - N - s,$,-, - : loop - s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3, - t loop - s,-$,, - s,^['$as_cr_digits']*\n,, - ' >$as_me.lineno && - chmod +x $as_me.lineno || - { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 - { (exit 1); exit 1; }; } - - # Don't try to exec as it changes $[0], causing all sort of problems - # (the dirname of $[0] is not the place where we might find the - # original and so on. Autoconf is especially sensible to this). - . ./$as_me.lineno - # Exit status is that of the last command. - exit -} - - -case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in - *c*,-n*) ECHO_N= ECHO_C=' -' ECHO_T=' ' ;; - *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; - *) ECHO_N= ECHO_C='\c' ECHO_T= ;; -esac - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -if mkdir -p . 2>/dev/null; then - as_mkdir_p=: -else - as_mkdir_p=false -fi - -as_executable_p="test -f" - -# Sed expression to map a string onto a valid CPP name. -as_tr_cpp="sed y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g" - -# Sed expression to map a string onto a valid variable name. -as_tr_sh="sed y%*+%pp%;s%[^_$as_cr_alnum]%_%g" - - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH - - -# Name of the host. -# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, -# so uname gets run too. -ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` - -exec 6>&1 - -# -# Initializations. -# -ac_default_prefix=/usr/local -ac_config_libobj_dir=. -cross_compiling=no -subdirs= -MFLAGS= -MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} - -# Maximum number of lines to put in a shell here document. -# This variable seems obsolete. It should probably be removed, and -# only ac_max_sed_lines should be used. -: ${ac_max_here_lines=38} - -# Identity of this package. -PACKAGE_NAME='Makefile.am' -PACKAGE_TARNAME='makefile-am' -PACKAGE_VERSION='0.9.3' -PACKAGE_STRING='Makefile.am 0.9.3' -PACKAGE_BUGREPORT='re2c-general@lists.sourceforge.net' - -ac_unique_file="actions.cc" -# Factoring default headers for most tests. -ac_includes_default="\ -#include -#if HAVE_SYS_TYPES_H -# include -#endif -#if HAVE_SYS_STAT_H -# include -#endif -#if STDC_HEADERS -# include -# include -#else -# if HAVE_STDLIB_H -# include -# endif -#endif -#if HAVE_STRING_H -# if !STDC_HEADERS && HAVE_MEMORY_H -# include -# endif -# include -#endif -#if HAVE_STRINGS_H -# include -#endif -#if HAVE_INTTYPES_H -# include -#else -# if HAVE_STDINT_H -# include -# endif -#endif -#if HAVE_UNISTD_H -# include -#endif" - -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO SET_MAKE YACC CXX CXXFLAGS LDFLAGS CPPFLAGS ac_ct_CXX EXEEXT OBJEXT CC CFLAGS ac_ct_CC CPP EGREP LIBOBJS LTLIBOBJS' -ac_subst_files='' - -# Initialize some variables set by options. -ac_init_help= -ac_init_version=false -# The variables have the same names as the options, with -# dashes changed to underlines. -cache_file=/dev/null -exec_prefix=NONE -no_create= -no_recursion= -prefix=NONE -program_prefix=NONE -program_suffix=NONE -program_transform_name=s,x,x, -silent= -site= -srcdir= -verbose= -x_includes=NONE -x_libraries=NONE - -# Installation directory options. -# These are left unexpanded so users can "make install exec_prefix=/foo" -# and all the variables that are supposed to be based on exec_prefix -# by default will actually change. -# Use braces instead of parens because sh, perl, etc. also accept them. -bindir='${exec_prefix}/bin' -sbindir='${exec_prefix}/sbin' -libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' -sysconfdir='${prefix}/etc' -sharedstatedir='${prefix}/com' -localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' -includedir='${prefix}/include' -oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -ac_prev= -for ac_option -do - # If the previous option needs an argument, assign it. - if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" - ac_prev= - continue - fi - - ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` - - # Accept the important Cygnus configure options, so we can diagnose typos. - - case $ac_option in - - -bindir | --bindir | --bindi | --bind | --bin | --bi) - ac_prev=bindir ;; - -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir=$ac_optarg ;; - - -build | --build | --buil | --bui | --bu) - ac_prev=build_alias ;; - -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build_alias=$ac_optarg ;; - - -cache-file | --cache-file | --cache-fil | --cache-fi \ - | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) - ac_prev=cache_file ;; - -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file=$ac_optarg ;; - - --config-cache | -C) - cache_file=config.cache ;; - - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) - ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir=$ac_optarg ;; - - -disable-* | --disable-*) - ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - eval "enable_$ac_feature=no" ;; - - -enable-* | --enable-*) - ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "enable_$ac_feature='$ac_optarg'" ;; - - -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ - | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ - | --exec | --exe | --ex) - ac_prev=exec_prefix ;; - -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ - | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ - | --exec=* | --exe=* | --ex=*) - exec_prefix=$ac_optarg ;; - - -gas | --gas | --ga | --g) - # Obsolete; use --with-gas. - with_gas=yes ;; - - -help | --help | --hel | --he | -h) - ac_init_help=long ;; - -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) - ac_init_help=recursive ;; - -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) - ac_init_help=short ;; - - -host | --host | --hos | --ho) - ac_prev=host_alias ;; - -host=* | --host=* | --hos=* | --ho=*) - host_alias=$ac_optarg ;; - - -includedir | --includedir | --includedi | --included | --include \ - | --includ | --inclu | --incl | --inc) - ac_prev=includedir ;; - -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ - | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir=$ac_optarg ;; - - -infodir | --infodir | --infodi | --infod | --info | --inf) - ac_prev=infodir ;; - -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir=$ac_optarg ;; - - -libdir | --libdir | --libdi | --libd) - ac_prev=libdir ;; - -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir=$ac_optarg ;; - - -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ - | --libexe | --libex | --libe) - ac_prev=libexecdir ;; - -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ - | --libexe=* | --libex=* | --libe=*) - libexecdir=$ac_optarg ;; - - -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) - ac_prev=localstatedir ;; - -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir=$ac_optarg ;; - - -mandir | --mandir | --mandi | --mand | --man | --ma | --m) - ac_prev=mandir ;; - -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir=$ac_optarg ;; - - -nfp | --nfp | --nf) - # Obsolete; use --without-fp. - with_fp=no ;; - - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c | -n) - no_create=yes ;; - - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) - no_recursion=yes ;; - - -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ - | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ - | --oldin | --oldi | --old | --ol | --o) - ac_prev=oldincludedir ;; - -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ - | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ - | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir=$ac_optarg ;; - - -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) - ac_prev=prefix ;; - -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix=$ac_optarg ;; - - -program-prefix | --program-prefix | --program-prefi | --program-pref \ - | --program-pre | --program-pr | --program-p) - ac_prev=program_prefix ;; - -program-prefix=* | --program-prefix=* | --program-prefi=* \ - | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix=$ac_optarg ;; - - -program-suffix | --program-suffix | --program-suffi | --program-suff \ - | --program-suf | --program-su | --program-s) - ac_prev=program_suffix ;; - -program-suffix=* | --program-suffix=* | --program-suffi=* \ - | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix=$ac_optarg ;; - - -program-transform-name | --program-transform-name \ - | --program-transform-nam | --program-transform-na \ - | --program-transform-n | --program-transform- \ - | --program-transform | --program-transfor \ - | --program-transfo | --program-transf \ - | --program-trans | --program-tran \ - | --progr-tra | --program-tr | --program-t) - ac_prev=program_transform_name ;; - -program-transform-name=* | --program-transform-name=* \ - | --program-transform-nam=* | --program-transform-na=* \ - | --program-transform-n=* | --program-transform-=* \ - | --program-transform=* | --program-transfor=* \ - | --program-transfo=* | --program-transf=* \ - | --program-trans=* | --program-tran=* \ - | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name=$ac_optarg ;; - - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - silent=yes ;; - - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) - ac_prev=sbindir ;; - -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ - | --sbi=* | --sb=*) - sbindir=$ac_optarg ;; - - -sharedstatedir | --sharedstatedir | --sharedstatedi \ - | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ - | --sharedst | --shareds | --shared | --share | --shar \ - | --sha | --sh) - ac_prev=sharedstatedir ;; - -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ - | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ - | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ - | --sha=* | --sh=*) - sharedstatedir=$ac_optarg ;; - - -site | --site | --sit) - ac_prev=site ;; - -site=* | --site=* | --sit=*) - site=$ac_optarg ;; - - -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) - ac_prev=srcdir ;; - -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir=$ac_optarg ;; - - -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ - | --syscon | --sysco | --sysc | --sys | --sy) - ac_prev=sysconfdir ;; - -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ - | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir=$ac_optarg ;; - - -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target_alias ;; - -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target_alias=$ac_optarg ;; - - -v | -verbose | --verbose | --verbos | --verbo | --verb) - verbose=yes ;; - - -version | --version | --versio | --versi | --vers | -V) - ac_init_version=: ;; - - -with-* | --with-*) - ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package| sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "with_$ac_package='$ac_optarg'" ;; - - -without-* | --without-*) - ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package | sed 's/-/_/g'` - eval "with_$ac_package=no" ;; - - --x) - # Obsolete; use --with-x. - with_x=yes ;; - - -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ - | --x-incl | --x-inc | --x-in | --x-i) - ac_prev=x_includes ;; - -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ - | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes=$ac_optarg ;; - - -x-libraries | --x-libraries | --x-librarie | --x-librari \ - | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) - ac_prev=x_libraries ;; - -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ - | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries=$ac_optarg ;; - - -*) { echo "$as_me: error: unrecognized option: $ac_option -Try \`$0 --help' for more information." >&2 - { (exit 1); exit 1; }; } - ;; - - *=*) - ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` - # Reject names that are not valid shell variable names. - expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 - { (exit 1); exit 1; }; } - ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` - eval "$ac_envvar='$ac_optarg'" - export $ac_envvar ;; - - *) - # FIXME: should be removed in autoconf 3.0. - echo "$as_me: WARNING: you should use --build, --host, --target" >&2 - expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && - echo "$as_me: WARNING: invalid host type: $ac_option" >&2 - : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} - ;; - - esac -done - -if test -n "$ac_prev"; then - ac_option=--`echo $ac_prev | sed 's/_/-/g'` - { echo "$as_me: error: missing argument to $ac_option" >&2 - { (exit 1); exit 1; }; } -fi - -# Be sure to have absolute paths. -for ac_var in exec_prefix prefix -do - eval ac_val=$`echo $ac_var` - case $ac_val in - [\\/$]* | ?:[\\/]* | NONE | '' ) ;; - *) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 - { (exit 1); exit 1; }; };; - esac -done - -# Be sure to have absolute paths. -for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \ - localstatedir libdir includedir oldincludedir infodir mandir -do - eval ac_val=$`echo $ac_var` - case $ac_val in - [\\/$]* | ?:[\\/]* ) ;; - *) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 - { (exit 1); exit 1; }; };; - esac -done - -# There might be people who depend on the old broken behavior: `$host' -# used to hold the argument of --host etc. -# FIXME: To remove some day. -build=$build_alias -host=$host_alias -target=$target_alias - -# FIXME: To remove some day. -if test "x$host_alias" != x; then - if test "x$build_alias" = x; then - cross_compiling=maybe - echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used." >&2 - elif test "x$build_alias" != "x$host_alias"; then - cross_compiling=yes - fi -fi - -ac_tool_prefix= -test -n "$host_alias" && ac_tool_prefix=$host_alias- - -test "$silent" = yes && exec 6>/dev/null - - -# Find the source files, if location was not specified. -if test -z "$srcdir"; then - ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_confdir=`(dirname "$0") 2>/dev/null || -$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$0" : 'X\(//\)[^/]' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$0" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then - srcdir=.. - fi -else - ac_srcdir_defaulted=no -fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2 - { (exit 1); exit 1; }; } - else - { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 - { (exit 1); exit 1; }; } - fi -fi -(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null || - { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2 - { (exit 1); exit 1; }; } -srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'` -ac_env_build_alias_set=${build_alias+set} -ac_env_build_alias_value=$build_alias -ac_cv_env_build_alias_set=${build_alias+set} -ac_cv_env_build_alias_value=$build_alias -ac_env_host_alias_set=${host_alias+set} -ac_env_host_alias_value=$host_alias -ac_cv_env_host_alias_set=${host_alias+set} -ac_cv_env_host_alias_value=$host_alias -ac_env_target_alias_set=${target_alias+set} -ac_env_target_alias_value=$target_alias -ac_cv_env_target_alias_set=${target_alias+set} -ac_cv_env_target_alias_value=$target_alias -ac_env_CXX_set=${CXX+set} -ac_env_CXX_value=$CXX -ac_cv_env_CXX_set=${CXX+set} -ac_cv_env_CXX_value=$CXX -ac_env_CXXFLAGS_set=${CXXFLAGS+set} -ac_env_CXXFLAGS_value=$CXXFLAGS -ac_cv_env_CXXFLAGS_set=${CXXFLAGS+set} -ac_cv_env_CXXFLAGS_value=$CXXFLAGS -ac_env_LDFLAGS_set=${LDFLAGS+set} -ac_env_LDFLAGS_value=$LDFLAGS -ac_cv_env_LDFLAGS_set=${LDFLAGS+set} -ac_cv_env_LDFLAGS_value=$LDFLAGS -ac_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_env_CPPFLAGS_value=$CPPFLAGS -ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_cv_env_CPPFLAGS_value=$CPPFLAGS -ac_env_CC_set=${CC+set} -ac_env_CC_value=$CC -ac_cv_env_CC_set=${CC+set} -ac_cv_env_CC_value=$CC -ac_env_CFLAGS_set=${CFLAGS+set} -ac_env_CFLAGS_value=$CFLAGS -ac_cv_env_CFLAGS_set=${CFLAGS+set} -ac_cv_env_CFLAGS_value=$CFLAGS -ac_env_CPP_set=${CPP+set} -ac_env_CPP_value=$CPP -ac_cv_env_CPP_set=${CPP+set} -ac_cv_env_CPP_value=$CPP - -# -# Report the --help message. -# -if test "$ac_init_help" = "long"; then - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat <<_ACEOF -\`configure' configures Makefile.am 0.9.3 to adapt to many kinds of systems. - -Usage: $0 [OPTION]... [VAR=VALUE]... - -To assign environment variables (e.g., CC, CFLAGS...), specify them as -VAR=VALUE. See below for descriptions of some of the useful variables. - -Defaults for the options are specified in brackets. - -Configuration: - -h, --help display this help and exit - --help=short display options specific to this package - --help=recursive display the short help of all the included packages - -V, --version display version information and exit - -q, --quiet, --silent do not print \`checking...' messages - --cache-file=FILE cache test results in FILE [disabled] - -C, --config-cache alias for \`--cache-file=config.cache' - -n, --no-create do not create output files - --srcdir=DIR find the sources in DIR [configure dir or \`..'] - -_ACEOF - - cat <<_ACEOF -Installation directories: - --prefix=PREFIX install architecture-independent files in PREFIX - [$ac_default_prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [PREFIX] - -By default, \`make install' will install all the files in -\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify -an installation prefix other than \`$ac_default_prefix' using \`--prefix', -for instance \`--prefix=\$HOME'. - -For better control, use the options below. - -Fine tuning of the installation directories: - --bindir=DIR user executables [EPREFIX/bin] - --sbindir=DIR system admin executables [EPREFIX/sbin] - --libexecdir=DIR program executables [EPREFIX/libexec] - --datadir=DIR read-only architecture-independent data [PREFIX/share] - --sysconfdir=DIR read-only single-machine data [PREFIX/etc] - --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] - --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --libdir=DIR object code libraries [EPREFIX/lib] - --includedir=DIR C header files [PREFIX/include] - --oldincludedir=DIR C header files for non-gcc [/usr/include] - --infodir=DIR info documentation [PREFIX/info] - --mandir=DIR man documentation [PREFIX/man] -_ACEOF - - cat <<\_ACEOF - -Program names: - --program-prefix=PREFIX prepend PREFIX to installed program names - --program-suffix=SUFFIX append SUFFIX to installed program names - --program-transform-name=PROGRAM run sed PROGRAM on installed program names -_ACEOF -fi - -if test -n "$ac_init_help"; then - case $ac_init_help in - short | recursive ) echo "Configuration of Makefile.am 0.9.3:";; - esac - cat <<\_ACEOF - -Some influential environment variables: - CXX C++ compiler command - CXXFLAGS C++ compiler flags - LDFLAGS linker flags, e.g. -L if you have libraries in a - nonstandard directory - CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have - headers in a nonstandard directory - CC C compiler command - CFLAGS C compiler flags - CPP C preprocessor - -Use these variables to override the choices made by `configure' or to help -it to find libraries and programs with nonstandard names/locations. - -Report bugs to . -_ACEOF -fi - -if test "$ac_init_help" = "recursive"; then - # If there are subdirs, report their specific --help. - ac_popdir=`pwd` - for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue - test -d $ac_dir || continue - ac_builddir=. - -if test "$ac_dir" != .; then - ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` - # A "../" for each directory in $ac_dir_suffix. - ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'` -else - ac_dir_suffix= ac_top_builddir= -fi - -case $srcdir in - .) # No --srcdir option. We are building in place. - ac_srcdir=. - if test -z "$ac_top_builddir"; then - ac_top_srcdir=. - else - ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'` - fi ;; - [\\/]* | ?:[\\/]* ) # Absolute path. - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir ;; - *) # Relative path. - ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_top_builddir$srcdir ;; -esac -# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be -# absolute. -ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` -ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` -ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` -ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` - - cd $ac_dir - # Check for guested configure; otherwise get Cygnus style configure. - if test -f $ac_srcdir/configure.gnu; then - echo - $SHELL $ac_srcdir/configure.gnu --help=recursive - elif test -f $ac_srcdir/configure; then - echo - $SHELL $ac_srcdir/configure --help=recursive - elif test -f $ac_srcdir/configure.ac || - test -f $ac_srcdir/configure.in; then - echo - $ac_configure --help - else - echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 - fi - cd $ac_popdir - done -fi - -test -n "$ac_init_help" && exit 0 -if $ac_init_version; then - cat <<\_ACEOF -Makefile.am configure 0.9.3 -generated by GNU Autoconf 2.57 - -Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002 -Free Software Foundation, Inc. -This configure script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it. -_ACEOF - exit 0 -fi -exec 5>config.log -cat >&5 <<_ACEOF -This file contains any messages produced by compilers while -running configure, to aid debugging if configure makes a mistake. - -It was created by Makefile.am $as_me 0.9.3, which was -generated by GNU Autoconf 2.57. Invocation command line was - - $ $0 $@ - -_ACEOF -{ -cat <<_ASUNAME -## --------- ## -## Platform. ## -## --------- ## - -hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` - -/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` -hostinfo = `(hostinfo) 2>/dev/null || echo unknown` -/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` -/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` - -_ASUNAME - -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - echo "PATH: $as_dir" -done - -} >&5 - -cat >&5 <<_ACEOF - - -## ----------- ## -## Core tests. ## -## ----------- ## - -_ACEOF - - -# Keep a trace of the command line. -# Strip out --no-create and --no-recursion so they do not pile up. -# Strip out --silent because we don't want to record it for future runs. -# Also quote any args containing shell meta-characters. -# Make two passes to allow for proper duplicate-argument suppression. -ac_configure_args= -ac_configure_args0= -ac_configure_args1= -ac_sep= -ac_must_keep_next=false -for ac_pass in 1 2 -do - for ac_arg - do - case $ac_arg in - -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - continue ;; - *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*) - ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; - esac - case $ac_pass in - 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; - 2) - ac_configure_args1="$ac_configure_args1 '$ac_arg'" - if test $ac_must_keep_next = true; then - ac_must_keep_next=false # Got value, back to normal. - else - case $ac_arg in - *=* | --config-cache | -C | -disable-* | --disable-* \ - | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ - | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ - | -with-* | --with-* | -without-* | --without-* | --x) - case "$ac_configure_args0 " in - "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; - esac - ;; - -* ) ac_must_keep_next=true ;; - esac - fi - ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'" - # Get rid of the leading space. - ac_sep=" " - ;; - esac - done -done -$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } -$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } - -# When interrupted or exit'd, cleanup temporary files, and complete -# config.log. We remove comments because anyway the quotes in there -# would cause problems or look ugly. -# WARNING: Be sure not to use single quotes in there, as some shells, -# such as our DU 5.0 friend, will then `close' the trap. -trap 'exit_status=$? - # Save into config.log some information that might help in debugging. - { - echo - - cat <<\_ASBOX -## ---------------- ## -## Cache variables. ## -## ---------------- ## -_ASBOX - echo - # The following way of writing the cache mishandles newlines in values, -{ - (set) 2>&1 | - case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in - *ac_space=\ *) - sed -n \ - "s/'"'"'/'"'"'\\\\'"'"''"'"'/g; - s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p" - ;; - *) - sed -n \ - "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} - echo - - cat <<\_ASBOX -## ----------------- ## -## Output variables. ## -## ----------------- ## -_ASBOX - echo - for ac_var in $ac_subst_vars - do - eval ac_val=$`echo $ac_var` - echo "$ac_var='"'"'$ac_val'"'"'" - done | sort - echo - - if test -n "$ac_subst_files"; then - cat <<\_ASBOX -## ------------- ## -## Output files. ## -## ------------- ## -_ASBOX - echo - for ac_var in $ac_subst_files - do - eval ac_val=$`echo $ac_var` - echo "$ac_var='"'"'$ac_val'"'"'" - done | sort - echo - fi - - if test -s confdefs.h; then - cat <<\_ASBOX -## ----------- ## -## confdefs.h. ## -## ----------- ## -_ASBOX - echo - sed "/^$/d" confdefs.h | sort - echo - fi - test "$ac_signal" != 0 && - echo "$as_me: caught signal $ac_signal" - echo "$as_me: exit $exit_status" - } >&5 - rm -f core core.* *.core && - rm -rf conftest* confdefs* conf$$* $ac_clean_files && - exit $exit_status - ' 0 -for ac_signal in 1 2 13 15; do - trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal -done -ac_signal=0 - -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo >confdefs.h - -# Predefined preprocessor variables. - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_NAME "$PACKAGE_NAME" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_TARNAME "$PACKAGE_TARNAME" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_VERSION "$PACKAGE_VERSION" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_STRING "$PACKAGE_STRING" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" -_ACEOF - - -# Let the site file select an alternate cache file if it wants to. -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi -fi -for ac_site_file in $CONFIG_SITE; do - if test -r "$ac_site_file"; then - { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 -echo "$as_me: loading site script $ac_site_file" >&6;} - sed 's/^/| /' "$ac_site_file" >&5 - . "$ac_site_file" - fi -done - -if test -r "$cache_file"; then - # Some versions of bash will fail to source /dev/null (special - # files actually), so we avoid doing that. - if test -f "$cache_file"; then - { echo "$as_me:$LINENO: loading cache $cache_file" >&5 -echo "$as_me: loading cache $cache_file" >&6;} - case $cache_file in - [\\/]* | ?:[\\/]* ) . $cache_file;; - *) . ./$cache_file;; - esac - fi -else - { echo "$as_me:$LINENO: creating cache $cache_file" >&5 -echo "$as_me: creating cache $cache_file" >&6;} - >$cache_file -fi - -# Check that the precious variables saved in the cache have kept the same -# value. -ac_cache_corrupted=false -for ac_var in `(set) 2>&1 | - sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do - eval ac_old_set=\$ac_cv_env_${ac_var}_set - eval ac_new_set=\$ac_env_${ac_var}_set - eval ac_old_val="\$ac_cv_env_${ac_var}_value" - eval ac_new_val="\$ac_env_${ac_var}_value" - case $ac_old_set,$ac_new_set in - set,) - { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} - ac_cache_corrupted=: ;; - ,set) - { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 -echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} - ac_cache_corrupted=: ;; - ,);; - *) - if test "x$ac_old_val" != "x$ac_new_val"; then - { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 -echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} - { echo "$as_me:$LINENO: former value: $ac_old_val" >&5 -echo "$as_me: former value: $ac_old_val" >&2;} - { echo "$as_me:$LINENO: current value: $ac_new_val" >&5 -echo "$as_me: current value: $ac_new_val" >&2;} - ac_cache_corrupted=: - fi;; - esac - # Pass precious variables to config.status. - if test "$ac_new_set" = set; then - case $ac_new_val in - *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*) - ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; - *) ac_arg=$ac_var=$ac_new_val ;; - esac - case " $ac_configure_args " in - *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. - *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; - esac - fi -done -if $ac_cache_corrupted; then - { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 -echo "$as_me: error: changes in the environment can compromise the build" >&2;} - { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 -echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - - - - - - - - - - - - - - - - - - - - - - - - - - -am__api_version="1.4" -ac_aux_dir= -for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do - if test -f $ac_dir/install-sh; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install-sh -c" - break - elif test -f $ac_dir/install.sh; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install.sh -c" - break - elif test -f $ac_dir/shtool; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/shtool install -c" - break - fi -done -if test -z "$ac_aux_dir"; then - { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5 -echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;} - { (exit 1); exit 1; }; } -fi -ac_config_guess="$SHELL $ac_aux_dir/config.guess" -ac_config_sub="$SHELL $ac_aux_dir/config.sub" -ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure. - -# Find a good install program. We prefer a C program (faster), -# so one script is as good as another. But avoid the broken or -# incompatible versions: -# SysV /etc/install, /usr/sbin/install -# SunOS /usr/etc/install -# IRIX /sbin/install -# AIX /bin/install -# AmigaOS /C/install, which installs bootblocks on floppy discs -# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag -# AFS /usr/afsws/bin/install, which mishandles nonexistent args -# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" -# ./install, which can be erroneously created by make from ./install.sh. -echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5 -echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6 -if test -z "$INSTALL"; then -if test "${ac_cv_path_install+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - # Account for people who put trailing slashes in PATH elements. -case $as_dir/ in - ./ | .// | /cC/* | \ - /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ - /usr/ucb/* ) ;; - *) - # OSF1 and SCO ODT 3.0 have their own names for install. - # Don't use installbsd from OSF since it installs stuff as root - # by default. - for ac_prog in ginstall scoinst install; do - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then - if test $ac_prog = install && - grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - elif test $ac_prog = install && - grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # program-specific install script used by HP pwplus--don't use. - : - else - ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" - break 3 - fi - fi - done - done - ;; -esac -done - - -fi - if test "${ac_cv_path_install+set}" = set; then - INSTALL=$ac_cv_path_install - else - # As a last resort, use the slow shell script. We don't cache a - # path for INSTALL within a source directory, because that will - # break other packages using the cache if that directory is - # removed, or if the path is relative. - INSTALL=$ac_install_sh - fi -fi -echo "$as_me:$LINENO: result: $INSTALL" >&5 -echo "${ECHO_T}$INSTALL" >&6 - -# Use test -z because SunOS4 sh mishandles braces in ${var-val}. -# It thinks the first close brace ends the variable substitution. -test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' - -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' - -test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' - -echo "$as_me:$LINENO: checking whether build environment is sane" >&5 -echo $ECHO_N "checking whether build environment is sane... $ECHO_C" >&6 -# Just in case -sleep 1 -echo timestamp > conftestfile -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` - if test "$*" = "X"; then - # -L didn't work. - set X `ls -t $srcdir/configure conftestfile` - fi - if test "$*" != "X $srcdir/configure conftestfile" \ - && test "$*" != "X conftestfile $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - { { echo "$as_me:$LINENO: error: ls -t appears to fail. Make sure there is not a broken -alias in your environment" >&5 -echo "$as_me: error: ls -t appears to fail. Make sure there is not a broken -alias in your environment" >&2;} - { (exit 1); exit 1; }; } - fi - - test "$2" = conftestfile - ) -then - # Ok. - : -else - { { echo "$as_me:$LINENO: error: newly created file is older than distributed files! -Check your system clock" >&5 -echo "$as_me: error: newly created file is older than distributed files! -Check your system clock" >&2;} - { (exit 1); exit 1; }; } -fi -rm -f conftest* -echo "$as_me:$LINENO: result: yes" >&5 -echo "${ECHO_T}yes" >&6 -test "$program_prefix" != NONE && - program_transform_name="s,^,$program_prefix,;$program_transform_name" -# Use a double $ so make ignores it. -test "$program_suffix" != NONE && - program_transform_name="s,\$,$program_suffix,;$program_transform_name" -# Double any \ or $. echo might interpret backslashes. -# By default was `s,x,x', remove it if useless. -cat <<\_ACEOF >conftest.sed -s/[\\$]/&&/g;s/;s,x,x,$// -_ACEOF -program_transform_name=`echo $program_transform_name | sed -f conftest.sed` -rm conftest.sed - -echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5 -echo $ECHO_N "checking whether ${MAKE-make} sets \$(MAKE)... $ECHO_C" >&6 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,./+-,__p_,'` -if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.make <<\_ACEOF -all: - @echo 'ac_maketemp="$(MAKE)"' -_ACEOF -# GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no -fi -rm -f conftest.make -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$as_me:$LINENO: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - SET_MAKE= -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 - SET_MAKE="MAKE=${MAKE-make}" -fi - - -PACKAGE=re2c - -VERSION=$PACKAGE_VERSION - -if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then - { { echo "$as_me:$LINENO: error: source directory already configured; run \"make distclean\" there first" >&5 -echo "$as_me: error: source directory already configured; run \"make distclean\" there first" >&2;} - { (exit 1); exit 1; }; } -fi - -cat >>confdefs.h <<_ACEOF -#define PACKAGE "$PACKAGE" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define VERSION "$VERSION" -_ACEOF - - - -missing_dir=`cd $ac_aux_dir && pwd` -echo "$as_me:$LINENO: checking for working aclocal-${am__api_version}" >&5 -echo $ECHO_N "checking for working aclocal-${am__api_version}... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (aclocal-${am__api_version} --version) < /dev/null > /dev/null 2>&1; then - ACLOCAL=aclocal-${am__api_version} - echo "$as_me:$LINENO: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - ACLOCAL="$missing_dir/missing aclocal-${am__api_version}" - echo "$as_me:$LINENO: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:$LINENO: checking for working autoconf" >&5 -echo $ECHO_N "checking for working autoconf... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (autoconf --version) < /dev/null > /dev/null 2>&1; then - AUTOCONF=autoconf - echo "$as_me:$LINENO: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOCONF="$missing_dir/missing autoconf" - echo "$as_me:$LINENO: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:$LINENO: checking for working automake-${am__api_version}" >&5 -echo $ECHO_N "checking for working automake-${am__api_version}... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (automake-${am__api_version} --version) < /dev/null > /dev/null 2>&1; then - AUTOMAKE=automake-${am__api_version} - echo "$as_me:$LINENO: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOMAKE="$missing_dir/missing automake-${am__api_version}" - echo "$as_me:$LINENO: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:$LINENO: checking for working autoheader" >&5 -echo $ECHO_N "checking for working autoheader... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (autoheader --version) < /dev/null > /dev/null 2>&1; then - AUTOHEADER=autoheader - echo "$as_me:$LINENO: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOHEADER="$missing_dir/missing autoheader" - echo "$as_me:$LINENO: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:$LINENO: checking for working makeinfo" >&5 -echo $ECHO_N "checking for working makeinfo... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (makeinfo --version) < /dev/null > /dev/null 2>&1; then - MAKEINFO=makeinfo - echo "$as_me:$LINENO: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - MAKEINFO="$missing_dir/missing makeinfo" - echo "$as_me:$LINENO: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - - - - - ac_config_headers="$ac_config_headers config.h" - - ac_config_commands="$ac_config_commands default-1" - - - - - - -# Checks for programs. -for ac_prog in 'bison -y' byacc -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_YACC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$YACC"; then - ac_cv_prog_YACC="$YACC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_YACC="$ac_prog" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -YACC=$ac_cv_prog_YACC -if test -n "$YACC"; then - echo "$as_me:$LINENO: result: $YACC" >&5 -echo "${ECHO_T}$YACC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$YACC" && break -done -test -n "$YACC" || YACC="yacc" - -ac_ext=cc -ac_cpp='$CXXCPP $CPPFLAGS' -ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_cxx_compiler_gnu -if test -n "$ac_tool_prefix"; then - for ac_prog in $CCC g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CXX+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CXX"; then - ac_cv_prog_CXX="$CXX" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -CXX=$ac_cv_prog_CXX -if test -n "$CXX"; then - echo "$as_me:$LINENO: result: $CXX" >&5 -echo "${ECHO_T}$CXX" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$CXX" && break - done -fi -if test -z "$CXX"; then - ac_ct_CXX=$CXX - for ac_prog in $CCC g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CXX"; then - ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_CXX="$ac_prog" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -ac_ct_CXX=$ac_cv_prog_ac_ct_CXX -if test -n "$ac_ct_CXX"; then - echo "$as_me:$LINENO: result: $ac_ct_CXX" >&5 -echo "${ECHO_T}$ac_ct_CXX" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$ac_ct_CXX" && break -done -test -n "$ac_ct_CXX" || ac_ct_CXX="g++" - - CXX=$ac_ct_CXX -fi - - -# Provide some information about the compiler. -echo "$as_me:$LINENO:" \ - "checking for C++ compiler version" >&5 -ac_compiler=`set X $ac_compile; echo $2` -{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 - (eval $ac_compiler --version &5) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } -{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v &5\"") >&5 - (eval $ac_compiler -v &5) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } -{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V &5\"") >&5 - (eval $ac_compiler -V &5) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } - -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files a.out a.exe b.out" -# Try to create an executable without -o first, disregard a.out. -# It will help us diagnose broken compilers, and finding out an intuition -# of exeext. -echo "$as_me:$LINENO: checking for C++ compiler default output" >&5 -echo $ECHO_N "checking for C++ compiler default output... $ECHO_C" >&6 -ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` -if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5 - (eval $ac_link_default) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; then - # Find the output, starting from the most likely. This scheme is -# not robust to junk in `.', hence go to wildcards (a.*) only as a last -# resort. - -# Be careful to initialize this variable, since it used to be cached. -# Otherwise an old cache value of `no' led to `EXEEXT = no' in a Makefile. -ac_cv_exeext= -# b.out is created by i960 compilers. -for ac_file in a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out -do - test -f "$ac_file" || continue - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) - ;; - conftest.$ac_ext ) - # This is the source file. - ;; - [ab].out ) - # We found the default executable, but exeext='' is most - # certainly right. - break;; - *.* ) - ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - # FIXME: I believe we export ac_cv_exeext for Libtool, - # but it would be cool to find out if it's true. Does anybody - # maintain Libtool? --akim. - export ac_cv_exeext - break;; - * ) - break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -{ { echo "$as_me:$LINENO: error: C++ compiler cannot create executables -See \`config.log' for more details." >&5 -echo "$as_me: error: C++ compiler cannot create executables -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; } -fi - -ac_exeext=$ac_cv_exeext -echo "$as_me:$LINENO: result: $ac_file" >&5 -echo "${ECHO_T}$ac_file" >&6 - -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:$LINENO: checking whether the C++ compiler works" >&5 -echo $ECHO_N "checking whether the C++ compiler works... $ECHO_C" >&6 -# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 -# If not cross compiling, check that we can run a simple program. -if test "$cross_compiling" != yes; then - if { ac_try='./$ac_file' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - cross_compiling=no - else - if test "$cross_compiling" = maybe; then - cross_compiling=yes - else - { { echo "$as_me:$LINENO: error: cannot run C++ compiled programs. -If you meant to cross compile, use \`--host'. -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run C++ compiled programs. -If you meant to cross compile, use \`--host'. -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } - fi - fi -fi -echo "$as_me:$LINENO: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - -rm -f a.out a.exe conftest$ac_cv_exeext b.out -ac_clean_files=$ac_clean_files_save -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:$LINENO: checking whether we are cross compiling" >&5 -echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6 -echo "$as_me:$LINENO: result: $cross_compiling" >&5 -echo "${ECHO_T}$cross_compiling" >&6 - -echo "$as_me:$LINENO: checking for suffix of executables" >&5 -echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6 -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; then - # If both `conftest.exe' and `conftest' are `present' (well, observable) -# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will -# work properly (i.e., refer to `conftest.exe'), while it won't with -# `rm'. -for ac_file in conftest.exe conftest conftest.*; do - test -f "$ac_file" || continue - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - export ac_cv_exeext - break;; - * ) break;; - esac -done -else - { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest$ac_cv_exeext -echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5 -echo "${ECHO_T}$ac_cv_exeext" >&6 - -rm -f conftest.$ac_ext -EXEEXT=$ac_cv_exeext -ac_exeext=$EXEEXT -echo "$as_me:$LINENO: checking for suffix of object files" >&5 -echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6 -if test "${ac_cv_objext+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.o conftest.obj -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg ) ;; - *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` - break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute suffix of object files: cannot compile -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest.$ac_cv_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_objext" >&5 -echo "${ECHO_T}$ac_cv_objext" >&6 -OBJEXT=$ac_cv_objext -ac_objext=$OBJEXT -echo "$as_me:$LINENO: checking whether we are using the GNU C++ compiler" >&5 -echo $ECHO_N "checking whether we are using the GNU C++ compiler... $ECHO_C" >&6 -if test "${ac_cv_cxx_compiler_gnu+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ -#ifndef __GNUC__ - choke me -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_compiler_gnu=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_compiler_gnu=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_cv_cxx_compiler_gnu=$ac_compiler_gnu - -fi -echo "$as_me:$LINENO: result: $ac_cv_cxx_compiler_gnu" >&5 -echo "${ECHO_T}$ac_cv_cxx_compiler_gnu" >&6 -GXX=`test $ac_compiler_gnu = yes && echo yes` -ac_test_CXXFLAGS=${CXXFLAGS+set} -ac_save_CXXFLAGS=$CXXFLAGS -CXXFLAGS="-g" -echo "$as_me:$LINENO: checking whether $CXX accepts -g" >&5 -echo $ECHO_N "checking whether $CXX accepts -g... $ECHO_C" >&6 -if test "${ac_cv_prog_cxx_g+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cxx_g=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_prog_cxx_g=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_prog_cxx_g" >&5 -echo "${ECHO_T}$ac_cv_prog_cxx_g" >&6 -if test "$ac_test_CXXFLAGS" = set; then - CXXFLAGS=$ac_save_CXXFLAGS -elif test $ac_cv_prog_cxx_g = yes; then - if test "$GXX" = yes; then - CXXFLAGS="-g -O2" - else - CXXFLAGS="-g" - fi -else - if test "$GXX" = yes; then - CXXFLAGS="-O2" - else - CXXFLAGS= - fi -fi -for ac_declaration in \ - ''\ - '#include ' \ - 'extern "C" void std::exit (int) throw (); using std::exit;' \ - 'extern "C" void std::exit (int); using std::exit;' \ - 'extern "C" void exit (int) throw ();' \ - 'extern "C" void exit (int);' \ - 'void exit (int);' -do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -continue -fi -rm -f conftest.$ac_objext conftest.$ac_ext - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -rm -f conftest* -if test -n "$ac_declaration"; then - echo '#ifdef __cplusplus' >>confdefs.h - echo $ac_declaration >>confdefs.h - echo '#endif' >>confdefs.h -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. -set dummy ${ac_tool_prefix}gcc; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_CC="${ac_tool_prefix}gcc" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:$LINENO: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_CC="gcc" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. -set dummy ${ac_tool_prefix}cc; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_CC="${ac_tool_prefix}cc" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:$LINENO: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_CC="cc" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -fi -if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_prog_rejected=no -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue - fi - ac_cv_prog_CC="cc" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -if test $ac_prog_rejected = yes; then - # We found a bogon in the path, so make sure we never use it. - set dummy $ac_cv_prog_CC - shift - if test $# != 0; then - # We chose a different compiler from the bogus one. - # However, it has the same basename, so the bogon will be chosen - # first if we set CC to just the basename; use the full file name. - shift - ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" - fi -fi -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:$LINENO: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - for ac_prog in cl - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_CC="$ac_tool_prefix$ac_prog" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:$LINENO: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$CC" && break - done -fi -if test -z "$CC"; then - ac_ct_CC=$CC - for ac_prog in cl -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_CC="$ac_prog" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$ac_ct_CC" && break -done - - CC=$ac_ct_CC -fi - -fi - - -test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH -See \`config.log' for more details." >&5 -echo "$as_me: error: no acceptable C compiler found in \$PATH -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } - -# Provide some information about the compiler. -echo "$as_me:$LINENO:" \ - "checking for C compiler version" >&5 -ac_compiler=`set X $ac_compile; echo $2` -{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 - (eval $ac_compiler --version &5) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } -{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v &5\"") >&5 - (eval $ac_compiler -v &5) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } -{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V &5\"") >&5 - (eval $ac_compiler -V &5) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } - -echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5 -echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6 -if test "${ac_cv_c_compiler_gnu+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ -#ifndef __GNUC__ - choke me -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_compiler_gnu=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_compiler_gnu=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_cv_c_compiler_gnu=$ac_compiler_gnu - -fi -echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5 -echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6 -GCC=`test $ac_compiler_gnu = yes && echo yes` -ac_test_CFLAGS=${CFLAGS+set} -ac_save_CFLAGS=$CFLAGS -CFLAGS="-g" -echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 -echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_g+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_g=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_prog_cc_g=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_g" >&6 -if test "$ac_test_CFLAGS" = set; then - CFLAGS=$ac_save_CFLAGS -elif test $ac_cv_prog_cc_g = yes; then - if test "$GCC" = yes; then - CFLAGS="-g -O2" - else - CFLAGS="-g" - fi -else - if test "$GCC" = yes; then - CFLAGS="-O2" - else - CFLAGS= - fi -fi -echo "$as_me:$LINENO: checking for $CC option to accept ANSI C" >&5 -echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_prog_cc_stdc=no -ac_save_CC=$CC -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -int -main () -{ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - ; - return 0; -} -_ACEOF -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX 10.20 and later -Ae -# HP-UX older versions -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_stdc=$ac_arg -break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -fi -rm -f conftest.$ac_objext -done -rm -f conftest.$ac_ext conftest.$ac_objext -CC=$ac_save_CC - -fi - -case "x$ac_cv_prog_cc_stdc" in - x|xno) - echo "$as_me:$LINENO: result: none needed" >&5 -echo "${ECHO_T}none needed" >&6 ;; - *) - echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6 - CC="$CC $ac_cv_prog_cc_stdc" ;; -esac - -# Some people use a C++ compiler to compile C. Since we use `exit', -# in C++ we need to declare it. In case someone uses the same compiler -# for both compiling C and C++ we need to have the C++ compiler decide -# the declaration of exit, since it's the most demanding environment. -cat >conftest.$ac_ext <<_ACEOF -#ifndef __cplusplus - choke me -#endif -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - for ac_declaration in \ - ''\ - '#include ' \ - 'extern "C" void std::exit (int) throw (); using std::exit;' \ - 'extern "C" void std::exit (int); using std::exit;' \ - 'extern "C" void exit (int) throw ();' \ - 'extern "C" void exit (int);' \ - 'void exit (int);' -do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -continue -fi -rm -f conftest.$ac_objext conftest.$ac_ext - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -rm -f conftest* -if test -n "$ac_declaration"; then - echo '#ifdef __cplusplus' >>confdefs.h - echo $ac_declaration >>confdefs.h - echo '#endif' >>confdefs.h -fi - -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -# Find a good install program. We prefer a C program (faster), -# so one script is as good as another. But avoid the broken or -# incompatible versions: -# SysV /etc/install, /usr/sbin/install -# SunOS /usr/etc/install -# IRIX /sbin/install -# AIX /bin/install -# AmigaOS /C/install, which installs bootblocks on floppy discs -# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag -# AFS /usr/afsws/bin/install, which mishandles nonexistent args -# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" -# ./install, which can be erroneously created by make from ./install.sh. -echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5 -echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6 -if test -z "$INSTALL"; then -if test "${ac_cv_path_install+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - # Account for people who put trailing slashes in PATH elements. -case $as_dir/ in - ./ | .// | /cC/* | \ - /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ - /usr/ucb/* ) ;; - *) - # OSF1 and SCO ODT 3.0 have their own names for install. - # Don't use installbsd from OSF since it installs stuff as root - # by default. - for ac_prog in ginstall scoinst install; do - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then - if test $ac_prog = install && - grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - elif test $ac_prog = install && - grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # program-specific install script used by HP pwplus--don't use. - : - else - ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" - break 3 - fi - fi - done - done - ;; -esac -done - - -fi - if test "${ac_cv_path_install+set}" = set; then - INSTALL=$ac_cv_path_install - else - # As a last resort, use the slow shell script. We don't cache a - # path for INSTALL within a source directory, because that will - # break other packages using the cache if that directory is - # removed, or if the path is relative. - INSTALL=$ac_install_sh - fi -fi -echo "$as_me:$LINENO: result: $INSTALL" >&5 -echo "${ECHO_T}$INSTALL" >&6 - -# Use test -z because SunOS4 sh mishandles braces in ${var-val}. -# It thinks the first close brace ends the variable substitution. -test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' - -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' - -test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' - - -# Checks for libraries. - -# Checks for header files. - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 -echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6 -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if test "${ac_cv_prog_CPP+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - break -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -echo "$as_me:$LINENO: result: $CPP" >&5 -echo "${ECHO_T}$CPP" >&6 -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - : -else - { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details." >&5 -echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - -echo "$as_me:$LINENO: checking for egrep" >&5 -echo $ECHO_N "checking for egrep... $ECHO_C" >&6 -if test "${ac_cv_prog_egrep+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if echo a | (grep -E '(a|b)') >/dev/null 2>&1 - then ac_cv_prog_egrep='grep -E' - else ac_cv_prog_egrep='egrep' - fi -fi -echo "$as_me:$LINENO: result: $ac_cv_prog_egrep" >&5 -echo "${ECHO_T}$ac_cv_prog_egrep" >&6 - EGREP=$ac_cv_prog_egrep - - -echo "$as_me:$LINENO: checking for ANSI C header files" >&5 -echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 -if test "${ac_cv_header_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#include -#include - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_header_stdc=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_header_stdc=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "memchr" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "free" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) \ - (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - exit(2); - exit (0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -ac_cv_header_stdc=no -fi -rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5 -echo "${ECHO_T}$ac_cv_header_stdc" >&6 -if test $ac_cv_header_stdc = yes; then - -cat >>confdefs.h <<\_ACEOF -#define STDC_HEADERS 1 -_ACEOF - -fi - - -# We only rely on standard C/C++ headers. If we ever have a pressing need -# for something non-standard, we should add a check for it here. -# AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) - -# Checks for typedefs, structures, and compiler characteristics. -# On IRIX 5.3, sys/types and inttypes.h are conflicting. - - - - - - - - - -for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ - inttypes.h stdint.h unistd.h -do -as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` -echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default - -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$as_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -eval "$as_ac_Header=no" -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 -if test `eval echo '${'$as_ac_Header'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -echo "$as_me:$LINENO: checking for stdbool.h that conforms to C99" >&5 -echo $ECHO_N "checking for stdbool.h that conforms to C99... $ECHO_C" >&6 -if test "${ac_cv_header_stdbool_h+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#ifndef bool -# error bool is not defined -#endif -#ifndef false -# error false is not defined -#endif -#if false -# error false is not 0 -#endif -#ifndef true -# error true is not defined -#endif -#if true != 1 -# error true is not 1 -#endif -#ifndef __bool_true_false_are_defined -# error __bool_true_false_are_defined is not defined -#endif - - struct s { _Bool s: 1; _Bool t; } s; - - char a[true == 1 ? 1 : -1]; - char b[false == 0 ? 1 : -1]; - char c[__bool_true_false_are_defined == 1 ? 1 : -1]; - char d[(bool) -0.5 == true ? 1 : -1]; - bool e = &s; - char f[(_Bool) -0.0 == false ? 1 : -1]; - char g[true]; - char h[sizeof (_Bool)]; - char i[sizeof s.t]; - -int -main () -{ - return !a + !b + !c + !d + !e + !f + !g + !h + !i; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_header_stdbool_h=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_header_stdbool_h=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_header_stdbool_h" >&5 -echo "${ECHO_T}$ac_cv_header_stdbool_h" >&6 -echo "$as_me:$LINENO: checking for _Bool" >&5 -echo $ECHO_N "checking for _Bool... $ECHO_C" >&6 -if test "${ac_cv_type__Bool+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((_Bool *) 0) - return 0; -if (sizeof (_Bool)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type__Bool=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type__Bool=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type__Bool" >&5 -echo "${ECHO_T}$ac_cv_type__Bool" >&6 -if test $ac_cv_type__Bool = yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE__BOOL 1 -_ACEOF - - -fi - -if test $ac_cv_header_stdbool_h = yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_STDBOOL_H 1 -_ACEOF - -fi - -echo "$as_me:$LINENO: checking for an ANSI C-conforming const" >&5 -echo $ECHO_N "checking for an ANSI C-conforming const... $ECHO_C" >&6 -if test "${ac_cv_c_const+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ -/* FIXME: Include the comments suggested by Paul. */ -#ifndef __cplusplus - /* Ultrix mips cc rejects this. */ - typedef int charset[2]; - const charset x; - /* SunOS 4.1.1 cc rejects this. */ - char const *const *ccp; - char **p; - /* NEC SVR4.0.2 mips cc rejects this. */ - struct point {int x, y;}; - static struct point const zero = {0,0}; - /* AIX XL C 1.02.0.0 rejects this. - It does not let you subtract one const X* pointer from another in - an arm of an if-expression whose if-part is not a constant - expression */ - const char *g = "string"; - ccp = &g + (g ? g-g : 0); - /* HPUX 7.0 cc rejects these. */ - ++ccp; - p = (char**) ccp; - ccp = (char const *const *) p; - { /* SCO 3.2v4 cc rejects this. */ - char *t; - char const *s = 0 ? (char *) 0 : (char const *) 0; - - *t++ = 0; - } - { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ - int x[] = {25, 17}; - const int *foo = &x[0]; - ++foo; - } - { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ - typedef const int *iptr; - iptr p = 0; - ++p; - } - { /* AIX XL C 1.02.0.0 rejects this saying - "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ - struct s { int j; const int *ap[3]; }; - struct s *b; b->j = 5; - } - { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ - const int foo = 10; - } -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_const=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_c_const=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_c_const" >&5 -echo "${ECHO_T}$ac_cv_c_const" >&6 -if test $ac_cv_c_const = no; then - -cat >>confdefs.h <<\_ACEOF -#define const -_ACEOF - -fi - -echo "$as_me:$LINENO: checking for inline" >&5 -echo $ECHO_N "checking for inline... $ECHO_C" >&6 -if test "${ac_cv_c_inline+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_c_inline=no -for ac_kw in inline __inline__ __inline; do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifndef __cplusplus -typedef int foo_t; -static $ac_kw foo_t static_foo () {return 0; } -$ac_kw foo_t foo () {return 0; } -#endif - -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_inline=$ac_kw; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done - -fi -echo "$as_me:$LINENO: result: $ac_cv_c_inline" >&5 -echo "${ECHO_T}$ac_cv_c_inline" >&6 -case $ac_cv_c_inline in - inline | yes) ;; - no) -cat >>confdefs.h <<\_ACEOF -#define inline -_ACEOF - ;; - *) cat >>confdefs.h <<_ACEOF -#define inline $ac_cv_c_inline -_ACEOF - ;; -esac - -echo "$as_me:$LINENO: checking for size_t" >&5 -echo $ECHO_N "checking for size_t... $ECHO_C" >&6 -if test "${ac_cv_type_size_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((size_t *) 0) - return 0; -if (sizeof (size_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_size_t=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_size_t=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_size_t" >&5 -echo "${ECHO_T}$ac_cv_type_size_t" >&6 -if test $ac_cv_type_size_t = yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define size_t unsigned -_ACEOF - -fi - -echo "$as_me:$LINENO: checking for working volatile" >&5 -echo $ECHO_N "checking for working volatile... $ECHO_C" >&6 -if test "${ac_cv_c_volatile+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - -volatile int x; -int * volatile y; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_volatile=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_c_volatile=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_c_volatile" >&5 -echo "${ECHO_T}$ac_cv_c_volatile" >&6 -if test $ac_cv_c_volatile = no; then - -cat >>confdefs.h <<\_ACEOF -#define volatile -_ACEOF - -fi - - -# Checks for library functions. - -for ac_header in stdlib.h -do -as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 -else - # Is the header compilable? -echo "$as_me:$LINENO: checking $ac_header usability" >&5 -echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_header_compiler=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_header_compiler=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -echo "${ECHO_T}$ac_header_compiler" >&6 - -# Is the header present? -echo "$as_me:$LINENO: checking $ac_header presence" >&5 -echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_header_preproc=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi -rm -f conftest.err conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -echo "${ECHO_T}$ac_header_preproc" >&6 - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc in - yes:no ) - { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - ( - cat <<\_ASBOX -## ------------------------------------ ## -## Report this to bug-autoconf@gnu.org. ## -## ------------------------------------ ## -_ASBOX - ) | - sed "s/^/$as_me: WARNING: /" >&2 - ;; - no:yes ) - { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - ( - cat <<\_ASBOX -## ------------------------------------ ## -## Report this to bug-autoconf@gnu.org. ## -## ------------------------------------ ## -_ASBOX - ) | - sed "s/^/$as_me: WARNING: /" >&2 - ;; -esac -echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - eval "$as_ac_Header=$ac_header_preproc" -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 - -fi -if test `eval echo '${'$as_ac_Header'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - -echo "$as_me:$LINENO: checking for GNU libc compatible malloc" >&5 -echo $ECHO_N "checking for GNU libc compatible malloc... $ECHO_C" >&6 -if test "${ac_cv_func_malloc_0_nonnull+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$cross_compiling" = yes; then - ac_cv_func_malloc_0_nonnull=no -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#if STDC_HEADERS || HAVE_STDLIB_H -# include -#else -char *malloc (); -#endif - -int -main () -{ -exit (malloc (0) ? 0 : 1); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_malloc_0_nonnull=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -ac_cv_func_malloc_0_nonnull=no -fi -rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_func_malloc_0_nonnull" >&5 -echo "${ECHO_T}$ac_cv_func_malloc_0_nonnull" >&6 -if test $ac_cv_func_malloc_0_nonnull = yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_MALLOC 1 -_ACEOF - -else - cat >>confdefs.h <<\_ACEOF -#define HAVE_MALLOC 0 -_ACEOF - - LIBOBJS="$LIBOBJS malloc.$ac_objext" - -cat >>confdefs.h <<\_ACEOF -#define malloc rpl_malloc -_ACEOF - -fi - - - -echo "$as_me:$LINENO: checking for working memcmp" >&5 -echo $ECHO_N "checking for working memcmp... $ECHO_C" >&6 -if test "${ac_cv_func_memcmp_working+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$cross_compiling" = yes; then - ac_cv_func_memcmp_working=no -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - /* Some versions of memcmp are not 8-bit clean. */ - char c0 = 0x40, c1 = 0x80, c2 = 0x81; - if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0) - exit (1); - - /* The Next x86 OpenStep bug shows up only when comparing 16 bytes - or more and with at least one buffer not starting on a 4-byte boundary. - William Lewis provided this test program. */ - { - char foo[21]; - char bar[21]; - int i; - for (i = 0; i < 4; i++) - { - char *a = foo + i; - char *b = bar + i; - strcpy (a, "--------01111111"); - strcpy (b, "--------10000000"); - if (memcmp (a, b, 16) >= 0) - exit (1); - } - exit (0); - } - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_memcmp_working=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -ac_cv_func_memcmp_working=no -fi -rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_func_memcmp_working" >&5 -echo "${ECHO_T}$ac_cv_func_memcmp_working" >&6 -test $ac_cv_func_memcmp_working = no && LIBOBJS="$LIBOBJS memcmp.$ac_objext" - - - -for ac_header in stdlib.h unistd.h -do -as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 -else - # Is the header compilable? -echo "$as_me:$LINENO: checking $ac_header usability" >&5 -echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_header_compiler=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_header_compiler=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -echo "${ECHO_T}$ac_header_compiler" >&6 - -# Is the header present? -echo "$as_me:$LINENO: checking $ac_header presence" >&5 -echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_header_preproc=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi -rm -f conftest.err conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -echo "${ECHO_T}$ac_header_preproc" >&6 - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc in - yes:no ) - { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - ( - cat <<\_ASBOX -## ------------------------------------ ## -## Report this to bug-autoconf@gnu.org. ## -## ------------------------------------ ## -_ASBOX - ) | - sed "s/^/$as_me: WARNING: /" >&2 - ;; - no:yes ) - { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - ( - cat <<\_ASBOX -## ------------------------------------ ## -## Report this to bug-autoconf@gnu.org. ## -## ------------------------------------ ## -_ASBOX - ) | - sed "s/^/$as_me: WARNING: /" >&2 - ;; -esac -echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - eval "$as_ac_Header=$ac_header_preproc" -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 - -fi -if test `eval echo '${'$as_ac_Header'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -for ac_func in getpagesize -do -as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` -echo "$as_me:$LINENO: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$as_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ -#ifdef __STDC__ -# include -#else -# include -#endif -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -{ -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -char (*f) () = $ac_func; -#endif -#ifdef __cplusplus -} -#endif - -int -main () -{ -return f != $ac_func; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$as_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -eval "$as_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 -if test `eval echo '${'$as_ac_var'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - -echo "$as_me:$LINENO: checking for working mmap" >&5 -echo $ECHO_N "checking for working mmap... $ECHO_C" >&6 -if test "${ac_cv_func_mmap_fixed_mapped+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$cross_compiling" = yes; then - ac_cv_func_mmap_fixed_mapped=no -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -/* malloc might have been renamed as rpl_malloc. */ -#undef malloc - -/* Thanks to Mike Haertel and Jim Avera for this test. - Here is a matrix of mmap possibilities: - mmap private not fixed - mmap private fixed at somewhere currently unmapped - mmap private fixed at somewhere already mapped - mmap shared not fixed - mmap shared fixed at somewhere currently unmapped - mmap shared fixed at somewhere already mapped - For private mappings, we should verify that changes cannot be read() - back from the file, nor mmap's back from the file at a different - address. (There have been systems where private was not correctly - implemented like the infamous i386 svr4.0, and systems where the - VM page cache was not coherent with the file system buffer cache - like early versions of FreeBSD and possibly contemporary NetBSD.) - For shared mappings, we should conversely verify that changes get - propagated back to all the places they're supposed to be. - - Grep wants private fixed already mapped. - The main things grep needs to know about mmap are: - * does it exist and is it safe to write into the mmap'd area - * how to use it (BSD variants) */ - -#include -#include - -#if !STDC_HEADERS && !HAVE_STDLIB_H -char *malloc (); -#endif - -/* This mess was copied from the GNU getpagesize.h. */ -#if !HAVE_GETPAGESIZE -/* Assume that all systems that can run configure have sys/param.h. */ -# if !HAVE_SYS_PARAM_H -# define HAVE_SYS_PARAM_H 1 -# endif - -# ifdef _SC_PAGESIZE -# define getpagesize() sysconf(_SC_PAGESIZE) -# else /* no _SC_PAGESIZE */ -# if HAVE_SYS_PARAM_H -# include -# ifdef EXEC_PAGESIZE -# define getpagesize() EXEC_PAGESIZE -# else /* no EXEC_PAGESIZE */ -# ifdef NBPG -# define getpagesize() NBPG * CLSIZE -# ifndef CLSIZE -# define CLSIZE 1 -# endif /* no CLSIZE */ -# else /* no NBPG */ -# ifdef NBPC -# define getpagesize() NBPC -# else /* no NBPC */ -# ifdef PAGESIZE -# define getpagesize() PAGESIZE -# endif /* PAGESIZE */ -# endif /* no NBPC */ -# endif /* no NBPG */ -# endif /* no EXEC_PAGESIZE */ -# else /* no HAVE_SYS_PARAM_H */ -# define getpagesize() 8192 /* punt totally */ -# endif /* no HAVE_SYS_PARAM_H */ -# endif /* no _SC_PAGESIZE */ - -#endif /* no HAVE_GETPAGESIZE */ - -int -main () -{ - char *data, *data2, *data3; - int i, pagesize; - int fd; - - pagesize = getpagesize (); - - /* First, make a file with some known garbage in it. */ - data = (char *) malloc (pagesize); - if (!data) - exit (1); - for (i = 0; i < pagesize; ++i) - *(data + i) = rand (); - umask (0); - fd = creat ("conftest.mmap", 0600); - if (fd < 0) - exit (1); - if (write (fd, data, pagesize) != pagesize) - exit (1); - close (fd); - - /* Next, try to mmap the file at a fixed address which already has - something else allocated at it. If we can, also make sure that - we see the same garbage. */ - fd = open ("conftest.mmap", O_RDWR); - if (fd < 0) - exit (1); - data2 = (char *) malloc (2 * pagesize); - if (!data2) - exit (1); - data2 += (pagesize - ((int) data2 & (pagesize - 1))) & (pagesize - 1); - if (data2 != mmap (data2, pagesize, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_FIXED, fd, 0L)) - exit (1); - for (i = 0; i < pagesize; ++i) - if (*(data + i) != *(data2 + i)) - exit (1); - - /* Finally, make sure that changes to the mapped area do not - percolate back to the file as seen by read(). (This is a bug on - some variants of i386 svr4.0.) */ - for (i = 0; i < pagesize; ++i) - *(data2 + i) = *(data2 + i) + 1; - data3 = (char *) malloc (pagesize); - if (!data3) - exit (1); - if (read (fd, data3, pagesize) != pagesize) - exit (1); - for (i = 0; i < pagesize; ++i) - if (*(data + i) != *(data3 + i)) - exit (1); - close (fd); - exit (0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_mmap_fixed_mapped=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -ac_cv_func_mmap_fixed_mapped=no -fi -rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_func_mmap_fixed_mapped" >&5 -echo "${ECHO_T}$ac_cv_func_mmap_fixed_mapped" >&6 -if test $ac_cv_func_mmap_fixed_mapped = yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_MMAP 1 -_ACEOF - -fi -rm -f conftest.mmap - - - - -for ac_func in memset munmap strdup -do -as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` -echo "$as_me:$LINENO: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$as_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ -#ifdef __STDC__ -# include -#else -# include -#endif -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -{ -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -char (*f) () = $ac_func; -#endif -#ifdef __cplusplus -} -#endif - -int -main () -{ -return f != $ac_func; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$as_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -eval "$as_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 -if test `eval echo '${'$as_ac_var'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - -echo "$as_me:$LINENO: checking for char" >&5 -echo $ECHO_N "checking for char... $ECHO_C" >&6 -if test "${ac_cv_type_char+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((char *) 0) - return 0; -if (sizeof (char)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_char=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_char=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_char" >&5 -echo "${ECHO_T}$ac_cv_type_char" >&6 - -echo "$as_me:$LINENO: checking size of char" >&5 -echo $ECHO_N "checking size of char... $ECHO_C" >&6 -if test "${ac_cv_sizeof_char+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_char" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (char))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (char))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (char))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (char))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (char))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_char=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (char), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (char), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (char)); } -unsigned long ulongval () { return (long) (sizeof (char)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (char))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (char)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (char)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_char=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (char), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (char), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_char=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_char" >&5 -echo "${ECHO_T}$ac_cv_sizeof_char" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_CHAR $ac_cv_sizeof_char -_ACEOF - - -echo "$as_me:$LINENO: checking for short" >&5 -echo $ECHO_N "checking for short... $ECHO_C" >&6 -if test "${ac_cv_type_short+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((short *) 0) - return 0; -if (sizeof (short)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_short=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_short=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_short" >&5 -echo "${ECHO_T}$ac_cv_type_short" >&6 - -echo "$as_me:$LINENO: checking size of short" >&5 -echo $ECHO_N "checking size of short... $ECHO_C" >&6 -if test "${ac_cv_sizeof_short+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_short" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (short))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (short))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (short))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (short))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (short))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_short=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (short), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (short), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (short)); } -unsigned long ulongval () { return (long) (sizeof (short)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (short))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (short)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (short)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_short=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (short), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (short), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_short=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_short" >&5 -echo "${ECHO_T}$ac_cv_sizeof_short" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_SHORT $ac_cv_sizeof_short -_ACEOF - - -echo "$as_me:$LINENO: checking for int" >&5 -echo $ECHO_N "checking for int... $ECHO_C" >&6 -if test "${ac_cv_type_int+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((int *) 0) - return 0; -if (sizeof (int)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_int=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_int=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_int" >&5 -echo "${ECHO_T}$ac_cv_type_int" >&6 - -echo "$as_me:$LINENO: checking size of int" >&5 -echo $ECHO_N "checking size of int... $ECHO_C" >&6 -if test "${ac_cv_sizeof_int+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_int" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (int))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (int))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (int))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (int))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (int))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_int=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (int), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (int), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (int)); } -unsigned long ulongval () { return (long) (sizeof (int)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (int))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (int)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (int)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_int=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (int), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (int), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_int=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_int" >&5 -echo "${ECHO_T}$ac_cv_sizeof_int" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_INT $ac_cv_sizeof_int -_ACEOF - - -echo "$as_me:$LINENO: checking for long" >&5 -echo $ECHO_N "checking for long... $ECHO_C" >&6 -if test "${ac_cv_type_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((long *) 0) - return 0; -if (sizeof (long)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_long=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_long=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_long" >&5 -echo "${ECHO_T}$ac_cv_type_long" >&6 - -echo "$as_me:$LINENO: checking size of long" >&5 -echo $ECHO_N "checking size of long... $ECHO_C" >&6 -if test "${ac_cv_sizeof_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_long" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_long=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (long), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (long), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (long)); } -unsigned long ulongval () { return (long) (sizeof (long)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (long))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (long)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (long)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_long=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (long), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (long), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_long=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_long" >&5 -echo "${ECHO_T}$ac_cv_sizeof_long" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_LONG $ac_cv_sizeof_long -_ACEOF - - - -echo "$as_me:$LINENO: checking for uchar" >&5 -echo $ECHO_N "checking for uchar... $ECHO_C" >&6 -if test "${ac_cv_type_uchar+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((uchar *) 0) - return 0; -if (sizeof (uchar)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_uchar=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_uchar=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_uchar" >&5 -echo "${ECHO_T}$ac_cv_type_uchar" >&6 -if test $ac_cv_type_uchar = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_UCHAR 1 -_ACEOF - - -fi - -echo "$as_me:$LINENO: checking for ushort" >&5 -echo $ECHO_N "checking for ushort... $ECHO_C" >&6 -if test "${ac_cv_type_ushort+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((ushort *) 0) - return 0; -if (sizeof (ushort)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_ushort=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_ushort=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_ushort" >&5 -echo "${ECHO_T}$ac_cv_type_ushort" >&6 -if test $ac_cv_type_ushort = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_USHORT 1 -_ACEOF - - -fi - -echo "$as_me:$LINENO: checking for uint" >&5 -echo $ECHO_N "checking for uint... $ECHO_C" >&6 -if test "${ac_cv_type_uint+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((uint *) 0) - return 0; -if (sizeof (uint)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_uint=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_uint=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_uint" >&5 -echo "${ECHO_T}$ac_cv_type_uint" >&6 -if test $ac_cv_type_uint = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_UINT 1 -_ACEOF - - -fi - -echo "$as_me:$LINENO: checking for ulong" >&5 -echo $ECHO_N "checking for ulong... $ECHO_C" >&6 -if test "${ac_cv_type_ulong+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((ulong *) 0) - return 0; -if (sizeof (ulong)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_ulong=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_ulong=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_ulong" >&5 -echo "${ECHO_T}$ac_cv_type_ulong" >&6 -if test $ac_cv_type_ulong = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_ULONG 1 -_ACEOF - - -fi - - - ac_config_files="$ac_config_files Makefile README makerpm re2c.1 re2c.spec" - - ac_config_commands="$ac_config_commands default-2" - -cat >confcache <<\_ACEOF -# This file is a shell script that caches the results of configure -# tests run on this system so they can be shared between configure -# scripts and configure runs, see configure's option --config-cache. -# It is not useful on other systems. If it contains results you don't -# want to keep, you may remove or edit it. -# -# config.status only pays attention to the cache file if you give it -# the --recheck option to rerun configure. -# -# `ac_cv_env_foo' variables (set or unset) will be overridden when -# loading this file, other *unset* `ac_cv_foo' will be assigned the -# following values. - -_ACEOF - -# The following way of writing the cache mishandles newlines in values, -# but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. -# Ultrix sh set writes to stderr and can't be redirected directly, -# and sets the high bit in the cache file unless we assign to the vars. -{ - (set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote - # substitution turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - "s/'/'\\\\''/g; - s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n \ - "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} | - sed ' - t clear - : clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ - t end - /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ - : end' >>confcache -if diff $cache_file confcache >/dev/null 2>&1; then :; else - if test -w $cache_file; then - test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file" - cat confcache >$cache_file - else - echo "not updating unwritable cache $cache_file" - fi -fi -rm -f confcache - -test "x$prefix" = xNONE && prefix=$ac_default_prefix -# Let make expand exec_prefix. -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' - -# VPATH may cause trouble with some makes, so we remove $(srcdir), -# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and -# trailing colons and then remove the whole line if VPATH becomes empty -# (actually we leave an empty line to preserve line numbers). -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=/{ -s/:*\$(srcdir):*/:/; -s/:*\${srcdir}:*/:/; -s/:*@srcdir@:*/:/; -s/^\([^=]*=[ ]*\):*/\1/; -s/:*$//; -s/^[^=]*=[ ]*$//; -}' -fi - -DEFS=-DHAVE_CONFIG_H - -ac_libobjs= -ac_ltlibobjs= -for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue - # 1. Remove the extension, and $U if already installed. - ac_i=`echo "$ac_i" | - sed 's/\$U\././;s/\.o$//;s/\.obj$//'` - # 2. Add them. - ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext" - ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo' -done -LIBOBJS=$ac_libobjs - -LTLIBOBJS=$ac_ltlibobjs - - - -: ${CONFIG_STATUS=./config.status} -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files $CONFIG_STATUS" -{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5 -echo "$as_me: creating $CONFIG_STATUS" >&6;} -cat >$CONFIG_STATUS <<_ACEOF -#! $SHELL -# Generated by $as_me. -# Run this file to recreate the current configuration. -# Compiler output produced by configure, useful for debugging -# configure, is in config.log if it exists. - -debug=false -ac_cs_recheck=false -ac_cs_silent=false -SHELL=\${CONFIG_SHELL-$SHELL} -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF -## --------------------- ## -## M4sh Initialization. ## -## --------------------- ## - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi - -# Support unset when possible. -if (FOO=FOO; unset FOO) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - - -# Work around bugs in pre-3.0 UWIN ksh. -$as_unset ENV MAIL MAILPATH -PS1='$ ' -PS2='> ' -PS4='+ ' - -# NLS nuisances. -for as_var in \ - LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ - LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ - LC_TELEPHONE LC_TIME -do - if (set +x; test -n "`(eval $as_var=C; export $as_var) 2>&1`"); then - eval $as_var=C; export $as_var - else - $as_unset $as_var - fi -done - -# Required to use basename. -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then - as_basename=basename -else - as_basename=false -fi - - -# Name of the executable. -as_me=`$as_basename "$0" || -$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)$' \| \ - . : '\(.\)' 2>/dev/null || -echo X/"$0" | - sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; } - /^X\/\(\/\/\)$/{ s//\1/; q; } - /^X\/\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - - -# PATH needs CR, and LINENO needs CR and PATH. -# Avoid depending upon Character Ranges. -as_cr_letters='abcdefghijklmnopqrstuvwxyz' -as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -as_cr_Letters=$as_cr_letters$as_cr_LETTERS -as_cr_digits='0123456789' -as_cr_alnum=$as_cr_Letters$as_cr_digits - -# The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then - echo "#! /bin/sh" >conf$$.sh - echo "exit 0" >>conf$$.sh - chmod +x conf$$.sh - if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then - PATH_SEPARATOR=';' - else - PATH_SEPARATOR=: - fi - rm -f conf$$.sh -fi - - - as_lineno_1=$LINENO - as_lineno_2=$LINENO - as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x$as_lineno_3" = "x$as_lineno_2" || { - # Find who we are. Look in the path if we contain no path at all - # relative or not. - case $0 in - *[\\/]* ) as_myself=$0 ;; - *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break -done - - ;; - esac - # We did not find ourselves, most probably we were run as `sh COMMAND' - # in which case we are not to be found in the path. - if test "x$as_myself" = x; then - as_myself=$0 - fi - if test ! -f "$as_myself"; then - { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5 -echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;} - { (exit 1); exit 1; }; } - fi - case $CONFIG_SHELL in - '') - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for as_base in sh bash ksh sh5; do - case $as_dir in - /*) - if ("$as_dir/$as_base" -c ' - as_lineno_1=$LINENO - as_lineno_2=$LINENO - as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x$as_lineno_3" = "x$as_lineno_2" ') 2>/dev/null; then - $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; } - $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; } - CONFIG_SHELL=$as_dir/$as_base - export CONFIG_SHELL - exec "$CONFIG_SHELL" "$0" ${1+"$@"} - fi;; - esac - done -done -;; - esac - - # Create $as_me.lineno as a copy of $as_myself, but with $LINENO - # uniformly replaced by the line number. The first 'sed' inserts a - # line-number line before each line; the second 'sed' does the real - # work. The second script uses 'N' to pair each line-number line - # with the numbered line, and appends trailing '-' during - # substitution so that $LINENO is not a special case at line end. - # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the - # second 'sed' script. Blame Lee E. McMahon for sed's syntax. :-) - sed '=' <$as_myself | - sed ' - N - s,$,-, - : loop - s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3, - t loop - s,-$,, - s,^['$as_cr_digits']*\n,, - ' >$as_me.lineno && - chmod +x $as_me.lineno || - { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5 -echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;} - { (exit 1); exit 1; }; } - - # Don't try to exec as it changes $[0], causing all sort of problems - # (the dirname of $[0] is not the place where we might find the - # original and so on. Autoconf is especially sensible to this). - . ./$as_me.lineno - # Exit status is that of the last command. - exit -} - - -case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in - *c*,-n*) ECHO_N= ECHO_C=' -' ECHO_T=' ' ;; - *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; - *) ECHO_N= ECHO_C='\c' ECHO_T= ;; -esac - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -if mkdir -p . 2>/dev/null; then - as_mkdir_p=: -else - as_mkdir_p=false -fi - -as_executable_p="test -f" - -# Sed expression to map a string onto a valid CPP name. -as_tr_cpp="sed y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g" - -# Sed expression to map a string onto a valid variable name. -as_tr_sh="sed y%*+%pp%;s%[^_$as_cr_alnum]%_%g" - - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH - -exec 6>&1 - -# Open the log real soon, to keep \$[0] and so on meaningful, and to -# report actual input values of CONFIG_FILES etc. instead of their -# values after options handling. Logging --version etc. is OK. -exec 5>>config.log -{ - echo - sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX -## Running $as_me. ## -_ASBOX -} >&5 -cat >&5 <<_CSEOF - -This file was extended by Makefile.am $as_me 0.9.3, which was -generated by GNU Autoconf 2.57. Invocation command line was - - CONFIG_FILES = $CONFIG_FILES - CONFIG_HEADERS = $CONFIG_HEADERS - CONFIG_LINKS = $CONFIG_LINKS - CONFIG_COMMANDS = $CONFIG_COMMANDS - $ $0 $@ - -_CSEOF -echo "on `(hostname || uname -n) 2>/dev/null | sed 1q`" >&5 -echo >&5 -_ACEOF - -# Files that config.status was made for. -if test -n "$ac_config_files"; then - echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_headers"; then - echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_links"; then - echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_commands"; then - echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS -fi - -cat >>$CONFIG_STATUS <<\_ACEOF - -ac_cs_usage="\ -\`$as_me' instantiates files from templates according to the -current configuration. - -Usage: $0 [OPTIONS] [FILE]... - - -h, --help print this help, then exit - -V, --version print version number, then exit - -q, --quiet do not print progress messages - -d, --debug don't remove temporary files - --recheck update $as_me by reconfiguring in the same conditions - --file=FILE[:TEMPLATE] - instantiate the configuration file FILE - --header=FILE[:TEMPLATE] - instantiate the configuration header FILE - -Configuration files: -$config_files - -Configuration headers: -$config_headers - -Configuration commands: -$config_commands - -Report bugs to ." -_ACEOF - -cat >>$CONFIG_STATUS <<_ACEOF -ac_cs_version="\\ -Makefile.am config.status 0.9.3 -configured by $0, generated by GNU Autoconf 2.57, - with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" - -Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 -Free Software Foundation, Inc. -This config.status script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it." -srcdir=$srcdir -INSTALL="$INSTALL" -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF -# If no file are specified by the user, then we need to provide default -# value. By we need to know if files were specified by the user. -ac_need_defaults=: -while test $# != 0 -do - case $1 in - --*=*) - ac_option=`expr "x$1" : 'x\([^=]*\)='` - ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` - ac_shift=: - ;; - -*) - ac_option=$1 - ac_optarg=$2 - ac_shift=shift - ;; - *) # This is not an option, so the user has probably given explicit - # arguments. - ac_option=$1 - ac_need_defaults=false;; - esac - - case $ac_option in - # Handling of the options. -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF - -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - ac_cs_recheck=: ;; - --version | --vers* | -V ) - echo "$ac_cs_version"; exit 0 ;; - --he | --h) - # Conflict between --help and --header - { { echo "$as_me:$LINENO: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; };; - --help | --hel | -h ) - echo "$ac_cs_usage"; exit 0 ;; - --debug | --d* | -d ) - debug=: ;; - --file | --fil | --fi | --f ) - $ac_shift - CONFIG_FILES="$CONFIG_FILES $ac_optarg" - ac_need_defaults=false;; - --header | --heade | --head | --hea ) - $ac_shift - CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg" - ac_need_defaults=false;; - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil | --si | --s) - ac_cs_silent=: ;; - - # This is an error. - -*) { { echo "$as_me:$LINENO: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; } ;; - - *) ac_config_targets="$ac_config_targets $1" ;; - - esac - shift -done - -ac_configure_extra_args= - -if $ac_cs_silent; then - exec 6>/dev/null - ac_configure_extra_args="$ac_configure_extra_args --silent" -fi - -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF -if \$ac_cs_recheck; then - echo "running $SHELL $0 " $ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6 - exec $SHELL $0 $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion -fi - -_ACEOF - -cat >>$CONFIG_STATUS <<_ACEOF -# -# INIT-COMMANDS section. -# - - - - -_ACEOF - - - -cat >>$CONFIG_STATUS <<\_ACEOF -for ac_config_target in $ac_config_targets -do - case "$ac_config_target" in - # Handling of arguments. - "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; - "README" ) CONFIG_FILES="$CONFIG_FILES README" ;; - "makerpm" ) CONFIG_FILES="$CONFIG_FILES makerpm" ;; - "re2c.1" ) CONFIG_FILES="$CONFIG_FILES re2c.1" ;; - "re2c.spec" ) CONFIG_FILES="$CONFIG_FILES re2c.spec" ;; - "default-1" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; - "default-2" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-2" ;; - "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; - *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 -echo "$as_me: error: invalid argument: $ac_config_target" >&2;} - { (exit 1); exit 1; }; };; - esac -done - -# If the user did not use the arguments to specify the items to instantiate, -# then the envvar interface is used. Set only those that are not. -# We use the long form for the default assignment because of an extremely -# bizarre bug on SunOS 4.1.3. -if $ac_need_defaults; then - test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files - test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers - test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands -fi - -# Have a temporary directory for convenience. Make it in the build tree -# simply because there is no reason to put it here, and in addition, -# creating and moving files from /tmp can sometimes cause problems. -# Create a temporary directory, and hook for its removal unless debugging. -$debug || -{ - trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 - trap '{ (exit 1); exit 1; }' 1 2 13 15 -} - -# Create a (secure) tmp directory for tmp files. - -{ - tmp=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` && - test -n "$tmp" && test -d "$tmp" -} || -{ - tmp=./confstat$$-$RANDOM - (umask 077 && mkdir $tmp) -} || -{ - echo "$me: cannot create a temporary directory in ." >&2 - { (exit 1); exit 1; } -} - -_ACEOF - -cat >>$CONFIG_STATUS <<_ACEOF - -# -# CONFIG_FILES section. -# - -# No need to generate the scripts if there are no CONFIG_FILES. -# This happens for instance when ./config.status config.h -if test -n "\$CONFIG_FILES"; then - # Protect against being on the right side of a sed subst in config.status. - sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g; - s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF -s,@SHELL@,$SHELL,;t t -s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t -s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t -s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t -s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t -s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t -s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t -s,@exec_prefix@,$exec_prefix,;t t -s,@prefix@,$prefix,;t t -s,@program_transform_name@,$program_transform_name,;t t -s,@bindir@,$bindir,;t t -s,@sbindir@,$sbindir,;t t -s,@libexecdir@,$libexecdir,;t t -s,@datadir@,$datadir,;t t -s,@sysconfdir@,$sysconfdir,;t t -s,@sharedstatedir@,$sharedstatedir,;t t -s,@localstatedir@,$localstatedir,;t t -s,@libdir@,$libdir,;t t -s,@includedir@,$includedir,;t t -s,@oldincludedir@,$oldincludedir,;t t -s,@infodir@,$infodir,;t t -s,@mandir@,$mandir,;t t -s,@build_alias@,$build_alias,;t t -s,@host_alias@,$host_alias,;t t -s,@target_alias@,$target_alias,;t t -s,@DEFS@,$DEFS,;t t -s,@ECHO_C@,$ECHO_C,;t t -s,@ECHO_N@,$ECHO_N,;t t -s,@ECHO_T@,$ECHO_T,;t t -s,@LIBS@,$LIBS,;t t -s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t -s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t -s,@INSTALL_DATA@,$INSTALL_DATA,;t t -s,@PACKAGE@,$PACKAGE,;t t -s,@VERSION@,$VERSION,;t t -s,@ACLOCAL@,$ACLOCAL,;t t -s,@AUTOCONF@,$AUTOCONF,;t t -s,@AUTOMAKE@,$AUTOMAKE,;t t -s,@AUTOHEADER@,$AUTOHEADER,;t t -s,@MAKEINFO@,$MAKEINFO,;t t -s,@SET_MAKE@,$SET_MAKE,;t t -s,@YACC@,$YACC,;t t -s,@CXX@,$CXX,;t t -s,@CXXFLAGS@,$CXXFLAGS,;t t -s,@LDFLAGS@,$LDFLAGS,;t t -s,@CPPFLAGS@,$CPPFLAGS,;t t -s,@ac_ct_CXX@,$ac_ct_CXX,;t t -s,@EXEEXT@,$EXEEXT,;t t -s,@OBJEXT@,$OBJEXT,;t t -s,@CC@,$CC,;t t -s,@CFLAGS@,$CFLAGS,;t t -s,@ac_ct_CC@,$ac_ct_CC,;t t -s,@CPP@,$CPP,;t t -s,@EGREP@,$EGREP,;t t -s,@LIBOBJS@,$LIBOBJS,;t t -s,@LTLIBOBJS@,$LTLIBOBJS,;t t -CEOF - -_ACEOF - - cat >>$CONFIG_STATUS <<\_ACEOF - # Split the substitutions into bite-sized pieces for seds with - # small command number limits, like on Digital OSF/1 and HP-UX. - ac_max_sed_lines=48 - ac_sed_frag=1 # Number of current file. - ac_beg=1 # First line for current file. - ac_end=$ac_max_sed_lines # Line after last line for current file. - ac_more_lines=: - ac_sed_cmds= - while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - else - sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - fi - if test ! -s $tmp/subs.frag; then - ac_more_lines=false - else - # The purpose of the label and of the branching condition is to - # speed up the sed processing (if there are no `@' at all, there - # is no need to browse any of the substitutions). - # These are the two extra sed commands mentioned above. - (echo ':t - /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed" - else - ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed" - fi - ac_sed_frag=`expr $ac_sed_frag + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_lines` - fi - done - if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat - fi -fi # test -n "$CONFIG_FILES" - -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF -for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories. - ac_dir=`(dirname "$ac_file") 2>/dev/null || -$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - { if $as_mkdir_p; then - mkdir -p "$ac_dir" - else - as_dir="$ac_dir" - as_dirs= - while test ! -d "$as_dir"; do - as_dirs="$as_dir $as_dirs" - as_dir=`(dirname "$as_dir") 2>/dev/null || -$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_dir" : 'X\(//\)[^/]' \| \ - X"$as_dir" : 'X\(//\)$' \| \ - X"$as_dir" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$as_dir" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - done - test ! -n "$as_dirs" || mkdir $as_dirs - fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5 -echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;} - { (exit 1); exit 1; }; }; } - - ac_builddir=. - -if test "$ac_dir" != .; then - ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` - # A "../" for each directory in $ac_dir_suffix. - ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'` -else - ac_dir_suffix= ac_top_builddir= -fi - -case $srcdir in - .) # No --srcdir option. We are building in place. - ac_srcdir=. - if test -z "$ac_top_builddir"; then - ac_top_srcdir=. - else - ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'` - fi ;; - [\\/]* | ?:[\\/]* ) # Absolute path. - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir ;; - *) # Relative path. - ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_top_builddir$srcdir ;; -esac -# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be -# absolute. -ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` -ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` -ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` -ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` - - - case $INSTALL in - [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; - *) ac_INSTALL=$ac_top_builddir$INSTALL ;; - esac - - if test x"$ac_file" != x-; then - { echo "$as_me:$LINENO: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - rm -f "$ac_file" - fi - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated by config.status. */ - if test x"$ac_file" = x-; then - configure_input= - else - configure_input="$ac_file. " - fi - configure_input=$configure_input"Generated from `echo $ac_file_in | - sed 's,.*/,,'` by configure." - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo $f;; - *) # Relative - if test -f "$f"; then - # Build tree - echo $f - elif test -f "$srcdir/$f"; then - # Source tree - echo $srcdir/$f - else - # /dev/null tree - { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF - sed "$ac_vpsub -$extrasub -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF -:t -/@[a-zA-Z_][a-zA-Z_0-9]*@/!b -s,@configure_input@,$configure_input,;t t -s,@srcdir@,$ac_srcdir,;t t -s,@abs_srcdir@,$ac_abs_srcdir,;t t -s,@top_srcdir@,$ac_top_srcdir,;t t -s,@abs_top_srcdir@,$ac_abs_top_srcdir,;t t -s,@builddir@,$ac_builddir,;t t -s,@abs_builddir@,$ac_abs_builddir,;t t -s,@top_builddir@,$ac_top_builddir,;t t -s,@abs_top_builddir@,$ac_abs_top_builddir,;t t -s,@INSTALL@,$ac_INSTALL,;t t -" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out - rm -f $tmp/stdin - if test x"$ac_file" != x-; then - mv $tmp/out $ac_file - else - cat $tmp/out - rm -f $tmp/out - fi - -done -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF - -# -# CONFIG_HEADER section. -# - -# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where -# NAME is the cpp macro being defined and VALUE is the value it is being given. -# -# ac_d sets the value in "#define NAME VALUE" lines. -ac_dA='s,^\([ ]*\)#\([ ]*define[ ][ ]*\)' -ac_dB='[ ].*$,\1#\2' -ac_dC=' ' -ac_dD=',;t' -# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE". -ac_uA='s,^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_uB='$,\1#\2define\3' -ac_uC=' ' -ac_uD=',;t' - -for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - test x"$ac_file" != x- && { echo "$as_me:$LINENO: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo $f;; - *) # Relative - if test -f "$f"; then - # Build tree - echo $f - elif test -f "$srcdir/$f"; then - # Source tree - echo $srcdir/$f - else - # /dev/null tree - { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } - # Remove the trailing spaces. - sed 's/[ ]*$//' $ac_file_inputs >$tmp/in - -_ACEOF - -# Transform confdefs.h into two sed scripts, `conftest.defines' and -# `conftest.undefs', that substitutes the proper values into -# config.h.in to produce config.h. The first handles `#define' -# templates, and the second `#undef' templates. -# And first: Protect against being on the right side of a sed subst in -# config.status. Protect against being in an unquoted here document -# in config.status. -rm -f conftest.defines conftest.undefs -# Using a here document instead of a string reduces the quoting nightmare. -# Putting comments in sed scripts is not portable. -# -# `end' is used to avoid that the second main sed command (meant for -# 0-ary CPP macros) applies to n-ary macro definitions. -# See the Autoconf documentation for `clear'. -cat >confdef2sed.sed <<\_ACEOF -s/[\\&,]/\\&/g -s,[\\$`],\\&,g -t clear -: clear -s,^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*\)\(([^)]*)\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1\2${ac_dC}\3${ac_dD},gp -t end -s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp -: end -_ACEOF -# If some macros were called several times there might be several times -# the same #defines, which is useless. Nevertheless, we may not want to -# sort them, since we want the *last* AC-DEFINE to be honored. -uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines -sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs -rm -f confdef2sed.sed - -# This sed command replaces #undef with comments. This is necessary, for -# example, in the case of _POSIX_SOURCE, which is predefined and required -# on some systems where configure will not decide to define it. -cat >>conftest.undefs <<\_ACEOF -s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */, -_ACEOF - -# Break up conftest.defines because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS -echo ' if grep "^[ ]*#[ ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS -echo ' # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS -echo ' :' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.defines >/dev/null -do - # Write a limited-size here document to $tmp/defines.sed. - echo ' cat >$tmp/defines.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#define' lines. - echo '/^[ ]*#[ ]*define/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/defines.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail - rm -f conftest.defines - mv conftest.tail conftest.defines -done -rm -f conftest.defines -echo ' fi # grep' >>$CONFIG_STATUS -echo >>$CONFIG_STATUS - -# Break up conftest.undefs because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #undef templates' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.undefs >/dev/null -do - # Write a limited-size here document to $tmp/undefs.sed. - echo ' cat >$tmp/undefs.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#undef' - echo '/^[ ]*#[ ]*undef/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/undefs.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail - rm -f conftest.undefs - mv conftest.tail conftest.undefs -done -rm -f conftest.undefs - -cat >>$CONFIG_STATUS <<\_ACEOF - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated by config.status. */ - if test x"$ac_file" = x-; then - echo "/* Generated by configure. */" >$tmp/config.h - else - echo "/* $ac_file. Generated by configure. */" >$tmp/config.h - fi - cat $tmp/in >>$tmp/config.h - rm -f $tmp/in - if test x"$ac_file" != x-; then - if diff $ac_file $tmp/config.h >/dev/null 2>&1; then - { echo "$as_me:$LINENO: $ac_file is unchanged" >&5 -echo "$as_me: $ac_file is unchanged" >&6;} - else - ac_dir=`(dirname "$ac_file") 2>/dev/null || -$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - { if $as_mkdir_p; then - mkdir -p "$ac_dir" - else - as_dir="$ac_dir" - as_dirs= - while test ! -d "$as_dir"; do - as_dirs="$as_dir $as_dirs" - as_dir=`(dirname "$as_dir") 2>/dev/null || -$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_dir" : 'X\(//\)[^/]' \| \ - X"$as_dir" : 'X\(//\)$' \| \ - X"$as_dir" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$as_dir" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - done - test ! -n "$as_dirs" || mkdir $as_dirs - fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5 -echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;} - { (exit 1); exit 1; }; }; } - - rm -f $ac_file - mv $tmp/config.h $ac_file - fi - else - cat $tmp/config.h - rm -f $tmp/config.h - fi -done -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF - -# -# CONFIG_COMMANDS section. -# -for ac_file in : $CONFIG_COMMANDS; do test "x$ac_file" = x: && continue - ac_dest=`echo "$ac_file" | sed 's,:.*,,'` - ac_source=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_dir=`(dirname "$ac_dest") 2>/dev/null || -$as_expr X"$ac_dest" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_dest" : 'X\(//\)[^/]' \| \ - X"$ac_dest" : 'X\(//\)$' \| \ - X"$ac_dest" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_dest" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - ac_builddir=. - -if test "$ac_dir" != .; then - ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` - # A "../" for each directory in $ac_dir_suffix. - ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'` -else - ac_dir_suffix= ac_top_builddir= -fi - -case $srcdir in - .) # No --srcdir option. We are building in place. - ac_srcdir=. - if test -z "$ac_top_builddir"; then - ac_top_srcdir=. - else - ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'` - fi ;; - [\\/]* | ?:[\\/]* ) # Absolute path. - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir ;; - *) # Relative path. - ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_top_builddir$srcdir ;; -esac -# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be -# absolute. -ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` -ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` -ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` -ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` - - - { echo "$as_me:$LINENO: executing $ac_dest commands" >&5 -echo "$as_me: executing $ac_dest commands" >&6;} - case $ac_dest in - default-1 ) test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h ;; - default-2 ) chmod +x makerpm ;; - esac -done -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF - -{ (exit 0); exit 0; } -_ACEOF -chmod +x $CONFIG_STATUS -ac_clean_files=$ac_clean_files_save - - -# configure is writing to config.log, and then calls config.status. -# config.status does its own redirection, appending to config.log. -# Unfortunately, on DOS this fails, as config.log is still kept open -# by configure, so config.status won't be able to write to it; its -# output is simply discarded. So we exec the FD to /dev/null, -# effectively closing config.log, so it can be properly (re)opened and -# appended to by config.status. When coming back to configure, we -# need to make the FD available again. -if test "$no_create" != yes; then - ac_cs_success=: - ac_config_status_args= - test "$silent" = yes && - ac_config_status_args="$ac_config_status_args --quiet" - exec 5>/dev/null - $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false - exec 5>>config.log - # Use ||, not &&, to avoid exiting from the if with $? = 1, which - # would make configure fail if this is the last instruction. - $ac_cs_success || { (exit 1); exit 1; } -fi - diff --git a/tools/re2c/configure.in b/tools/re2c/configure.in deleted file mode 100644 index 128d2ebba..000000000 --- a/tools/re2c/configure.in +++ /dev/null @@ -1,59 +0,0 @@ -AC_PREREQ([2.57]) -AC_INIT(Makefile.am, 0.9.3, re2c-general@lists.sourceforge.net) -AM_INIT_AUTOMAKE(re2c, $PACKAGE_VERSION) -AC_CONFIG_SRCDIR(actions.cc) -AM_CONFIG_HEADER(config.h) - -AC_SUBST(PACKAGE_VERSION) -AC_SUBST(PACKAGE_NAME) -AC_SUBST(PACKAGE_TARNAME) - -# Checks for programs. -AC_PROG_YACC -AC_PROG_CXX -AC_PROG_CC -AC_PROG_INSTALL - -# Checks for libraries. - -# Checks for header files. -AC_HEADER_STDC - -# We only rely on standard C/C++ headers. If we ever have a pressing need -# for something non-standard, we should add a check for it here. -# AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) - -# Checks for typedefs, structures, and compiler characteristics. -AC_HEADER_STDBOOL -AC_C_CONST -AC_C_INLINE -AC_TYPE_SIZE_T -AC_C_VOLATILE - -# Checks for library functions. -AC_FUNC_MALLOC -AC_FUNC_MEMCMP -AC_FUNC_MMAP -AC_CHECK_FUNCS([memset munmap strdup]) - -AC_CHECK_SIZEOF([char]) -AC_CHECK_SIZEOF([short]) -AC_CHECK_SIZEOF([int]) -AC_CHECK_SIZEOF([long]) - -AC_CHECK_TYPE([uchar], [ - AC_DEFINE([HAVE_UCHAR], [1], [Define to 1 if you have uchar type definition]) -]) -AC_CHECK_TYPE([ushort], [ - AC_DEFINE([HAVE_USHORT], [1], [Define to 1 if you have ushort type definition]) -]) -AC_CHECK_TYPE([uint], [ - AC_DEFINE([HAVE_UINT], [1], [Define to 1 if you have uint type definition]) -]) -AC_CHECK_TYPE([ulong], [ - AC_DEFINE([HAVE_ULONG], [1], [Define to 1 if you have ulong type definition]) -]) - -AC_CONFIG_FILES([Makefile README makerpm re2c.1 re2c.spec]) -AC_OUTPUT_COMMANDS([chmod +x makerpm]) -AC_OUTPUT diff --git a/tools/re2c/dfa.cc b/tools/re2c/dfa.cc index 660db6026..2d3779f48 100644 --- a/tools/re2c/dfa.cc +++ b/tools/re2c/dfa.cc @@ -5,222 +5,389 @@ #include "substr.h" #include "dfa.h" -inline char octCh(uint c){ - return '0' + c%8; -} +namespace re2c +{ -void prtCh(std::ostream &o, uchar c){ - uchar oc = talx[c]; - switch(oc){ - case '\'': o << "\\'"; break; - case '\n': o << "\\n"; break; - case '\t': o << "\\t"; break; - case '\v': o << "\\v"; break; - case '\b': o << "\\b"; break; - case '\r': o << "\\r"; break; - case '\f': o << "\\f"; break; - case '\a': o << "\\a"; break; - case '\\': o << "\\\\"; break; - default: - if(isprint(oc)) - o << (char) oc; +void prtChOrHex(std::ostream& o, uint c, bool useTalx) +{ + int oc = (int)(re2c::wFlag || !useTalx ? c : re2c::talx[c]); + + if ((oc < 256) && isprint(oc)) + { + o << '\''; + prtCh(o, oc); + o << '\''; + } else - o << '\\' << octCh(c/64) << octCh(c/8) << octCh(c); - } + { + prtHex(o, c); + } } -void printSpan(std::ostream &o, uint lb, uint ub){ - if(lb > ub) - o << "*"; - o << "["; - if((ub - lb) == 1){ - prtCh(o, lb); - } else { - prtCh(o, lb); - o << "-"; - prtCh(o, ub-1); - } - o << "]"; +void prtHex(std::ostream& o, uint c, bool useTalx) +{ + int oc = (int)(re2c::wFlag || !useTalx ? c : re2c::talx[c]); + + if (re2c::wFlag) + { + o << "0x" + << hexCh(oc >> 12) + << hexCh(oc >> 8) + << hexCh(oc >> 4) + << hexCh(oc); + } + else + { + o << "0x" + << hexCh(oc >> 4) + << hexCh(oc); + } } -uint Span::show(std::ostream &o, uint lb){ - if(to){ - printSpan(o, lb, ub); - o << " " << to->label << "; "; - } - return ub; +void prtCh(std::ostream& o, uint c, bool useTalx) +{ + int oc = (int)(re2c::wFlag || !useTalx ? c : re2c::talx[c]); + + switch (oc) + { + case '\'': + o << "\\'"; + break; + + case '\n': + o << "\\n"; + break; + + case '\t': + o << "\\t"; + break; + + case '\v': + o << "\\v"; + break; + + case '\b': + o << "\\b"; + break; + + case '\r': + o << "\\r"; + break; + + case '\f': + o << "\\f"; + break; + + case '\a': + o << "\\a"; + break; + + case '\\': + o << "\\\\"; + break; + + default: + + if ((oc < 256) && isprint(oc)) + { + o << (char) oc; + } + else if (re2c::wFlag) + { + o << "0x" + << hexCh(oc >> 12) + << hexCh(oc >> 8) + << hexCh(oc >> 4) + << hexCh(oc); + } + else + { + o << '\\' << octCh(oc / 64) << octCh(oc / 8) << octCh(oc); + } + } } -std::ostream& operator<<(std::ostream &o, const State &s){ - o << "state " << s.label; - if(s.rule) - o << " accepts " << s.rule->accept; - o << "\n"; - ++oline; - uint lb = 0; - for(uint i = 0; i < s.go.nSpans; ++i) - lb = s.go.span[i].show(o, lb); - return o; +void printSpan(std::ostream& o, uint lb, uint ub) +{ + if (lb > ub) + { + o << "*"; + } + + o << "["; + + if ((ub - lb) == 1) + { + prtCh(o, lb); + } + else + { + prtCh(o, lb); + o << "-"; + prtCh(o, ub - 1); + } + + o << "]"; } -std::ostream& operator<<(std::ostream &o, const DFA &dfa){ - for(State *s = dfa.head; s; s = s->next) - { - o << s << "\n\n"; - ++oline; - } - return o; +uint Span::show(std::ostream &o, uint lb) const +{ + if (to) + { + printSpan(o, lb, ub); + o << " " << to->label << "; "; + } + + return ub; } -State::State() : rule(NULL), link(NULL), kCount(0), kernel(NULL), action(NULL) { - go.nSpans = 0; - go.span = NULL; +std::ostream& operator<<(std::ostream &o, const State &s) +{ + o << "state " << s.label; + + if (s.rule) + { + o << " accepts " << s.rule->accept; + } + + o << "\n"; + + uint lb = 0; + + for (uint i = 0; i < s.go.nSpans; ++i) + { + lb = s.go.span[i].show(o, lb); + } + + return o; } -State::~State(){ - delete [] kernel; - delete [] go.span; +std::ostream& operator<<(std::ostream &o, const DFA &dfa) +{ + for (State *s = dfa.head; s; s = s->next) + { + o << s << "\n\n"; + } + + return o; } -static Ins **closure(Ins **cP, Ins *i){ - while(!isMarked(i)){ - mark(i); - *(cP++) = i; - if(i->i.tag == FORK){ - cP = closure(cP, i + 1); - i = (Ins*) i->i.link; - } else if(i->i.tag == GOTO){ - i = (Ins*) i->i.link; - } else - break; - } - return cP; +State::State() + : label(0) + , rule(NULL) + , next(0) + , link(NULL) + , depth(0) + , kCount(0) + , kernel(NULL) + , isPreCtxt(false) + , isBase(false) + , go() + , action(NULL) +{ } -struct GoTo { - Char ch; - void *to; +State::~State() +{ + delete [] kernel; + delete [] go.span; +} + +static Ins **closure(Ins **cP, Ins *i) +{ + while (!isMarked(i)) + { + mark(i); + *(cP++) = i; + + if (i->i.tag == FORK) + { + cP = closure(cP, i + 1); + i = (Ins*) i->i.link; + } + else if (i->i.tag == GOTO || i->i.tag == CTXT) + { + i = (Ins*) i->i.link; + } + else + break; + } + + return cP; +} + +struct GoTo +{ + Char ch; + void *to; }; DFA::DFA(Ins *ins, uint ni, uint lb, uint ub, Char *rep) - : lbChar(lb), ubChar(ub) { - Ins **work = new Ins*[ni+1]; - uint nc = ub - lb; - GoTo *goTo = new GoTo[nc]; - Span *span = new Span[nc]; - memset((char*) goTo, 0, nc*sizeof(GoTo)); - tail = &head; - head = NULL; - nStates = 0; - toDo = NULL; - findState(work, closure(work, &ins[0]) - work); - while(toDo){ - State *s = toDo; - toDo = s->link; + : lbChar(lb) + , ubChar(ub) + , nStates(0) + , head(NULL) + , tail(&head) + , toDo(NULL) +{ + Ins **work = new Ins * [ni + 1]; + uint nc = ub - lb; + GoTo *goTo = new GoTo[nc]; + Span *span = new Span[nc]; + memset((char*) goTo, 0, nc*sizeof(GoTo)); + findState(work, closure(work, &ins[0]) - work); - Ins **cP, **iP, *i; - uint nGoTos = 0; - uint j; + while (toDo) + { + State *s = toDo; + toDo = s->link; - s->rule = NULL; - for(iP = s->kernel; (i = *iP); ++iP){ - if(i->i.tag == CHAR){ - for(Ins *j = i + 1; j < (Ins*) i->i.link; ++j){ - if(!(j->c.link = goTo[j->c.value - lb].to)) - goTo[nGoTos++].ch = (Char)j->c.value; - goTo[j->c.value - lb].to = j; + Ins **cP, **iP, *i; + uint nGoTos = 0; + uint j; + + s->rule = NULL; + + for (iP = s->kernel; (i = *iP); ++iP) + { + if (i->i.tag == CHAR) + { + for (Ins *j = i + 1; j < (Ins*) i->i.link; ++j) + { + if (!(j->c.link = goTo[j->c.value - lb].to)) + goTo[nGoTos++].ch = j->c.value; + + goTo[j->c.value - lb].to = j; + } + } + else if (i->i.tag == TERM) + { + if (!s->rule || ((RuleOp*) i->i.link)->accept < s->rule->accept) + s->rule = (RuleOp*) i->i.link; + } + else if (i->i.tag == CTXT) + { + s->isPreCtxt = true; + } } - } else if(i->i.tag == TERM){ - if(!s->rule || ((RuleOp*) i->i.link)->accept < s->rule->accept) - s->rule = (RuleOp*) i->i.link; - } + + for (j = 0; j < nGoTos; ++j) + { + GoTo *go = &goTo[goTo[j].ch - lb]; + i = (Ins*) go->to; + + for (cP = work; i; i = (Ins*) i->c.link) + cP = closure(cP, i + i->c.bump); + + go->to = findState(work, cP - work); + } + + s->go.nSpans = 0; + + for (j = 0; j < nc;) + { + State *to = (State*) goTo[rep[j]].to; + + while (++j < nc && goTo[rep[j]].to == to) ; + + span[s->go.nSpans].ub = lb + j; + + span[s->go.nSpans].to = to; + + s->go.nSpans++; + } + + for (j = nGoTos; j-- > 0;) + goTo[goTo[j].ch - lb].to = NULL; + + s->go.span = new Span[s->go.nSpans]; + + memcpy((char*) s->go.span, (char*) span, s->go.nSpans*sizeof(Span)); + + (void) new Match(s); + } - for(j = 0; j < nGoTos; ++j){ - GoTo *go = &goTo[goTo[j].ch - lb]; - i = (Ins*) go->to; - for(cP = work; i; i = (Ins*) i->c.link) - cP = closure(cP, i + i->c.bump); - go->to = findState(work, cP - work); - } - - s->go.nSpans = 0; - for(j = 0; j < nc;){ - State *to = (State*) goTo[rep[j]].to; - while(++j < nc && goTo[rep[j]].to == to); - span[s->go.nSpans].ub = lb + j; - span[s->go.nSpans].to = to; - s->go.nSpans++; - } - - for(j = nGoTos; j-- > 0;) - goTo[goTo[j].ch - lb].to = NULL; - - s->go.span = new Span[s->go.nSpans]; - memcpy((char*) s->go.span, (char*) span, s->go.nSpans*sizeof(Span)); - - (void) new Match(s); - - } - delete [] work; - delete [] goTo; - delete [] span; + delete [] work; + delete [] goTo; + delete [] span; } -DFA::~DFA(){ - State *s; - while((s = head)){ - head = s->next; - delete s; - } -} +DFA::~DFA() +{ + State *s; -void DFA::addState(State **a, State *s){ - s->label = nStates++; - s->next = *a; - *a = s; - if(a == tail) - tail = &s->next; -} - -State *DFA::findState(Ins **kernel, uint kCount){ - Ins **cP, **iP, *i; - State *s; - - kernel[kCount] = NULL; - - cP = kernel; - for(iP = kernel; (i = *iP); ++iP){ - if(i->i.tag == CHAR || i->i.tag == TERM){ - *cP++ = i; - } else { - unmark(i); + while ((s = head)) + { + head = s->next; + delete s; } - } - kCount = cP - kernel; - kernel[kCount] = NULL; +} - for(s = head; s; s = s->next){ - if(s->kCount == kCount){ - for(iP = s->kernel; (i = *iP); ++iP) - if(!isMarked(i)) - goto nextState; - goto unmarkAll; - } - nextState:; - } +void DFA::addState(State **a, State *s) +{ + s->label = nStates++; + s->next = *a; + *a = s; - s = new State; - addState(tail, s); - s->kCount = kCount; - s->kernel = new Ins*[kCount+1]; - memcpy(s->kernel, kernel, (kCount+1)*sizeof(Ins*)); - s->link = toDo; - toDo = s; + if (a == tail) + tail = &s->next; +} + +State *DFA::findState(Ins **kernel, uint kCount) +{ + Ins **cP, **iP, *i; + State *s; + + kernel[kCount] = NULL; + + cP = kernel; + + for (iP = kernel; (i = *iP); ++iP) + { + if (i->i.tag == CHAR || i->i.tag == TERM || i->i.tag == CTXT) + { + *cP++ = i; + } + else + { + unmark(i); + } + } + + kCount = cP - kernel; + kernel[kCount] = NULL; + + for (s = head; s; s = s->next) + { + if (s->kCount == kCount) + { + for (iP = s->kernel; (i = *iP); ++iP) + if (!isMarked(i)) + goto nextState; + + goto unmarkAll; + } + +nextState: + ; + } + + s = new State; + addState(tail, s); + s->kCount = kCount; + s->kernel = new Ins * [kCount + 1]; + memcpy(s->kernel, kernel, (kCount + 1)*sizeof(Ins*)); + s->link = toDo; + toDo = s; unmarkAll: - for(iP = kernel; (i = *iP); ++iP) - unmark(i); - return s; + for (iP = kernel; (i = *iP); ++iP) + unmark(i); + + return s; } + +} // end namespace re2c + diff --git a/tools/re2c/dfa.h b/tools/re2c/dfa.h index b44fbe6c6..eb1f89ceb 100644 --- a/tools/re2c/dfa.h +++ b/tools/re2c/dfa.h @@ -1,175 +1,365 @@ -/* $Id: dfa.h,v 1.5 2004/05/13 02:58:17 nuffer Exp $ */ +/* $Id: dfa.h,v 1.23 2006/05/14 13:38:26 helly Exp $ */ #ifndef _dfa_h #define _dfa_h #include +#include #include "re.h" -extern void prtCh(std::ostream&, uchar); +namespace re2c +{ + +extern void prtCh(std::ostream&, uint, bool useTalx = true); +extern void prtHex(std::ostream&, uint, bool useTalx = true); +extern void prtChOrHex(std::ostream&, uint, bool useTalx = true); extern void printSpan(std::ostream&, uint, uint); class DFA; + class State; -class Action { +class Action +{ + public: - State *state; + State *state; + public: - Action(State*); - virtual ~Action() {} - virtual void emit(std::ostream&, bool&) = 0; - virtual bool isRule() const; - virtual bool isMatch() const; - virtual bool readAhead() const; + Action(State*); + virtual ~Action(); + + virtual void emit(std::ostream&, uint, bool&) const = 0; + virtual bool isRule() const; + virtual bool isMatch() const; + virtual bool isInitial() const; + virtual bool readAhead() const; + +#ifdef PEDANTIC +protected: + Action(const Action& oth) + : state(oth.state) + { + } + Action& operator = (const Action& oth) + { + state = oth.state; + return *this; + } +#endif }; -class Match: public Action { +class Match: public Action +{ public: - Match(State*); - void emit(std::ostream&, bool&); - bool isMatch() const; + Match(State*); + void emit(std::ostream&, uint, bool&) const; + bool isMatch() const; }; -class Enter: public Action { +class Enter: public Action +{ public: - uint label; + uint label; + public: - Enter(State*, uint); - void emit(std::ostream&, bool&); + Enter(State*, uint); + void emit(std::ostream&, uint, bool&) const; }; -class Save: public Match { +class Initial: public Enter +{ public: - uint selector; + bool setMarker; + public: - Save(State*, uint); - void emit(std::ostream&, bool&); - bool isMatch() const; + Initial(State*, uint, bool); + void emit(std::ostream&, uint, bool&) const; + bool isInitial() const; }; -class Move: public Action { +class Save: public Match +{ + public: - Move(State*); - void emit(std::ostream&, bool&); + uint selector; + +public: + Save(State*, uint); + void emit(std::ostream&, uint, bool&) const; + bool isMatch() const; }; -class Accept: public Action { +class Move: public Action +{ + public: - uint nRules; - uint *saves; - State **rules; -public: - Accept(State*, uint, uint*, State**); - void emit(std::ostream&, bool&); + Move(State*); + void emit(std::ostream&, uint, bool&) const; }; -class Rule: public Action { +class Accept: public Action +{ + public: - RuleOp *rule; + typedef std::map RuleMap; + + uint nRules; + uint *saves; + State **rules; + RuleMap mapRules; + public: - Rule(State*, RuleOp*); - void emit(std::ostream&, bool&); - bool isRule() const; + Accept(State*, uint, uint*, State**); + void emit(std::ostream&, uint, bool&) const; + void emitBinary(std::ostream &o, uint ind, uint l, uint r, bool &readCh) const; + void genRuleMap(); + +#ifdef PEDANTIC +private: + Accept(const Accept& oth) + : Action(oth) + , nRules(oth.nRules) + , saves(oth.saves) + , rules(oth.rules) + { + } + Accept& operator=(const Accept& oth) + { + new(this) Accept(oth); + return *this; + } +#endif }; -class Span { +class Rule: public Action +{ + public: - uint ub; - State *to; + RuleOp *rule; + public: - uint show(std::ostream&, uint); + Rule(State*, RuleOp*); + void emit(std::ostream&, uint, bool&) const; + bool isRule() const; + +#ifdef PEDANTIC +private: + Rule (const Rule& oth) + : Action(oth) + , rule(oth.rule) + { + } + Rule& operator=(const Rule& oth) + { + new(this) Rule(oth); + return *this; + } +#endif }; -class Go { +class Span +{ + public: - uint nSpans; - Span *span; + uint ub; + State *to; + public: - void genGoto(std::ostream&, State *from, State*, bool &readCh); - void genBase(std::ostream&, State *from, State*, bool &readCh); - void genLinear(std::ostream&, State *from, State*, bool &readCh); - void genBinary(std::ostream&, State *from, State*, bool &readCh); - void genSwitch(std::ostream&, State *from, State*, bool &readCh); - void compact(); - void unmap(Go*, State*); + uint show(std::ostream&, uint) const; }; -class State { +class Go +{ public: - uint label; - RuleOp *rule; - State *next; - State *link; - uint depth; // for finding SCCs - uint kCount; - Ins **kernel; - bool isBase:1; - Go go; - Action *action; + Go() + : nSpans(0) + , wSpans(~0u) + , lSpans(~0u) + , dSpans(~0u) + , lTargets(~0u) + , span(NULL) + { + } + public: - State(); - ~State(); - void emit(std::ostream&, bool&); - friend std::ostream& operator<<(std::ostream&, const State&); - friend std::ostream& operator<<(std::ostream&, const State*); + uint nSpans; // number of spans + uint wSpans; // number of spans in wide mode + uint lSpans; // number of low (non wide) spans + uint dSpans; // number of decision spans (decide between g and b mode) + uint lTargets; + Span *span; + +public: + void genGoto( std::ostream&, uint ind, const State *from, const State *next, bool &readCh); + void genBase( std::ostream&, uint ind, const State *from, const State *next, bool &readCh, uint mask) const; + void genLinear(std::ostream&, uint ind, const State *from, const State *next, bool &readCh, uint mask) const; + void genBinary(std::ostream&, uint ind, const State *from, const State *next, bool &readCh, uint mask) const; + void genSwitch(std::ostream&, uint ind, const State *from, const State *next, bool &readCh, uint mask) const; + void genCpGoto(std::ostream&, uint ind, const State *from, const State *next, bool &readCh) const; + void compact(); + void unmap(Go*, const State*); }; -class DFA { -public: - uint lbChar; - uint ubChar; - uint nStates; - State *head, **tail; - State *toDo; -public: - DFA(Ins*, uint, uint, uint, Char*); - ~DFA(); - void addState(State**, State*); - State *findState(Ins**, uint); - void split(State*); +class State +{ - void findSCCs(); - void emit(std::ostream&); +public: + uint label; + RuleOp *rule; + State *next; + State *link; + uint depth; // for finding SCCs + uint kCount; + Ins **kernel; - friend std::ostream& operator<<(std::ostream&, const DFA&); - friend std::ostream& operator<<(std::ostream&, const DFA*); + bool isPreCtxt; + bool isBase; + Go go; + Action *action; + +public: + State(); + ~State(); + void emit(std::ostream&, uint, bool&) const; + friend std::ostream& operator<<(std::ostream&, const State&); + friend std::ostream& operator<<(std::ostream&, const State*); + +#ifdef PEDANTIC +private: + State(const State& oth) + : label(oth.label) + , rule(oth.rule) + , next(oth.next) + , link(oth.link) + , depth(oth.depth) + , kCount(oth.kCount) + , kernel(oth.kernel) + , isBase(oth.isBase) + , go(oth.go) + , action(oth.action) + { + } + State& operator = (const State& oth) + { + new(this) State(oth); + return *this; + } +#endif }; -inline Action::Action(State *s) : state(s) { - s->action = this; +class DFA +{ + +public: + uint lbChar; + uint ubChar; + uint nStates; + State *head, **tail; + State *toDo; + +public: + DFA(Ins*, uint, uint, uint, Char*); + ~DFA(); + void addState(State**, State*); + State *findState(Ins**, uint); + void split(State*); + + void findSCCs(); + void findBaseState(); + void emit(std::ostream&, uint); + + friend std::ostream& operator<<(std::ostream&, const DFA&); + friend std::ostream& operator<<(std::ostream&, const DFA*); + +#ifdef PEDANTIC + DFA(const DFA& oth) + : lbChar(oth.lbChar) + , ubChar(oth.ubChar) + , nStates(oth.nStates) + , head(oth.head) + , tail(oth.tail) + , toDo(oth.toDo) + { + } + DFA& operator = (const DFA& oth) + { + new(this) DFA(oth); + return *this; + } +#endif +}; + +inline Action::Action(State *s) : state(s) +{ + s->action = this; +} + +inline Action::~Action() +{ } inline bool Action::isRule() const - { return false; } +{ + return false; +} inline bool Action::isMatch() const - { return false; } +{ + return false; +} + +inline bool Action::isInitial() const +{ + return false; +} inline bool Action::readAhead() const - { return !isMatch() || (state && state->next && state->next->action && !state->next->action->isRule()); } +{ + return !isMatch() || (state && state->next && state->next->action && !state->next->action->isRule()); +} inline Match::Match(State *s) : Action(s) - { } +{ } inline bool Match::isMatch() const - { return true; } +{ + return true; +} inline Enter::Enter(State *s, uint l) : Action(s), label(l) - { } +{ } + +inline Initial::Initial(State *s, uint l, bool b) : Enter(s, l), setMarker(b) +{ } + +inline bool Initial::isInitial() const +{ + return true; +} inline Save::Save(State *s, uint i) : Match(s), selector(i) - { } +{ } inline bool Save::isMatch() const - { return false; } +{ + return false; +} inline bool Rule::isRule() const - { return true; } +{ + return true; +} inline std::ostream& operator<<(std::ostream &o, const State *s) - { return o << *s; } +{ + return o << *s; +} inline std::ostream& operator<<(std::ostream &o, const DFA *dfa) - { return o << *dfa; } +{ + return o << *dfa; +} + +} // end namespace re2c #endif diff --git a/tools/re2c/examples/push.re b/tools/re2c/examples/push.re new file mode 100644 index 000000000..a76b7aec3 --- /dev/null +++ b/tools/re2c/examples/push.re @@ -0,0 +1,340 @@ +/* + * A push-model scanner example for re2c -f + * Written Mon Apr 11 2005 by mgix@mgix.com + * This file is in the public domain. + * + */ + +// ---------------------------------------------------------------------- + +#include +#include +#include +#include +#include + +#if defined(WIN32) + + typedef signed char int8_t; + typedef signed short int16_t; + typedef signed int int32_t; + + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + +#else + + #include + #include + + #ifndef O_BINARY + #define O_BINARY 0 + #endif + +#endif + +// ---------------------------------------------------------------------- +#define TOKENS \ + \ + TOK(kEOF) \ + TOK(kEOL) \ + TOK(kUnknown) \ + TOK(kIdentifier) \ + TOK(kDecimalConstant) \ + \ + TOK(kEqual) \ + TOK(kLeftParen) \ + TOK(kRightParen) \ + TOK(kMinus) \ + TOK(kPlus) \ + TOK(kStar) \ + TOK(kSlash) \ + \ + TOK(kIf) \ + TOK(kFor) \ + TOK(kElse) \ + TOK(kGoto) \ + TOK(kBreak) \ + TOK(kWhile) \ + TOK(kReturn) \ + + +// ---------------------------------------------------------------------- +static const char *tokenNames[] = +{ + #define TOK(x) #x, + TOKENS + #undef TOK +}; + +// ---------------------------------------------------------------------- +class PushScanner +{ +public: + + enum Token + { + #define TOK(x) x, + TOKENS + #undef TOK + }; + +private: + + bool eof; + int32_t state; + + uint8_t *limit; + uint8_t *start; + uint8_t *cursor; + uint8_t *marker; + + uint8_t *buffer; + uint8_t *bufferEnd; + + uint8_t yych; + uint32_t yyaccept; + +public: + + // ---------------------------------------------------------------------- + PushScanner() + { + limit = 0; + start = 0; + state = -1; + cursor = 0; + marker = 0; + buffer = 0; + eof = false; + bufferEnd = 0; + } + + // ---------------------------------------------------------------------- + ~PushScanner() + { + } + + // ---------------------------------------------------------------------- + void send( + Token token + ) + { + size_t tokenSize = cursor-start; + const char *tokenName = tokenNames[token]; + printf( + "scanner is pushing out a token of type %d (%s)", + token, + tokenName + ); + + if(token==kEOF) putchar('\n'); + else + { + size_t tokenNameSize = strlen(tokenNames[token]); + size_t padSize = 20-(20"); + + fwrite( + start, + tokenSize, + 1, + stdout + ); + + printf("<----\n"); + } + } + + // ---------------------------------------------------------------------- + uint32_t push( + const void *input, + ssize_t inputSize + ) + { + printf( + "scanner is receiving a new data batch of length %d\n" + "scanner continues with saved state = %d\n", + inputSize, + state + ); + + /* + * Data source is signaling end of file when batch size + * is less than maxFill. This is slightly annoying because + * maxFill is a value that can only be known after re2c does + * its thing. Practically though, maxFill is never bigger than + * the longest keyword, so given our grammar, 32 is a safe bet. + */ + uint8_t null[64]; + const ssize_t maxFill = 32; + if(inputSize +#include +#include + +#define RET(n) printf("%d\n", n); return n + +int scan(char *s, int l){ +char *p = s; +char *q; +#define YYCTYPE char +#define YYCURSOR p +#define YYLIMIT (s+l) +#define YYMARKER q +#define YYFILL(n) +/*!re2c + 'a'{1}"\n" {RET(1);} + 'a'{2,3}"\n" {RET(2);} + 'a'{6}"\n" {RET(4);} + 'a'{4,}"\n" {RET(3);} + [^aq]|"\n" {RET(0);} +*/ +} + +#define do_scan(str) scan(str, strlen(str)) + +main() +{ + do_scan("a\n"); + do_scan("aa\n"); + do_scan("aaa\n"); + do_scan("aaaa\n"); + do_scan("q"); + do_scan("a"); + do_scan("A\n"); + do_scan("AA\n"); + do_scan("aAa\n"); + do_scan("AaaA\n"); + do_scan("Q"); + do_scan("AaaAa\n"); + do_scan("AaaAaA\n"); + do_scan("A"); + do_scan("\n"); + do_scan("0"); +} diff --git a/tools/re2c/globals.h b/tools/re2c/globals.h index ed83e81da..0c21047d3 100644 --- a/tools/re2c/globals.h +++ b/tools/re2c/globals.h @@ -1,18 +1,73 @@ -/* $Id: globals.h,v 1.4 2004/05/13 03:47:52 nuffer Exp $ */ +/* $Id: globals.h,v 1.31 2006/05/14 13:38:26 helly Exp $ */ #ifndef _globals_h #define _globals_h #include "basics.h" +#include +#include +#include +#include "stream_lc.h" + +namespace re2c +{ + +extern file_info sourceFileInfo; +extern file_info outputFileInfo; -extern char *fileName; -extern char *outputFileName; -extern bool sFlag; extern bool bFlag; -extern unsigned int oline; +extern bool dFlag; +extern bool eFlag; +extern bool fFlag; +extern bool gFlag; +extern bool iFlag; +extern bool sFlag; +extern bool wFlag; -extern uchar asc2ebc[256]; -extern uchar ebc2asc[256]; +extern bool bSinglePass; +extern bool bLastPass; -extern uchar *xlat, *talx; +extern bool bUsedYYAccept; +extern bool bUsedYYMaxFill; +extern bool bUsedYYMarker; + +extern bool bUseStartLabel; +extern std::string startLabelName; +extern uint maxFill; +extern uint next_label; +extern uint cGotoThreshold; + +/* configurations */ +extern uint topIndent; +extern std::string indString; +extern bool yybmHexTable; +extern bool bUseStateAbort; +extern bool bUseStateNext; +extern bool bWroteGetState; +extern bool bUseYYFill; + +extern uint asc2ebc[256]; +extern uint ebc2asc[256]; + +extern uint *xlat, *talx; + +extern uint next_fill_index; +extern uint last_fill_index; +extern std::set vUsedLabels; + +extern uint nRealChars; + +inline char octCh(uint c) +{ + return '0' + c % 8; +} + +inline char hexCh(uint c) +{ + static const char * sHex = "0123456789ABCDEF"; + + return sHex[c & 0x0F]; +} + +} // end namespace re2c #endif diff --git a/tools/re2c/ins.h b/tools/re2c/ins.h index efd6034c4..013273859 100644 --- a/tools/re2c/ins.h +++ b/tools/re2c/ins.h @@ -1,11 +1,13 @@ -/* $Id: ins.h,v 1.3 2004/05/13 02:58:17 nuffer Exp $ */ +/* $Id: ins.h,v 1.7 2006/01/03 11:40:38 helly Exp $ */ #ifndef _ins_h #define _ins_h #include "basics.h" -const uint nChars = 256; -typedef uchar Char; +namespace re2c +{ + +typedef unsigned short Char; const uint CHAR = 0; const uint GOTO = 1; @@ -14,28 +16,41 @@ const uint TERM = 3; const uint CTXT = 4; union Ins { - struct { - byte tag; - byte marked; - void *link; - } i; - struct { - ushort value; - ushort bump; - void *link; - } c; + + struct + { + byte tag; + byte marked; + void *link; + } + + i; + + struct + { + ushort value; + ushort bump; + void *link; + } + + c; }; -inline bool isMarked(Ins *i){ - return i->i.marked != 0; +inline bool isMarked(Ins *i) +{ + return i->i.marked != 0; } -inline void mark(Ins *i){ - i->i.marked = true; +inline void mark(Ins *i) +{ + i->i.marked = true; } -inline void unmark(Ins *i){ - i->i.marked = false; +inline void unmark(Ins *i) +{ + i->i.marked = false; } +} // end namespace re2c + #endif diff --git a/tools/re2c/install-sh b/tools/re2c/install-sh deleted file mode 100644 index e9de23842..000000000 --- a/tools/re2c/install-sh +++ /dev/null @@ -1,251 +0,0 @@ -#!/bin/sh -# -# install - install a program, script, or datafile -# This comes from X11R5 (mit/util/scripts/install.sh). -# -# Copyright 1991 by the Massachusetts Institute of Technology -# -# Permission to use, copy, modify, distribute, and sell this software and its -# documentation for any purpose is hereby granted without fee, provided that -# the above copyright notice appear in all copies and that both that -# copyright notice and this permission notice appear in supporting -# documentation, and that the name of M.I.T. not be used in advertising or -# publicity pertaining to distribution of the software without specific, -# written prior permission. M.I.T. makes no representations about the -# suitability of this software for any purpose. It is provided "as is" -# without express or implied warranty. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. It can only install one file at a time, a restriction -# shared with many OS's install programs. - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -transformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 -else - true -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d $dst ]; then - instcmd=: - chmodcmd="" - else - instcmd=mkdir - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f $src -o -d $src ] - then - true - else - echo "install: $src does not exist" - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "install: no destination specified" - exit 1 - else - true - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d $dst ] - then - dst="$dst"/`basename $src` - else - true - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' -' -IFS="${IFS-${defaultIFS}}" - -oIFS="${IFS}" -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS="${oIFS}" - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp="${pathcomp}${1}" - shift - - if [ ! -d "${pathcomp}" ] ; - then - $mkdirprog "${pathcomp}" - else - true - fi - - pathcomp="${pathcomp}/" -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd $dst && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename $dst` - else - dstfile=`basename $dst $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename $dst` - else - true - fi - -# Make a temp file name in the proper directory. - - dsttmp=$dstdir/#inst.$$# - -# Move or copy the file name to the temp name - - $doit $instcmd $src $dsttmp && - - trap "rm -f ${dsttmp}" 0 && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && - -# Now rename the file to the real destination. - - $doit $rmcmd -f $dstdir/$dstfile && - $doit $mvcmd $dsttmp $dstdir/$dstfile - -fi && - - -exit 0 diff --git a/tools/re2c/main.cc b/tools/re2c/main.cc index 08d896f6f..fccbde842 100644 --- a/tools/re2c/main.cc +++ b/tools/re2c/main.cc @@ -1,8 +1,8 @@ -/* $Id: main.cc,v 1.10 2004/05/13 03:47:52 nuffer Exp $ */ +/* $Id: main.cc,v 1.53 2006/05/14 13:38:26 helly Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" -#elif _WIN32 -#include "configwin.h" +#elif defined(_WIN32) +#include "config_w32.h" #endif #include @@ -15,89 +15,234 @@ #include "dfa.h" #include "mbo_getopt.h" -char *fileName = 0; -char *outputFileName = 0; -bool sFlag = false; +namespace re2c +{ + +file_info sourceFileInfo; +file_info outputFileInfo; + bool bFlag = false; -unsigned int oline = 1; +bool dFlag = false; +bool eFlag = false; +bool fFlag = false; +bool gFlag = false; +bool iFlag = false; +bool sFlag = false; +bool wFlag = false; + +bool bSinglePass = false; +bool bLastPass = false; + +bool bUsedYYAccept = false; +bool bUsedYYMaxFill = false; +bool bUsedYYMarker = true; + +bool bUseStartLabel= false; +bool bUseStateNext = false; +bool bUseYYFill = true; + +std::string startLabelName; +uint maxFill = 1; +uint next_label = 0; +uint cGotoThreshold = 9; + +uint topIndent = 0; +std::string indString("\t"); +bool yybmHexTable = false; +bool bUseStateAbort = false; +bool bWroteGetState = false; + +uint nRealChars = 256; + +uint next_fill_index = 0; +uint last_fill_index = 0; +std::set vUsedLabels; using namespace std; static char *opt_arg = NULL; static int opt_ind = 1; -static const mbo_opt_struct OPTIONS[] = { - {'?', 0, "help"}, - {'b', 0, "bit-vectors"}, - {'e', 0, "ecb"}, - {'h', 0, "help"}, - {'s', 0, "nested-ifs"}, - {'o', 1, "output"}, - {'v', 0, "version"} +static const mbo_opt_struct OPTIONS[] = +{ + mbo_opt_struct('?', 0, "help"), + mbo_opt_struct('b', 0, "bit-vectors"), + mbo_opt_struct('d', 0, "debug-output"), + mbo_opt_struct('e', 0, "ecb"), + mbo_opt_struct('f', 0, "storable-state"), + mbo_opt_struct('g', 0, "computed-gotos"), + mbo_opt_struct('h', 0, "help"), + mbo_opt_struct('i', 0, "no-debug-info"), + mbo_opt_struct('o', 1, "output"), + mbo_opt_struct('s', 0, "nested-ifs"), + mbo_opt_struct('v', 0, "version"), + mbo_opt_struct('V', 0, "vernum"), + mbo_opt_struct('w', 0, "wide-chars"), + mbo_opt_struct('1', 0, "two-pass"), + mbo_opt_struct('-', 0, NULL) /* end of args */ }; static void usage() { - cerr << "usage: re2c [-esbvh] file\n" - "\n" - "-? -h --help Display this info.\n" - "\n" - "-b --bit-vectors Implies -s. Use bit vectors as well in the attempt to\n" - " coax better code out of the compiler. Most useful for\n" - " specifications with more than a few keywords (e.g. for\n" - " most programming languages).\n" - "\n" - "-e --ecb Cross-compile from an ASCII platform to\n" - " an EBCDIC one.\n" - "\n" - "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n" - " need this assist to generate better code.\n" - "\n" - "-o --output=output Specify the output file instead of stdout\n" - "\n" - "-v --version Show version information.\n"; + cerr << "usage: re2c [-bdefghisvVw1] [-o file] file\n" + "\n" + "-? -h --help Display this info.\n" + "\n" + "-b --bit-vectors Implies -s. Use bit vectors as well in the attempt to\n" + " coax better code out of the compiler. Most useful for\n" + " specifications with more than a few keywords (e.g. for\n" + " most programming languages).\n" + "\n" + "-d --debug-output Creates a parser that dumps information during\n" + " about the current position and in which state the\n" + " parser is.\n" + "\n" + "-e --ecb Cross-compile from an ASCII platform to\n" + " an EBCDIC one.\n" + "\n" + "-f --storable-state Generate a scanner that supports storable states.\n" + "\n" + "-g --computed-gotos Implies -b. Generate computed goto code (only useable\n" + " with gcc).\n" + "\n" + "-i --no-debug-info Do not generate '#line' info (usefull for versioning).\n" + "\n" + "-o --output=output Specify the output file instead of stdout\n" + " This cannot be used together with -e switch.\n" + "\n" + "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n" + " need this assist to generate better code.\n" + "\n" + "-v --version Show version information.\n" + "-V --vernum Show version as one number.\n" + "\n" + "-w --wide-chars Create a parser that supports wide chars (UCS-2). This\n" + " implies -s and cannot be used together with -e switch.\n" + "\n" + "-1 --single-pass Force single pass generation, this cannot be combined\n" + " with -f and disables YYMAXFILL generation prior to last\n" + " re2c block.\n" + ; } +} // end namespace re2c + +using namespace re2c; + int main(int argc, char *argv[]) { int c; - fileName = NULL; + const char *sourceFileName = 0; + const char *outputFileName = 0; - if (argc == 1) { + if (argc == 1) + { usage(); return 2; } - while ((c = mbo_getopt(argc, argv, OPTIONS, &opt_arg, &opt_ind, 0))!=-1) { - switch (c) { + while ((c = mbo_getopt(argc, argv, OPTIONS, &opt_arg, &opt_ind, 0)) != -1) + { + switch (c) + { + case 'b': - sFlag = true; - bFlag = true; - break; + bFlag = true; + sFlag = true; + break; + case 'e': - xlat = asc2ebc; - talx = ebc2asc; - break; - case 's': - sFlag = true; - break; + xlat = asc2ebc; + talx = ebc2asc; + eFlag = true; + break; + + case 'd': + dFlag = true; + break; + + case 'f': + fFlag = true; + if (bSinglePass) { + std::cerr << "re2c: error: cannot combine -1 and -f switch\n"; + return 1; + } + break; + + case 'g': + gFlag = true; + bFlag = true; + sFlag = true; + break; + + case 'i': + iFlag = true; + break; + case 'o': - outputFileName = opt_arg; - break; + outputFileName = opt_arg; + break; + + case 's': + sFlag = true; + break; + + case '1': + if (bFlag) { + std::cerr << "re2c: error: cannot combine -1 and -f switch\n"; + return 1; + } + bSinglePass = true; + break; + case 'v': - cerr << "re2c " << PACKAGE_VERSION << "\n"; + cout << "re2c " << PACKAGE_VERSION << "\n"; + return 2; + + case 'V': { + string vernum(PACKAGE_VERSION); + + if (vernum[1] == '.') + { + vernum.insert(0, "0"); + } + vernum.erase(2, 1); + if (vernum[3] == '.') + { + vernum.insert(2, "0"); + } + vernum.erase(4, 1); + if (vernum.length() < 6 || vernum[5] < '0' || vernum[5] > '9') + { + vernum.insert(4, "0"); + } + vernum.resize(6); + cout << vernum << endl; return 2; + } + + case 'w': + nRealChars = (1<<16); + sFlag = true; + wFlag = true; + break; + case 'h': case '?': default: - usage(); - return 2; + usage(); + return 2; } } - if (argc == opt_ind + 1) + if (wFlag && eFlag) { - fileName = argv[opt_ind]; + usage(); + return 2; + } + else if (argc == opt_ind + 1) + { + sourceFileName = argv[opt_ind]; } else { @@ -105,45 +250,65 @@ int main(int argc, char *argv[]) return 2; } - // set up the input stream - istream* input = 0; - ifstream inputFile; - if (fileName[0] == '-' && fileName[1] == '\0') + // set up the source stream + re2c::ifstream_lc source; + + if (sourceFileName[0] == '-' && sourceFileName[1] == '\0') { - fileName = ""; - input = &cin; - } - else - { - inputFile.open(fileName); - if (!inputFile) + if (fFlag) { - cerr << "can't open " << fileName << "\n"; + std::cerr << "re2c: error: multiple /*!re2c stdin is not acceptable when -f is specified\n"; return 1; } - input = &inputFile; + sourceFileName = ""; + source.open(stdin); + } + else if (!source.open(sourceFileName).is_open()) + { + cerr << "re2c: error: cannot open " << sourceFileName << "\n"; + return 1; } // set up the output stream - ostream* output = 0; - ofstream outputFile; - if (outputFileName == 0 || (fileName[0] == '-' && fileName[1] == '\0')) + re2c::ofstream_lc output; + + if (outputFileName == 0 || (sourceFileName[0] == '-' && sourceFileName[1] == '\0')) { outputFileName = ""; - output = &cout; + output.open(stdout); } - else + else if (!output.open(outputFileName).is_open()) { - outputFile.open(outputFileName); - if (!outputFile) + cerr << "re2c: error: cannot open " << outputFileName << "\n"; + return 1; + } + Scanner scanner(sourceFileName, source, output); + sourceFileInfo = file_info(sourceFileName, &scanner); + outputFileInfo = file_info(outputFileName, &output); + + if (!bSinglePass) + { + bUsedYYMarker = false; + + re2c::ifstream_lc null_source; + + if (!null_source.open(sourceFileName).is_open()) { - cerr << "can't open " << outputFileName << "\n"; + cerr << "re2c: error: cannot re-open " << sourceFileName << "\n"; return 1; } - output = &outputFile; + + null_stream null_dev; + Scanner null_scanner(sourceFileName, null_source, null_dev); + parse(null_scanner, null_dev); + next_label = 0; + next_fill_index = 0; + Symbol::ClearTable(); + bWroteGetState = false; + bUsedYYMaxFill = false; } - parse(*input, *output); + bLastPass = true; + parse(scanner, output); return 0; - } diff --git a/tools/re2c/makerpm.in b/tools/re2c/makerpm.in deleted file mode 100644 index 7ce05d770..000000000 --- a/tools/re2c/makerpm.in +++ /dev/null @@ -1,45 +0,0 @@ -#! /bin/sh - -# $Id: makerpm.in,v 1.7 2004/04/19 23:31:34 helly Exp $ -# M.Boerger - -PREFIX="@PACKAGE_NAME@" -VERSION="@PACKAGE_VERSION@" -TARDIR="`basename \`pwd\``" -RELEASE=${1:-1} - -echo "Usage:" -echo "$0 " -echo -echo "e.g.:" -echo "$0" -echo -n "Building RPM version $VERSION, release: $RELEASE " -sleep 1 ; echo -n . ; sleep 1 ; echo -n . ; sleep 1 ; echo -n . -echo - -TAR=@PACKAGE_TARNAME@-$VERSION.tar.gz -SPEC=re2c-${VERSION}.spec - -RPMBASE=/usr/src/redhat -for i in /usr/src/redhat /usr/src/packages /usr/src/RPM; do - if test -d $i; then - RPMBASE=$i - break - fi -done - -RPMDIR=${RPMBASE}/RPMS -SPECDIR=${RPMBASE}/SPECS -SRCDIR=${RPMBASE}/SOURCES - -make dist -cp $TAR $SRCDIR - -cat re2c.spec | sed -e "s/RPM_RELEASE/${RELEASE}/g" > ${SPEC} - -echo "CP: (`pwd`) cp -a $SPEC $SPECDIR/${SPEC}" -cp -a $SPEC $SPECDIR/${SPEC} -#cp -a *.patch $SRCDIR -cd $SPECDIR -echo "RPM: rpm -ba ${SPEC}" -rpmbuild -ba ${SPEC} diff --git a/tools/re2c/mbo_getopt.cc b/tools/re2c/mbo_getopt.cc index c5723f614..145013d38 100644 --- a/tools/re2c/mbo_getopt.cc +++ b/tools/re2c/mbo_getopt.cc @@ -1,8 +1,8 @@ /* - Author: Marcus Boerger + Author: Marcus Boerger */ -/* $Id: mbo_getopt.cc,v 1.1 2004/04/19 21:14:46 helly Exp $ */ +/* $Id: mbo_getopt.cc,v 1.5 2006/04/17 19:28:47 helly Exp $ */ #include #include @@ -13,130 +13,189 @@ #define OPTERRNF (2) #define OPTERRARG (3) +namespace re2c +{ -static int mbo_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err) +static int mbo_opt_error(int, char * const *argv, int oint, int optchr, int err, int show_err) { if (show_err) { - fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1); - switch(err) + fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr + 1); + + switch (err) { - case OPTERRCOLON: + + case OPTERRCOLON: fprintf(stderr, ": in flags\n"); break; - case OPTERRNF: + + case OPTERRNF: fprintf(stderr, "option not found %c\n", argv[oint][optchr]); break; - case OPTERRARG: + + case OPTERRARG: fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]); break; - default: + + default: fprintf(stderr, "unknown\n"); break; } } - return('?'); + + return ('?'); } -int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct opts[], char **optarg, int *optind, int show_err) +int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct *opts, char **optarg, int *optind, int show_err) { static int optchr = 0; static int dash = 0; /* have already seen the - */ - size_t arg_start = 2; + int arg_start = 2; int opts_idx = -1; - if (*optind >= argc) { - return(EOF); + if (*optind >= argc) + { + return (EOF); } - if (!dash) { - if ((argv[*optind][0] != '-')) { - return(EOF); - } else { + + if (!dash) + { + if ((argv[*optind][0] != '-')) + { + return (EOF); + } + else + { if (!argv[*optind][1]) { /* * use to specify stdin. Need to let pgm process this and * the following args - */ - return(EOF); + */ + return (EOF); } } } - if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) { + + if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) + { /* '--' indicates end of args if not followed by a known long option name */ - while (1) { + + while (1) + { opts_idx++; - if (opts[opts_idx].opt_char == '-') { + + if (opts[opts_idx].opt_char == '-') + { (*optind)++; - return(EOF); - } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) { + return (EOF); + } + else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) + { break; } } + optchr = 0; dash = 1; arg_start = 2 + strlen(opts[opts_idx].opt_name); } - if (!dash) { + + if (!dash) + { dash = 1; optchr = 1; } /* Check if the guy tries to do a -: kind of flag */ - if (argv[*optind][optchr] == ':') { + if (argv[*optind][optchr] == ':') + { dash = 0; (*optind)++; - return (mbo_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err)); + return (mbo_opt_error(argc, argv, *optind - 1, optchr, OPTERRCOLON, show_err)); } - if (opts_idx < 0) { - while (1) { + + if (opts_idx < 0) + { + while (1) + { opts_idx++; - if (opts[opts_idx].opt_char == '-') { + + if (opts[opts_idx].opt_char == '-') + { int errind = *optind; int errchr = optchr; - - if (!argv[*optind][optchr+1]) { + + if (!argv[*optind][optchr + 1]) + { dash = 0; (*optind)++; - } else { + } + else + { optchr++; } - return(mbo_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err)); - } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) { + + return (mbo_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err)); + } + else if (argv[*optind][optchr] == opts[opts_idx].opt_char) + { break; } } } - if (opts[opts_idx].need_param) { + + if (opts[opts_idx].need_param) + { /* Check for cases where the value of the argument is in the form - or in the form - */ dash = 0; - if(!argv[*optind][arg_start]) { + + if (!argv[*optind][arg_start]) + { (*optind)++; - if (*optind == argc) { - return(mbo_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err)); + + if (*optind == argc) + { + return (mbo_opt_error(argc, argv, *optind - 1, optchr, OPTERRARG, show_err)); } + *optarg = argv[(*optind)++]; - } else { + } + else + { *optarg = &argv[*optind][arg_start]; (*optind)++; } + return opts[opts_idx].opt_char; - } else { - if (arg_start == 2) { - if (!argv[*optind][optchr+1]) + } + else + { + if (arg_start == 2) + { + if (!argv[*optind][optchr + 1]) { dash = 0; (*optind)++; - } else { + } + else + { optchr++; } - } else { + } + else + { (*optind)++; } + return opts[opts_idx].opt_char; } + assert(0); - return(0); /* never reached */ + return (0); /* never reached */ } + +} // end namespace re2c + diff --git a/tools/re2c/mbo_getopt.h b/tools/re2c/mbo_getopt.h index 781d553b3..f38b7ab5e 100644 --- a/tools/re2c/mbo_getopt.h +++ b/tools/re2c/mbo_getopt.h @@ -1,16 +1,34 @@ /* - Author: Marcus Boerger + Author: Marcus Boerger */ -/* $Id: mbo_getopt.h,v 1.1 2004/04/19 21:14:46 helly Exp $ */ +/* $Id: mbo_getopt.h,v 1.5 2006/04/17 19:28:47 helly Exp $ */ /* Define structure for one recognized option (both single char and long name). * If short_open is '-' this is the last option. */ -typedef struct _mbo_opt_struct { - const char opt_char; - const int need_param; - const char * opt_name; -} mbo_opt_struct; -int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct opts[], char **optarg, int *optind, int show_err); +#ifndef RE2C_MBO_GETOPT_H_INCLUDE_GUARD_ +#define RE2C_MBO_GETOPT_H_INCLUDE_GUARD_ + +namespace re2c +{ + +struct mbo_opt_struct +{ + mbo_opt_struct(char _opt_char, int _need_param, const char * _opt_name) + : opt_char(_opt_char), need_param(_need_param), opt_name(_opt_name) + { + } + + const char opt_char; + const int need_param; + const char * opt_name; +}; + +int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct *opts, char **optarg, int *optind, int show_err); + +} // end namespace re2c + +#endif + diff --git a/tools/re2c/missing b/tools/re2c/missing deleted file mode 100644 index 22e101ab1..000000000 --- a/tools/re2c/missing +++ /dev/null @@ -1,198 +0,0 @@ -#! /bin/sh -# Common stub for a few missing GNU programs while installing. -# Copyright (C) 1996, 1997, 2001, 2002 Free Software Foundation, Inc. -# Franc,ois Pinard , 1996. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# 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. - -if test $# -eq 0; then - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 -fi - -# In the cases where this matters, `missing' is being run in the -# srcdir already. -if test -f configure.in; then - configure_ac=configure.ac -else - configure_ac=configure.in -fi - -case "$1" in - - -h|--h|--he|--hel|--help) - echo "\ -$0 [OPTION]... PROGRAM [ARGUMENT]... - -Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an -error status if there is no known handling for PROGRAM. - -Options: - -h, --help display this help and exit - -v, --version output version information and exit - -Supported PROGRAM values: - aclocal touch file \`aclocal.m4' - autoconf touch file \`configure' - autoheader touch file \`config.h.in' - automake touch all \`Makefile.in' files - bison create \`y.tab.[ch]', if possible, from existing .[ch] - flex create \`lex.yy.c', if possible, from existing .c - lex create \`lex.yy.c', if possible, from existing .c - makeinfo touch the output file - yacc create \`y.tab.[ch]', if possible, from existing .[ch]" - ;; - - -v|--v|--ve|--ver|--vers|--versi|--versio|--version) - echo "missing - GNU libit 0.0" - ;; - - -*) - echo 1>&2 "$0: Unknown \`$1' option" - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 - ;; - - aclocal*) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`acinclude.m4' or \`$configure_ac'. You might want - to install the \`Automake' and \`Perl' packages. Grab them from - any GNU archive site." - touch aclocal.m4 - ;; - - autoconf) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`$configure_ac'. You might want to install the - \`Autoconf' and \`GNU m4' packages. Grab them from any GNU - archive site." - touch configure - ;; - - autoheader) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`acconfig.h' or \`$configure_ac'. You might want - to install the \`Autoconf' and \`GNU m4' packages. Grab them - from any GNU archive site." - files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' $configure_ac` - test -z "$files" && files="config.h" - touch_files= - for f in $files; do - case "$f" in - *:*) touch_files="$touch_files "`echo "$f" | - sed -e 's/^[^:]*://' -e 's/:.*//'`;; - *) touch_files="$touch_files $f.in";; - esac - done - touch $touch_files - ;; - - automake*) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`Makefile.am', \`acinclude.m4' or \`$configure_ac'. - You might want to install the \`Automake' and \`Perl' packages. - Grab them from any GNU archive site." - find . -type f -name Makefile.am -print | - sed 's/\.am$/.in/' | - while read f; do touch "$f"; done - ;; - - bison|yacc) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified a \`.y' file. You may need the \`Bison' package - in order for those modifications to take effect. You can get - \`Bison' from any GNU archive site." - rm -f y.tab.c y.tab.h - if [ $# -ne 1 ]; then - eval LASTARG="\${$#}" - case "$LASTARG" in - *.y) - SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" y.tab.c - fi - SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" y.tab.h - fi - ;; - esac - fi - if [ ! -f y.tab.h ]; then - echo >y.tab.h - fi - if [ ! -f y.tab.c ]; then - echo 'main() { return 0; }' >y.tab.c - fi - ;; - - lex|flex) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified a \`.l' file. You may need the \`Flex' package - in order for those modifications to take effect. You can get - \`Flex' from any GNU archive site." - rm -f lex.yy.c - if [ $# -ne 1 ]; then - eval LASTARG="\${$#}" - case "$LASTARG" in - *.l) - SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" lex.yy.c - fi - ;; - esac - fi - if [ ! -f lex.yy.c ]; then - echo 'main() { return 0; }' >lex.yy.c - fi - ;; - - makeinfo) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified a \`.texi' or \`.texinfo' file, or any other file - indirectly affecting the aspect of the manual. The spurious - call might also be the consequence of using a buggy \`make' (AIX, - DU, IRIX). You might want to install the \`Texinfo' package or - the \`GNU make' package. Grab either from any GNU archive site." - file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` - if test -z "$file"; then - file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` - file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` - fi - touch $file - ;; - - *) - echo 1>&2 "\ -WARNING: \`$1' is needed, and you do not seem to have it handy on your - system. You might have modified some files without having the - proper tools for further handling them. Check the \`README' file, - it often tells you about the needed prerequirements for installing - this package. You may also peek at any GNU archive site, in case - some other package would contain this missing \`$1' program." - exit 1 - ;; -esac - -exit 0 diff --git a/tools/re2c/mkinstalldirs b/tools/re2c/mkinstalldirs deleted file mode 100644 index 4f58503ea..000000000 --- a/tools/re2c/mkinstalldirs +++ /dev/null @@ -1,40 +0,0 @@ -#! /bin/sh -# mkinstalldirs --- make directory hierarchy -# Author: Noah Friedman -# Created: 1993-05-16 -# Public domain - -# $Id: mkinstalldirs,v 1.13 1999/01/05 03:18:55 bje Exp $ - -errstatus=0 - -for file -do - set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` - shift - - pathcomp= - for d - do - pathcomp="$pathcomp$d" - case "$pathcomp" in - -* ) pathcomp=./$pathcomp ;; - esac - - if test ! -d "$pathcomp"; then - echo "mkdir $pathcomp" - - mkdir "$pathcomp" || lasterr=$? - - if test ! -d "$pathcomp"; then - errstatus=$lasterr - fi - fi - - pathcomp="$pathcomp/" - done -done - -exit $errstatus - -# mkinstalldirs ends here diff --git a/tools/re2c/parser.cc b/tools/re2c/parser.cc index c99d63a63..2b9cacc21 100644 --- a/tools/re2c/parser.cc +++ b/tools/re2c/parser.cc @@ -1,7 +1,7 @@ -/* A Bison parser, made by GNU Bison 1.875. */ +/* A Bison parser, made by GNU Bison 2.1. */ /* Skeleton parser for Yacc-like parsing with Bison, - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,8 +15,8 @@ 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. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction. @@ -36,6 +36,9 @@ /* Identify Bison output. */ #define YYBISON 1 +/* Bison version. */ +#define YYBISON_VERSION "2.1" + /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -58,15 +61,22 @@ ID = 260, CODE = 261, RANGE = 262, - STRING = 263 + STRING = 263, + CONFIG = 264, + VALUE = 265, + NUMBER = 266 }; #endif +/* Tokens. */ #define CLOSESIZE 258 #define CLOSE 259 #define ID 260 #define CODE 261 #define RANGE 262 #define STRING 263 +#define CONFIG 264 +#define VALUE 265 +#define NUMBER 266 @@ -75,12 +85,10 @@ #line 1 "parser.y" -/* $Id: parser.y,v 1.9 2004/05/13 14:26:01 nuffer Exp $ */ +/* $Id: parser.y,v 1.20 2006/04/16 15:15:46 helly Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" -#elif _WIN32 -#include "configwin.h" #endif #include @@ -90,15 +98,20 @@ #include "globals.h" #include "parser.h" +#include "basics.h" + +#define YYMALLOC malloc +#define YYFREE free + +using namespace re2c; extern "C" { -int yyparse(); int yylex(); -void yyerror(char*); +void yyerror(const char*); } -static uint accept; +static re2c::uint accept; static RegExp *spec; static Scanner *in; @@ -138,17 +151,24 @@ static char* strdup(const char* s) # define YYERROR_VERBOSE 0 #endif +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 53 "parser.y" +#line 58 "parser.y" typedef union YYSTYPE { - Symbol *symbol; - RegExp *regexp; - Token *token; - char op; - ExtOp extop; + re2c::Symbol *symbol; + re2c::RegExp *regexp; + re2c::Token *token; + char op; + int number; + re2c::ExtOp extop; + re2c::Str *str; } YYSTYPE; -/* Line 191 of yacc.c. */ -#line 149 "y.tab.c" +/* Line 196 of yacc.c. */ +#line 172 "parser.cc" # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 @@ -159,22 +179,48 @@ typedef union YYSTYPE { /* Copy the second part of user declarations. */ -/* Line 214 of yacc.c. */ -#line 161 "y.tab.c" +/* Line 219 of yacc.c. */ +#line 184 "parser.cc" + +#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) +# define YYSIZE_T __SIZE_TYPE__ +#endif +#if ! defined (YYSIZE_T) && defined (size_t) +# define YYSIZE_T size_t +#endif +#if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus)) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +#endif +#if ! defined (YYSIZE_T) +# define YYSIZE_T unsigned int +#endif + +#ifndef YY_ +# if YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif #if ! defined (yyoverflow) || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ -# if YYSTACK_USE_ALLOCA -# define YYSTACK_ALLOC alloca -# else -# ifndef YYSTACK_USE_ALLOCA -# if defined (alloca) || defined (_ALLOCA_H) -# define YYSTACK_ALLOC alloca +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca # else -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca +# define YYSTACK_ALLOC alloca +# if defined (__STDC__) || defined (__cplusplus) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYINCLUDED_STDLIB_H # endif # endif # endif @@ -183,25 +229,51 @@ typedef union YYSTYPE { # ifdef YYSTACK_ALLOC /* Pacify GCC's `empty if-body' warning. */ # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# else -# if defined (__STDC__) || defined (__cplusplus) -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2005 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1) +# endif +# ifdef __cplusplus +extern "C" { +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \ + && (defined (__STDC__) || defined (__cplusplus))) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \ + && (defined (__STDC__) || defined (__cplusplus))) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifdef __cplusplus +} # endif -# define YYSTACK_ALLOC malloc -# define YYSTACK_FREE free # endif #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ #if (! defined (yyoverflow) \ && (! defined (__cplusplus) \ - || (YYSTYPE_IS_TRIVIAL))) + || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { - short yyss; + short int yyss; YYSTYPE yyvs; }; @@ -211,20 +283,20 @@ union yyalloc /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ - ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ + ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) /* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY -# if 1 < __GNUC__ +# if defined (__GNUC__) && 1 < __GNUC__ # define YYCOPY(To, From, Count) \ __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else # define YYCOPY(To, From, Count) \ do \ { \ - register YYSIZE_T yyi; \ + YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (To)[yyi] = (From)[yyi]; \ } \ @@ -253,28 +325,28 @@ union yyalloc #if defined (__STDC__) || defined (__cplusplus) typedef signed char yysigned_char; #else - typedef short yysigned_char; + typedef short int yysigned_char; #endif /* YYFINAL -- State number of the termination state. */ #define YYFINAL 2 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 28 +#define YYLAST 37 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 16 +#define YYNTOKENS 19 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 11 /* YYNRULES -- Number of rules. */ -#define YYNRULES 23 +#define YYNRULES 26 /* YYNRULES -- Number of states. */ -#define YYNSTATES 33 +#define YYNSTATES 40 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 263 +#define YYMAXUTOK 266 -#define YYTRANSLATE(YYX) \ +#define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ @@ -284,15 +356,15 @@ static const unsigned char yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 14, 15, 2, 2, 2, 2, 2, 11, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, - 2, 9, 2, 2, 2, 2, 2, 2, 2, 2, + 17, 18, 2, 2, 2, 2, 2, 14, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 13, + 2, 12, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 13, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 16, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 12, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 15, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -306,7 +378,7 @@ static const unsigned char yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8 + 5, 6, 7, 8, 9, 10, 11 }; #if YYDEBUG @@ -314,68 +386,69 @@ static const unsigned char yytranslate[] = YYRHS. */ static const unsigned char yyprhs[] = { - 0, 0, 3, 4, 7, 10, 15, 19, 20, 23, - 25, 29, 31, 35, 37, 40, 42, 45, 48, 50, - 53, 55, 57, 59 + 0, 0, 3, 4, 7, 10, 15, 20, 25, 30, + 34, 35, 38, 40, 44, 46, 50, 52, 55, 57, + 60, 63, 65, 68, 70, 72, 74 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yysigned_char yyrhs[] = { - 17, 0, -1, -1, 17, 19, -1, 17, 18, -1, - 5, 9, 21, 10, -1, 21, 20, 6, -1, -1, - 11, 21, -1, 22, -1, 21, 12, 22, -1, 23, - -1, 22, 13, 23, -1, 24, -1, 23, 24, -1, - 26, -1, 26, 25, -1, 26, 3, -1, 4, -1, - 25, 4, -1, 5, -1, 7, -1, 8, -1, 14, - 21, 15, -1 + 20, 0, -1, -1, 20, 22, -1, 20, 21, -1, + 5, 12, 24, 13, -1, 9, 12, 10, 13, -1, + 9, 12, 11, 13, -1, 5, 12, 24, 14, -1, + 24, 23, 6, -1, -1, 14, 24, -1, 25, -1, + 24, 15, 25, -1, 26, -1, 25, 16, 26, -1, + 27, -1, 26, 27, -1, 29, -1, 29, 28, -1, + 29, 3, -1, 4, -1, 28, 4, -1, 5, -1, + 7, -1, 8, -1, 17, 24, 18, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const unsigned char yyrline[] = { - 0, 74, 74, 76, 78, 81, 87, 92, 93, 97, - 99, 103, 105, 112, 114, 118, 120, 134, 140, 142, - 146, 150, 152, 154 + 0, 84, 84, 86, 88, 91, 95, 97, 101, 105, + 110, 111, 115, 117, 121, 123, 130, 132, 136, 138, + 152, 158, 160, 164, 168, 170, 172 }; #endif -#if YYDEBUG || YYERROR_VERBOSE -/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "$end", "error", "$undefined", "CLOSESIZE", "CLOSE", "ID", "CODE", - "RANGE", "STRING", "'='", "';'", "'/'", "'|'", "'\\\\'", "'('", "')'", - "$accept", "spec", "decl", "rule", "look", "expr", "diff", "term", - "factor", "close", "primary", 0 + "$end", "error", "$undefined", "CLOSESIZE", "CLOSE", "ID", "CODE", + "RANGE", "STRING", "CONFIG", "VALUE", "NUMBER", "'='", "';'", "'/'", + "'|'", "'\\\\'", "'('", "')'", "$accept", "spec", "decl", "rule", "look", + "expr", "diff", "term", "factor", "close", "primary", 0 }; #endif # ifdef YYPRINT /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to token YYLEX-NUM. */ -static const unsigned short yytoknum[] = +static const unsigned short int yytoknum[] = { - 0, 256, 257, 258, 259, 260, 261, 262, 263, 61, - 59, 47, 124, 92, 40, 41 + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 61, 59, 47, 124, 92, 40, 41 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const unsigned char yyr1[] = { - 0, 16, 17, 17, 17, 18, 19, 20, 20, 21, - 21, 22, 22, 23, 23, 24, 24, 24, 25, 25, - 26, 26, 26, 26 + 0, 19, 20, 20, 20, 21, 21, 21, 21, 22, + 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, + 27, 28, 28, 29, 29, 29, 29 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const unsigned char yyr2[] = { - 0, 2, 0, 2, 2, 4, 3, 0, 2, 1, - 3, 1, 3, 1, 2, 1, 2, 2, 1, 2, - 1, 1, 1, 3 + 0, 2, 0, 2, 2, 4, 4, 4, 4, 3, + 0, 2, 1, 3, 1, 3, 1, 2, 1, 2, + 2, 1, 2, 1, 1, 1, 3 }; /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state @@ -383,35 +456,35 @@ static const unsigned char yyr2[] = means the default is an error. */ static const unsigned char yydefact[] = { - 2, 0, 1, 20, 21, 22, 0, 4, 3, 7, - 9, 11, 13, 15, 0, 20, 0, 0, 0, 0, - 0, 14, 17, 18, 16, 0, 23, 8, 10, 6, - 12, 19, 5 + 2, 0, 1, 23, 24, 25, 0, 0, 4, 3, + 10, 12, 14, 16, 18, 0, 0, 23, 0, 0, + 0, 0, 0, 17, 20, 21, 19, 0, 0, 0, + 26, 11, 13, 9, 15, 22, 5, 8, 6, 7 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yysigned_char yydefgoto[] = { - -1, 1, 7, 8, 19, 9, 10, 11, 12, 24, - 13 + -1, 1, 8, 9, 21, 10, 11, 12, 13, 26, + 14 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ -#define YYPACT_NINF -12 +#define YYPACT_NINF -13 static const yysigned_char yypact[] = { - -12, 1, -12, 13, -12, -12, 9, -12, -12, 0, - 5, 9, -12, 17, 9, -12, -8, 9, 9, 18, - 9, -12, -12, -12, 21, -7, -12, 14, 5, -12, - 9, -12, -12 + -13, 1, -13, -5, -13, -13, 0, -3, -13, -13, + 9, 13, -3, -13, 22, -3, 17, -13, -2, -3, + -3, 11, -3, -13, -13, -13, 26, 6, 18, 19, + -13, 20, 13, -13, -3, -13, -13, -13, -13, -13 }; /* YYPGOTO[NTERM-NUM]. */ static const yysigned_char yypgoto[] = { - -12, -12, -12, -12, -12, -4, 10, 7, -11, -12, - -12 + -13, -13, -13, -13, -13, -4, 14, 15, -12, -13, + -13 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If @@ -421,44 +494,30 @@ static const yysigned_char yypgoto[] = #define YYTABLE_NINF -1 static const unsigned char yytable[] = { - 21, 2, 16, 32, 18, 18, 3, 26, 4, 5, - 25, 17, 18, 27, 15, 6, 4, 5, 20, 21, - 22, 23, 14, 6, 29, 31, 18, 30, 28 + 23, 2, 17, 18, 4, 5, 3, 15, 4, 5, + 6, 27, 16, 20, 7, 31, 30, 33, 7, 36, + 37, 20, 23, 19, 20, 24, 25, 28, 29, 22, + 35, 38, 39, 0, 32, 20, 0, 34 }; -static const unsigned char yycheck[] = +static const yysigned_char yycheck[] = { - 11, 0, 6, 10, 12, 12, 5, 15, 7, 8, - 14, 11, 12, 17, 5, 14, 7, 8, 13, 30, - 3, 4, 9, 14, 6, 4, 12, 20, 18 + 12, 0, 5, 7, 7, 8, 5, 12, 7, 8, + 9, 15, 12, 15, 17, 19, 18, 6, 17, 13, + 14, 15, 34, 14, 15, 3, 4, 10, 11, 16, + 4, 13, 13, -1, 20, 15, -1, 22 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const unsigned char yystos[] = { - 0, 17, 0, 5, 7, 8, 14, 18, 19, 21, - 22, 23, 24, 26, 9, 5, 21, 11, 12, 20, - 13, 24, 3, 4, 25, 21, 15, 21, 22, 6, - 23, 4, 10 + 0, 20, 0, 5, 7, 8, 9, 17, 21, 22, + 24, 25, 26, 27, 29, 12, 12, 5, 24, 14, + 15, 23, 16, 27, 3, 4, 28, 24, 10, 11, + 18, 24, 25, 6, 26, 4, 13, 14, 13, 13 }; -#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) -# define YYSIZE_T __SIZE_TYPE__ -#endif -#if ! defined (YYSIZE_T) && defined (size_t) -# define YYSIZE_T size_t -#endif -#if ! defined (YYSIZE_T) -# if defined (__STDC__) || defined (__cplusplus) -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# endif -#endif -#if ! defined (YYSIZE_T) -# define YYSIZE_T unsigned int -#endif - #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) #define YYEMPTY (-2) @@ -466,7 +525,7 @@ static const unsigned char yystos[] = #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab -#define YYERROR goto yyerrlab1 +#define YYERROR goto yyerrorlab /* Like YYERROR except do call yyerror. This remains here temporarily @@ -488,26 +547,59 @@ do \ goto yybackup; \ } \ else \ - { \ - yyerror ("syntax error: cannot back up");\ + { \ + yyerror (YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (0) + #define YYTERROR 1 #define YYERRCODE 256 -/* YYLLOC_DEFAULT -- Compute the default location (before the actions - are run). */ +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.first_line = Rhs[1].first_line; \ - Current.first_column = Rhs[1].first_column; \ - Current.last_line = Rhs[N].last_line; \ - Current.last_column = Rhs[N].last_column; +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (0) #endif + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + /* YYLEX -- calling `yylex' with the right arguments. */ #ifdef YYLEX_PARAM @@ -530,36 +622,30 @@ do { \ YYFPRINTF Args; \ } while (0) -# define YYDSYMPRINT(Args) \ -do { \ - if (yydebug) \ - yysymprint Args; \ -} while (0) - -# define YYDSYMPRINTF(Title, Token, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ - yysymprint (stderr, \ - Token, Value); \ + yysymprint (stderr, \ + Type, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) /*------------------------------------------------------------------. | yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (cinluded). | +| TOP (included). | `------------------------------------------------------------------*/ #if defined (__STDC__) || defined (__cplusplus) static void -yy_stack_print (short *bottom, short *top) +yy_stack_print (short int *bottom, short int *top) #else static void yy_stack_print (bottom, top) - short *bottom; - short *top; + short int *bottom; + short int *top; #endif { YYFPRINTF (stderr, "Stack now"); @@ -589,13 +675,13 @@ yy_reduce_print (yyrule) #endif { int yyi; - unsigned int yylineno = yyrline[yyrule]; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", - yyrule - 1, yylineno); + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ", + yyrule - 1, yylno); /* Print the symbols being reduced, and their result. */ for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) - YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); - YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]); + YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); + YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]); } # define YY_REDUCE_PRINT(Rule) \ @@ -609,8 +695,7 @@ do { \ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) -# define YYDSYMPRINT(Args) -# define YYDSYMPRINTF(Title, Token, Value, Location) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ @@ -625,13 +710,9 @@ int yydebug; if the built-in stack extension method is used). Do not make this value too large; the results are undefined if - SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) evaluated with infinite-precision integer arithmetic. */ -#if YYMAXDEPTH == 0 -# undef YYMAXDEPTH -#endif - #ifndef YYMAXDEPTH # define YYMAXDEPTH 10000 #endif @@ -653,7 +734,7 @@ yystrlen (yystr) const char *yystr; # endif { - register const char *yys = yystr; + const char *yys = yystr; while (*yys++ != '\0') continue; @@ -678,8 +759,8 @@ yystpcpy (yydest, yysrc) const char *yysrc; # endif { - register char *yyd = yydest; - register const char *yys = yysrc; + char *yyd = yydest; + const char *yys = yysrc; while ((*yyd++ = *yys++) != '\0') continue; @@ -689,7 +770,55 @@ yystpcpy (yydest, yysrc) # endif # endif -#endif /* !YYERROR_VERBOSE */ +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + size_t yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +#endif /* YYERROR_VERBOSE */ @@ -713,15 +842,15 @@ yysymprint (yyoutput, yytype, yyvaluep) (void) yyvaluep; if (yytype < YYNTOKENS) - { - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); -# ifdef YYPRINT - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - } + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); else YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# endif switch (yytype) { default: @@ -737,10 +866,11 @@ yysymprint (yyoutput, yytype, yyvaluep) #if defined (__STDC__) || defined (__cplusplus) static void -yydestruct (int yytype, YYSTYPE *yyvaluep) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) #else static void -yydestruct (yytype, yyvaluep) +yydestruct (yymsg, yytype, yyvaluep) + const char *yymsg; int yytype; YYSTYPE *yyvaluep; #endif @@ -748,6 +878,10 @@ yydestruct (yytype, yyvaluep) /* Pacify ``unused variable'' warnings. */ (void) yyvaluep; + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + switch (yytype) { @@ -775,10 +909,10 @@ int yyparse (); -/* The lookahead symbol. */ +/* The look-ahead symbol. */ int yychar; -/* The semantic value of the lookahead symbol. */ +/* The semantic value of the look-ahead symbol. */ YYSTYPE yylval; /* Number of syntax errors so far. */ @@ -804,17 +938,17 @@ yyparse (void) #else int yyparse () - + ; #endif #endif { - register int yystate; - register int yyn; + int yystate; + int yyn; int yyresult; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; - /* Lookahead token as an internal (translated) token number. */ + /* Look-ahead token as an internal (translated) token number. */ int yytoken = 0; /* Three stacks and their tools: @@ -826,14 +960,14 @@ yyparse () to reallocate them elsewhere. */ /* The state stack. */ - short yyssa[YYINITDEPTH]; - short *yyss = yyssa; - register short *yyssp; + short int yyssa[YYINITDEPTH]; + short int *yyss = yyssa; + short int *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs = yyvsa; - register YYSTYPE *yyvsp; + YYSTYPE *yyvsp; @@ -890,14 +1024,14 @@ yyparse () these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; - short *yyss1 = yyss; + short int *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ - yyoverflow ("parser stack overflow", + yyoverflow (YY_("memory exhausted"), &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), @@ -908,21 +1042,21 @@ yyparse () } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE - goto yyoverflowlab; + goto yyexhaustedlab; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyoverflowlab; + goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { - short *yyss1 = yyss; + short int *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) - goto yyoverflowlab; + goto yyexhaustedlab; YYSTACK_RELOCATE (yyss); YYSTACK_RELOCATE (yyvs); @@ -954,18 +1088,18 @@ yyparse () yybackup: /* Do appropriate processing given the current state. */ -/* Read a lookahead token if we need one and don't already have one. */ +/* Read a look-ahead token if we need one and don't already have one. */ /* yyresume: */ - /* First try to decide what to do without reference to lookahead token. */ + /* First try to decide what to do without reference to look-ahead token. */ yyn = yypact[yystate]; if (yyn == YYPACT_NINF) goto yydefault; - /* Not known => get a lookahead token if don't already have one. */ + /* Not known => get a look-ahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); @@ -980,7 +1114,7 @@ yybackup: else { yytoken = YYTRANSLATE (yychar); - YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to @@ -1000,8 +1134,8 @@ yybackup: if (yyn == YYFINAL) YYACCEPT; - /* Shift the lookahead token. */ - YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); + /* Shift the look-ahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the token being shifted unless it is eof. */ if (yychar != YYEOF) @@ -1051,137 +1185,153 @@ yyreduce: switch (yyn) { case 2: -#line 74 "parser.y" +#line 84 "parser.y" { accept = 0; spec = NULL; } break; case 3: -#line 77 "parser.y" - { spec = spec? mkAlt(spec, yyvsp[0].regexp) : yyvsp[0].regexp; } +#line 87 "parser.y" + { spec = spec? mkAlt(spec, (yyvsp[0].regexp)) : (yyvsp[0].regexp); } break; case 5: -#line 82 "parser.y" - { if(yyvsp[-3].symbol->re) +#line 92 "parser.y" + { if((yyvsp[-3].symbol)->re) in->fatal("sym already defined"); - yyvsp[-3].symbol->re = yyvsp[-1].regexp; } + (yyvsp[-3].symbol)->re = (yyvsp[-1].regexp); } break; case 6: -#line 88 "parser.y" - { yyval.regexp = new RuleOp(yyvsp[-2].regexp, yyvsp[-1].regexp, yyvsp[0].token, accept++); } +#line 96 "parser.y" + { in->config(*(yyvsp[-3].str), *(yyvsp[-1].str)); } break; case 7: -#line 92 "parser.y" - { yyval.regexp = new NullOp; } +#line 98 "parser.y" + { in->config(*(yyvsp[-3].str), (yyvsp[-1].number)); } break; case 8: -#line 94 "parser.y" - { yyval.regexp = yyvsp[0].regexp; } +#line 102 "parser.y" + { in->fatal("trailing contexts are not allowed in named definitions"); } break; case 9: -#line 98 "parser.y" - { yyval.regexp = yyvsp[0].regexp; } +#line 106 "parser.y" + { (yyval.regexp) = new RuleOp((yyvsp[-2].regexp), (yyvsp[-1].regexp), (yyvsp[0].token), accept++); } break; case 10: -#line 100 "parser.y" - { yyval.regexp = mkAlt(yyvsp[-2].regexp, yyvsp[0].regexp); } +#line 110 "parser.y" + { (yyval.regexp) = new NullOp; } break; case 11: -#line 104 "parser.y" - { yyval.regexp = yyvsp[0].regexp; } +#line 112 "parser.y" + { (yyval.regexp) = (yyvsp[0].regexp); } break; case 12: -#line 106 "parser.y" - { yyval.regexp = mkDiff(yyvsp[-2].regexp, yyvsp[0].regexp); - if(!yyval.regexp) +#line 116 "parser.y" + { (yyval.regexp) = (yyvsp[0].regexp); } + break; + + case 13: +#line 118 "parser.y" + { (yyval.regexp) = mkAlt((yyvsp[-2].regexp), (yyvsp[0].regexp)); } + break; + + case 14: +#line 122 "parser.y" + { (yyval.regexp) = (yyvsp[0].regexp); } + break; + + case 15: +#line 124 "parser.y" + { (yyval.regexp) = mkDiff((yyvsp[-2].regexp), (yyvsp[0].regexp)); + if(!(yyval.regexp)) in->fatal("can only difference char sets"); } break; - case 13: -#line 113 "parser.y" - { yyval.regexp = yyvsp[0].regexp; } - break; - - case 14: -#line 115 "parser.y" - { yyval.regexp = new CatOp(yyvsp[-1].regexp, yyvsp[0].regexp); } - break; - - case 15: -#line 119 "parser.y" - { yyval.regexp = yyvsp[0].regexp; } - break; - case 16: -#line 121 "parser.y" +#line 131 "parser.y" + { (yyval.regexp) = (yyvsp[0].regexp); } + break; + + case 17: +#line 133 "parser.y" + { (yyval.regexp) = new CatOp((yyvsp[-1].regexp), (yyvsp[0].regexp)); } + break; + + case 18: +#line 137 "parser.y" + { (yyval.regexp) = (yyvsp[0].regexp); } + break; + + case 19: +#line 139 "parser.y" { - switch(yyvsp[0].op){ + switch((yyvsp[0].op)){ case '*': - yyval.regexp = mkAlt(new CloseOp(yyvsp[-1].regexp), new NullOp()); + (yyval.regexp) = mkAlt(new CloseOp((yyvsp[-1].regexp)), new NullOp()); break; case '+': - yyval.regexp = new CloseOp(yyvsp[-1].regexp); + (yyval.regexp) = new CloseOp((yyvsp[-1].regexp)); break; case '?': - yyval.regexp = mkAlt(yyvsp[-1].regexp, new NullOp()); + (yyval.regexp) = mkAlt((yyvsp[-1].regexp), new NullOp()); break; } } break; - case 17: -#line 135 "parser.y" + case 20: +#line 153 "parser.y" { - yyval.regexp = new CloseVOp(yyvsp[-1].regexp, yyvsp[0].extop.minsize, yyvsp[0].extop.maxsize); + (yyval.regexp) = new CloseVOp((yyvsp[-1].regexp), (yyvsp[0].extop).minsize, (yyvsp[0].extop).maxsize); } break; - case 18: -#line 141 "parser.y" - { yyval.op = yyvsp[0].op; } - break; - - case 19: -#line 143 "parser.y" - { yyval.op = (yyvsp[-1].op == yyvsp[0].op) ? yyvsp[-1].op : '*'; } - break; - - case 20: -#line 147 "parser.y" - { if(!yyvsp[0].symbol->re) - in->fatal("can't find symbol"); - yyval.regexp = yyvsp[0].symbol->re; } - break; - case 21: -#line 151 "parser.y" - { yyval.regexp = yyvsp[0].regexp; } +#line 159 "parser.y" + { (yyval.op) = (yyvsp[0].op); } break; case 22: -#line 153 "parser.y" - { yyval.regexp = yyvsp[0].regexp; } +#line 161 "parser.y" + { (yyval.op) = ((yyvsp[-1].op) == (yyvsp[0].op)) ? (yyvsp[-1].op) : '*'; } break; case 23: -#line 155 "parser.y" - { yyval.regexp = yyvsp[-1].regexp; } +#line 165 "parser.y" + { if(!(yyvsp[0].symbol)->re) + in->fatal("can't find symbol"); + (yyval.regexp) = (yyvsp[0].symbol)->re; } + break; + + case 24: +#line 169 "parser.y" + { (yyval.regexp) = (yyvsp[0].regexp); } + break; + + case 25: +#line 171 "parser.y" + { (yyval.regexp) = (yyvsp[0].regexp); } + break; + + case 26: +#line 173 "parser.y" + { (yyval.regexp) = (yyvsp[-1].regexp); } break; + default: break; } -/* Line 999 of yacc.c. */ -#line 1182 "y.tab.c" +/* Line 1126 of yacc.c. */ +#line 1335 "parser.cc" yyvsp -= yylen; yyssp -= yylen; @@ -1220,87 +1370,152 @@ yyerrlab: if (YYPACT_NINF < yyn && yyn < YYLAST) { - YYSIZE_T yysize = 0; int yytype = YYTRANSLATE (yychar); - char *yymsg; - int yyx, yycount; + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + char *yymsg = 0; +# define YYERROR_VERBOSE_ARGS_MAXIMUM 5 + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + +#if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +#endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; - yycount = 0; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. */ - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - yysize += yystrlen (yytname[yyx]) + 15, yycount++; - yysize += yystrlen ("syntax error, unexpected ") + 1; - yysize += yystrlen (yytname[yytype]); - yymsg = (char *) YYSTACK_ALLOC (yysize); - if (yymsg != 0) - { - char *yyp = yystpcpy (yymsg, "syntax error, unexpected "); - yyp = yystpcpy (yyp, yytname[yytype]); + int yyxbegin = yyn < 0 ? -yyn : 0; - if (yycount < 5) + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= yysize1 < yysize; + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= yysize1 < yysize; + yysize = yysize1; + + if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM) + yymsg = (char *) YYSTACK_ALLOC (yysize); + if (yymsg) + { + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yymsg; + int yyi = 0; + while ((*yyp = *yyf)) { - yycount = 0; - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); - yyx++) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - const char *yyq = ! yycount ? ", expecting " : " or "; - yyp = yystpcpy (yyp, yyq); - yyp = yystpcpy (yyp, yytname[yyx]); - yycount++; - } + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } } yyerror (yymsg); YYSTACK_FREE (yymsg); } else - yyerror ("syntax error; also virtual memory exhausted"); + { + yyerror (YY_("syntax error")); + goto yyexhaustedlab; + } } else #endif /* YYERROR_VERBOSE */ - yyerror ("syntax error"); + yyerror (YY_("syntax error")); } if (yyerrstatus == 3) { - /* If just tried and failed to reuse lookahead token after an + /* If just tried and failed to reuse look-ahead token after an error, discard it. */ - /* Return failure if at end of input. */ - if (yychar == YYEOF) + if (yychar <= YYEOF) { - /* Pop the error token. */ - YYPOPSTACK; - /* Pop the rest of the stack. */ - while (yyss < yyssp) - { - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[*yyssp], yyvsp); - YYPOPSTACK; - } - YYABORT; + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; } - - YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); - yydestruct (yytoken, &yylval); - yychar = YYEMPTY; - + else + { + yydestruct ("Error: discarding", yytoken, &yylval); + yychar = YYEMPTY; + } } - /* Else will try to reuse lookahead token after shifting the error + /* Else will try to reuse look-ahead token after shifting the error token. */ goto yyerrlab1; -/*----------------------------------------------------. -| yyerrlab1 -- error raised explicitly by an action. | -`----------------------------------------------------*/ +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (0) + goto yyerrorlab; + +yyvsp -= yylen; + yyssp -= yylen; + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ @@ -1322,22 +1537,22 @@ yyerrlab1: if (yyssp == yyss) YYABORT; - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[yystate], yyvsp); - yyvsp--; - yystate = *--yyssp; + yydestruct ("Error: popping", yystos[yystate], yyvsp); + YYPOPSTACK; + yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } if (yyn == YYFINAL) YYACCEPT; - YYDPRINTF ((stderr, "Shifting error token, ")); - *++yyvsp = yylval; + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + yystate = yyn; goto yynewstate; @@ -1357,16 +1572,25 @@ yyabortlab: goto yyreturn; #ifndef yyoverflow -/*----------------------------------------------. -| yyoverflowlab -- parser overflow comes here. | -`----------------------------------------------*/ -yyoverflowlab: - yyerror ("parser stack overflow"); +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: + if (yychar != YYEOF && yychar != YYEMPTY) + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp); + YYPOPSTACK; + } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); @@ -1375,11 +1599,12 @@ yyreturn: } -#line 158 "parser.y" +#line 176 "parser.y" extern "C" { -void yyerror(char* s){ +void yyerror(const char* s) +{ in->fatal(s); } @@ -1388,46 +1613,29 @@ int yylex(){ } } // end extern "C" -void line_source(unsigned int line, std::ostream& o) +namespace re2c { - char * fnamebuf; - char * token; - o << "#line " << line << " \""; - if( fileName != NULL ) { - fnamebuf = strdup( fileName ); - } else { - fnamebuf = strdup( "" ); - } - token = strtok( fnamebuf, "\\" ); - for(;;) { - o << token; - token = strtok( NULL, "\\" ); - if( token == NULL ) break; - o << "\\\\"; - } - o << "\"\n"; - ++oline; - free( fnamebuf ); +void parse(Scanner& i, std::ostream& o) +{ + in = &i; + + o << "/* Generated by re2c " PACKAGE_VERSION " on "; + time_t now = time(&now); + o.write(ctime(&now), 24); + o << " */\n"; + o << sourceFileInfo; + + while(i.echo()) + { + yyparse(); + if(spec) + { + genCode(o, topIndent, spec); + } + o << sourceFileInfo; + } } -void parse(std::istream& i, std::ostream &o){ - - o << "/* Generated by re2c " PACKAGE_VERSION " on "; - time_t now = time(&now); - o.write(ctime(&now), 24); - o << " */\n"; - oline += 2; - - in = new Scanner(i); - - line_source(in->line(), o); - - while(in->echo(o)){ - yyparse(); - if(spec) - genCode(o, spec); - line_source(in->line(), o); - } -} +} // end namespace re2c diff --git a/tools/re2c/parser.h b/tools/re2c/parser.h index 37a313797..1d1707f84 100644 --- a/tools/re2c/parser.h +++ b/tools/re2c/parser.h @@ -1,23 +1,61 @@ -/* $Id: parser.h,v 1.4 2004/05/13 02:58:17 nuffer Exp $ */ +/* $Id: parser.h,v 1.10 2006/01/21 15:51:02 helly Exp $ */ #ifndef _parser_h #define _parser_h #include "scanner.h" #include "re.h" #include +#include -class Symbol { +namespace re2c +{ + +class Symbol +{ public: - static Symbol *first; - Symbol *next; - Str name; - RegExp *re; -public: - Symbol(const SubStr&); - static Symbol *find(const SubStr&); + + RegExp* re; + + static Symbol *find(const SubStr&); + static void ClearTable(); + + ~Symbol() + { + /** \todo should we delete 're'? */ + } + + typedef std::map SymbolTable; + +protected: + + Symbol(const SubStr& str) + : re(NULL) + , name(str) + { + } + +private: + + static SymbolTable symbol_table; + + Str name; + +#if PEDANTIC + Symbol(const Symbol& oth) + : re(oth.re) + , name(oth.name) + { + } + Symbol& operator = (const Symbol& oth) + { + new(this) Symbol(oth); + return *this; + } +#endif }; -void line_source(unsigned int, std::ostream&); -void parse(std::istream&, std::ostream&); +void parse(Scanner&, std::ostream&); + +} // end namespace re2c #endif diff --git a/tools/re2c/parser.y b/tools/re2c/parser.y index 0259fe62d..5e3255b17 100644 --- a/tools/re2c/parser.y +++ b/tools/re2c/parser.y @@ -1,6 +1,6 @@ %{ -/* $Id: parser.y,v 1.9 2004/05/13 14:26:01 nuffer Exp $ */ +/* $Id: parser.y,v 1.20 2006/04/16 15:15:46 helly Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -13,15 +13,20 @@ #include "globals.h" #include "parser.h" +#include "basics.h" + +#define YYMALLOC malloc +#define YYFREE free + +using namespace re2c; extern "C" { -int yyparse(); int yylex(); -void yyerror(char*); +void yyerror(const char*); } -static uint accept; +static re2c::uint accept; static RegExp *spec; static Scanner *in; @@ -51,14 +56,17 @@ static char* strdup(const char* s) %start spec %union { - Symbol *symbol; - RegExp *regexp; - Token *token; - char op; - ExtOp extop; + re2c::Symbol *symbol; + re2c::RegExp *regexp; + re2c::Token *token; + char op; + int number; + re2c::ExtOp extop; + re2c::Str *str; }; %token CLOSESIZE CLOSE ID CODE RANGE STRING +%token CONFIG VALUE NUMBER %type CLOSE %type close @@ -67,6 +75,8 @@ static char* strdup(const char* s) %type CODE %type RANGE STRING %type rule look expr diff term factor primary +%type CONFIG VALUE +%type NUMBER %% @@ -82,6 +92,14 @@ decl : ID '=' expr ';' { if($1->re) in->fatal("sym already defined"); $1->re = $3; } + | CONFIG '=' VALUE ';' + { in->config(*$1, *$3); } + | CONFIG '=' NUMBER ';' + { in->config(*$1, $3); } + ; + +decl : ID '=' expr '/' + { in->fatal("trailing contexts are not allowed in named definitions"); } ; rule : expr look CODE @@ -158,7 +176,8 @@ primary : ID %% extern "C" { -void yyerror(char* s){ +void yyerror(const char* s) +{ in->fatal(s); } @@ -167,45 +186,28 @@ int yylex(){ } } // end extern "C" -void line_source(unsigned int line, std::ostream& o) +namespace re2c { - char * fnamebuf; - char * token; - o << "#line " << line << " \""; - if( fileName != NULL ) { - fnamebuf = strdup( fileName ); - } else { - fnamebuf = strdup( "" ); - } - token = strtok( fnamebuf, "\\" ); - for(;;) { - o << token; - token = strtok( NULL, "\\" ); - if( token == NULL ) break; - o << "\\\\"; - } - o << "\"\n"; - ++oline; - free( fnamebuf ); +void parse(Scanner& i, std::ostream& o) +{ + in = &i; + + o << "/* Generated by re2c " PACKAGE_VERSION " on "; + time_t now = time(&now); + o.write(ctime(&now), 24); + o << " */\n"; + o << sourceFileInfo; + + while(i.echo()) + { + yyparse(); + if(spec) + { + genCode(o, topIndent, spec); + } + o << sourceFileInfo; + } } -void parse(std::istream& i, std::ostream &o){ - - o << "/* Generated by re2c " PACKAGE_VERSION " on "; - time_t now = time(&now); - o.write(ctime(&now), 24); - o << " */\n"; - oline += 2; - - in = new Scanner(i); - - line_source(in->line(), o); - - while(in->echo(o)){ - yyparse(); - if(spec) - genCode(o, spec); - line_source(in->line(), o); - } -} +} // end namespace re2c diff --git a/tools/re2c/re.h b/tools/re2c/re.h index 47e876eee..226757651 100644 --- a/tools/re2c/re.h +++ b/tools/re2c/re.h @@ -1,207 +1,424 @@ -/* $Id: re.h,v 1.5 2004/05/13 02:58:18 nuffer Exp $ */ +/* $Id: re.h,v 1.17 2006/04/09 00:06:33 helly Exp $ */ #ifndef _re_h #define _re_h #include #include "token.h" #include "ins.h" +#include "globals.h" -typedef struct extop { - char op; - int minsize; - int maxsize; -} ExtOp; +namespace re2c +{ -struct CharPtn { - uint card; - CharPtn *fix; - CharPtn *nxt; -}; - -struct CharSet { - CharPtn *fix; - CharPtn *freeHead, **freeTail; - CharPtn *rep[nChars]; - CharPtn ptn[nChars]; -}; - -class Range { -public: - Range *next; - uint lb, ub; // [lb,ub) -public: - Range(uint l, uint u) : next(NULL), lb(l), ub(u) - { } - Range(Range &r) : next(NULL), lb(r.lb), ub(r.ub) - { } - friend std::ostream& operator<<(std::ostream&, const Range&); - friend std::ostream& operator<<(std::ostream&, const Range*); -}; - -inline std::ostream& operator<<(std::ostream &o, const Range *r){ - return r? o << *r : o; +typedef struct extop +{ + char op; + int minsize; + int maxsize; } -class RegExp { +ExtOp; + +struct CharPtn +{ + uint card; + CharPtn *fix; + CharPtn *nxt; +}; + +typedef CharPtn *CharPtr; + +struct CharSet +{ + CharSet(); + ~CharSet(); + + CharPtn *fix; + CharPtn *freeHead, **freeTail; + CharPtr *rep; + CharPtn *ptn; +}; + +class Range +{ + public: - uint size; + Range *next; + uint lb, ub; // [lb,ub) + +public: + Range(uint l, uint u) : next(NULL), lb(l), ub(u) + { } + + Range(Range &r) : next(NULL), lb(r.lb), ub(r.ub) + { } + + friend std::ostream& operator<<(std::ostream&, const Range&); + friend std::ostream& operator<<(std::ostream&, const Range*); +}; + +inline std::ostream& operator<<(std::ostream &o, const Range *r) +{ + return r ? o << *r : o; +} + +class RegExp +{ + +public: + uint size; + +public: + RegExp() : size(0) + { + } + virtual ~RegExp() {} -public: - virtual char *typeOf() = 0; - RegExp *isA(char *t) - { return typeOf() == t? this : NULL; } - virtual void split(CharSet&) = 0; - virtual void calcSize(Char*) = 0; - virtual uint fixedLength(); - virtual void compile(Char*, Ins*) = 0; - virtual void display(std::ostream&) const = 0; - friend std::ostream& operator<<(std::ostream&, const RegExp&); - friend std::ostream& operator<<(std::ostream&, const RegExp*); + virtual const char *typeOf() = 0; + RegExp *isA(const char *t) + { + return typeOf() == t ? this : NULL; + } + + virtual void split(CharSet&) = 0; + virtual void calcSize(Char*) = 0; + virtual uint fixedLength(); + virtual void compile(Char*, Ins*) = 0; + virtual void display(std::ostream&) const = 0; + friend std::ostream& operator<<(std::ostream&, const RegExp&); + friend std::ostream& operator<<(std::ostream&, const RegExp*); }; -inline std::ostream& operator<<(std::ostream &o, const RegExp &re){ - re.display(o); - return o; +inline std::ostream& operator<<(std::ostream &o, const RegExp &re) +{ + re.display(o); + return o; } -inline std::ostream& operator<<(std::ostream &o, const RegExp *re){ - return o << *re; +inline std::ostream& operator<<(std::ostream &o, const RegExp *re) +{ + return o << *re; } -class NullOp: public RegExp { +class NullOp: public RegExp +{ + public: - static char *type; + static const char *type; + public: - char *typeOf() - { return type; } - void split(CharSet&); - void calcSize(Char*); - uint fixedLength(); - void compile(Char*, Ins*); - void display(std::ostream &o) const { - o << "_"; - } + const char *typeOf() + { + return type; + } + + void split(CharSet&); + void calcSize(Char*); + uint fixedLength(); + void compile(Char*, Ins*); + void display(std::ostream &o) const + { + o << "_"; + } }; -class MatchOp: public RegExp { -public: - static char *type; - Range *match; -public: - MatchOp(Range *m) : match(m) - { } - char *typeOf() - { return type; } - void split(CharSet&); - void calcSize(Char*); - uint fixedLength(); - void compile(Char*, Ins*); - void display(std::ostream&) const; -}; +class MatchOp: public RegExp +{ -class RuleOp: public RegExp { +public: + static const char *type; + Range *match; + +public: + MatchOp(Range *m) : match(m) + { + } + + const char *typeOf() + { + return type; + } + + void split(CharSet&); + void calcSize(Char*); + uint fixedLength(); + void compile(Char*, Ins*); + void display(std::ostream&) const; + +#ifdef PEDANTIC private: - RegExp *exp; -public: - RegExp *ctx; - static char *type; - Ins *ins; - uint accept; - Token *code; - uint line; -public: - RuleOp(RegExp*, RegExp*, Token*, uint); - char *typeOf() - { return type; } - void split(CharSet&); - void calcSize(Char*); - void compile(Char*, Ins*); - void display(std::ostream &o) const { - o << exp << "/" << ctx << ";"; - } + MatchOp(const MatchOp& oth) + : RegExp(oth) + , match(oth.match) + { + } + + MatchOp& operator = (const MatchOp& oth) + { + new(this) MatchOp(oth); + return *this; + } +#endif }; -class AltOp: public RegExp { +class RuleOp: public RegExp +{ +public: + static const char *type; + private: - RegExp *exp1, *exp2; + RegExp *exp; + public: - static char *type; + RegExp *ctx; + Ins *ins; + uint accept; + Token *code; + uint line; + public: - AltOp(RegExp *e1, RegExp *e2) - { exp1 = e1; exp2 = e2; } - char *typeOf() - { return type; } - void split(CharSet&); - void calcSize(Char*); - uint fixedLength(); - void compile(Char*, Ins*); - void display(std::ostream &o) const { - o << exp1 << "|" << exp2; - } - friend RegExp *mkAlt(RegExp*, RegExp*); + RuleOp(RegExp*, RegExp*, Token*, uint); + const char *typeOf() + { + return type; + } + + void split(CharSet&); + void calcSize(Char*); + void compile(Char*, Ins*); + void display(std::ostream &o) const + { + o << exp << "/" << ctx << ";"; + } + +#ifdef PEDANTIC +private: + RuleOp(const RuleOp& oth) + : RegExp(oth) + , exp(oth.exp) + , ctx(oth.ctx) + , ins(oth.ins) + , accept(oth.accept) + , code(oth.code) + , line(oth.line) + { + } + RuleOp& operator = (const RuleOp& oth) + { + new(this) RuleOp(oth); + return *this; + } +#endif }; -class CatOp: public RegExp { -private: - RegExp *exp1, *exp2; +class RuleLine: public line_number +{ public: - static char *type; -public: - CatOp(RegExp *e1, RegExp *e2) - { exp1 = e1; exp2 = e2; } - char *typeOf() - { return type; } - void split(CharSet&); - void calcSize(Char*); - uint fixedLength(); - void compile(Char*, Ins*); - void display(std::ostream &o) const { - o << exp1 << exp2; - } + + RuleLine(const RuleOp& _op) + : op(_op) + { + } + + uint get_line() const + { + return op.code->line; + } + + const RuleOp& op; }; -class CloseOp: public RegExp { +class AltOp: public RegExp +{ + private: - RegExp *exp; + RegExp *exp1, *exp2; + public: - static char *type; + static const char *type; + public: - CloseOp(RegExp *e) - { exp = e; } - char *typeOf() - { return type; } - void split(CharSet&); - void calcSize(Char*); - void compile(Char*, Ins*); - void display(std::ostream &o) const { - o << exp << "+"; - } + AltOp(RegExp *e1, RegExp *e2) + : exp1(e1) + , exp2(e2) + { + } + + const char *typeOf() + { + return type; + } + + void split(CharSet&); + void calcSize(Char*); + uint fixedLength(); + void compile(Char*, Ins*); + void display(std::ostream &o) const + { + o << exp1 << "|" << exp2; + } + + friend RegExp *mkAlt(RegExp*, RegExp*); + +#ifdef PEDANTIC +private: + AltOp(const AltOp& oth) + : RegExp(oth) + , exp1(oth.exp1) + , exp2(oth.exp2) + { + } + AltOp& operator = (const AltOp& oth) + { + new(this) AltOp(oth); + return *this; + } +#endif }; -class CloseVOp: public RegExp { +class CatOp: public RegExp +{ + private: - RegExp *exp; - int min; - int max; + RegExp *exp1, *exp2; + public: - static char *type; + static const char *type; + public: - CloseVOp(RegExp *e, int lb, int ub) - { exp = e; min = lb; max = ub; } - char *typeOf() - { return type; } - void split(CharSet&); - void calcSize(Char*); - void compile(Char*, Ins*); - void display(std::ostream &o) const { - o << exp << "+"; - } + CatOp(RegExp *e1, RegExp *e2) + : exp1(e1) + , exp2(e2) + { + } + + const char *typeOf() + { + return type; + } + + void split(CharSet&); + void calcSize(Char*); + uint fixedLength(); + void compile(Char*, Ins*); + void display(std::ostream &o) const + { + o << exp1 << exp2; + } + +#ifdef PEDANTIC +private: + CatOp(const CatOp& oth) + : RegExp(oth) + , exp1(oth.exp1) + , exp2(oth.exp2) + { + } + CatOp& operator = (const CatOp& oth) + { + new(this) CatOp(oth); + return *this; + } +#endif +}; + +class CloseOp: public RegExp +{ + +private: + RegExp *exp; + +public: + static const char *type; + +public: + CloseOp(RegExp *e) + : exp(e) + { + } + + const char *typeOf() + { + return type; + } + + void split(CharSet&); + void calcSize(Char*); + void compile(Char*, Ins*); + void display(std::ostream &o) const + { + o << exp << "+"; + } + +#ifdef PEDANTIC +private: + CloseOp(const CloseOp& oth) + : RegExp(oth) + , exp(oth.exp) + { + } + CloseOp& operator = (const CloseOp& oth) + { + new(this) CloseOp(oth); + return *this; + } +#endif +}; + +class CloseVOp: public RegExp +{ + +private: + RegExp *exp; + int min; + int max; + +public: + static const char *type; + +public: + CloseVOp(RegExp *e, int lb, int ub) + : exp(e) + , min(lb) + , max(ub) + { + } + + const char *typeOf() + { + return type; + } + + void split(CharSet&); + void calcSize(Char*); + void compile(Char*, Ins*); + void display(std::ostream &o) const + { + o << exp << "+"; + } +#ifdef PEDANTIC +private: + CloseVOp(const CloseVOp& oth) + : RegExp(oth) + , exp(oth.exp) + , min(oth.min) + , max(oth.max) + { + } + CloseVOp& operator = (const CloseVOp& oth) + { + new(this) CloseVOp(oth); + return *this; + } +#endif }; extern void genCode(std::ostream&, RegExp*); +extern void genCode(std::ostream&, uint, RegExp*); +extern void genGetState(std::ostream&, uint&, uint); extern RegExp *mkDiff(RegExp*, RegExp*); -extern RegExp *strToRE(SubStr); -extern RegExp *ranToRE(SubStr); -extern RegExp *strToCaseInsensitiveRE(SubStr s); - +extern RegExp *mkAlt(RegExp*, RegExp*); + +} // end namespace re2c + #endif diff --git a/tools/re2c/re2c.1 b/tools/re2c/re2c.1 index 5f4824bf7..b7ea56aa5 100644 --- a/tools/re2c/re2c.1 +++ b/tools/re2c/re2c.1 @@ -1,50 +1,16 @@ ./" -./" $Id: re2c.1.in,v 1.9 2004/05/26 13:33:25 nuffer Exp $ +./" $Id: re2c.1.in,v 1.60 2006/05/14 13:39:16 helly Exp $ ./" -.TH RE2C 1 "14 March 1994" "Version 0.9.3" +.TH RE2C 1 "22 April 2005" "Version 0.10.3" .ds re \fBre2c\fP .ds le \fBlex\fP .ds rx regular expression .ds lx \fIl\fP-expression -\"$Log: re2c.1.in,v $ -\"Revision 1.9 2004/05/26 13:33:25 nuffer -\"Added description of -o option. -\" -\"Revision 1.8 2004/04/19 22:32:48 helly -\"Update -\" -\"Revision 1.7 2004/04/19 02:13:48 helly -\"Featurerequest #869298 (Add case insensitive string literals) -\" -\"Revision 1.6 2004/04/17 15:49:13 helly -\"Fix example, cur must be set to make the uncommented printf's working -\" -\"Revision 1.5 2004/03/30 01:02:45 helly -\"Update docu -\" -\"Revision 1.4 2004/03/14 14:23:40 helly -\"Update -\" -\"Revision 1.3 2004/03/14 12:54:19 helly -\"Next step of autogen patch -\" -\"Revision 1.2 2004/03/13 20:35:12 helly -\"Updated configure stuff -\" -\"Revision 1.1 2004/01/31 15:44:39 nuffer -\"Applied patch from Marcus Boerger -\" -\"Revision 1.2 1994/04/16 15:50:32 peter -\"Fix bug in simple example. -\" -\"Revision 1.1 1994/04/08 15:39:09 peter -\"Initial revision -\" .SH NAME re2c \- convert regular expressions to C/C++ .SH SYNOPSIS -\*(re [\fB-esbvh\fP] [\fB-o output\fP] file\fP +\*(re [\fB-bdefghisvVw1\fP] [\fB-o output\fP] file\fP .SH DESCRIPTION \*(re is a preprocessor that generates C-based recognizers from regular @@ -61,12 +27,11 @@ For example, given the following code .in +3 .nf #define NULL ((char*) 0) -char *scan(char *p){ -char *q; +char *scan(char *p) +{ #define YYCTYPE char #define YYCURSOR p #define YYLIMIT p -#define YYMARKER q #define YYFILL(n) /*!re2c [0-9]+ {return YYCURSOR;} @@ -83,12 +48,11 @@ char *q; /* Generated by re2c on Sat Apr 16 11:40:58 1994 */ #line 1 "simple.re" #define NULL ((char*) 0) -char *scan(char *p){ -char *q; +char *scan(char *p) +{ #define YYCTYPE char #define YYCURSOR p #define YYLIMIT p -#define YYMARKER q #define YYFILL(n) { YYCTYPE yych; @@ -103,11 +67,11 @@ yy0: yy2: yych = *++YYCURSOR; goto yy7; yy3: -#line 10 +#line 9 {return YYCURSOR;} yy4: yych = *++YYCURSOR; yy5: -#line 11 +#line 10 {return NULL;} yy6: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -116,77 +80,234 @@ yy7: if(yych <= '/') goto yy3; if(yych <= '9') goto yy6; goto yy3; } -#line 12 +#line 11 } .fi .in -3 +You can place one \fC/*!max:re2c */\fP comment that will output a "#define +\fCYYMAXFILL\fP " line that holds the maximum number of characters +required to parse the input. That is the maximum value \fCYYFILL\fP(n) +will receive. If -1 is in effect then YYMAXFILL can only be triggered once +after the last \fC/*!re2c */\fP. + +You can also use \fC/*!ignore:re2c */\fP blocks that allows to document the +scanner code and will not be part of the output. + .SH OPTIONS \*(re provides the following options: .TP -\fB-e\fP -Cross-compile from an ASCII platform to an EBCDIC one. -.TP -\fB-s\fP -Generate nested \fCif\fPs for some \fCswitch\fPes. Many compilers need this -assist to generate better code. +\fB-?\fP +\fB-h\fP +Invoke a short help. .TP \fB-b\fP Implies \fB-s\fP. Use bit vectors as well in the attempt to coax better code out of the compiler. Most useful for specifications with more than a few keywords (e.g. for most programming languages). .TP -\fB-h\fP -\fB-?\fP -Invoke a short help. +\fB-d\fP +Creates a parser that dumps information about the current position and in +which state the parser is while parsing the input. This is useful to debug +parser issues and states. If you use this switch you need to define a macro +\fIYYDEBUG\fP that is called like a function with two parameters: +\fIvoid YYDEBUG(int state, char current)\fP. The first parameter receives the +state or -1 and the second parameter receives the input at the current cursor. +.TP +\fB-e\fP +Cross-compile from an ASCII platform to an EBCDIC one. +.TP +\fB-f\fP +Generate a scanner with support for storable state. +For details see below at \fBSCANNER WITH STORABLE STATES\fP. +.TP +\fB-g\fP +Generate a scanner that utilizes GCC's computed goto feature. That is re2c +generates jump tables whenever a decision is of a certain complexity (e.g. a +lot of if conditions are otherwise necessary). This is only useable with GCC +and produces output that cannot be compiled with any other compiler. Note that +this implies -b and that the complexity threshold can be configured using the +inplace configuration "cgoto:threshold". +.TP +\fB-i\fP +Do not output #line information. This is usefull when you want use a CMS tool +with the re2c output which you might want if you do not require your users to +have re2c themselves when building from your source. +\fB-o output\fP +Specify the output file. +.TP +\fB-s\fP +Generate nested \fCif\fPs for some \fCswitch\fPes. Many compilers need this +assist to generate better code. .TP \fB-v\fP Show version information. .TP -\fB-o output\fP -Specify the output file. - +\fB-V\fP +Show the version as a number XXYYZZ. +.TP +\fB-w\fP +Create a parser that supports wide chars (UCS-2). This implies \fB-s\fP and +cannot be used together with \fB-e\fP switch. +.TP +\fB-1\fP +Force single pass generation, this cannot be combined with -f and disables +YYMAXFILL generation prior to last re2c block. .SH "INTERFACE CODE" Unlike other scanner generators, \*(re does not generate complete scanners: the user must supply some interface code. In particular, the user must define the following macros: .TP -\fCYYCHAR\fP +\fCYYCTYPE\fP Type used to hold an input symbol. Usually \fCchar\fP or \fCunsigned char\fP. .TP \fCYYCURSOR\fP -\*(lx of type \fC*YYCHAR\fP that points to the current input symbol. +\*(lx of type \fC*YYCTYPE\fP that points to the current input symbol. The generated code advances \fCYYCURSOR\fP as symbols are matched. On entry, \fCYYCURSOR\fP is assumed to point to the first character of the current token. On exit, \fCYYCURSOR\fP will point to the first character of the following token. .TP -\fCYLIMIT\fP -Expression of type \fC*YYCHAR\fP that marks the end of the buffer -(\fCYLIMIT[-1]\fP is the last character in the buffer). -The generated code repeatedly compares \fCYYCURSOR\fP to \fCYLIMIT\fP +\fCYYLIMIT\fP +Expression of type \fC*YYCTYPE\fP that marks the end of the buffer +(\fCYYLIMIT[-1]\fP is the last character in the buffer). +The generated code repeatedly compares \fCYYCURSOR\fP to \fCYYLIMIT\fP to determine when the buffer needs (re)filling. .TP \fCYYMARKER\fP -\*(lx of type \fC*YYCHAR\fP. -The generated code saves backtracking information in \fCYYMARKER\fP. +\*(lx of type \fC*YYCTYPE\fP. +The generated code saves backtracking information in \fCYYMARKER\fP. Some easy +scanners might not use this. +.TP +\fCYYCTXMARKER\fP +\*(lx of type \fC*YYCTYPE\fP. +The generated code saves trailing context backtracking information in \fCYYCTXMARKER\fP. +The user only needs to define this macro if a scanner specification uses trailing +context in one or more of its regular expressions. .TP \fCYYFILL(\fP\fIn\fP\fC)\fP -The generated code "calls" \fCYYFILL\fP when the buffer needs +The generated code "calls" \fCYYFILL\fP(n) when the buffer needs (re)filling: at least \fIn\fP additional characters should -be provided. \fCYYFILL\fP should adjust \fCYYCURSOR\fP, \fCYYLIMIT\fP and -\fCYYMARKER\fP as needed. Note that for typical programming languages -\fIn\fP will be the length of the longest keyword plus one. +be provided. \fCYYFILL\fP(n) should adjust \fCYYCURSOR\fP, \fCYYLIMIT\fP, +\fCYYMARKER\fP and \fCYYCTXMARKER\fP as needed. Note that for typical +programming languages \fIn\fP will be the length of the longest keyword plus one. +The user can place a comment of the form \fC/*!max:re2c */\fP once to insert +a \fCYYMAXFILL\fP definition that is set to the maximum length value. If -1 +switch is used then YYMAXFILL can be triggered once after the last \fC/*!re2c */\fP +block. +.TP +\fCYYGETSTATE()\fP +The user only needs to define this macro if the \fB-f\fP flag was specified. +In that case, the generated code "calls" \fCYYGETSTATE\fP at the very beginning +of the scanner in order to obtain the saved state. YYGETSTATE must return a signed +integer. The value must be either -1, indicating that the scanner is entered for the +first time, or a value previously saved by \fCYYSETSTATE\fP. In the second case, the +scanner will resume operations right after where the last \fCYYFILL\fP(n) was called. +.TP +\fCYYSETSTATE(\fP\fIn\fP\fC)\fP +The user only needs to define this macro if the \fB-f\fP flag was specified. +In that case, the generated code "calls" \fCYYSETSTATE\fP just before calling +\fCYYFILL\fP(n). The parameter to \fCYYSETSTATE\fP is a signed integer that uniquely +identifies the specific instance of \fCYYFILL\fP(n) that is about to be called. +Should the user wish to save the state of the scanner and have \fCYYFILL\fP(n) return +to the caller, all he has to do is store that unique identifer in a variable. +Later, when the scannered is called again, it will call \fCYYGETSTATE()\fP and +resume execution right where it left off. +.TP +\fCYYDEBUG(\fP\fIstate\fP,\fIcurrent\fC)\fP +This is only needed if the \fB-d\fP flag was specified. It allows to easily debug +the generated parser by calling a user defined function for every state. The function +should have the following signature: \fIvoid YYDEBUG(int state, char current)\fP. +The first parameter receives the state or -1 and the second parameter receives the +input at the current cursor. +.TP +\fCYYMAXFILL +This will be automatically defined by \fC/*!max:re2c */\fP blocks as explained above. + +.SH "SCANNER WITH STORABLE STATES" +When the \fB-f\fP flag is specified, re2c generates a scanner that +can store its current state, return to the caller, and later resume +operations exactly where it left off. + +The default operation of re2c is a "pull" model, where the scanner asks +for extra input whenever it needs it. However, this mode of operation +assumes that the scanner is the "owner" the parsing loop, and that may +not always be convenient. + +Typically, if there is a preprocessor ahead of the scanner in the stream, +or for that matter any other procedural source of data, the scanner cannot +"ask" for more data unless both scanner and source live in a separate threads. + +The \fB-f\fP flag is useful for just this situation : it lets users design +scanners that work in a "push" model, i.e. where data is fed to the scanner +chunk by chunk. When the scanner runs out of data to consume, it just stores +its state, and return to the caller. When more input data is fed to the scanner, +it resumes operations exactly where it left off. + +When using the -f option re2c does not accept stdin because it has to do the +full generation process twice which means it has to read the input twice. That +means re2c would fail in case it cannot open the input twice or reading the +input for the first time influences the second read attempt. + +Changes needed compared to the "pull" model. + +1. User has to supply macros YYSETSTATE() and YYGETSTATE(state) + +2. The \fB-f\fP option inhibits declaration of \fIyych\fP and +\fIyyaccept\fP. So the user has to declare these. Also the user has +to save and restore these. In the example \fIexamples/push.re\fP these +are declared as fields of the (C++) class of which the scanner is a +method, so they do not need to be saved/restored explicitly. For C +they could e.g. be made macros that select fields from a structure +passed in as parameter. Alternatively, they could be declared as local +variables, saved with YYFILL(n) when it decides to return and restored +at entry to the function. Also, it could be more efficient to save the +state from YYFILL(n) because YYSETSTATE(state) is called +unconditionally. YYFILL(n) however does not get \fIstate\fP as +parameter, so we would have to store state in a local variable by +YYSETSTATE(state). + +3. Modify YYFILL(n) to return (from the function calling it) if more +input is needed. + +4. Modify caller to recognise "more input is needed" and respond +appropriately. + +5. The generated code will contain a switch block that is used to restores +the last state by jumping behind the corrspoding YYFILL(n) call. This code is +automatically generated in the epilog of the first "\fC/*!re2c */\fP" block. +It is possible to trigger generation of the YYGETSTATE() block earlier by +placing a "\fC/*!getstate:re2c */\fP" comment. This is especially useful when +the scanner code should be wrapped inside a loop. + +Please see examples/push.re for push-model scanner. The generated code can be +tweaked using inplace configurations "\fBstate:abort\fP" and "\fBstate:nextlabel\fP". .SH "SCANNER SPECIFICATIONS" -Each scanner specification consists of a set of \fIrules\fP and name -definitions. -Rules consist of a regular expression along with a block of C/C++ code that -is to be executed when the associated regular expression is matched. -Name definitions are of the form -``\fIname\fP \fC=\fP \fIregular expression\fP\fC;\fP''. +Each scanner specification consists of a set of \fIrules\fP, \fIname +definitions\fP and \fIconfigurations\fP. +.LP +\fIRules\fP consist of a regular expression along with a block of C/C++ code that +is to be executed when the associated \fIregular expression\fP is matched. +.P +.RS +\fIregular expression\fP \fC{\fP \fIC/C++ code\fP \fC}\fP +.RE +.LP +Named definitions are of the form: +.P +.RS +\fIname\fP \fC=\fP \fIregular expression\fP\fC;\fP +.RE +.LP +Configurations look like name definitions whose names start +with "\fBre2c:\fP": +.P +.RS +\fCre2c:\fP\fIname\fP \fC=\fP \fIvalue\fP\fC;\fP +.RE .SH "SUMMARY OF RE2C REGULAR EXPRESSIONS" .TP @@ -207,6 +328,9 @@ a "character class" with a range in it; matches an '\fCa\fP', a '\fCb\fP', any letter from '\fCj\fP' through '\fCo\fP', or a '\fCZ\fP'. .TP +\fC[^\fIclass\fP\fC]\fP +an inverted "character class". +.TP \fIr\fP\fC\e\fP\fIs\fP match any \fIr\fP which isn't an \fIs\fP. \fIr\fP and \fIs\fP must be regular expressions which can be expressed as character classes. @@ -234,8 +358,9 @@ an \fIr\fP followed by an \fIs\fP ("concatenation") either an \fIr\fP or an \fIs\fP .TP \fIr\fP\fC/\fP\fIs\fP -an \fIr\fP but only if it is followed by an \fIs\fP. The s is not part of -the matched text. This type of \*(rx is called "trailing context". +an \fIr\fP but only if it is followed by an \fIs\fP. The \fIs\fP is not part of +the matched text. This type of \*(rx is called "trailing context". A trailing +context can only be the end of a rule and not part of a named definition. .TP \fIr\fP\fC{\fP\fIn\fP\fC}\fP matches \fIr\fP exactly \fIn\fP times. @@ -245,293 +370,90 @@ matches \fIr\fP at least \fIn\fP times. .TP \fIr\fP\fC{\fP\fIn\fP\fC,\fP\fIm\fP\fC}\fP matches \fIr\fP at least \fIn\fP but not more than \fIm\fP times. - +.TP +\fC.\fP +match any character except newline (\\n). +.TP +\fIdef\fP +matches named definition as specified by \fIdef\fP. +.LP +Character classes and string literals may contain octoal or hexadecimal +character definitions and the following set of escape sequences (\fB\\n\fP, + \fB\\t\fP, \fB\\v\fP, \fB\\b\fP, \fB\\r\fP, \fB\\f\fP, \fB\\a\fP, \fB\\\\\fP). +An octal character is defined by a backslash followed by its three octal digits +and a hexadecimal character is defined by backslash, a lower cased '\fBx\fP' +and its two hexadecimal digits or a backslash, an upper cased \fBX\fP and its +four hexadecimal digits. +.LP +re2c +further more supports the c/c++ unicode notation. That is a backslash followed +by either a lowercased \fBu\fP and its four hexadecimal digits or an uppercased +\fBU\fP and its eight hexadecimal digits. However using the U notation it is +not possible to support characters greater \fB\\U0000FFFF\fP due to an internal +limitation of re2c. +.LP +Since characters greater \fB\\X00FF\fP are not allowed in non unicode mode, the +only portable "\fBany\fP" rules are \fB(.|"\\n")\fP and \fB[^]\fP. .LP The regular expressions listed above are grouped according to precedence, from highest precedence at the top to lowest at the bottom. Those grouped together have equal precedence. -.SH "A LARGER EXAMPLE" +.SH "INPLACE CONFIGURATION" .LP -.in +3 -.nf -#include -#include -#include -#include +It is possible to configure code generation inside re2c blocks. The following +lists the available configurations: +.TP +\fIre2c:indent:top\fP \fB=\fP 0 \fB;\fP +Specifies the minimum number of indendation to use. Requires a numeric value +greater than or equal zero. +.TP +\fIre2c:indent:string\fP \fB=\fP "\\t" \fB;\fP +Specifies the string to use for indendation. Requires a string that should +contain only whitespace unless you need this for external tools. The easiest +way to specify spaces is to enclude them in single or double quotes. If you do +not want any indendation at all you can simply set this to \fB""\fP. +.TP +\fIre2c:yybm:hex\fP \fB=\fP 0 \fB;\fP +If set to zero then a decimal table is being used else a hexadecimal table +will be generated. +.TP +\fIre2c:yyfill:enable\fP \fB=\fP 1 \fB;\fP +Set this to zero to suppress generation of YYFILL(n). When using this be sure +to verify that the generated scanner does not read behind input. Allowing +this behavior might introduce sever security issues to you programs. +.TP +\fIre2c:startlabel\fP \fB=\fP 0 \fB;\fP +If set to a non zero integer then the start label of the next scanner blocks +will be generated even if not used by the scanner itself. Otherwise the normal +\fByy0\fP like start label is only being generated if needed. If set to a text +value then a label with that text will be generated regardless of whether the +normal start label is being used or not. This setting is being reset to \fB0\fP +after a start label has been generated. +.TP +\fIre2c:state:abort\fP \fB=\fP 0 \fB;\fP +When not zero and switch -f is active then the \fCYYGETSTATE\fP block will +contain a default case that aborts and a -1 case is used for initialization. +.TP +\fIre2c:state:nextlabel\fP \fB=\fP 0 \fB;\fP +Used when -f is active to control whether the \fCYYGETSTATE\fP block is +followed by a \fCyyNext:\fP label line. Instead of using \fCyyNext\fP you can +usually also use configuration \fIstartlabel\fP to force a specific start label +or default to \fCyy0\fP as start label. Instead of using a dedicated label it +is often better to separate the YYGETSTATE code from the actual scanner code by +placing a "\fC/*!getstate:re2c */\fP" comment. +.TP +\fIre2c:cgoto:threshold\fP \fB=\fP 9 \fB;\fP +When -g is active this value specifies the complexity threshold that triggers +generation of jump tables rather than using nested if's and decision bitfields. +The threshold is compared against a calculated estimation of if-s needed where +every used bitmap divides the threshold by 2. -#define ADDEQ 257 -#define ANDAND 258 -#define ANDEQ 259 -#define ARRAY 260 -#define ASM 261 -#define AUTO 262 -#define BREAK 263 -#define CASE 264 -#define CHAR 265 -#define CONST 266 -#define CONTINUE 267 -#define DECR 268 -#define DEFAULT 269 -#define DEREF 270 -#define DIVEQ 271 -#define DO 272 -#define DOUBLE 273 -#define ELLIPSIS 274 -#define ELSE 275 -#define ENUM 276 -#define EQL 277 -#define EXTERN 278 -#define FCON 279 -#define FLOAT 280 -#define FOR 281 -#define FUNCTION 282 -#define GEQ 283 -#define GOTO 284 -#define ICON 285 -#define ID 286 -#define IF 287 -#define INCR 288 -#define INT 289 -#define LEQ 290 -#define LONG 291 -#define LSHIFT 292 -#define LSHIFTEQ 293 -#define MODEQ 294 -#define MULEQ 295 -#define NEQ 296 -#define OREQ 297 -#define OROR 298 -#define POINTER 299 -#define REGISTER 300 -#define RETURN 301 -#define RSHIFT 302 -#define RSHIFTEQ 303 -#define SCON 304 -#define SHORT 305 -#define SIGNED 306 -#define SIZEOF 307 -#define STATIC 308 -#define STRUCT 309 -#define SUBEQ 310 -#define SWITCH 311 -#define TYPEDEF 312 -#define UNION 313 -#define UNSIGNED 314 -#define VOID 315 -#define VOLATILE 316 -#define WHILE 317 -#define XOREQ 318 -#define EOI 319 - -typedef unsigned int uint; -typedef unsigned char uchar; - -#define BSIZE 8192 - -#define YYCTYPE uchar -#define YYCURSOR cursor -#define YYLIMIT s->lim -#define YYMARKER s->ptr -#define YYFILL(n) {cursor = fill(s, cursor);} - -#define RET(i) {s->cur = cursor; return i;} - -typedef struct Scanner { - int fd; - uchar *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof; - uint line; -} Scanner; - -uchar *fill(Scanner *s, uchar *cursor){ - if(!s->eof){ - uint cnt = s->tok - s->bot; - if(cnt){ - memcpy(s->bot, s->tok, s->lim - s->tok); - s->tok = s->bot; - s->ptr -= cnt; - cursor -= cnt; - s->pos -= cnt; - s->lim -= cnt; - } - if((s->top - s->lim) < BSIZE){ - uchar *buf = (uchar*) - malloc(((s->lim - s->bot) + BSIZE)*sizeof(uchar)); - memcpy(buf, s->tok, s->lim - s->tok); - s->tok = buf; - s->ptr = &buf[s->ptr - s->bot]; - cursor = &buf[cursor - s->bot]; - s->pos = &buf[s->pos - s->bot]; - s->lim = &buf[s->lim - s->bot]; - s->top = &s->lim[BSIZE]; - free(s->bot); - s->bot = buf; - } - if((cnt = read(s->fd, (char*) s->lim, BSIZE)) != BSIZE){ - s->eof = &s->lim[cnt]; *(s->eof)++ = '\\n'; - } - s->lim += cnt; - } - s->cur = cursor; - return cursor; -} - -int scan(Scanner *s){ - uchar *cursor = s->cur; -std: - s->tok = cursor; -/*!re2c -any = [\\000-\\377]; -O = [0-7]; -D = [0-9]; -L = [a-zA-Z_]; -H = [a-fA-F0-9]; -E = [Ee] [+-]? D+; -FS = [fFlL]; -IS = [uUlL]*; -ESC = [\\\\] ([abfnrtv?'"\\\\] | "x" H+ | O+); -*/ - -/*!re2c - "/*" { goto comment; } - - "auto" { RET(AUTO); } - "break" { RET(BREAK); } - "case" { RET(CASE); } - "char" { RET(CHAR); } - "const" { RET(CONST); } - "continue" { RET(CONTINUE); } - "default" { RET(DEFAULT); } - "do" { RET(DO); } - "double" { RET(DOUBLE); } - "else" { RET(ELSE); } - "enum" { RET(ENUM); } - "extern" { RET(EXTERN); } - "float" { RET(FLOAT); } - "for" { RET(FOR); } - "goto" { RET(GOTO); } - "if" { RET(IF); } - "int" { RET(INT); } - "long" { RET(LONG); } - "register" { RET(REGISTER); } - "return" { RET(RETURN); } - "short" { RET(SHORT); } - "signed" { RET(SIGNED); } - "sizeof" { RET(SIZEOF); } - "static" { RET(STATIC); } - "struct" { RET(STRUCT); } - "switch" { RET(SWITCH); } - "typedef" { RET(TYPEDEF); } - "union" { RET(UNION); } - "unsigned" { RET(UNSIGNED); } - "void" { RET(VOID); } - "volatile" { RET(VOLATILE); } - "while" { RET(WHILE); } - - L (L|D)* { RET(ID); } - - ("0" [xX] H+ IS?) | ("0" D+ IS?) | (D+ IS?) | - (['] (ESC|any\\[\\n\\\\'])* [']) - { RET(ICON); } - - (D+ E FS?) | (D* "." D+ E? FS?) | (D+ "." D* E? FS?) - { RET(FCON); } - - (["] (ESC|any\\[\\n\\\\"])* ["]) - { RET(SCON); } - - "..." { RET(ELLIPSIS); } - ">>=" { RET(RSHIFTEQ); } - "<<=" { RET(LSHIFTEQ); } - "+=" { RET(ADDEQ); } - "-=" { RET(SUBEQ); } - "*=" { RET(MULEQ); } - "/=" { RET(DIVEQ); } - "%=" { RET(MODEQ); } - "&=" { RET(ANDEQ); } - "^=" { RET(XOREQ); } - "|=" { RET(OREQ); } - ">>" { RET(RSHIFT); } - "<<" { RET(LSHIFT); } - "++" { RET(INCR); } - "--" { RET(DECR); } - "->" { RET(DEREF); } - "&&" { RET(ANDAND); } - "||" { RET(OROR); } - "<=" { RET(LEQ); } - ">=" { RET(GEQ); } - "==" { RET(EQL); } - "!=" { RET(NEQ); } - ";" { RET(';'); } - "{" { RET('{'); } - "}" { RET('}'); } - "," { RET(','); } - ":" { RET(':'); } - "=" { RET('='); } - "(" { RET('('); } - ")" { RET(')'); } - "[" { RET('['); } - "]" { RET(']'); } - "." { RET('.'); } - "&" { RET('&'); } - "!" { RET('!'); } - "~" { RET('~'); } - "-" { RET('-'); } - "+" { RET('+'); } - "*" { RET('*'); } - "/" { RET('/'); } - "%" { RET('%'); } - "<" { RET('<'); } - ">" { RET('>'); } - "^" { RET('^'); } - "|" { RET('|'); } - "?" { RET('?'); } - - - [ \\t\\v\\f]+ { goto std; } - - "\\n" - { - if(cursor == s->eof) RET(EOI); - s->pos = cursor; s->line++; - goto std; - } - - any - { - printf("unexpected character: %c\\n", *s->tok); - goto std; - } -*/ - -comment: -/*!re2c - "*/" { goto std; } - "\\n" - { - if(cursor == s->eof) RET(EOI); - s->tok = s->pos = cursor; s->line++; - goto comment; - } - any { goto comment; } -*/ -} - -main(){ - Scanner in; - int t; - memset((char*) &in, 0, sizeof(in)); - in.fd = 0; - while((t = scan(&in)) != EOI){ -/* - printf("%d\\t%.*s\\n", t, in.cur - in.tok, in.tok); - printf("%d\\n", t); -*/ - } - close(in.fd); -} -.fi -.in -3 +.SH "UNDERSTANDING RE2C" +.LP +The subdirectory lessons of the re2c distribution contains a few step by step +lessons to get you started with re2c. All examples in the lessons subdirectory +can be compiled and actually work. .SH FEATURES .LP @@ -546,26 +468,17 @@ The user must arrange for a sentinel token to appear at the end of input \*(re does not provide an \fC<>\fP expression. If the source is from a null-byte terminated string, a rule matching a null character will suffice. If the source is from a -file then the approach taken in the example can be used: pad the input with -a newline (or some other character that can't appear within another token); -upon recognizing such a character check to see if it is the sentinel -and act accordingly. +file then you could pad the input with a newline (or some other character that +cannot appear within another token); upon recognizing such a character check +to see if it is the sentinel and act accordingly. And you can also use YYFILL(n) +to end the scanner in case not enough characters are available which is nothing +else then e detection of end of data/file. .LP \*(re does not provide start conditions: use a separate scanner specification for each start condition (as illustrated in the above example). -.LP -No [^x]. Use difference instead. + .SH BUGS .LP -Only fixed length trailing context can be handled. -.LP -The maximum value appearing as a parameter \fIn\fP to \fCYYFILL\fP is not -provided to the generated code (this value is needed for constructing -the interface code). -Note that this value is usually relatively small: for -typical programming languages \fIn\fP will be the length of the longest -keyword plus one. -.LP Difference only works for character sets. .LP The \*(re internal algorithms need documentation. @@ -593,9 +506,11 @@ Marcus Boerger .P Hartmut Kaiser .P +Emmanuel Mogenet added storable state +.P .PD 1 .SH VERSION INFORMATION -This manpage describes \fBre2c\fP, version 0.9.3. +This manpage describes \fBre2c\fP, version 0.10.3. .fi diff --git a/tools/re2c/re2c.1.in b/tools/re2c/re2c.1.in deleted file mode 100644 index 63a88310e..000000000 --- a/tools/re2c/re2c.1.in +++ /dev/null @@ -1,601 +0,0 @@ -./" -./" $Id: re2c.1.in,v 1.9 2004/05/26 13:33:25 nuffer Exp $ -./" -.TH RE2C 1 "14 March 1994" "Version @PACKAGE_VERSION@" -.ds re \fBre2c\fP -.ds le \fBlex\fP -.ds rx regular expression -.ds lx \fIl\fP-expression -\"$Log: re2c.1.in,v $ -\"Revision 1.9 2004/05/26 13:33:25 nuffer -\"Added description of -o option. -\" -\"Revision 1.8 2004/04/19 22:32:48 helly -\"Update -\" -\"Revision 1.7 2004/04/19 02:13:48 helly -\"Featurerequest #869298 (Add case insensitive string literals) -\" -\"Revision 1.6 2004/04/17 15:49:13 helly -\"Fix example, cur must be set to make the uncommented printf's working -\" -\"Revision 1.5 2004/03/30 01:02:45 helly -\"Update docu -\" -\"Revision 1.4 2004/03/14 14:23:40 helly -\"Update -\" -\"Revision 1.3 2004/03/14 12:54:19 helly -\"Next step of autogen patch -\" -\"Revision 1.2 2004/03/13 20:35:12 helly -\"Updated configure stuff -\" -\"Revision 1.1 2004/01/31 15:44:39 nuffer -\"Applied patch from Marcus Boerger -\" -\"Revision 1.2 1994/04/16 15:50:32 peter -\"Fix bug in simple example. -\" -\"Revision 1.1 1994/04/08 15:39:09 peter -\"Initial revision -\" -.SH NAME -re2c \- convert regular expressions to C/C++ - -.SH SYNOPSIS -\*(re [\fB-esbvh\fP] [\fB-o output\fP] file\fP - -.SH DESCRIPTION -\*(re is a preprocessor that generates C-based recognizers from regular -expressions. -The input to \*(re consists of C/C++ source interleaved with -comments of the form \fC/*!re2c\fP ... \fC*/\fP which contain -scanner specifications. -In the output these comments are replaced with code that, when -executed, will find the next input token and then execute -some user-supplied token-specific code. - -For example, given the following code - -.in +3 -.nf -#define NULL ((char*) 0) -char *scan(char *p){ -char *q; -#define YYCTYPE char -#define YYCURSOR p -#define YYLIMIT p -#define YYMARKER q -#define YYFILL(n) -/*!re2c - [0-9]+ {return YYCURSOR;} - [\\000-\\377] {return NULL;} -*/ -} -.fi -.in -3 - -\*(re will generate - -.in +3 -.nf -/* Generated by re2c on Sat Apr 16 11:40:58 1994 */ -#line 1 "simple.re" -#define NULL ((char*) 0) -char *scan(char *p){ -char *q; -#define YYCTYPE char -#define YYCURSOR p -#define YYLIMIT p -#define YYMARKER q -#define YYFILL(n) -{ - YYCTYPE yych; - unsigned int yyaccept; - goto yy0; -yy1: ++YYCURSOR; -yy0: - if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if(yych <= '/') goto yy4; - if(yych >= ':') goto yy4; -yy2: yych = *++YYCURSOR; - goto yy7; -yy3: -#line 10 - {return YYCURSOR;} -yy4: yych = *++YYCURSOR; -yy5: -#line 11 - {return NULL;} -yy6: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy7: if(yych <= '/') goto yy3; - if(yych <= '9') goto yy6; - goto yy3; -} -#line 12 - -} -.fi -.in -3 - -.SH OPTIONS -\*(re provides the following options: -.TP -\fB-e\fP -Cross-compile from an ASCII platform to an EBCDIC one. -.TP -\fB-s\fP -Generate nested \fCif\fPs for some \fCswitch\fPes. Many compilers need this -assist to generate better code. -.TP -\fB-b\fP -Implies \fB-s\fP. Use bit vectors as well in the attempt to coax better -code out of the compiler. Most useful for specifications with more than a -few keywords (e.g. for most programming languages). -.TP -\fB-h\fP -\fB-?\fP -Invoke a short help. -.TP -\fB-v\fP -Show version information. -.TP -\fB-o output\fP -Specify the output file. - -.SH "INTERFACE CODE" -Unlike other scanner generators, \*(re does not generate complete scanners: -the user must supply some interface code. -In particular, the user must define the following macros: -.TP -\fCYYCHAR\fP -Type used to hold an input symbol. -Usually \fCchar\fP or \fCunsigned char\fP. -.TP -\fCYYCURSOR\fP -\*(lx of type \fC*YYCHAR\fP that points to the current input symbol. -The generated code advances \fCYYCURSOR\fP as symbols are matched. -On entry, \fCYYCURSOR\fP is assumed to point to the first character of the -current token. On exit, \fCYYCURSOR\fP will point to the first character of -the following token. -.TP -\fCYLIMIT\fP -Expression of type \fC*YYCHAR\fP that marks the end of the buffer -(\fCYLIMIT[-1]\fP is the last character in the buffer). -The generated code repeatedly compares \fCYYCURSOR\fP to \fCYLIMIT\fP -to determine when the buffer needs (re)filling. -.TP -\fCYYMARKER\fP -\*(lx of type \fC*YYCHAR\fP. -The generated code saves backtracking information in \fCYYMARKER\fP. -.TP -\fCYYFILL(\fP\fIn\fP\fC)\fP -The generated code "calls" \fCYYFILL\fP when the buffer needs -(re)filling: at least \fIn\fP additional characters should -be provided. \fCYYFILL\fP should adjust \fCYYCURSOR\fP, \fCYYLIMIT\fP and -\fCYYMARKER\fP as needed. Note that for typical programming languages -\fIn\fP will be the length of the longest keyword plus one. - -.SH "SCANNER SPECIFICATIONS" -Each scanner specification consists of a set of \fIrules\fP and name -definitions. -Rules consist of a regular expression along with a block of C/C++ code that -is to be executed when the associated regular expression is matched. -Name definitions are of the form -``\fIname\fP \fC=\fP \fIregular expression\fP\fC;\fP''. - -.SH "SUMMARY OF RE2C REGULAR EXPRESSIONS" -.TP -\fC"foo"\fP -the literal string \fCfoo\fP. -ANSI-C escape sequences can be used. -.TP -\fC'foo'\fP -the literal string \fCfoo\fP (characters [a-zA-Z] treated case-insensitive). -ANSI-C escape sequences can be used. -.TP -\fC[xyz]\fP -a "character class"; in this case, -the \*(rx matches either an '\fCx\fP', a '\fCy\fP', or a '\fCz\fP'. -.TP -\fC[abj-oZ]\fP -a "character class" with a range in it; -matches an '\fCa\fP', a '\fCb\fP', any letter from '\fCj\fP' through '\fCo\fP', -or a '\fCZ\fP'. -.TP -\fIr\fP\fC\e\fP\fIs\fP -match any \fIr\fP which isn't an \fIs\fP. \fIr\fP and \fIs\fP must be regular expressions -which can be expressed as character classes. -.TP -\fIr\fP\fC*\fP -zero or more \fIr\fP's, where \fIr\fP is any regular expression -.TP -\fC\fIr\fP\fC+\fP -one or more \fIr\fP's -.TP -\fC\fIr\fP\fC?\fP -zero or one \fIr\fP's (that is, "an optional \fIr\fP") -.TP -name -the expansion of the "name" definition (see above) -.TP -\fC(\fP\fIr\fP\fC)\fP -an \fIr\fP; parentheses are used to override precedence -(see below) -.TP -\fIrs\fP -an \fIr\fP followed by an \fIs\fP ("concatenation") -.TP -\fIr\fP\fC|\fP\fIs\fP -either an \fIr\fP or an \fIs\fP -.TP -\fIr\fP\fC/\fP\fIs\fP -an \fIr\fP but only if it is followed by an \fIs\fP. The s is not part of -the matched text. This type of \*(rx is called "trailing context". -.TP -\fIr\fP\fC{\fP\fIn\fP\fC}\fP -matches \fIr\fP exactly \fIn\fP times. -.TP -\fIr\fP\fC{\fP\fIn\fP\fC,}\fP -matches \fIr\fP at least \fIn\fP times. -.TP -\fIr\fP\fC{\fP\fIn\fP\fC,\fP\fIm\fP\fC}\fP -matches \fIr\fP at least \fIn\fP but not more than \fIm\fP times. - -.LP -The regular expressions listed above are grouped according to -precedence, from highest precedence at the top to lowest at the bottom. -Those grouped together have equal precedence. - -.SH "A LARGER EXAMPLE" -.LP -.in +3 -.nf -#include -#include -#include -#include - -#define ADDEQ 257 -#define ANDAND 258 -#define ANDEQ 259 -#define ARRAY 260 -#define ASM 261 -#define AUTO 262 -#define BREAK 263 -#define CASE 264 -#define CHAR 265 -#define CONST 266 -#define CONTINUE 267 -#define DECR 268 -#define DEFAULT 269 -#define DEREF 270 -#define DIVEQ 271 -#define DO 272 -#define DOUBLE 273 -#define ELLIPSIS 274 -#define ELSE 275 -#define ENUM 276 -#define EQL 277 -#define EXTERN 278 -#define FCON 279 -#define FLOAT 280 -#define FOR 281 -#define FUNCTION 282 -#define GEQ 283 -#define GOTO 284 -#define ICON 285 -#define ID 286 -#define IF 287 -#define INCR 288 -#define INT 289 -#define LEQ 290 -#define LONG 291 -#define LSHIFT 292 -#define LSHIFTEQ 293 -#define MODEQ 294 -#define MULEQ 295 -#define NEQ 296 -#define OREQ 297 -#define OROR 298 -#define POINTER 299 -#define REGISTER 300 -#define RETURN 301 -#define RSHIFT 302 -#define RSHIFTEQ 303 -#define SCON 304 -#define SHORT 305 -#define SIGNED 306 -#define SIZEOF 307 -#define STATIC 308 -#define STRUCT 309 -#define SUBEQ 310 -#define SWITCH 311 -#define TYPEDEF 312 -#define UNION 313 -#define UNSIGNED 314 -#define VOID 315 -#define VOLATILE 316 -#define WHILE 317 -#define XOREQ 318 -#define EOI 319 - -typedef unsigned int uint; -typedef unsigned char uchar; - -#define BSIZE 8192 - -#define YYCTYPE uchar -#define YYCURSOR cursor -#define YYLIMIT s->lim -#define YYMARKER s->ptr -#define YYFILL(n) {cursor = fill(s, cursor);} - -#define RET(i) {s->cur = cursor; return i;} - -typedef struct Scanner { - int fd; - uchar *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof; - uint line; -} Scanner; - -uchar *fill(Scanner *s, uchar *cursor){ - if(!s->eof){ - uint cnt = s->tok - s->bot; - if(cnt){ - memcpy(s->bot, s->tok, s->lim - s->tok); - s->tok = s->bot; - s->ptr -= cnt; - cursor -= cnt; - s->pos -= cnt; - s->lim -= cnt; - } - if((s->top - s->lim) < BSIZE){ - uchar *buf = (uchar*) - malloc(((s->lim - s->bot) + BSIZE)*sizeof(uchar)); - memcpy(buf, s->tok, s->lim - s->tok); - s->tok = buf; - s->ptr = &buf[s->ptr - s->bot]; - cursor = &buf[cursor - s->bot]; - s->pos = &buf[s->pos - s->bot]; - s->lim = &buf[s->lim - s->bot]; - s->top = &s->lim[BSIZE]; - free(s->bot); - s->bot = buf; - } - if((cnt = read(s->fd, (char*) s->lim, BSIZE)) != BSIZE){ - s->eof = &s->lim[cnt]; *(s->eof)++ = '\\n'; - } - s->lim += cnt; - } - s->cur = cursor; - return cursor; -} - -int scan(Scanner *s){ - uchar *cursor = s->cur; -std: - s->tok = cursor; -/*!re2c -any = [\\000-\\377]; -O = [0-7]; -D = [0-9]; -L = [a-zA-Z_]; -H = [a-fA-F0-9]; -E = [Ee] [+-]? D+; -FS = [fFlL]; -IS = [uUlL]*; -ESC = [\\\\] ([abfnrtv?'"\\\\] | "x" H+ | O+); -*/ - -/*!re2c - "/*" { goto comment; } - - "auto" { RET(AUTO); } - "break" { RET(BREAK); } - "case" { RET(CASE); } - "char" { RET(CHAR); } - "const" { RET(CONST); } - "continue" { RET(CONTINUE); } - "default" { RET(DEFAULT); } - "do" { RET(DO); } - "double" { RET(DOUBLE); } - "else" { RET(ELSE); } - "enum" { RET(ENUM); } - "extern" { RET(EXTERN); } - "float" { RET(FLOAT); } - "for" { RET(FOR); } - "goto" { RET(GOTO); } - "if" { RET(IF); } - "int" { RET(INT); } - "long" { RET(LONG); } - "register" { RET(REGISTER); } - "return" { RET(RETURN); } - "short" { RET(SHORT); } - "signed" { RET(SIGNED); } - "sizeof" { RET(SIZEOF); } - "static" { RET(STATIC); } - "struct" { RET(STRUCT); } - "switch" { RET(SWITCH); } - "typedef" { RET(TYPEDEF); } - "union" { RET(UNION); } - "unsigned" { RET(UNSIGNED); } - "void" { RET(VOID); } - "volatile" { RET(VOLATILE); } - "while" { RET(WHILE); } - - L (L|D)* { RET(ID); } - - ("0" [xX] H+ IS?) | ("0" D+ IS?) | (D+ IS?) | - (['] (ESC|any\\[\\n\\\\'])* [']) - { RET(ICON); } - - (D+ E FS?) | (D* "." D+ E? FS?) | (D+ "." D* E? FS?) - { RET(FCON); } - - (["] (ESC|any\\[\\n\\\\"])* ["]) - { RET(SCON); } - - "..." { RET(ELLIPSIS); } - ">>=" { RET(RSHIFTEQ); } - "<<=" { RET(LSHIFTEQ); } - "+=" { RET(ADDEQ); } - "-=" { RET(SUBEQ); } - "*=" { RET(MULEQ); } - "/=" { RET(DIVEQ); } - "%=" { RET(MODEQ); } - "&=" { RET(ANDEQ); } - "^=" { RET(XOREQ); } - "|=" { RET(OREQ); } - ">>" { RET(RSHIFT); } - "<<" { RET(LSHIFT); } - "++" { RET(INCR); } - "--" { RET(DECR); } - "->" { RET(DEREF); } - "&&" { RET(ANDAND); } - "||" { RET(OROR); } - "<=" { RET(LEQ); } - ">=" { RET(GEQ); } - "==" { RET(EQL); } - "!=" { RET(NEQ); } - ";" { RET(';'); } - "{" { RET('{'); } - "}" { RET('}'); } - "," { RET(','); } - ":" { RET(':'); } - "=" { RET('='); } - "(" { RET('('); } - ")" { RET(')'); } - "[" { RET('['); } - "]" { RET(']'); } - "." { RET('.'); } - "&" { RET('&'); } - "!" { RET('!'); } - "~" { RET('~'); } - "-" { RET('-'); } - "+" { RET('+'); } - "*" { RET('*'); } - "/" { RET('/'); } - "%" { RET('%'); } - "<" { RET('<'); } - ">" { RET('>'); } - "^" { RET('^'); } - "|" { RET('|'); } - "?" { RET('?'); } - - - [ \\t\\v\\f]+ { goto std; } - - "\\n" - { - if(cursor == s->eof) RET(EOI); - s->pos = cursor; s->line++; - goto std; - } - - any - { - printf("unexpected character: %c\\n", *s->tok); - goto std; - } -*/ - -comment: -/*!re2c - "*/" { goto std; } - "\\n" - { - if(cursor == s->eof) RET(EOI); - s->tok = s->pos = cursor; s->line++; - goto comment; - } - any { goto comment; } -*/ -} - -main(){ - Scanner in; - int t; - memset((char*) &in, 0, sizeof(in)); - in.fd = 0; - while((t = scan(&in)) != EOI){ -/* - printf("%d\\t%.*s\\n", t, in.cur - in.tok, in.tok); - printf("%d\\n", t); -*/ - } - close(in.fd); -} -.fi -.in -3 - -.SH FEATURES -.LP -\*(re does not provide a default action: -the generated code assumes that the input -will consist of a sequence of tokens. -Typically this can be dealt with by adding a rule such as the one for -unexpected characters in the example above. -.LP -The user must arrange for a sentinel token to appear at the end of input -(and provide a rule for matching it): -\*(re does not provide an \fC<>\fP expression. -If the source is from a null-byte terminated string, a -rule matching a null character will suffice. If the source is from a -file then the approach taken in the example can be used: pad the input with -a newline (or some other character that can't appear within another token); -upon recognizing such a character check to see if it is the sentinel -and act accordingly. -.LP -\*(re does not provide start conditions: use a separate scanner -specification for each start condition (as illustrated in the above example). -.LP -No [^x]. Use difference instead. -.SH BUGS -.LP -Only fixed length trailing context can be handled. -.LP -The maximum value appearing as a parameter \fIn\fP to \fCYYFILL\fP is not -provided to the generated code (this value is needed for constructing -the interface code). -Note that this value is usually relatively small: for -typical programming languages \fIn\fP will be the length of the longest -keyword plus one. -.LP -Difference only works for character sets. -.LP -The \*(re internal algorithms need documentation. - -.SH "SEE ALSO" -.LP -flex(1), lex(1). -.P -More information on \fBre2c\fP can be found here: -.PD 0 -.P -.B http://sourceforge.net/projects/re2c/ -.PD 1 - -.SH AUTHORS -.PD 0 -.P -Peter Bumbulis -.P -Brian Young -.P -Dan Nuffer -.P -Marcus Boerger -.P -Hartmut Kaiser -.P -.PD 1 - -.SH VERSION INFORMATION -This manpage describes \fBre2c\fP, version @PACKAGE_VERSION@. - -.fi diff --git a/tools/re2c/re2c.spec.in b/tools/re2c/re2c.spec.in deleted file mode 100644 index 2963b6970..000000000 --- a/tools/re2c/re2c.spec.in +++ /dev/null @@ -1,51 +0,0 @@ -Summary: re2c - A tool for generating C-based recognizers from regular expressions -Name: @PACKAGE_NAME@ -Version: @PACKAGE_VERSION@ -Release: RPM_RELEASE -Group: Development -License: public domain -URL: http://sourceforge.net/projects/re2c/ -Source: %{name}-%{version}.tar.gz -BuildRoot: %{_tmppath}/%{name}-%{version}-root - -%description -re2c is a great tool for writing fast and flexible lexers. It has -served many people well for many years and it deserves to be -maintained more actively. re2c is on the order of 2-3 times faster -than a flex based scanner, and its input model is much more -flexible. - -%prep -%setup -q -n @PACKAGE_NAME@-@PACKAGE_VERSION@ - -%build -./configure \ - --prefix=%{_prefix} -make re2c -#regenerate file scanner.cc -rm -f scanner.cc -./re2c scanner.re > scanner.cc -rm -f re2c scanner.o -make - -%install -rm -rf $RPM_BUILD_ROOT -mkdir -p $RPM_BUILD_ROOT%{_bindir} -install -m 0755 re2c $RPM_BUILD_ROOT%{_bindir} - -mkdir -p $RPM_BUILD_ROOT%{_mandir}/man1 -install -m 0755 re2c.1 $RPM_BUILD_ROOT%{_mandir}/man1 - -%clean -rm -rf $RPM_BUILD_ROOT - -%changelog -* Sun Jan 04 2003 Marcus Boerger -- Initial version. - -%files -%defattr(-,root,root) -%{_bindir}/re2c -%{_mandir}/man1/re2c.1* - -%doc README examples doc/* diff --git a/tools/re2c/re2c.vcproj b/tools/re2c/re2c.vcproj index d159248e4..56250b1ed 100644 --- a/tools/re2c/re2c.vcproj +++ b/tools/re2c/re2c.vcproj @@ -100,88 +100,6 @@ Name="VCPostBuildEventTool" /> - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + @@ -435,6 +483,14 @@ RelativePath=".\basics.h" > + + + + @@ -463,6 +519,10 @@ RelativePath=".\scanner.h" > + + diff --git a/tools/re2c/scanner.cc b/tools/re2c/scanner.cc index 38cc693de..5d86717c1 100644 --- a/tools/re2c/scanner.cc +++ b/tools/re2c/scanner.cc @@ -1,639 +1,1634 @@ -/* Generated by re2c 0.9.3 on Wed May 26 17:58:01 2004 */ -#line 1 "scanner.re" -/* $Id: scanner.re,v 1.10 2004/05/13 02:58:18 nuffer Exp $ */ -#include -#include -#include -#include "scanner.h" -#include "parser.h" -#include "y.tab.h" - -extern YYSTYPE yylval; - -#ifndef MAX -#define MAX(a,b) (((a)>(b))?(a):(b)) -#endif - -#define BSIZE 8192 - -#define YYCTYPE char -#define YYCURSOR cursor -#define YYLIMIT lim -#define YYMARKER ptr -#define YYFILL(n) {cursor = fill(cursor);} - -#define RETURN(i) {cur = cursor; return i;} - - -Scanner::Scanner(std::istream& i) : in(i), - bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL), - top(NULL), eof(NULL), tchar(0), tline(0), cline(1) { - ; -} - -char *Scanner::fill(char *cursor){ - if(!eof){ - uint cnt = tok - bot; - if(cnt){ - memcpy(bot, tok, lim - tok); - tok = bot; - ptr -= cnt; - cursor -= cnt; - pos -= cnt; - lim -= cnt; - } - if((top - lim) < BSIZE){ - char *buf = new char[(lim - bot) + BSIZE]; - memcpy(buf, tok, lim - tok); - tok = buf; - ptr = &buf[ptr - bot]; - cursor = &buf[cursor - bot]; - pos = &buf[pos - bot]; - lim = &buf[lim - bot]; - top = &lim[BSIZE]; - delete [] bot; - bot = buf; - } - if((cnt = in.rdbuf()->sgetn((char*) lim, BSIZE)) != BSIZE){ - eof = &lim[cnt]; *eof++ = '\n'; - } - lim += cnt; - } - return cursor; -} - -#line 72 "scanner.re" - - -int Scanner::echo(std::ostream &out){ - char *cursor = cur; - - // Catch EOF - if (eof && cursor == eof) - return 0; - - tok = cursor; -echo: - -#line 7 "scanner.cc" -{ - YYCTYPE yych; - unsigned int yyaccept; - goto yy0; -yy1: ++YYCURSOR; -yy0: - if((YYLIMIT - YYCURSOR) < 7) YYFILL(7); - yych = *YYCURSOR; - if(yych == '\n') goto yy4; - if(yych != '/') goto yy6; - goto yy2; -yy2: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == '*') goto yy7; - goto yy3; -yy3: -#line 91 "scanner.re" -{ goto echo; } -#line 26 "scanner.cc" -yy4: ++YYCURSOR; - goto yy5; -yy5: -#line 87 "scanner.re" -{ if(cursor == eof) RETURN(0); - out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); - tok = pos = cursor; cline++; - goto echo; } -#line 35 "scanner.cc" -yy6: yych = *++YYCURSOR; - goto yy3; -yy7: yych = *++YYCURSOR; - if(yych == '!') goto yy9; - goto yy8; -yy8: YYCURSOR = YYMARKER; - switch(yyaccept){ - case 0: goto yy3; - } -yy9: yych = *++YYCURSOR; - if(yych != 'r') goto yy8; - goto yy10; -yy10: yych = *++YYCURSOR; - if(yych != 'e') goto yy8; - goto yy11; -yy11: yych = *++YYCURSOR; - if(yych != '2') goto yy8; - goto yy12; -yy12: yych = *++YYCURSOR; - if(yych != 'c') goto yy8; - goto yy13; -yy13: ++YYCURSOR; - goto yy14; -yy14: -#line 84 "scanner.re" -{ out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok)); - tok = cursor; - RETURN(1); } -#line 64 "scanner.cc" -} -#line 92 "scanner.re" - -} - - -int Scanner::scan(){ - char *cursor = cur; - uint depth; - -scan: - tchar = cursor - pos; - tline = cline; - tok = cursor; - -#line 68 "scanner.cc" -{ - YYCTYPE yych; - unsigned int yyaccept; - goto yy15; -yy16: ++YYCURSOR; -yy15: - if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if(yych <= '/'){ - if(yych <= '"'){ - if(yych <= '\n'){ - if(yych <= '\b') goto yy37; - if(yych <= '\t') goto yy33; - goto yy35; - } else { - if(yych == ' ') goto yy33; - if(yych <= '!') goto yy37; - goto yy23; - } - } else { - if(yych <= ')'){ - if(yych <= '&') goto yy37; - if(yych <= '\'') goto yy25; - goto yy29; - } else { - if(yych <= '*') goto yy21; - if(yych <= '+') goto yy30; - if(yych <= '.') goto yy37; - goto yy19; - } - } - } else { - if(yych <= '@'){ - if(yych <= '<'){ - if(yych == ';') goto yy29; - goto yy37; - } else { - if(yych <= '=') goto yy29; - if(yych == '?') goto yy30; - goto yy37; - } - } else { - if(yych <= '`'){ - if(yych <= 'Z') goto yy31; - if(yych <= '[') goto yy27; - if(yych <= '\\') goto yy29; - goto yy37; - } else { - if(yych <= 'z') goto yy31; - if(yych <= '{') goto yy17; - if(yych <= '|') goto yy29; - goto yy37; - } - } - } -yy17: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych <= '/') goto yy18; - if(yych <= '9') goto yy63; - goto yy18; -yy18: -#line 105 "scanner.re" -{ depth = 1; - goto code; - } -#line 134 "scanner.cc" -yy19: ++YYCURSOR; - if((yych = *YYCURSOR) == '*') goto yy61; - goto yy20; -yy20: -#line 131 "scanner.re" -{ RETURN(*tok); } -#line 141 "scanner.cc" -yy21: ++YYCURSOR; - if((yych = *YYCURSOR) == '/') goto yy59; - goto yy22; -yy22: -#line 133 "scanner.re" -{ yylval.op = *tok; - RETURN(CLOSE); } -#line 149 "scanner.cc" -yy23: yyaccept = 1; - yych = *(YYMARKER = ++YYCURSOR); - if(yych != '\n') goto yy55; - goto yy24; -yy24: -#line 122 "scanner.re" -{ fatal("unterminated string constant (missing \")"); } -#line 157 "scanner.cc" -yy25: yyaccept = 2; - yych = *(YYMARKER = ++YYCURSOR); - if(yych != '\n') goto yy50; - goto yy26; -yy26: -#line 123 "scanner.re" -{ fatal("unterminated string constant (missing ')"); } -#line 165 "scanner.cc" -yy27: yyaccept = 3; - yych = *(YYMARKER = ++YYCURSOR); - if(yych != '\n') goto yy44; - goto yy28; -yy28: -#line 129 "scanner.re" -{ fatal("unterminated range (missing ])"); } -#line 173 "scanner.cc" -yy29: yych = *++YYCURSOR; - goto yy20; -yy30: yych = *++YYCURSOR; - goto yy22; -yy31: ++YYCURSOR; - yych = *YYCURSOR; - goto yy42; -yy32: -#line 148 "scanner.re" -{ cur = cursor; - yylval.symbol = Symbol::find(token()); - return ID; } -#line 185 "scanner.cc" -yy33: ++YYCURSOR; - yych = *YYCURSOR; - goto yy40; -yy34: -#line 152 "scanner.re" -{ goto scan; } -#line 191 "scanner.cc" -yy35: ++YYCURSOR; - goto yy36; -yy36: -#line 154 "scanner.re" -{ if(cursor == eof) RETURN(0); - pos = cursor; cline++; - goto scan; - } -#line 200 "scanner.cc" -yy37: ++YYCURSOR; - goto yy38; -yy38: -#line 159 "scanner.re" -{ std::cerr << "unexpected character: " << *tok << std::endl; - goto scan; - } -#line 208 "scanner.cc" -yy39: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy40; -yy40: if(yych == '\t') goto yy39; - if(yych == ' ') goto yy39; - goto yy34; -yy41: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy42; -yy42: if(yych <= '@'){ - if(yych <= '/') goto yy32; - if(yych <= '9') goto yy41; - goto yy32; - } else { - if(yych <= 'Z') goto yy41; - if(yych <= '`') goto yy32; - if(yych <= 'z') goto yy41; - goto yy32; - } -yy43: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy44; -yy44: if(yych <= '['){ - if(yych != '\n') goto yy43; - goto yy45; - } else { - if(yych <= '\\') goto yy46; - if(yych <= ']') goto yy47; - goto yy43; - } -yy45: YYCURSOR = YYMARKER; - switch(yyaccept){ - case 0: goto yy18; - case 1: goto yy24; - case 2: goto yy26; - case 3: goto yy28; - } -yy46: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yych == '\n') goto yy45; - goto yy43; -yy47: ++YYCURSOR; - goto yy48; -yy48: -#line 125 "scanner.re" -{ cur = cursor; - yylval.regexp = ranToRE(token()); - return RANGE; } -#line 265 "scanner.cc" -yy49: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy50; -yy50: if(yych <= '&'){ - if(yych == '\n') goto yy45; - goto yy49; - } else { - if(yych <= '\'') goto yy52; - if(yych != '\\') goto yy49; - goto yy51; - } -yy51: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yych == '\n') goto yy45; - goto yy49; -yy52: ++YYCURSOR; - goto yy53; -yy53: -#line 118 "scanner.re" -{ cur = cursor; - yylval.regexp = strToCaseInsensitiveRE(token()); - return STRING; } -#line 292 "scanner.cc" -yy54: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy55; -yy55: if(yych <= '!'){ - if(yych == '\n') goto yy45; - goto yy54; - } else { - if(yych <= '"') goto yy57; - if(yych != '\\') goto yy54; - goto yy56; - } -yy56: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yych == '\n') goto yy45; - goto yy54; -yy57: ++YYCURSOR; - goto yy58; -yy58: -#line 114 "scanner.re" -{ cur = cursor; - yylval.regexp = strToRE(token()); - return STRING; } -#line 319 "scanner.cc" -yy59: ++YYCURSOR; - goto yy60; -yy60: -#line 111 "scanner.re" -{ tok = cursor; - RETURN(0); } -#line 326 "scanner.cc" -yy61: ++YYCURSOR; - goto yy62; -yy62: -#line 108 "scanner.re" -{ depth = 1; - goto comment; } -#line 333 "scanner.cc" -yy63: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy64; -yy64: if(yych <= '/'){ - if(yych == ',') goto yy67; - goto yy45; - } else { - if(yych <= '9') goto yy63; - if(yych != '}') goto yy45; - goto yy65; - } -yy65: ++YYCURSOR; - goto yy66; -yy66: -#line 136 "scanner.re" -{ yylval.extop.minsize = atoi((char *)tok+1); - yylval.extop.maxsize = atoi((char *)tok+1); - RETURN(CLOSESIZE); } -#line 354 "scanner.cc" -yy67: yych = *++YYCURSOR; - if(yych != '}') goto yy71; - goto yy68; -yy68: ++YYCURSOR; - goto yy69; -yy69: -#line 144 "scanner.re" -{ yylval.extop.minsize = atoi((char *)tok+1); - yylval.extop.maxsize = -1; - RETURN(CLOSESIZE); } -#line 365 "scanner.cc" -yy70: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy71; -yy71: if(yych <= '/') goto yy45; - if(yych <= '9') goto yy70; - if(yych != '}') goto yy45; - goto yy72; -yy72: ++YYCURSOR; - goto yy73; -yy73: -#line 140 "scanner.re" -{ yylval.extop.minsize = atoi((char *)tok+1); - yylval.extop.maxsize = MAX(yylval.extop.minsize,atoi(strchr((char *)tok, ',')+1)); - RETURN(CLOSESIZE); } -#line 382 "scanner.cc" -} -#line 162 "scanner.re" - - -code: - -#line 386 "scanner.cc" -{ - YYCTYPE yych; - unsigned int yyaccept; - goto yy74; -yy75: ++YYCURSOR; -yy74: - if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if(yych <= '&'){ - if(yych <= '\n'){ - if(yych <= '\t') goto yy82; - goto yy80; - } else { - if(yych == '"') goto yy84; - goto yy82; - } - } else { - if(yych <= '{'){ - if(yych <= '\'') goto yy85; - if(yych <= 'z') goto yy82; - goto yy78; - } else { - if(yych != '}') goto yy82; - goto yy76; - } - } -yy76: ++YYCURSOR; - goto yy77; -yy77: -#line 166 "scanner.re" -{ if(--depth == 0){ - cur = cursor; - yylval.token = new Token(token(), tline); - return CODE; - } - goto code; } -#line 423 "scanner.cc" -yy78: ++YYCURSOR; - goto yy79; -yy79: -#line 172 "scanner.re" -{ ++depth; - goto code; } -#line 430 "scanner.cc" -yy80: ++YYCURSOR; - goto yy81; -yy81: -#line 174 "scanner.re" -{ if(cursor == eof) fatal("missing '}'"); - pos = cursor; cline++; - goto code; - } -#line 439 "scanner.cc" -yy82: ++YYCURSOR; - goto yy83; -yy83: -#line 178 "scanner.re" -{ goto code; } -#line 445 "scanner.cc" -yy84: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == '\n') goto yy83; - goto yy91; -yy85: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == '\n') goto yy83; - goto yy87; -yy86: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy87; -yy87: if(yych <= '&'){ - if(yych != '\n') goto yy86; - goto yy88; - } else { - if(yych <= '\'') goto yy82; - if(yych == '\\') goto yy89; - goto yy86; - } -yy88: YYCURSOR = YYMARKER; - switch(yyaccept){ - case 0: goto yy83; - } -yy89: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yych == '\n') goto yy88; - goto yy86; -yy90: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy91; -yy91: if(yych <= '!'){ - if(yych == '\n') goto yy88; - goto yy90; - } else { - if(yych <= '"') goto yy82; - if(yych != '\\') goto yy90; - goto yy92; - } -yy92: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yych == '\n') goto yy88; - goto yy90; -} -#line 179 "scanner.re" - - -comment: - -#line 499 "scanner.cc" -{ - YYCTYPE yych; - unsigned int yyaccept; - goto yy93; -yy94: ++YYCURSOR; -yy93: - if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if(yych <= ')'){ - if(yych == '\n') goto yy98; - goto yy100; - } else { - if(yych <= '*') goto yy95; - if(yych == '/') goto yy97; - goto yy100; - } -yy95: ++YYCURSOR; - if((yych = *YYCURSOR) == '/') goto yy103; - goto yy96; -yy96: -#line 193 "scanner.re" -{ goto comment; } -#line 522 "scanner.cc" -yy97: yych = *++YYCURSOR; - if(yych == '*') goto yy101; - goto yy96; -yy98: ++YYCURSOR; - goto yy99; -yy99: -#line 189 "scanner.re" -{ if(cursor == eof) RETURN(0); - tok = pos = cursor; cline++; - goto comment; - } -#line 534 "scanner.cc" -yy100: yych = *++YYCURSOR; - goto yy96; -yy101: ++YYCURSOR; - goto yy102; -yy102: -#line 187 "scanner.re" -{ ++depth; - goto comment; } -#line 543 "scanner.cc" -yy103: ++YYCURSOR; - goto yy104; -yy104: -#line 183 "scanner.re" -{ if(--depth == 0) - goto scan; - else - goto comment; } -#line 552 "scanner.cc" -} -#line 194 "scanner.re" - -} - -void Scanner::fatal(char *msg){ - std::cerr << "line " << tline << ", column " << (tchar + 1) << ": " - << msg << std::endl; - exit(1); -} +/* Generated by re2c 0.10.3 on Wed May 24 19:55:36 2006 */ +#line 1 "scanner.re" +/* $Id: scanner.re,v 1.42 2006/04/17 00:18:45 helly Exp $ */ +#include +#include +#include +#include +#include "scanner.h" +#include "parser.h" +#include "y.tab.h" +#include "globals.h" +#include "dfa.h" + +extern YYSTYPE yylval; + +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif + +#define BSIZE 8192 + +#define YYCTYPE char +#define YYCURSOR cursor +#define YYLIMIT lim +#define YYMARKER ptr +#define YYFILL(n) {cursor = fill(cursor);} + +#define RETURN(i) {cur = cursor; return i;} + +namespace re2c +{ + +Scanner::Scanner(const char *fn, std::istream& i, std::ostream& o) + : in(i) + , out(o) + , bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL) + , top(NULL), eof(NULL), tchar(0), tline(0), cline(1), iscfg(0) + , filename(fn) +{ + ; +} + +char *Scanner::fill(char *cursor) +{ + if(!eof) + { + uint cnt = tok - bot; + if(cnt) + { + memcpy(bot, tok, lim - tok); + tok = bot; + ptr -= cnt; + cursor -= cnt; + pos -= cnt; + lim -= cnt; + } + if((top - lim) < BSIZE) + { + char *buf = new char[(lim - bot) + BSIZE]; + memcpy(buf, tok, lim - tok); + tok = buf; + ptr = &buf[ptr - bot]; + cursor = &buf[cursor - bot]; + pos = &buf[pos - bot]; + lim = &buf[lim - bot]; + top = &lim[BSIZE]; + delete [] bot; + bot = buf; + } + in.read(lim, BSIZE); + if ((cnt = in.gcount()) != BSIZE ) + { + eof = &lim[cnt]; *eof++ = '\0'; + } + lim += cnt; + } + return cursor; +} + +#line 96 "scanner.re" + + +int Scanner::echo() +{ + char *cursor = cur; + bool ignore_eoc = false; + int ignore_cnt = 0; + + if (eof && cursor == eof) // Catch EOF + { + return 0; + } + + tok = cursor; +echo: + +#line 98 "" +{ + YYCTYPE yych; + unsigned int yyaccept = 0; + + if((YYLIMIT - YYCURSOR) < 16) YYFILL(16); + yych = *YYCURSOR; + switch(yych){ + case 0x00: goto yy7; + case 0x0A: goto yy5; + case '*': goto yy4; + case '/': goto yy2; + default: goto yy9; + } +yy2: + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case '*': goto yy16; + default: goto yy3; + } +yy3: +#line 185 "scanner.re" + { + goto echo; + } +#line 124 "" +yy4: + yych = *++YYCURSOR; + switch(yych){ + case '/': goto yy10; + default: goto yy3; + } +yy5: + ++YYCURSOR; +#line 168 "scanner.re" + { + if (ignore_eoc) { + ignore_cnt++; + } else { + out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + } + tok = pos = cursor; cline++; + goto echo; + } +#line 143 "" +yy7: + ++YYCURSOR; +#line 177 "scanner.re" + { + if (!ignore_eoc) { + out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok) - 1); // -1 so we don't write out the \0 + } + if(cursor == eof) { + RETURN(0); + } + } +#line 155 "" +yy9: + yych = *++YYCURSOR; + goto yy3; +yy10: + yyaccept = 1; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case 0x0A: goto yy14; + case 0x0D: goto yy12; + default: goto yy11; + } +yy11: +#line 155 "scanner.re" + { + if (ignore_eoc) { + if (ignore_cnt) { + out << "\n" << sourceFileInfo; + } + ignore_eoc = false; + ignore_cnt = 0; + } else { + out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + } + tok = pos = cursor; + goto echo; + } +#line 182 "" +yy12: + yych = *++YYCURSOR; + switch(yych){ + case 0x0A: goto yy14; + default: goto yy13; + } +yy13: + YYCURSOR = YYMARKER; + switch(yyaccept) { + case 0: goto yy3; + case 1: goto yy11; + } +yy14: + ++YYCURSOR; +#line 141 "scanner.re" + { + cline++; + if (ignore_eoc) { + if (ignore_cnt) { + out << sourceFileInfo; + } + ignore_eoc = false; + ignore_cnt = 0; + } else { + out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + } + tok = pos = cursor; + goto echo; + } +#line 212 "" +yy16: + yych = *++YYCURSOR; + switch(yych){ + case '!': goto yy17; + default: goto yy13; + } +yy17: + yych = *++YYCURSOR; + switch(yych){ + case 'g': goto yy19; + case 'i': goto yy18; + case 'm': goto yy20; + case 'r': goto yy21; + default: goto yy13; + } +yy18: + yych = *++YYCURSOR; + switch(yych){ + case 'g': goto yy47; + default: goto yy13; + } +yy19: + yych = *++YYCURSOR; + switch(yych){ + case 'e': goto yy34; + default: goto yy13; + } +yy20: + yych = *++YYCURSOR; + switch(yych){ + case 'a': goto yy26; + default: goto yy13; + } +yy21: + yych = *++YYCURSOR; + switch(yych){ + case 'e': goto yy22; + default: goto yy13; + } +yy22: + yych = *++YYCURSOR; + switch(yych){ + case '2': goto yy23; + default: goto yy13; + } +yy23: + yych = *++YYCURSOR; + switch(yych){ + case 'c': goto yy24; + default: goto yy13; + } +yy24: + ++YYCURSOR; +#line 112 "scanner.re" + { + if (bUsedYYMaxFill && bSinglePass) { + fatal("found scanner block after YYMAXFILL declaration"); + } + out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok)); + tok = cursor; + RETURN(1); + } +#line 275 "" +yy26: + yych = *++YYCURSOR; + switch(yych){ + case 'x': goto yy27; + default: goto yy13; + } +yy27: + yych = *++YYCURSOR; + switch(yych){ + case ':': goto yy28; + default: goto yy13; + } +yy28: + yych = *++YYCURSOR; + switch(yych){ + case 'r': goto yy29; + default: goto yy13; + } +yy29: + yych = *++YYCURSOR; + switch(yych){ + case 'e': goto yy30; + default: goto yy13; + } +yy30: + yych = *++YYCURSOR; + switch(yych){ + case '2': goto yy31; + default: goto yy13; + } +yy31: + yych = *++YYCURSOR; + switch(yych){ + case 'c': goto yy32; + default: goto yy13; + } +yy32: + ++YYCURSOR; +#line 120 "scanner.re" + { + if (bUsedYYMaxFill) { + fatal("cannot generate YYMAXFILL twice"); + } + out << "#define YYMAXFILL " << maxFill << std::endl; + tok = pos = cursor; + ignore_eoc = true; + bUsedYYMaxFill = true; + goto echo; + } +#line 325 "" +yy34: + yych = *++YYCURSOR; + switch(yych){ + case 't': goto yy35; + default: goto yy13; + } +yy35: + yych = *++YYCURSOR; + switch(yych){ + case 's': goto yy36; + default: goto yy13; + } +yy36: + yych = *++YYCURSOR; + switch(yych){ + case 't': goto yy37; + default: goto yy13; + } +yy37: + yych = *++YYCURSOR; + switch(yych){ + case 'a': goto yy38; + default: goto yy13; + } +yy38: + yych = *++YYCURSOR; + switch(yych){ + case 't': goto yy39; + default: goto yy13; + } +yy39: + yych = *++YYCURSOR; + switch(yych){ + case 'e': goto yy40; + default: goto yy13; + } +yy40: + yych = *++YYCURSOR; + switch(yych){ + case ':': goto yy41; + default: goto yy13; + } +yy41: + yych = *++YYCURSOR; + switch(yych){ + case 'r': goto yy42; + default: goto yy13; + } +yy42: + yych = *++YYCURSOR; + switch(yych){ + case 'e': goto yy43; + default: goto yy13; + } +yy43: + yych = *++YYCURSOR; + switch(yych){ + case '2': goto yy44; + default: goto yy13; + } +yy44: + yych = *++YYCURSOR; + switch(yych){ + case 'c': goto yy45; + default: goto yy13; + } +yy45: + ++YYCURSOR; +#line 130 "scanner.re" + { + tok = pos = cursor; + genGetState(out, topIndent, 0); + ignore_eoc = true; + goto echo; + } +#line 401 "" +yy47: + yych = *++YYCURSOR; + switch(yych){ + case 'n': goto yy48; + default: goto yy13; + } +yy48: + yych = *++YYCURSOR; + switch(yych){ + case 'o': goto yy49; + default: goto yy13; + } +yy49: + yych = *++YYCURSOR; + switch(yych){ + case 'r': goto yy50; + default: goto yy13; + } +yy50: + yych = *++YYCURSOR; + switch(yych){ + case 'e': goto yy51; + default: goto yy13; + } +yy51: + yych = *++YYCURSOR; + switch(yych){ + case ':': goto yy52; + default: goto yy13; + } +yy52: + yych = *++YYCURSOR; + switch(yych){ + case 'r': goto yy53; + default: goto yy13; + } +yy53: + yych = *++YYCURSOR; + switch(yych){ + case 'e': goto yy54; + default: goto yy13; + } +yy54: + yych = *++YYCURSOR; + switch(yych){ + case '2': goto yy55; + default: goto yy13; + } +yy55: + yych = *++YYCURSOR; + switch(yych){ + case 'c': goto yy56; + default: goto yy13; + } +yy56: + ++YYCURSOR; +#line 136 "scanner.re" + { + tok = pos = cursor; + ignore_eoc = true; + goto echo; + } +#line 464 "" +} +#line 188 "scanner.re" + +} + + +int Scanner::scan() +{ + char *cursor = cur; + uint depth; + +scan: + tchar = cursor - pos; + tline = cline; + tok = cursor; + if (iscfg == 1) + { + goto config; + } + else if (iscfg == 2) + { + goto value; + } + +#line 489 "" +{ + YYCTYPE yych; + unsigned int yyaccept = 0; + if((YYLIMIT - YYCURSOR) < 5) YYFILL(5); + yych = *YYCURSOR; + switch(yych){ + case 0x09: + case ' ': goto yy79; + case 0x0A: goto yy81; + case 0x0D: goto yy83; + case '"': goto yy66; + case '\'': goto yy68; + case '(': + case ')': + case ';': + case '=': + case '\\': + case '|': goto yy72; + case '*': goto yy64; + case '+': + case '?': goto yy73; + case '.': goto yy77; + case '/': goto yy62; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy76; + case '[': goto yy70; + case 'r': goto yy74; + case '{': goto yy60; + default: goto yy85; + } +yy60: + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case ',': goto yy126; + case '0': goto yy123; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy124; + default: goto yy61; + } +yy61: +#line 210 "scanner.re" + { depth = 1; + goto code; + } +#line 591 "" +yy62: + ++YYCURSOR; + switch((yych = *YYCURSOR)) { + case '*': goto yy121; + default: goto yy63; + } +yy63: +#line 240 "scanner.re" + { RETURN(*tok); } +#line 601 "" +yy64: + ++YYCURSOR; + switch((yych = *YYCURSOR)) { + case '/': goto yy119; + default: goto yy65; + } +yy65: +#line 242 "scanner.re" + { yylval.op = *tok; + RETURN(CLOSE); } +#line 612 "" +yy66: + yyaccept = 1; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case 0x0A: goto yy67; + default: goto yy115; + } +yy67: +#line 227 "scanner.re" + { fatal("unterminated string constant (missing \")"); } +#line 623 "" +yy68: + yyaccept = 2; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case 0x0A: goto yy69; + default: goto yy110; + } +yy69: +#line 228 "scanner.re" + { fatal("unterminated string constant (missing ')"); } +#line 634 "" +yy70: + yyaccept = 3; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case 0x0A: goto yy71; + case '^': goto yy101; + default: goto yy100; + } +yy71: +#line 238 "scanner.re" + { fatal("unterminated range (missing ])"); } +#line 646 "" +yy72: + yych = *++YYCURSOR; + goto yy63; +yy73: + yych = *++YYCURSOR; + goto yy65; +yy74: + ++YYCURSOR; + switch((yych = *YYCURSOR)) { + case 'e': goto yy91; + default: goto yy90; + } +yy75: +#line 269 "scanner.re" + { cur = cursor; + yylval.symbol = Symbol::find(token()); + return ID; } +#line 664 "" +yy76: + yych = *++YYCURSOR; + goto yy90; +yy77: + ++YYCURSOR; +#line 273 "scanner.re" + { cur = cursor; + yylval.regexp = mkDot(); + return RANGE; + } +#line 675 "" +yy79: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy88; +yy80: +#line 278 "scanner.re" + { goto scan; } +#line 683 "" +yy81: + ++YYCURSOR; +yy82: +#line 280 "scanner.re" + { if(cursor == eof) RETURN(0); + pos = cursor; cline++; + goto scan; + } +#line 692 "" +yy83: + ++YYCURSOR; + switch((yych = *YYCURSOR)) { + case 0x0A: goto yy86; + default: goto yy84; + } +yy84: +#line 285 "scanner.re" + { std::ostringstream msg; + msg << "unexpected character: "; + prtChOrHex(msg, *tok); + fatal(msg.str().c_str()); + goto scan; + } +#line 707 "" +yy85: + yych = *++YYCURSOR; + goto yy84; +yy86: + yych = *++YYCURSOR; + goto yy82; +yy87: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy88: + switch(yych){ + case 0x09: + case ' ': goto yy87; + default: goto yy80; + } +yy89: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy90: + switch(yych){ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy89; + default: goto yy75; + } +yy91: + yych = *++YYCURSOR; + switch(yych){ + case '2': goto yy92; + default: goto yy90; + } +yy92: + yych = *++YYCURSOR; + switch(yych){ + case 'c': goto yy93; + default: goto yy90; + } +yy93: + yyaccept = 4; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case ':': goto yy94; + default: goto yy90; + } +yy94: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy96; + default: goto yy95; + } +yy95: + YYCURSOR = YYMARKER; + switch(yyaccept) { + case 0: goto yy61; + case 1: goto yy67; + case 2: goto yy69; + case 3: goto yy71; + case 4: goto yy75; + case 5: goto yy98; + case 6: goto yy127; + } +yy96: + yyaccept = 5; + YYMARKER = ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy96; + case ':': goto yy94; + default: goto yy98; + } +yy98: +#line 262 "scanner.re" + { cur = cursor; + tok+= 5; /* skip "re2c:" */ + iscfg = 1; + yylval.str = new Str(token()); + return CONFIG; + } +#line 963 "" +yy99: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy100: + switch(yych){ + case 0x0A: goto yy95; + case '\\': goto yy103; + case ']': goto yy104; + default: goto yy99; + } +yy101: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy95; + case '\\': goto yy106; + case ']': goto yy107; + default: goto yy101; + } +yy103: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy95; + default: goto yy99; + } +yy104: + ++YYCURSOR; +#line 234 "scanner.re" + { cur = cursor; + yylval.regexp = ranToRE(token()); + return RANGE; } +#line 999 "" +yy106: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy95; + default: goto yy101; + } +yy107: + ++YYCURSOR; +#line 230 "scanner.re" + { cur = cursor; + yylval.regexp = invToRE(token()); + return RANGE; } +#line 1014 "" +yy109: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy110: + switch(yych){ + case 0x0A: goto yy95; + case '\'': goto yy112; + case '\\': goto yy111; + default: goto yy109; + } +yy111: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy95; + default: goto yy109; + } +yy112: + ++YYCURSOR; +#line 223 "scanner.re" + { cur = cursor; + yylval.regexp = strToCaseInsensitiveRE(token()); + return STRING; } +#line 1040 "" +yy114: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy115: + switch(yych){ + case 0x0A: goto yy95; + case '"': goto yy117; + case '\\': goto yy116; + default: goto yy114; + } +yy116: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy95; + default: goto yy114; + } +yy117: + ++YYCURSOR; +#line 219 "scanner.re" + { cur = cursor; + yylval.regexp = strToRE(token()); + return STRING; } +#line 1066 "" +yy119: + ++YYCURSOR; +#line 216 "scanner.re" + { tok = cursor; + RETURN(0); } +#line 1072 "" +yy121: + ++YYCURSOR; +#line 213 "scanner.re" + { depth = 1; + goto comment; } +#line 1078 "" +yy123: + yych = *++YYCURSOR; + switch(yych){ + case ',': goto yy137; + default: goto yy125; + } +yy124: + ++YYCURSOR; + if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; +yy125: + switch(yych){ + case ',': goto yy130; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy124; + case '}': goto yy128; + default: goto yy95; + } +yy126: + ++YYCURSOR; +yy127: +#line 260 "scanner.re" + { fatal("illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers"); } +#line 1110 "" +yy128: + ++YYCURSOR; +#line 248 "scanner.re" + { yylval.extop.minsize = atoi((char *)tok+1); + yylval.extop.maxsize = atoi((char *)tok+1); + RETURN(CLOSESIZE); } +#line 1117 "" +yy130: + yyaccept = 6; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy133; + case '}': goto yy131; + default: goto yy127; + } +yy131: + ++YYCURSOR; +#line 256 "scanner.re" + { yylval.extop.minsize = atoi((char *)tok+1); + yylval.extop.maxsize = -1; + RETURN(CLOSESIZE); } +#line 1141 "" +yy133: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy133; + case '}': goto yy135; + default: goto yy95; + } +yy135: + ++YYCURSOR; +#line 252 "scanner.re" + { yylval.extop.minsize = atoi((char *)tok+1); + yylval.extop.maxsize = MAX(yylval.extop.minsize,atoi(strchr((char *)tok, ',')+1)); + RETURN(CLOSESIZE); } +#line 1166 "" +yy137: + yyaccept = 6; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy133; + case '}': goto yy138; + default: goto yy127; + } +yy138: + ++YYCURSOR; +#line 245 "scanner.re" + { yylval.op = '*'; + RETURN(CLOSE); } +#line 1189 "" +} +#line 291 "scanner.re" + + +code: + +#line 1196 "" +{ + YYCTYPE yych; + if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy146; + case '"': goto yy150; + case '\'': goto yy151; + case '{': goto yy144; + case '}': goto yy142; + default: goto yy148; + } +yy142: + ++YYCURSOR; +#line 295 "scanner.re" + { if(--depth == 0){ + cur = cursor; + yylval.token = new Token(token(), tline); + return CODE; + } + goto code; } +#line 1218 "" +yy144: + ++YYCURSOR; +#line 301 "scanner.re" + { ++depth; + goto code; } +#line 1224 "" +yy146: + ++YYCURSOR; +#line 303 "scanner.re" + { if(cursor == eof) fatal("missing '}'"); + pos = cursor; cline++; + goto code; + } +#line 1232 "" +yy148: + ++YYCURSOR; +yy149: +#line 307 "scanner.re" + { goto code; } +#line 1238 "" +yy150: + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case 0x0A: goto yy149; + default: goto yy157; + } +yy151: + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case 0x0A: goto yy149; + default: goto yy153; + } +yy152: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy153: + switch(yych){ + case 0x0A: goto yy154; + case '\'': goto yy148; + case '\\': goto yy155; + default: goto yy152; + } +yy154: + YYCURSOR = YYMARKER; + goto yy149; +yy155: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy154; + default: goto yy152; + } +yy156: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy157: + switch(yych){ + case 0x0A: goto yy154; + case '"': goto yy148; + case '\\': goto yy158; + default: goto yy156; + } +yy158: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy154; + default: goto yy156; + } +} +#line 308 "scanner.re" + + +comment: + +#line 1298 "" +{ + YYCTYPE yych; + if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy164; + case '*': goto yy161; + case '/': goto yy163; + default: goto yy166; + } +yy161: + ++YYCURSOR; + switch((yych = *YYCURSOR)) { + case '/': goto yy169; + default: goto yy162; + } +yy162: +#line 323 "scanner.re" + { if(cursor == eof) RETURN(0); + goto comment; } +#line 1319 "" +yy163: + yych = *++YYCURSOR; + switch(yych){ + case '*': goto yy167; + default: goto yy162; + } +yy164: + ++YYCURSOR; +#line 319 "scanner.re" + { if(cursor == eof) RETURN(0); + tok = pos = cursor; cline++; + goto comment; + } +#line 1333 "" +yy166: + yych = *++YYCURSOR; + goto yy162; +yy167: + ++YYCURSOR; +#line 316 "scanner.re" + { ++depth; + fatal("ambiguous /* found"); + goto comment; } +#line 1343 "" +yy169: + ++YYCURSOR; +#line 312 "scanner.re" + { if(--depth == 0) + goto scan; + else + goto comment; } +#line 1351 "" +} +#line 325 "scanner.re" + + +config: + +#line 1358 "" +{ + YYCTYPE yych; + if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + switch(yych){ + case 0x09: + case ' ': goto yy173; + case '=': goto yy175; + default: goto yy177; + } +yy173: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy182; +yy174: +#line 329 "scanner.re" + { goto config; } +#line 1376 "" +yy175: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy180; +yy176: +#line 330 "scanner.re" + { iscfg = 2; + cur = cursor; + RETURN('='); + } +#line 1387 "" +yy177: + ++YYCURSOR; +#line 334 "scanner.re" + { fatal("missing '='"); } +#line 1392 "" +yy179: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy180: + switch(yych){ + case 0x09: + case ' ': goto yy179; + default: goto yy176; + } +yy181: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy182: + switch(yych){ + case 0x09: + case ' ': goto yy181; + default: goto yy174; + } +} +#line 335 "scanner.re" + + +value: + +#line 1419 "" +{ + YYCTYPE yych; + if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + switch(yych){ + case 0x09: + case 0x0A: + case 0x0D: + case ' ': + case ';': goto yy185; + case '"': goto yy193; + case '\'': goto yy195; + case '-': goto yy188; + case '0': goto yy186; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy189; + default: goto yy191; + } +yy185: +#line 344 "scanner.re" + { cur = cursor; + yylval.str = new Str(token()); + iscfg = 0; + return VALUE; + } +#line 1452 "" +yy186: + ++YYCURSOR; + switch((yych = *YYCURSOR)) { + case 0x09: + case 0x0A: + case 0x0D: + case ' ': + case ';': goto yy187; + default: goto yy191; + } +yy187: +#line 339 "scanner.re" + { cur = cursor; + yylval.number = atoi(token().to_string().c_str()); + iscfg = 0; + return NUMBER; + } +#line 1470 "" +yy188: + yych = *++YYCURSOR; + switch(yych){ + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy189; + default: goto yy192; + } +yy189: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x09: + case 0x0A: + case 0x0D: + case ' ': + case ';': goto yy187; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy189; + default: goto yy191; + } +yy191: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy192: + switch(yych){ + case 0x09: + case 0x0A: + case 0x0D: + case ' ': + case ';': goto yy185; + default: goto yy191; + } +yy193: + YYMARKER = ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x09: + case 0x0D: + case ' ': + case ';': goto yy203; + case 0x0A: goto yy185; + case '"': goto yy191; + case '\\': goto yy205; + default: goto yy193; + } +yy195: + YYMARKER = ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x09: + case 0x0D: + case ' ': + case ';': goto yy197; + case 0x0A: goto yy185; + case '\'': goto yy191; + case '\\': goto yy200; + default: goto yy195; + } +yy197: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy199; + case '\'': goto yy201; + case '\\': goto yy202; + default: goto yy197; + } +yy199: + YYCURSOR = YYMARKER; + goto yy185; +yy200: + YYMARKER = ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x09: + case 0x0D: + case ' ': + case ';': goto yy197; + case 0x0A: goto yy185; + default: goto yy195; + } +yy201: + yych = *++YYCURSOR; + goto yy185; +yy202: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy199; + default: goto yy197; + } +yy203: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy199; + case '"': goto yy201; + case '\\': goto yy206; + default: goto yy203; + } +yy205: + YYMARKER = ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x09: + case 0x0D: + case ' ': + case ';': goto yy203; + case 0x0A: goto yy185; + default: goto yy193; + } +yy206: + ++YYCURSOR; + if(YYLIMIT == YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch(yych){ + case 0x0A: goto yy199; + default: goto yy203; + } +} +#line 349 "scanner.re" + +} + +void Scanner::fatal(uint ofs, const char *msg) const +{ + out.flush(); +#ifdef _MSC_VER + std::cerr << filename << "(" << tline << "): error : " + << "column " << (tchar + ofs + 1) << ": " + << msg << std::endl; +#else + std::cerr << "re2c: error: " + << "line " << tline << ", column " << (tchar + ofs + 1) << ": " + << msg << std::endl; +#endif + exit(1); +} + +} // end namespace re2c + diff --git a/tools/re2c/scanner.h b/tools/re2c/scanner.h index edaa05aab..94358b389 100644 --- a/tools/re2c/scanner.h +++ b/tools/re2c/scanner.h @@ -1,34 +1,74 @@ -/* $Id: scanner.h,v 1.5 2004/05/13 02:58:18 nuffer Exp $ */ +/* $Id: scanner.h,v 1.17 2006/02/25 12:57:50 helly Exp $ */ #ifndef _scanner_h #define _scanner_h #include +#include #include "token.h" +#include "re.h" +#include "globals.h" -class Scanner { - private: - std::istream& in; - char *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof; - uint tchar, tline, cline; - private: - char *fill(char*); - Scanner(const Scanner&); //unimplemented - Scanner& operator=(const Scanner&); //unimplemented - public: - Scanner(std::istream&); - int echo(std::ostream&); - int scan(); - void fatal(char*); - SubStr token(); - uint line(); +namespace re2c +{ + +class Scanner: + public line_number +{ +private: + std::istream& in; + std::ostream& out; + char *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof; + uint tchar, tline, cline, iscfg; + const char *filename; + +private: + char *fill(char*); + Scanner(const Scanner&); //unimplemented + Scanner& operator=(const Scanner&); //unimplemented + +public: + Scanner(const char*, std::istream&, std::ostream&); + int echo(); + int scan(); + + void fatal(const char*) const; + void fatal(uint, const char*) const; + + void config(const Str&, int); + void config(const Str&, const Str&); + + SubStr token() const; + virtual uint get_line() const; + uint xlat(uint c) const; + + uint unescape(SubStr &s) const; + std::string& unescape(SubStr& str_in, std::string& str_out) const; + + Range * getRange(SubStr &s) const; + RegExp * matchChar(uint c) const; + RegExp * strToName(SubStr s) const; + RegExp * strToRE(SubStr s) const; + RegExp * strToCaseInsensitiveRE(SubStr s) const; + RegExp * ranToRE(SubStr s) const; + RegExp * invToRE(SubStr s) const; + RegExp * mkDot() const; }; -inline SubStr Scanner::token(){ - return SubStr(tok, cur - tok); +inline void Scanner::fatal(const char *msg) const +{ + fatal(0, msg); } -inline uint Scanner::line(){ - return cline; +inline SubStr Scanner::token() const +{ + return SubStr(tok, cur - tok); } +inline uint Scanner::xlat(uint c) const +{ + return re2c::wFlag ? c : re2c::xlat[c]; +} + +} // end namespace re2c + #endif diff --git a/tools/re2c/scanner.re b/tools/re2c/scanner.re index 863179784..3822e3b75 100644 --- a/tools/re2c/scanner.re +++ b/tools/re2c/scanner.re @@ -1,10 +1,13 @@ -/* $Id: scanner.re,v 1.10 2004/05/13 02:58:18 nuffer Exp $ */ +/* $Id: scanner.re,v 1.42 2006/04/17 00:18:45 helly Exp $ */ #include #include #include +#include #include "scanner.h" #include "parser.h" #include "y.tab.h" +#include "globals.h" +#include "dfa.h" extern YYSTYPE yylval; @@ -22,78 +25,172 @@ extern YYSTYPE yylval; #define RETURN(i) {cur = cursor; return i;} +namespace re2c +{ -Scanner::Scanner(std::istream& i) : in(i), - bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL), - top(NULL), eof(NULL), tchar(0), tline(0), cline(1) { +Scanner::Scanner(const char *fn, std::istream& i, std::ostream& o) + : in(i) + , out(o) + , bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL) + , top(NULL), eof(NULL), tchar(0), tline(0), cline(1), iscfg(0) + , filename(fn) +{ ; } -char *Scanner::fill(char *cursor){ - if(!eof){ - uint cnt = tok - bot; - if(cnt){ - memcpy(bot, tok, lim - tok); - tok = bot; - ptr -= cnt; - cursor -= cnt; - pos -= cnt; - lim -= cnt; +char *Scanner::fill(char *cursor) +{ + if(!eof) + { + uint cnt = tok - bot; + if(cnt) + { + memcpy(bot, tok, lim - tok); + tok = bot; + ptr -= cnt; + cursor -= cnt; + pos -= cnt; + lim -= cnt; + } + if((top - lim) < BSIZE) + { + char *buf = new char[(lim - bot) + BSIZE]; + memcpy(buf, tok, lim - tok); + tok = buf; + ptr = &buf[ptr - bot]; + cursor = &buf[cursor - bot]; + pos = &buf[pos - bot]; + lim = &buf[lim - bot]; + top = &lim[BSIZE]; + delete [] bot; + bot = buf; + } + in.read(lim, BSIZE); + if ((cnt = in.gcount()) != BSIZE ) + { + eof = &lim[cnt]; *eof++ = '\0'; + } + lim += cnt; } - if((top - lim) < BSIZE){ - char *buf = new char[(lim - bot) + BSIZE]; - memcpy(buf, tok, lim - tok); - tok = buf; - ptr = &buf[ptr - bot]; - cursor = &buf[cursor - bot]; - pos = &buf[pos - bot]; - lim = &buf[lim - bot]; - top = &lim[BSIZE]; - delete [] bot; - bot = buf; - } - if((cnt = in.rdbuf()->sgetn((char*) lim, BSIZE)) != BSIZE){ - eof = &lim[cnt]; *eof++ = '\n'; - } - lim += cnt; - } - return cursor; + return cursor; } /*!re2c -any = [\000-\377]; -dot = any \ [\n]; -esc = dot \ [\\]; -cstring = "[" ((esc \ [\]]) | "\\" dot)* "]" ; -dstring = "\"" ((esc \ ["] ) | "\\" dot)* "\""; -sstring = "'" ((esc \ ['] ) | "\\" dot)* "'" ; -letter = [a-zA-Z]; -digit = [0-9]; +zero = "\000"; +any = [\000-\377]; +dot = any \ [\n]; +esc = dot \ [\\]; +istring = "[" "^" ((esc \ [\]]) | "\\" dot)* "]" ; +cstring = "[" ((esc \ [\]]) | "\\" dot)* "]" ; +dstring = "\"" ((esc \ ["] ) | "\\" dot)* "\""; +sstring = "'" ((esc \ ['] ) | "\\" dot)* "'" ; +letter = [a-zA-Z]; +digit = [0-9]; +number = "0" | ("-"? [1-9] digit*); +name = letter (letter|digit)*; +cname = ":" letter (letter|digit|"_")*; +space = [ \t]; +eol = ("\r\n" | "\n"); +config = "re2c" cname+; +value = [^\r\n; \t]* | dstring | sstring; */ -int Scanner::echo(std::ostream &out){ +int Scanner::echo() +{ char *cursor = cur; + bool ignore_eoc = false; + int ignore_cnt = 0; - // Catch EOF - if (eof && cursor == eof) + if (eof && cursor == eof) // Catch EOF + { return 0; + } tok = cursor; echo: /*!re2c - "/*!re2c" { out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok)); - tok = cursor; - RETURN(1); } - "\n" { if(cursor == eof) RETURN(0); - out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); - tok = pos = cursor; cline++; - goto echo; } - any { goto echo; } + "/*!re2c" { + if (bUsedYYMaxFill && bSinglePass) { + fatal("found scanner block after YYMAXFILL declaration"); + } + out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok)); + tok = cursor; + RETURN(1); + } + "/*!max:re2c" { + if (bUsedYYMaxFill) { + fatal("cannot generate YYMAXFILL twice"); + } + out << "#define YYMAXFILL " << maxFill << std::endl; + tok = pos = cursor; + ignore_eoc = true; + bUsedYYMaxFill = true; + goto echo; + } + "/*!getstate:re2c" { + tok = pos = cursor; + genGetState(out, topIndent, 0); + ignore_eoc = true; + goto echo; + } + "/*!ignore:re2c" { + tok = pos = cursor; + ignore_eoc = true; + goto echo; + } + "*" "/" "\r"? "\n" { + cline++; + if (ignore_eoc) { + if (ignore_cnt) { + out << sourceFileInfo; + } + ignore_eoc = false; + ignore_cnt = 0; + } else { + out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + } + tok = pos = cursor; + goto echo; + } + "*" "/" { + if (ignore_eoc) { + if (ignore_cnt) { + out << "\n" << sourceFileInfo; + } + ignore_eoc = false; + ignore_cnt = 0; + } else { + out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + } + tok = pos = cursor; + goto echo; + } + "\n" { + if (ignore_eoc) { + ignore_cnt++; + } else { + out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + } + tok = pos = cursor; cline++; + goto echo; + } + zero { + if (!ignore_eoc) { + out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok) - 1); // -1 so we don't write out the \0 + } + if(cursor == eof) { + RETURN(0); + } + } + any { + goto echo; + } */ } -int Scanner::scan(){ +int Scanner::scan() +{ char *cursor = cur; uint depth; @@ -101,6 +198,14 @@ scan: tchar = cursor - pos; tline = cline; tok = cursor; + if (iscfg == 1) + { + goto config; + } + else if (iscfg == 2) + { + goto value; + } /*!re2c "{" { depth = 1; goto code; @@ -122,6 +227,10 @@ scan: "\"" { fatal("unterminated string constant (missing \")"); } "'" { fatal("unterminated string constant (missing ')"); } + istring { cur = cursor; + yylval.regexp = invToRE(token()); + return RANGE; } + cstring { cur = cursor; yylval.regexp = ranToRE(token()); return RANGE; } @@ -133,6 +242,9 @@ scan: [*+?] { yylval.op = *tok; RETURN(CLOSE); } + "{0,}" { yylval.op = '*'; + RETURN(CLOSE); } + "{" [0-9]+ "}" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = atoi((char *)tok+1); RETURN(CLOSESIZE); } @@ -145,18 +257,35 @@ scan: yylval.extop.maxsize = -1; RETURN(CLOSESIZE); } - letter (letter|digit)* { cur = cursor; + "{" [0-9]* "," { fatal("illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers"); } + + config { cur = cursor; + tok+= 5; /* skip "re2c:" */ + iscfg = 1; + yylval.str = new Str(token()); + return CONFIG; + } + + name { cur = cursor; yylval.symbol = Symbol::find(token()); return ID; } - [ \t]+ { goto scan; } + "." { cur = cursor; + yylval.regexp = mkDot(); + return RANGE; + } - "\n" { if(cursor == eof) RETURN(0); + space+ { goto scan; } + + eol { if(cursor == eof) RETURN(0); pos = cursor; cline++; goto scan; } - any { std::cerr << "unexpected character: " << *tok << std::endl; + any { std::ostringstream msg; + msg << "unexpected character: "; + prtChOrHex(msg, *tok); + fatal(msg.str().c_str()); goto scan; } */ @@ -180,22 +309,60 @@ code: comment: /*!re2c - "*/" { if(--depth == 0) + "*/" { if(--depth == 0) goto scan; else goto comment; } - "/*" { ++depth; + "/*" { ++depth; + fatal("ambiguous /* found"); goto comment; } - "\n" { if(cursor == eof) RETURN(0); + "\n" { if(cursor == eof) RETURN(0); tok = pos = cursor; cline++; goto comment; } - any { goto comment; } + any { if(cursor == eof) RETURN(0); + goto comment; } +*/ + +config: +/*!re2c + space+ { goto config; } + "=" space* { iscfg = 2; + cur = cursor; + RETURN('='); + } + any { fatal("missing '='"); } +*/ + +value: +/*!re2c + number { cur = cursor; + yylval.number = atoi(token().to_string().c_str()); + iscfg = 0; + return NUMBER; + } + value { cur = cursor; + yylval.str = new Str(token()); + iscfg = 0; + return VALUE; + } */ } -void Scanner::fatal(char *msg){ - std::cerr << "line " << tline << ", column " << (tchar + 1) << ": " - << msg << std::endl; - exit(1); +void Scanner::fatal(uint ofs, const char *msg) const +{ + out.flush(); +#ifdef _MSC_VER + std::cerr << filename << "(" << tline << "): error : " + << "column " << (tchar + ofs + 1) << ": " + << msg << std::endl; +#else + std::cerr << "re2c: error: " + << "line " << tline << ", column " << (tchar + ofs + 1) << ": " + << msg << std::endl; +#endif + exit(1); } + +} // end namespace re2c + diff --git a/tools/re2c/stamp-h.in b/tools/re2c/stamp-h.in deleted file mode 100644 index e69de29bb..000000000 diff --git a/tools/re2c/stream_lc.h b/tools/re2c/stream_lc.h new file mode 100644 index 000000000..5f8e5e6bd --- /dev/null +++ b/tools/re2c/stream_lc.h @@ -0,0 +1,425 @@ +/* + Author: Marcus Boerger +*/ + +/* $Id: stream_lc.h,v 1.10 2006/02/26 20:36:09 helly Exp $ */ + +#ifndef _stream_lc_h +#define _stream_lc_h + +#include +#include +#include +#include + +namespace re2c +{ + +template > +class basic_null_streambuf + : public std::basic_streambuf<_E, _Tr> +{ +public: + basic_null_streambuf() + : std::basic_streambuf<_E, _Tr>() + { + } +}; + +typedef basic_null_streambuf null_streambuf; + +template > +class basic_null_stream + : public std::basic_ostream<_E, _Tr> +{ +public: + basic_null_stream() + : std::basic_ostream<_E, _Tr>(null_buf = new basic_null_streambuf<_E, _Tr>()) + { + } + + virtual ~basic_null_stream() + { + delete null_buf; + } + + basic_null_stream& put(_E) + { + // nothing to do + return *this; + } + + basic_null_stream& write(const _E *, std::streamsize) + { + // nothing to do + return *this; + } + +protected: + basic_null_streambuf<_E, _Tr> * null_buf; +}; + +typedef basic_null_stream null_stream; + +class line_number +{ +public: + virtual ~line_number() + { + } + + virtual uint get_line() const = 0; +}; + +template > +class basic_filebuf_lc + : public std::basic_streambuf<_E, _Tr> + , public line_number +{ +public: + typedef std::basic_streambuf<_E, _Tr> _Mybase; + typedef basic_filebuf_lc<_E, _Tr> _Myt; + typedef _E char_type; + typedef _Tr traits_type; + typedef typename _Tr::int_type int_type; + typedef typename _Tr::pos_type pos_type; + typedef typename _Tr::off_type off_type; + + basic_filebuf_lc(FILE *_fp = 0) + : _Mybase() + , fp(_fp) + , must_close(false) + , fline(1) + { + } + + virtual ~basic_filebuf_lc() + { + sync(); + if (must_close) + { + close(); + } + } + + uint get_line() const + { + return fline + 1; + } + + bool is_open() const + { + return fp != 0; + } + + _Myt* open(const char *filename, std::ios_base::openmode mode = std::ios_base::out) + { + if (fp != 0) + { + return 0; + } + const char * fmode = (mode & std::ios_base::out) + ? "wt" + : "rt"; + if ((fp = fopen(filename, fmode)) == 0) + { + return 0; + } + + must_close = true; + return this; + } + + _Myt* open(FILE * _fp) + { + if (fp != 0) + { + return 0; + } + fp = _fp; + must_close = false; + return this; + } + + _Myt* close() + { + sync(); + + if (fp == 0 || fclose(fp) != 0) + { + fp = 0; + return 0; + } + else + { + fp = 0; + return this; + } + } + +protected: + + virtual int_type overflow(int_type c = _Tr::eof()) + { + if (c == '\n') + { + ++fline; + } + if (_Tr::eq_int_type(_Tr::eof(), c)) + { + return _Tr::not_eof(c); + } + else + { + buffer += _Tr::to_char_type(c); + return c; + } + } + + virtual int_type pbackfail(int_type c = _Tr::eof()) + { + assert(0); + c = 0; + return _Tr::eof(); + } + + virtual int_type underflow() // don't point past it + { + int c; + + if (buffer.length()) + { + return buffer[0]; + } + if (fp == 0 || ((c = fgetc(fp)) == EOF)) + { + return _Tr::eof(); + } + buffer += (char)c; + return c; + } + + virtual int_type uflow() // point past it + { + int c; + + if (buffer.length()) + { + c = buffer[0]; + buffer.erase(0, 1); + return c; + } + if (fp == 0 || ((c = fgetc(fp)) == EOF)) + { + return _Tr::eof(); + } + else if (c == '\n') + { + ++fline; + } + return c; + } + +#if 0 + virtual std::streamsize xsgetn(_E* buf, std::streamsize n) + { + std::streamsize r = 0; + while(n--) + { + int_type c = underflow(); + if (_Tr::eq_int_type(_Tr::eof(), c)) + { + break; + } + buf[r++] = c; + } + buf[r] = '\0'; + return r; + } +#endif + + virtual pos_type seekoff(off_type off, std::ios_base::seekdir whence, + std::ios_base::openmode = (std::ios_base::openmode)(std::ios_base::in | std::ios_base::out)) + { + return fseek(fp, (long)off, whence); + } + + virtual pos_type seekpos(pos_type fpos, + std::ios_base::openmode = (std::ios_base::openmode)(std::ios_base::in | std::ios_base::out)) + { + return fseek(fp, (long)fpos, SEEK_SET); + } + + virtual _Mybase * setbuf(_E *, std::streamsize) + { + assert(0); + return this; + } + + virtual int sync() + { + fwrite(buffer.c_str(), sizeof(_E), buffer.length(), fp); + buffer.clear(); + return fp == 0 + || _Tr::eq_int_type(_Tr::eof(), overflow()) + || 0 <= fflush(fp) ? 0 : -1; + } + + virtual std::streamsize xsputn(const _E *buf, std::streamsize cnt) + { + fwrite(buffer.c_str(), sizeof(_E), buffer.length(), fp); + buffer.clear(); + /*fline += std::count(buf, buf + cnt, '\n');*/ + for (std::streamsize pos = 0; pos < cnt; ++pos) + { + if (buf[pos] == '\n') + { + ++fline; + } + } + return fwrite(buf, sizeof(_E), cnt, fp); + } + +private: + + FILE * fp; + bool must_close; + uint fline; + std::basic_string<_E, _Tr> buffer; +}; + +typedef basic_filebuf_lc filebuf_lc; + +template< + class _E, + class _BaseStream, + std::ios_base::openmode _DefOpenMode, + class _Tr = std::char_traits<_E> > +class basic_fstream_lc + : public _BaseStream + , public line_number +{ +public: + typedef basic_fstream_lc<_E, _BaseStream, _DefOpenMode, _Tr> _Myt; + typedef std::basic_ios<_E, _Tr> _Myios; + typedef _BaseStream _Mybase; + typedef basic_filebuf_lc<_E, _Tr> _Mybuf; + + basic_fstream_lc() + : _Mybase(mybuf = new _Mybuf()) + { + } + + virtual ~basic_fstream_lc() + { + delete mybuf; + } + + bool is_open() const + { + return mybuf->is_open(); + } + + _Myt& open(const char * filename, std::ios_base::openmode mode = _DefOpenMode) + { + if ((mode & _DefOpenMode) == 0 || mybuf->open(filename, mode) == 0) + { + _Myios::setstate(std::ios_base::failbit); + } + return *this; + } + + _Myt& open(FILE *fp) + { + if (mybuf->open(fp) == 0) + { + _Myios::setstate(std::ios_base::failbit); + } + return *this; + } + + void close() + { + if (mybuf->close() == 0) + { + _Myios::setstate(std::ios_base::failbit); + } + } + + uint get_line() const + { + return mybuf->get_line(); + } + +protected: + mutable _Mybuf *mybuf; +}; + +template > +class basic_ofstream_lc + : public basic_fstream_lc<_E, std::basic_ostream<_E, _Tr>, std::ios_base::out, _Tr> +{ +}; + +typedef basic_ofstream_lc ofstream_lc; + +template > +class basic_ifstream_lc + : public basic_fstream_lc<_E, std::basic_istream<_E, _Tr>, std::ios_base::in, _Tr> +{ +}; + +typedef basic_ifstream_lc ifstream_lc; + +class file_info +{ +public: + + static std::string escape(const std::string& _str) + { + std::string str(_str); + size_t l = str.length(); + for (size_t p = 0; p < l; ++p) + { + if (str[p] == '\\') + { + str.insert(++p, "\\"); + ++l; + } + } + return str; + } + + file_info() + : ln(NULL) + { + } + + file_info(const std::string& _fname, const line_number* _ln, bool _escape = true) + : fname(_escape ? escape(_fname) : _fname) + , ln(_ln) + { + } + + file_info(const file_info& oth, const line_number* _ln = NULL) + : fname(oth.fname) + , ln(_ln) + { + } + + file_info& operator = (const file_info& oth) + { + *(const_cast(&this->fname)) = oth.fname; + ln = oth.ln; + return *this; + } + + const std::string fname; + const line_number* ln; +}; + +std::ostream& operator << (std::ostream& o, const file_info& li); + +} // end namespace re2c + +#endif /* _stream_lc_h */ diff --git a/tools/re2c/substr.cc b/tools/re2c/substr.cc index 1cb564fea..be667f290 100644 --- a/tools/re2c/substr.cc +++ b/tools/re2c/substr.cc @@ -1,37 +1,62 @@ -/* $Id: substr.cc,v 1.4 2004/05/13 02:58:18 nuffer Exp $ */ +/* $Id: substr.cc,v 1.11 2006/02/26 20:30:54 helly Exp $ */ #include +#include #include "substr.h" #include "globals.h" -void SubStr::out(std::ostream& o) const { - o.write(str, len); - for (size_t i = 0; i < (size_t)len; ++i) - { - if (str[i] == '\n') - ++oline; - } +#ifndef HAVE_STRNDUP + +char *strndup(const char *str, size_t len) +{ + char * ret = (char*)malloc(len + 1); + + memcpy(ret, str, len); + ret[len] = '\0'; + return ret; } -bool operator==(const SubStr &s1, const SubStr &s2){ - return (bool) (s1.len == s2.len && memcmp(s1.str, s2.str, s1.len) == 0); +#endif + +namespace re2c +{ + +void SubStr::out(std::ostream& o) const +{ + o.write(str, len); } -Str::Str(const SubStr& s) : SubStr(new char[s.len], s.len) { - memcpy(str, s.str, s.len); +bool operator==(const SubStr &s1, const SubStr &s2) +{ + return (bool) (s1.len == s2.len && memcmp(s1.str, s2.str, s1.len) == 0); } -Str::Str(Str& s) : SubStr(s.str, s.len) { - s.str = NULL; - s.len = 0; +Str::Str(const SubStr& s) + : SubStr(strndup(s.str, s.len), s.len) +{ + ; } -Str::Str() : SubStr((char*) NULL, 0) { - ; +Str::Str(Str& s) + : SubStr(s.str, s.len) +{ + s.str = NULL; + s.len = 0; +} + +Str::Str() + : SubStr((char*) NULL, 0) +{ + ; } -Str::~Str() { - delete str; - str = (char*)-1; - len = (uint)-1; +Str::~Str() +{ + if (str) { + free((void*)str); + } + str = (char*) - 1; + len = (uint) - 1; } + +} // end namespace re2c diff --git a/tools/re2c/substr.h b/tools/re2c/substr.h index 985299fd0..eec50614a 100644 --- a/tools/re2c/substr.h +++ b/tools/re2c/substr.h @@ -1,46 +1,101 @@ -/* $Id: substr.h,v 1.3 2004/05/13 02:58:18 nuffer Exp $ */ +/* $Id: substr.h,v 1.10 2006/01/01 13:42:10 helly Exp $ */ #ifndef _substr_h #define _substr_h #include +#include #include "basics.h" -class SubStr { +namespace re2c +{ + +class SubStr +{ public: - char *str; - uint len; + const char * str; + const char * const org; + uint len; + public: - friend bool operator==(const SubStr &, const SubStr &); - SubStr(uchar*, uint); - SubStr(char*, uint); - SubStr(const SubStr&); - void out(std::ostream&) const; + friend bool operator==(const SubStr &, const SubStr &); + SubStr(const uchar*, uint); + SubStr(const char*, uint); + SubStr(const char*); + SubStr(const SubStr&); + virtual ~SubStr(); + void out(std::ostream&) const; + std::string to_string() const; + uint ofs() const; + +#ifdef PEDANTIC +protected: + SubStr& operator = (const SubStr& oth); +#endif }; -class Str: public SubStr { +class Str: public SubStr +{ public: - Str(const SubStr&); - Str(Str&); - Str(); - ~Str(); + Str(const SubStr&); + Str(Str&); + Str(); + ~Str(); }; -inline std::ostream& operator<<(std::ostream& o, const SubStr &s){ - s.out(o); - return o; +inline std::ostream& operator<<(std::ostream& o, const SubStr &s) +{ + s.out(o); + return o; } -inline std::ostream& operator<<(std::ostream& o, const SubStr* s){ - return o << *s; +inline std::ostream& operator<<(std::ostream& o, const SubStr* s) +{ + return o << *s; } -inline SubStr::SubStr(uchar *s, uint l) - : str((char*) s), len(l) { } +inline SubStr::SubStr(const uchar *s, uint l) + : str((char*)s), org((char*)s), len(l) +{ } -inline SubStr::SubStr(char *s, uint l) - : str(s), len(l) { } +inline SubStr::SubStr(const char *s, uint l) + : str(s), org(s), len(l) +{ } + +inline SubStr::SubStr(const char *s) + : str(s), org(s), len(strlen(s)) +{ } inline SubStr::SubStr(const SubStr &s) - : str(s.str), len(s.len) { } + : str(s.str), org(s.str), len(s.len) +{ } + +inline SubStr::~SubStr() +{ } + +inline std::string SubStr::to_string() const +{ + return std::string(str, len); +} + +inline uint SubStr::ofs() const +{ + return str - org; +} + +#ifdef PEDANTIC +inline SubStr& SubStr::operator = (const SubStr& oth) +{ + new(this) SubStr(oth); + return *this; +} +#endif + +} // end namespace re2c + +#ifndef HAVE_STRNDUP + +char *strndup(const char *str, size_t len); + +#endif #endif diff --git a/tools/re2c/test.c b/tools/re2c/test.c deleted file mode 100644 index d7cfda311..000000000 --- a/tools/re2c/test.c +++ /dev/null @@ -1,162 +0,0 @@ -/* Generated by re2c 0.9.3 on Mon Feb 14 13:46:36 2005 */ -#line 1 "test.re" - -#line 6 "test.c" -{ - YYCTYPE yych; - unsigned int yyaccept; - goto yy0; -yy1: ++YYCURSOR; -yy0: - if((YYLIMIT - YYCURSOR) < 4) YYFILL(4); - yych = *YYCURSOR; - switch(yych){ - case '.': goto yy4; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy2; - default: goto yy6; - } -yy2: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - goto yy16; -yy3: -#line 4 "test.re" -{ return true; } -#line 35 "test.c" -yy4: ++YYCURSOR; - switch((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy7; - default: goto yy5; - } -yy5: -#line 5 "test.re" -{ return false; } -#line 53 "test.c" -yy6: yych = *++YYCURSOR; - goto yy5; -yy7: yyaccept = 0; - YYMARKER = ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy8; -yy8: switch(yych){ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy7; - case 'D': - case 'E': case 'd': - case 'e': goto yy9; - default: goto yy3; - } -yy9: yych = *++YYCURSOR; - switch(yych){ - case '+': case '-': goto yy11; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy12; - default: goto yy10; - } -yy10: YYCURSOR = YYMARKER; - switch(yyaccept){ - case 0: goto yy3; - } -yy11: yych = *++YYCURSOR; - switch(yych){ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy12; - default: goto yy10; - } -yy12: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - goto yy13; -yy13: switch(yych){ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy12; - default: goto yy3; - } -yy14: yych = *++YYCURSOR; - switch(yych){ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy7; - default: goto yy10; - } -yy15: yyaccept = 0; - YYMARKER = ++YYCURSOR; - if((YYLIMIT - YYCURSOR) < 3) YYFILL(3); - yych = *YYCURSOR; - goto yy16; -yy16: switch(yych){ - case '.': goto yy14; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy15; - case 'D': - case 'E': case 'd': - case 'e': goto yy9; - default: goto yy3; - } -} -#line 6 "test.re" diff --git a/tools/re2c/test.re b/tools/re2c/test.re deleted file mode 100644 index 77132b9d7..000000000 --- a/tools/re2c/test.re +++ /dev/null @@ -1,6 +0,0 @@ -/*!re2c -digits = [0-9]; - -(digits+ | digits* "." digits+) ([dDeE] [+-]? digits+)? { return true; } -[\000-\377] { return false; } -*/ \ No newline at end of file diff --git a/tools/re2c/token.h b/tools/re2c/token.h index d3940d58b..b0bb6cc25 100644 --- a/tools/re2c/token.h +++ b/tools/re2c/token.h @@ -1,19 +1,28 @@ -/* $Id: token.h,v 1.2 2004/01/31 15:44:39 nuffer Exp $ */ +/* $Id: token.h,v 1.4 2004/11/01 04:35:57 nuffer Exp $ */ #ifndef _token_h #define _token_h #include "substr.h" -class Token { - public: - Str text; - uint line; - public: - Token(SubStr, uint); +namespace re2c +{ + +class Token +{ + +public: + Str text; + uint line; + +public: + Token(SubStr, uint); }; -inline Token::Token(SubStr t, uint l) : text(t), line(l) { - ; +inline Token::Token(SubStr t, uint l) : text(t), line(l) +{ + ; } +} // end namespace re2c + #endif diff --git a/tools/re2c/translate.cc b/tools/re2c/translate.cc index 6e492aaa8..9ac65a885 100644 --- a/tools/re2c/translate.cc +++ b/tools/re2c/translate.cc @@ -1,62 +1,70 @@ -/* $Id: translate.cc,v 1.2 2004/01/31 15:44:39 nuffer Exp $ */ +/* $Id: translate.cc,v 1.5 2005/12/28 18:33:37 helly Exp $ */ #include "globals.h" -uchar asc2asc[256] = { -0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, -0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, -0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f, -0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, -0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, -0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f, -0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f, -0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f, -0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, -0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, -0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, -0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, -0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, -0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, -0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef, -0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff -}; +namespace re2c +{ -uchar *xlat = asc2asc; -uchar *talx = asc2asc; +uint asc2asc[256] = + { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff + }; -uchar asc2ebc[256] = { /* Based on ISO 8859/1 and Code Page 37 */ -0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f,0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, -0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26,0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f, -0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d,0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, -0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, -0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, -0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, -0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, -0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, -0x20,0x21,0x22,0x23,0x24,0x15,0x06,0x17,0x28,0x29,0x2a,0x2b,0x2c,0x09,0x0a,0x1b, -0x30,0x31,0x1a,0x33,0x34,0x35,0x36,0x08,0x38,0x39,0x3a,0x3b,0x04,0x14,0x3e,0xff, -0x41,0xaa,0x4a,0xb1,0x9f,0xb2,0x6a,0xb5,0xbd,0xb4,0x9a,0x8a,0x5f,0xca,0xaf,0xbc, -0x90,0x8f,0xea,0xfa,0xbe,0xa0,0xb6,0xb3,0x9d,0xda,0x9b,0x8b,0xb7,0xb8,0xb9,0xab, -0x64,0x65,0x62,0x66,0x63,0x67,0x9e,0x68,0x74,0x71,0x72,0x73,0x78,0x75,0x76,0x77, -0xac,0x69,0xed,0xee,0xeb,0xef,0xec,0xbf,0x80,0xfd,0xfe,0xfb,0xfc,0xad,0x8e,0x59, -0x44,0x45,0x42,0x46,0x43,0x47,0x9c,0x48,0x54,0x51,0x52,0x53,0x58,0x55,0x56,0x57, -0x8c,0x49,0xcd,0xce,0xcb,0xcf,0xcc,0xe1,0x70,0xdd,0xde,0xdb,0xdc,0x8d,0xae,0xdf -}; +uint *xlat = asc2asc; +uint *talx = asc2asc; -uchar ebc2asc[256] = { /* Based on ISO 8859/1 and Code Page 37 */ -0x00,0x01,0x02,0x03,0x9c,0x09,0x86,0x7f,0x97,0x8d,0x8e,0x0b,0x0c,0x0d,0x0e,0x0f, -0x10,0x11,0x12,0x13,0x9d,0x85,0x08,0x87,0x18,0x19,0x92,0x8f,0x1c,0x1d,0x1e,0x1f, -0x80,0x81,0x82,0x83,0x84,0x0a,0x17,0x1b,0x88,0x89,0x8a,0x8b,0x8c,0x05,0x06,0x07, -0x90,0x91,0x16,0x93,0x94,0x95,0x96,0x04,0x98,0x99,0x9a,0x9b,0x14,0x15,0x9e,0x1a, -0x20,0xa0,0xe2,0xe4,0xe0,0xe1,0xe3,0xe5,0xe7,0xf1,0xa2,0x2e,0x3c,0x28,0x2b,0x7c, -0x26,0xe9,0xea,0xeb,0xe8,0xed,0xee,0xef,0xec,0xdf,0x21,0x24,0x2a,0x29,0x3b,0xac, -0x2d,0x2f,0xc2,0xc4,0xc0,0xc1,0xc3,0xc5,0xc7,0xd1,0xa6,0x2c,0x25,0x5f,0x3e,0x3f, -0xf8,0xc9,0xca,0xcb,0xc8,0xcd,0xce,0xcf,0xcc,0x60,0x3a,0x23,0x40,0x27,0x3d,0x22, -0xd8,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0xab,0xbb,0xf0,0xfd,0xde,0xb1, -0xb0,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0xaa,0xba,0xe6,0xb8,0xc6,0xa4, -0xb5,0x7e,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0xa1,0xbf,0xd0,0xdd,0xfe,0xae, -0x5e,0xa3,0xa5,0xb7,0xa9,0xa7,0xb6,0xbc,0xbd,0xbe,0x5b,0x5d,0xaf,0xa8,0xb4,0xd7, -0x7b,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0xad,0xf4,0xf6,0xf2,0xf3,0xf5, -0x7d,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xb9,0xfb,0xfc,0xf9,0xfa,0xff, -0x5c,0xf7,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0xb2,0xd4,0xd6,0xd2,0xd3,0xd5, -0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0xb3,0xdb,0xdc,0xd9,0xda,0x9f -}; +uint asc2ebc[256] = + { /* Based on ISO 8859/1 and Code Page 37 */ + 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, + 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, + 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, + 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xba, 0xe0, 0xbb, 0xb0, 0x6d, + 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x06, 0x17, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x1b, + 0x30, 0x31, 0x1a, 0x33, 0x34, 0x35, 0x36, 0x08, 0x38, 0x39, 0x3a, 0x3b, 0x04, 0x14, 0x3e, 0xff, + 0x41, 0xaa, 0x4a, 0xb1, 0x9f, 0xb2, 0x6a, 0xb5, 0xbd, 0xb4, 0x9a, 0x8a, 0x5f, 0xca, 0xaf, 0xbc, + 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3, 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, + 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68, 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, + 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf, 0x80, 0xfd, 0xfe, 0xfb, 0xfc, 0xad, 0x8e, 0x59, + 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48, 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, + 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1, 0x70, 0xdd, 0xde, 0xdb, 0xdc, 0x8d, 0xae, 0xdf + }; + +uint ebc2asc[256] = + { /* Based on ISO 8859/1 and Code Page 37 */ + 0x00, 0x01, 0x02, 0x03, 0x9c, 0x09, 0x86, 0x7f, 0x97, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x9d, 0x85, 0x08, 0x87, 0x18, 0x19, 0x92, 0x8f, 0x1c, 0x1d, 0x1e, 0x1f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x0a, 0x17, 0x1b, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, + 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, + 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5, 0xe7, 0xf1, 0xa2, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, + 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef, 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0xac, + 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5, 0xc7, 0xd1, 0xa6, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, + 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf, 0xcc, 0x60, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, + 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xde, 0xb1, + 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, + 0xb5, 0x7e, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xfe, 0xae, + 0x5e, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc, 0xbd, 0xbe, 0x5b, 0x5d, 0xaf, 0xa8, 0xb4, 0xd7, + 0x7b, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, + 0x7d, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xf9, 0xfa, 0xff, + 0x5c, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0xb3, 0xdb, 0xdc, 0xd9, 0xda, 0x9f + }; + +} // end namespace re2c diff --git a/tools/re2c/y.tab.h b/tools/re2c/y.tab.h index 905645a45..1c3e5849e 100644 --- a/tools/re2c/y.tab.h +++ b/tools/re2c/y.tab.h @@ -1,7 +1,7 @@ -/* A Bison parser, made by GNU Bison 1.875. */ +/* A Bison parser, made by GNU Bison 2.1. */ /* Skeleton parser for Yacc-like parsing with Bison, - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,8 +15,8 @@ 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. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction. @@ -34,30 +34,39 @@ ID = 260, CODE = 261, RANGE = 262, - STRING = 263 + STRING = 263, + CONFIG = 264, + VALUE = 265, + NUMBER = 266 }; #endif +/* Tokens. */ #define CLOSESIZE 258 #define CLOSE 259 #define ID 260 #define CODE 261 #define RANGE 262 #define STRING 263 +#define CONFIG 264 +#define VALUE 265 +#define NUMBER 266 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 53 "parser.y" +#line 58 "parser.y" typedef union YYSTYPE { - Symbol *symbol; - RegExp *regexp; - Token *token; - char op; - ExtOp extop; + re2c::Symbol *symbol; + re2c::RegExp *regexp; + re2c::Token *token; + char op; + int number; + re2c::ExtOp extop; + re2c::Str *str; } YYSTYPE; -/* Line 1240 of yacc.c. */ -#line 60 "y.tab.h" +/* Line 1447 of yacc.c. */ +#line 70 "y.tab.h" # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 diff --git a/tools/xlatcc/xlat-parse.tab.c b/tools/xlatcc/xlat-parse.tab.c index fe6a5b598..87eaccdcb 100644 --- a/tools/xlatcc/xlat-parse.tab.c +++ b/tools/xlatcc/xlat-parse.tab.c @@ -1,29 +1,107 @@ +/* A Bison parser, made by GNU Bison 2.1. */ -/* A Bison parser, made from xlat-parse.y - by GNU Bison version 1.28 */ +/* Skeleton parser for Yacc-like parsing with Bison, + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. -#define YYBISON 1 /* Identify Bison output. */ + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -#define NUM 257 -#define SYMNUM 258 -#define SYM 259 -#define STRING 260 -#define DEFINE 261 -#define INCLUDE 262 -#define TAG 263 -#define LINEID 264 -#define SPECIAL 265 -#define FLAGS 266 -#define ARG2 267 -#define ARG3 268 -#define ARG4 269 -#define ARG5 270 -#define OR_EQUAL 271 -#define ENUM 272 -#define PRINT 273 -#define ENDL 274 -#define NEG 275 + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* Written by Richard Stallman by simplifying the original so called + ``semantic'' parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.1" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Using locations. */ +#define YYLSP_NEEDED 0 + + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + NUM = 258, + SYMNUM = 259, + SYM = 260, + STRING = 261, + DEFINE = 262, + INCLUDE = 263, + TAG = 264, + LINEID = 265, + SPECIAL = 266, + FLAGS = 267, + ARG2 = 268, + ARG3 = 269, + ARG4 = 270, + ARG5 = 271, + OR_EQUAL = 272, + ENUM = 273, + PRINT = 274, + ENDL = 275, + NEG = 276 + }; +#endif +/* Tokens. */ +#define NUM 258 +#define SYMNUM 259 +#define SYM 260 +#define STRING 261 +#define DEFINE 262 +#define INCLUDE 263 +#define TAG 264 +#define LINEID 265 +#define SPECIAL 266 +#define FLAGS 267 +#define ARG2 268 +#define ARG3 269 +#define ARG4 270 +#define ARG5 271 +#define OR_EQUAL 272 +#define ENUM 273 +#define PRINT 274 +#define ENDL 275 +#define NEG 276 + + + + +/* Copy the first part of user declarations. */ #line 7 "xlat-parse.y" #include "xlat.h" @@ -68,8 +146,28 @@ typedef struct _morelines } MoreLines; + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + +#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) #line 51 "xlat-parse.y" -typedef union { +typedef union YYSTYPE { int val; char sym[80]; char string[80]; @@ -90,616 +188,1021 @@ typedef union { BoomArg boomline; MoreLines *boomlines; } YYSTYPE; -#include - -#ifndef __cplusplus -#ifndef __STDC__ -#define const -#endif +/* Line 196 of yacc.c. */ +#line 193 "xlat-parse.tab.c" +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 #endif -#define YYFINAL 175 -#define YYFLAG -32768 -#define YYNTBASE 39 +/* Copy the second part of user declarations. */ -#define YYTRANSLATE(x) ((unsigned)(x) <= 275 ? yytranslate[x] : 66) -static const char yytranslate[] = { 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 23, 2, 29, - 30, 26, 25, 31, 24, 2, 27, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 36, 35, 2, - 34, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 37, 2, 38, 22, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 32, 21, 33, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 1, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 28 -}; +/* Line 219 of yacc.c. */ +#line 205 "xlat-parse.tab.c" -#if YYDEBUG != 0 -static const short yyprhs[] = { 0, - 0, 2, 4, 8, 12, 16, 20, 24, 28, 32, - 35, 39, 40, 43, 45, 47, 49, 51, 53, 55, - 57, 62, 63, 65, 69, 71, 73, 75, 81, 84, - 85, 91, 92, 94, 98, 100, 104, 108, 109, 111, - 115, 122, 123, 131, 132, 134, 138, 147, 156, 168, - 169, 172, 176, 178, 180, 182, 184, 186, 188, 190, - 192, 197, 199, 203, 207, 208, 210, 214, 220, 228, - 238, 242, 248, 256, 266, 268, 272, 278, 286, 296, - 298, 302, 308, 316, 326, 330, 336, 344, 354, 360, - 368, 378, 386, 396 -}; +#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) +# define YYSIZE_T __SIZE_TYPE__ +#endif +#if ! defined (YYSIZE_T) && defined (size_t) +# define YYSIZE_T size_t +#endif +#if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus)) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +#endif +#if ! defined (YYSIZE_T) +# define YYSIZE_T unsigned int +#endif -static const short yyrhs[] = { 3, - 0, 4, 0, 39, 25, 39, 0, 39, 24, 39, - 0, 39, 26, 39, 0, 39, 27, 39, 0, 39, - 21, 39, 0, 39, 23, 39, 0, 39, 22, 39, - 0, 24, 39, 0, 29, 39, 30, 0, 0, 40, - 41, 0, 45, 0, 46, 0, 42, 0, 47, 0, - 56, 0, 57, 0, 51, 0, 19, 29, 43, 30, - 0, 0, 44, 0, 44, 31, 43, 0, 6, 0, - 39, 0, 20, 0, 7, 5, 29, 39, 30, 0, - 8, 6, 0, 0, 18, 32, 48, 49, 33, 0, - 0, 50, 0, 50, 31, 49, 0, 5, 0, 5, - 34, 39, 0, 11, 52, 35, 0, 0, 53, 0, - 53, 31, 52, 0, 39, 36, 5, 29, 55, 30, - 0, 0, 39, 36, 4, 54, 29, 55, 30, 0, - 0, 39, 0, 39, 31, 39, 0, 39, 34, 39, - 31, 39, 29, 65, 30, 0, 39, 34, 39, 31, - 5, 29, 65, 30, 0, 37, 39, 38, 29, 39, - 31, 39, 30, 32, 58, 33, 0, 0, 59, 58, - 0, 60, 61, 62, 0, 12, 0, 13, 0, 14, - 0, 15, 0, 16, 0, 34, 0, 17, 0, 39, - 0, 39, 37, 63, 38, 0, 64, 0, 64, 31, - 63, 0, 39, 36, 39, 0, 0, 9, 0, 9, - 31, 39, 0, 9, 31, 39, 31, 39, 0, 9, - 31, 39, 31, 39, 31, 39, 0, 9, 31, 39, - 31, 39, 31, 39, 31, 39, 0, 9, 31, 9, - 0, 9, 31, 9, 31, 39, 0, 9, 31, 9, - 31, 39, 31, 39, 0, 9, 31, 9, 31, 39, - 31, 39, 31, 39, 0, 10, 0, 10, 31, 39, - 0, 10, 31, 39, 31, 39, 0, 10, 31, 39, - 31, 39, 31, 39, 0, 10, 31, 39, 31, 39, - 31, 39, 31, 39, 0, 39, 0, 39, 31, 39, - 0, 39, 31, 39, 31, 39, 0, 39, 31, 39, - 31, 39, 31, 39, 0, 39, 31, 39, 31, 39, - 31, 39, 31, 39, 0, 39, 31, 9, 0, 39, - 31, 9, 31, 39, 0, 39, 31, 9, 31, 39, - 31, 39, 0, 39, 31, 9, 31, 39, 31, 39, - 31, 39, 0, 39, 31, 39, 31, 9, 0, 39, - 31, 39, 31, 9, 31, 39, 0, 39, 31, 39, - 31, 9, 31, 39, 31, 39, 0, 39, 31, 39, - 31, 39, 31, 9, 0, 39, 31, 39, 31, 39, - 31, 9, 31, 39, 0, 39, 31, 39, 31, 39, - 31, 39, 31, 9, 0 -}; +#ifndef YY_ +# if YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +#if ! defined (yyoverflow) || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# else +# define YYSTACK_ALLOC alloca +# if defined (__STDC__) || defined (__cplusplus) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYINCLUDED_STDLIB_H +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2005 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1) +# endif +# ifdef __cplusplus +extern "C" { +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \ + && (defined (__STDC__) || defined (__cplusplus))) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \ + && (defined (__STDC__) || defined (__cplusplus))) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifdef __cplusplus +} +# endif +# endif +#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ + + +#if (! defined (yyoverflow) \ + && (! defined (__cplusplus) \ + || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + short int yyss; + YYSTYPE yyvs; + }; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined (__GNUC__) && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (0) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack, Stack, yysize); \ + Stack = &yyptr->Stack; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (0) #endif -#if YYDEBUG != 0 -static const short yyrline[] = { 0, - 115, 117, 118, 119, 120, 121, 122, 123, 124, 125, - 126, 129, 130, 133, 135, 136, 137, 138, 139, 140, - 143, 150, 152, 153, 156, 158, 159, 162, 166, 170, - 171, 174, 176, 177, 180, 182, 188, 192, 194, 195, - 198, 200, 202, 205, 207, 208, 211, 222, 228, 275, - 280, 288, 323, 325, 326, 327, 328, 331, 333, 336, - 342, 349, 356, 364, 368, 374, 379, 388, 397, 406, - 416, 424, 432, 440, 449, 454, 463, 472, 481, 491, - 500, 509, 518, 527, 537, 546, 555, 564, 574, 583, - 592, 602, 611, 621 -}; -#endif - - -#if YYDEBUG != 0 || defined (YYERROR_VERBOSE) - -static const char * const yytname[] = { "$","error","$undefined.","NUM","SYMNUM", -"SYM","STRING","DEFINE","INCLUDE","TAG","LINEID","SPECIAL","FLAGS","ARG2","ARG3", -"ARG4","ARG5","OR_EQUAL","ENUM","PRINT","ENDL","'|'","'^'","'&'","'-'","'+'", -"'*'","'/'","NEG","'('","')'","','","'{'","'}'","'='","';'","':'","'['","']'", -"exp","translation_unit","external_declaration","print_statement","print_list", -"print_item","define_statement","include_statement","enum_statement","@1","enum_list", -"single_enum","special_declaration","special_list","special_def","@2","maybe_argcount", -"linetype_declaration","boom_declaration","boom_body","boom_line","boom_selector", -"boom_op","boom_args","arg_list","list_val","special_args", NULL -}; -#endif - -static const short yyr1[] = { 0, - 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, - 39, 40, 40, 41, 41, 41, 41, 41, 41, 41, - 42, 43, 43, 43, 44, 44, 44, 45, 46, 48, - 47, 49, 49, 49, 50, 50, 51, 52, 52, 52, - 53, 54, 53, 55, 55, 55, 56, 56, 57, 58, - 58, 59, 60, 60, 60, 60, 60, 61, 61, 62, - 62, 63, 63, 64, 65, 65, 65, 65, 65, 65, - 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, - 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, - 65, 65, 65, 65 -}; - -static const short yyr2[] = { 0, - 1, 1, 3, 3, 3, 3, 3, 3, 3, 2, - 3, 0, 2, 1, 1, 1, 1, 1, 1, 1, - 4, 0, 1, 3, 1, 1, 1, 5, 2, 0, - 5, 0, 1, 3, 1, 3, 3, 0, 1, 3, - 6, 0, 7, 0, 1, 3, 8, 8, 11, 0, - 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, - 4, 1, 3, 3, 0, 1, 3, 5, 7, 9, - 3, 5, 7, 9, 1, 3, 5, 7, 9, 1, - 3, 5, 7, 9, 3, 5, 7, 9, 5, 7, - 9, 7, 9, 9 -}; - -static const short yydefact[] = { 12, - 0, 1, 2, 0, 0, 38, 0, 0, 0, 0, - 0, 0, 13, 16, 14, 15, 17, 20, 18, 19, - 0, 29, 0, 0, 39, 30, 22, 10, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 37, 38, 32, 25, 27, 26, 0, 23, 11, 0, - 7, 9, 8, 4, 3, 5, 6, 0, 0, 42, - 0, 40, 35, 0, 33, 21, 22, 0, 0, 28, - 0, 44, 0, 31, 32, 24, 0, 0, 0, 44, - 45, 0, 36, 34, 0, 65, 65, 0, 0, 41, - 0, 66, 75, 80, 0, 0, 43, 46, 0, 0, - 0, 0, 48, 47, 50, 71, 67, 76, 85, 81, - 53, 54, 55, 56, 57, 0, 50, 0, 0, 0, - 0, 0, 0, 49, 51, 59, 58, 0, 72, 68, - 77, 86, 89, 82, 60, 52, 0, 0, 0, 0, - 0, 0, 0, 73, 69, 78, 87, 90, 92, 83, - 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, - 0, 61, 0, 74, 70, 79, 88, 91, 93, 94, - 84, 64, 63, 0, 0 -}; - -static const short yydefgoto[] = { 23, - 1, 13, 14, 47, 48, 15, 16, 17, 43, 64, - 65, 18, 24, 25, 71, 82, 19, 20, 116, 117, - 118, 128, 136, 152, 153, 95 -}; - -static const short yypact[] = {-32768, - 40,-32768,-32768, 0, -3, 17, -25, 10, 17, 17, - 17, 165,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, - 13,-32768, 142, -16, 14,-32768, -2,-32768, 377, -10, - 17, 17, 17, 17, 17, 17, 17, 17, 17, 20, --32768, 17, 24,-32768,-32768, 416, 27, 34,-32768, 45, - 157, 170, 36, 67, 67,-32768,-32768, 179, 387,-32768, - 47,-32768, 62, 50, 77,-32768, -2, 17, 49,-32768, - 51, 17, 17,-32768, 24,-32768, 190, 69, 407, 17, - 201, 83, 416,-32768, 17, 46, 46, 84, 17,-32768, - 397, 85, 92, 212, 95, 98,-32768, 416, 101, 78, - 17, 86,-32768,-32768, 432, 99, 223, 234, 103, 245, --32768,-32768,-32768,-32768,-32768, 110, 432, -11, 17, 17, - 17, 17, 88,-32768,-32768,-32768,-32768, 17, 256, 267, - 278, 289, 104, 300, 124,-32768, 17, 17, 17, 17, - 17, 100, 17, 311, 322, 333, 344, 355, 113, 366, - 149, 94, 121, 17, 17, 17, 17, 17, 17, 102, - 17,-32768, 17, 416, 416, 416, 416, 416, 416,-32768, - 416, 416,-32768, 177,-32768 -}; - -static const short yypgoto[] = { -1, --32768,-32768,-32768, 131,-32768,-32768,-32768,-32768,-32768, 132, --32768,-32768, 166,-32768,-32768, 129,-32768,-32768, 112,-32768, --32768,-32768,-32768, 55,-32768, 133 -}; - - -#define YYLAST 448 - - -static const short yytable[] = { 12, - 2, 3, 22, 44, 21, 126, 26, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 45, 41, 2, - 3, 9, 127, 60, 61, 46, 10, 50, 63, 51, - 52, 53, 54, 55, 56, 57, 58, 59, 27, 174, - 9, 39, 2, 3, 42, 10, 4, 5, 2, 3, - 6, 2, 3, 78, 92, 93, 66, 7, 8, 34, - 35, 36, 37, 9, 67, 46, 77, 79, 10, 9, - 81, 83, 9, 68, 10, 72, 11, 10, 81, 80, - 2, 3, 74, 91, 94, 94, 106, 98, 2, 3, - 2, 3, 36, 37, 109, 73, 133, 86, 107, 108, - 110, 9, 2, 3, 2, 3, 10, 75, 149, 9, - 170, 9, 90, 97, 10, 100, 10, 129, 130, 131, - 132, 134, 101, 9, 103, 9, 135, 104, 10, 119, - 10, 162, 105, 122, 141, 144, 145, 146, 147, 148, - 150, 151, 124, 159, 31, 32, 33, 34, 35, 36, - 37, 163, 164, 165, 166, 167, 168, 169, 171, 172, - 143, 151, 31, 32, 33, 34, 35, 36, 37, 31, - 32, 33, 34, 35, 36, 37, 175, 40, 32, 33, - 34, 35, 36, 37, 161, 31, 32, 33, 34, 35, - 36, 37, 33, 34, 35, 36, 37, 76, 38, 31, - 32, 33, 34, 35, 36, 37, 84, 62, 88, 69, - 31, 32, 33, 34, 35, 36, 37, 173, 0, 96, - 85, 31, 32, 33, 34, 35, 36, 37, 125, 0, - 0, 89, 31, 32, 33, 34, 35, 36, 37, 0, - 0, 0, 102, 31, 32, 33, 34, 35, 36, 37, - 0, 0, 0, 120, 31, 32, 33, 34, 35, 36, - 37, 0, 0, 0, 121, 31, 32, 33, 34, 35, - 36, 37, 0, 0, 0, 123, 31, 32, 33, 34, - 35, 36, 37, 0, 0, 0, 137, 31, 32, 33, - 34, 35, 36, 37, 0, 0, 0, 138, 31, 32, - 33, 34, 35, 36, 37, 0, 0, 0, 139, 31, - 32, 33, 34, 35, 36, 37, 0, 0, 0, 140, - 31, 32, 33, 34, 35, 36, 37, 0, 0, 0, - 142, 31, 32, 33, 34, 35, 36, 37, 0, 0, - 0, 154, 31, 32, 33, 34, 35, 36, 37, 0, - 0, 0, 155, 31, 32, 33, 34, 35, 36, 37, - 0, 0, 0, 156, 31, 32, 33, 34, 35, 36, - 37, 0, 0, 0, 157, 31, 32, 33, 34, 35, - 36, 37, 0, 0, 0, 158, 31, 32, 33, 34, - 35, 36, 37, 0, 0, 0, 160, 31, 32, 33, - 34, 35, 36, 37, 0, 0, 49, 31, 32, 33, - 34, 35, 36, 37, 0, 0, 70, 31, 32, 33, - 34, 35, 36, 37, 0, 0, 99, 31, 32, 33, - 34, 35, 36, 37, 0, 87, 31, 32, 33, 34, - 35, 36, 37, 111, 112, 113, 114, 115 -}; - -static const short yycheck[] = { 1, - 3, 4, 6, 6, 5, 17, 32, 9, 10, 11, - 21, 22, 23, 24, 25, 26, 27, 20, 35, 3, - 4, 24, 34, 4, 5, 27, 29, 38, 5, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 29, 0, - 24, 29, 3, 4, 31, 29, 7, 8, 3, 4, - 11, 3, 4, 5, 9, 10, 30, 18, 19, 24, - 25, 26, 27, 24, 31, 67, 68, 69, 29, 24, - 72, 73, 24, 29, 29, 29, 37, 29, 80, 29, - 3, 4, 33, 85, 86, 87, 9, 89, 3, 4, - 3, 4, 26, 27, 9, 34, 9, 29, 100, 101, - 102, 24, 3, 4, 3, 4, 29, 31, 9, 24, - 9, 24, 30, 30, 29, 31, 29, 119, 120, 121, - 122, 123, 31, 24, 30, 24, 128, 30, 29, 31, - 29, 38, 32, 31, 31, 137, 138, 139, 140, 141, - 142, 143, 33, 31, 21, 22, 23, 24, 25, 26, - 27, 31, 154, 155, 156, 157, 158, 159, 160, 161, - 37, 163, 21, 22, 23, 24, 25, 26, 27, 21, - 22, 23, 24, 25, 26, 27, 0, 36, 22, 23, - 24, 25, 26, 27, 36, 21, 22, 23, 24, 25, - 26, 27, 23, 24, 25, 26, 27, 67, 34, 21, - 22, 23, 24, 25, 26, 27, 75, 42, 80, 31, - 21, 22, 23, 24, 25, 26, 27, 163, -1, 87, - 31, 21, 22, 23, 24, 25, 26, 27, 117, -1, - -1, 31, 21, 22, 23, 24, 25, 26, 27, -1, - -1, -1, 31, 21, 22, 23, 24, 25, 26, 27, - -1, -1, -1, 31, 21, 22, 23, 24, 25, 26, - 27, -1, -1, -1, 31, 21, 22, 23, 24, 25, - 26, 27, -1, -1, -1, 31, 21, 22, 23, 24, - 25, 26, 27, -1, -1, -1, 31, 21, 22, 23, - 24, 25, 26, 27, -1, -1, -1, 31, 21, 22, - 23, 24, 25, 26, 27, -1, -1, -1, 31, 21, - 22, 23, 24, 25, 26, 27, -1, -1, -1, 31, - 21, 22, 23, 24, 25, 26, 27, -1, -1, -1, - 31, 21, 22, 23, 24, 25, 26, 27, -1, -1, - -1, 31, 21, 22, 23, 24, 25, 26, 27, -1, - -1, -1, 31, 21, 22, 23, 24, 25, 26, 27, - -1, -1, -1, 31, 21, 22, 23, 24, 25, 26, - 27, -1, -1, -1, 31, 21, 22, 23, 24, 25, - 26, 27, -1, -1, -1, 31, 21, 22, 23, 24, - 25, 26, 27, -1, -1, -1, 31, 21, 22, 23, - 24, 25, 26, 27, -1, -1, 30, 21, 22, 23, - 24, 25, 26, 27, -1, -1, 30, 21, 22, 23, - 24, 25, 26, 27, -1, -1, 30, 21, 22, 23, - 24, 25, 26, 27, -1, 29, 21, 22, 23, 24, - 25, 26, 27, 12, 13, 14, 15, 16 -}; -/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ -#line 3 "/usr/local/share/bison.simple" -/* This file comes from bison-1.28. */ - -/* Skeleton output parser for bison, - Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - 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. */ - -/* As a special exception, when this file is copied by Bison into a - Bison output file, you may use that output file without restriction. - This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ - -/* This is the parser code that is written into each bison parser - when the %semantic_parser declaration is not specified in the grammar. - It was written by Richard Stallman by simplifying the hairy parser - used when %semantic_parser is specified. */ - -#ifndef YYSTACK_USE_ALLOCA -#ifdef alloca -#define YYSTACK_USE_ALLOCA -#else /* alloca not defined */ -#ifdef __GNUC__ -#define YYSTACK_USE_ALLOCA -#define alloca __builtin_alloca -#else /* not GNU C. */ -#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386)) -#define YYSTACK_USE_ALLOCA -#include -#else /* not sparc */ -/* We think this test detects Watcom and Microsoft C. */ -/* This used to test MSDOS, but that is a bad idea - since that symbol is in the user namespace. */ -#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__) -#if 0 /* No need for malloc.h, which pollutes the namespace; - instead, just don't use alloca. */ -#include -#endif -#else /* not MSDOS, or __TURBOC__ */ -#if defined(_AIX) -/* I don't know what this was needed for, but it pollutes the namespace. - So I turned it off. rms, 2 May 1997. */ -/* #include */ - #pragma alloca -#define YYSTACK_USE_ALLOCA -#else /* not MSDOS, or __TURBOC__, or _AIX */ -#if 0 -#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up, - and on HPUX 10. Eventually we can turn this on. */ -#define YYSTACK_USE_ALLOCA -#define alloca __builtin_alloca -#endif /* __hpux */ -#endif -#endif /* not _AIX */ -#endif /* not MSDOS, or __TURBOC__ */ -#endif /* not sparc */ -#endif /* not GNU C */ -#endif /* alloca not defined */ -#endif /* YYSTACK_USE_ALLOCA not defined */ - -#ifdef YYSTACK_USE_ALLOCA -#define YYSTACK_ALLOC alloca +#if defined (__STDC__) || defined (__cplusplus) + typedef signed char yysigned_char; #else -#define YYSTACK_ALLOC malloc + typedef short int yysigned_char; #endif -/* Note: there must be only one dollar sign in this file. - It is replaced by the list of actions, each action - as one case of the switch. */ +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 2 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 449 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 39 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 28 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 95 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 175 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 276 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const unsigned char yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 23, 2, + 29, 30, 26, 25, 31, 24, 2, 27, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 36, 35, + 2, 34, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 37, 2, 38, 22, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 32, 21, 33, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 28 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const unsigned short int yyprhs[] = +{ + 0, 0, 3, 5, 7, 11, 15, 19, 23, 27, + 31, 35, 38, 42, 43, 46, 48, 50, 52, 54, + 56, 58, 60, 65, 66, 68, 72, 74, 76, 78, + 84, 87, 88, 94, 95, 97, 101, 103, 107, 111, + 112, 114, 118, 125, 126, 134, 135, 137, 141, 150, + 159, 171, 172, 175, 179, 181, 183, 185, 187, 189, + 191, 193, 195, 200, 202, 206, 210, 211, 213, 217, + 223, 231, 241, 245, 251, 259, 269, 271, 275, 281, + 289, 299, 301, 305, 311, 319, 329, 333, 339, 347, + 357, 363, 371, 381, 389, 399 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yysigned_char yyrhs[] = +{ + 41, 0, -1, 3, -1, 4, -1, 40, 25, 40, + -1, 40, 24, 40, -1, 40, 26, 40, -1, 40, + 27, 40, -1, 40, 21, 40, -1, 40, 23, 40, + -1, 40, 22, 40, -1, 24, 40, -1, 29, 40, + 30, -1, -1, 41, 42, -1, 46, -1, 47, -1, + 43, -1, 48, -1, 57, -1, 58, -1, 52, -1, + 19, 29, 44, 30, -1, -1, 45, -1, 45, 31, + 44, -1, 6, -1, 40, -1, 20, -1, 7, 5, + 29, 40, 30, -1, 8, 6, -1, -1, 18, 32, + 49, 50, 33, -1, -1, 51, -1, 51, 31, 50, + -1, 5, -1, 5, 34, 40, -1, 11, 53, 35, + -1, -1, 54, -1, 54, 31, 53, -1, 40, 36, + 5, 29, 56, 30, -1, -1, 40, 36, 4, 55, + 29, 56, 30, -1, -1, 40, -1, 40, 31, 40, + -1, 40, 34, 40, 31, 40, 29, 66, 30, -1, + 40, 34, 40, 31, 5, 29, 66, 30, -1, 37, + 40, 38, 29, 40, 31, 40, 30, 32, 59, 33, + -1, -1, 60, 59, -1, 61, 62, 63, -1, 12, + -1, 13, -1, 14, -1, 15, -1, 16, -1, 34, + -1, 17, -1, 40, -1, 40, 37, 64, 38, -1, + 65, -1, 65, 31, 64, -1, 40, 36, 40, -1, + -1, 9, -1, 9, 31, 40, -1, 9, 31, 40, + 31, 40, -1, 9, 31, 40, 31, 40, 31, 40, + -1, 9, 31, 40, 31, 40, 31, 40, 31, 40, + -1, 9, 31, 9, -1, 9, 31, 9, 31, 40, + -1, 9, 31, 9, 31, 40, 31, 40, -1, 9, + 31, 9, 31, 40, 31, 40, 31, 40, -1, 10, + -1, 10, 31, 40, -1, 10, 31, 40, 31, 40, + -1, 10, 31, 40, 31, 40, 31, 40, -1, 10, + 31, 40, 31, 40, 31, 40, 31, 40, -1, 40, + -1, 40, 31, 40, -1, 40, 31, 40, 31, 40, + -1, 40, 31, 40, 31, 40, 31, 40, -1, 40, + 31, 40, 31, 40, 31, 40, 31, 40, -1, 40, + 31, 9, -1, 40, 31, 9, 31, 40, -1, 40, + 31, 9, 31, 40, 31, 40, -1, 40, 31, 9, + 31, 40, 31, 40, 31, 40, -1, 40, 31, 40, + 31, 9, -1, 40, 31, 40, 31, 9, 31, 40, + -1, 40, 31, 40, 31, 9, 31, 40, 31, 40, + -1, 40, 31, 40, 31, 40, 31, 9, -1, 40, + 31, 40, 31, 40, 31, 9, 31, 40, -1, 40, + 31, 40, 31, 40, 31, 40, 31, 9, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const unsigned short int yyrline[] = +{ + 0, 116, 116, 117, 118, 119, 120, 121, 122, 123, + 124, 125, 126, 129, 130, 134, 135, 136, 137, 138, + 139, 140, 144, 150, 152, 153, 157, 158, 159, 163, + 167, 171, 171, 174, 176, 177, 181, 182, 189, 192, + 194, 195, 199, 201, 200, 206, 207, 208, 212, 222, + 229, 277, 280, 289, 324, 325, 326, 327, 328, 332, + 333, 337, 342, 350, 356, 365, 370, 374, 379, 388, + 397, 406, 416, 424, 432, 440, 449, 454, 463, 472, + 481, 491, 500, 509, 518, 527, 537, 546, 555, 564, + 574, 583, 592, 602, 611, 621 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "NUM", "SYMNUM", "SYM", "STRING", + "DEFINE", "INCLUDE", "TAG", "LINEID", "SPECIAL", "FLAGS", "ARG2", "ARG3", + "ARG4", "ARG5", "OR_EQUAL", "ENUM", "PRINT", "ENDL", "'|'", "'^'", "'&'", + "'-'", "'+'", "'*'", "'/'", "NEG", "'('", "')'", "','", "'{'", "'}'", + "'='", "';'", "':'", "'['", "']'", "$accept", "exp", "translation_unit", + "external_declaration", "print_statement", "print_list", "print_item", + "define_statement", "include_statement", "enum_statement", "@1", + "enum_list", "single_enum", "special_declaration", "special_list", + "special_def", "@2", "maybe_argcount", "linetype_declaration", + "boom_declaration", "boom_body", "boom_line", "boom_selector", "boom_op", + "boom_args", "arg_list", "list_val", "special_args", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const unsigned short int yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 124, 94, 38, 45, 43, 42, 47, 276, 40, + 41, 44, 123, 125, 61, 59, 58, 91, 93 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const unsigned char yyr1[] = +{ + 0, 39, 40, 40, 40, 40, 40, 40, 40, 40, + 40, 40, 40, 41, 41, 42, 42, 42, 42, 42, + 42, 42, 43, 44, 44, 44, 45, 45, 45, 46, + 47, 49, 48, 50, 50, 50, 51, 51, 52, 53, + 53, 53, 54, 55, 54, 56, 56, 56, 57, 57, + 58, 59, 59, 60, 61, 61, 61, 61, 61, 62, + 62, 63, 63, 64, 64, 65, 66, 66, 66, 66, + 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, + 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, + 66, 66, 66, 66, 66, 66 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const unsigned char yyr2[] = +{ + 0, 2, 1, 1, 3, 3, 3, 3, 3, 3, + 3, 2, 3, 0, 2, 1, 1, 1, 1, 1, + 1, 1, 4, 0, 1, 3, 1, 1, 1, 5, + 2, 0, 5, 0, 1, 3, 1, 3, 3, 0, + 1, 3, 6, 0, 7, 0, 1, 3, 8, 8, + 11, 0, 2, 3, 1, 1, 1, 1, 1, 1, + 1, 1, 4, 1, 3, 3, 0, 1, 3, 5, + 7, 9, 3, 5, 7, 9, 1, 3, 5, 7, + 9, 1, 3, 5, 7, 9, 3, 5, 7, 9, + 5, 7, 9, 7, 9, 9 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const unsigned char yydefact[] = +{ + 13, 0, 1, 2, 3, 0, 0, 39, 0, 0, + 0, 0, 0, 0, 14, 17, 15, 16, 18, 21, + 19, 20, 0, 30, 0, 0, 40, 31, 23, 11, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 38, 39, 33, 26, 28, 27, 0, 24, + 12, 0, 8, 10, 9, 5, 4, 6, 7, 0, + 0, 43, 0, 41, 36, 0, 34, 22, 23, 0, + 0, 29, 0, 45, 0, 32, 33, 25, 0, 0, + 0, 45, 46, 0, 37, 35, 0, 66, 66, 0, + 0, 42, 0, 67, 76, 81, 0, 0, 44, 47, + 0, 0, 0, 0, 49, 48, 51, 72, 68, 77, + 86, 82, 54, 55, 56, 57, 58, 0, 51, 0, + 0, 0, 0, 0, 0, 50, 52, 60, 59, 0, + 73, 69, 78, 87, 90, 83, 61, 53, 0, 0, + 0, 0, 0, 0, 0, 74, 70, 79, 88, 91, + 93, 84, 0, 0, 63, 0, 0, 0, 0, 0, + 0, 0, 0, 62, 0, 75, 71, 80, 89, 92, + 94, 95, 85, 65, 64 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const short int yydefgoto[] = +{ + -1, 24, 1, 14, 15, 48, 49, 16, 17, 18, + 44, 65, 66, 19, 25, 26, 72, 83, 20, 21, + 117, 118, 119, 129, 137, 153, 154, 96 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -28 +static const short int yypact[] = +{ + -28, 41, -28, -28, -28, 2, 6, 50, -27, 11, + 50, 50, 50, 166, -28, -28, -28, -28, -28, -28, + -28, -28, 14, -28, 143, -7, -5, -28, 0, -28, + 378, -8, 50, 50, 50, 50, 50, 50, 50, 50, + 50, -3, -28, 50, 53, -28, -28, 417, 16, 24, + -28, 46, 158, 171, 37, 68, 68, -28, -28, 180, + 388, -28, 48, -28, 32, 51, 66, -28, 0, 50, + 18, -28, 52, 50, 50, -28, 53, -28, 191, 70, + 408, 50, 202, 84, 417, -28, 50, 47, 47, 85, + 50, -28, 398, 78, 86, 213, 94, 96, -28, 417, + 97, 79, 50, 87, -28, -28, 433, 100, 224, 235, + 102, 246, -28, -28, -28, -28, -28, 111, 433, -9, + 50, 50, 50, 50, 89, -28, -28, -28, -28, 50, + 257, 268, 279, 290, 104, 301, 125, -28, 50, 50, + 50, 50, 50, 101, 50, 312, 323, 334, 345, 356, + 105, 367, 150, 107, 122, 50, 50, 50, 50, 50, + 50, 103, 50, -28, 50, 417, 417, 417, 417, 417, + 417, -28, 417, 417, -28 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const short int yypgoto[] = +{ + -28, -1, -28, -28, -28, 110, -28, -28, -28, -28, + -28, 58, -28, -28, 156, -28, -28, 127, -28, -28, + 91, -28, -28, -28, -28, 55, -28, 132 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const unsigned char yytable[] = +{ + 13, 61, 62, 3, 4, 27, 45, 22, 127, 29, + 30, 31, 23, 32, 33, 34, 35, 36, 37, 38, + 46, 3, 4, 79, 10, 128, 43, 47, 42, 11, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 28, 2, 10, 40, 3, 4, 67, 11, 5, 6, + 3, 4, 7, 3, 4, 68, 93, 94, 64, 8, + 9, 35, 36, 37, 38, 10, 74, 47, 78, 80, + 11, 10, 82, 84, 10, 69, 11, 73, 12, 11, + 82, 81, 3, 4, 75, 92, 95, 95, 107, 99, + 3, 4, 3, 4, 37, 38, 110, 76, 134, 87, + 108, 109, 111, 10, 3, 4, 3, 4, 11, 101, + 150, 10, 171, 10, 91, 98, 11, 102, 11, 130, + 131, 132, 133, 135, 104, 10, 105, 10, 136, 106, + 11, 120, 11, 123, 85, 142, 160, 145, 146, 147, + 148, 149, 151, 152, 125, 163, 32, 33, 34, 35, + 36, 37, 38, 164, 165, 166, 167, 168, 169, 170, + 172, 173, 144, 152, 32, 33, 34, 35, 36, 37, + 38, 32, 33, 34, 35, 36, 37, 38, 77, 41, + 33, 34, 35, 36, 37, 38, 162, 32, 33, 34, + 35, 36, 37, 38, 34, 35, 36, 37, 38, 63, + 39, 32, 33, 34, 35, 36, 37, 38, 89, 126, + 0, 70, 32, 33, 34, 35, 36, 37, 38, 174, + 97, 0, 86, 32, 33, 34, 35, 36, 37, 38, + 0, 0, 0, 90, 32, 33, 34, 35, 36, 37, + 38, 0, 0, 0, 103, 32, 33, 34, 35, 36, + 37, 38, 0, 0, 0, 121, 32, 33, 34, 35, + 36, 37, 38, 0, 0, 0, 122, 32, 33, 34, + 35, 36, 37, 38, 0, 0, 0, 124, 32, 33, + 34, 35, 36, 37, 38, 0, 0, 0, 138, 32, + 33, 34, 35, 36, 37, 38, 0, 0, 0, 139, + 32, 33, 34, 35, 36, 37, 38, 0, 0, 0, + 140, 32, 33, 34, 35, 36, 37, 38, 0, 0, + 0, 141, 32, 33, 34, 35, 36, 37, 38, 0, + 0, 0, 143, 32, 33, 34, 35, 36, 37, 38, + 0, 0, 0, 155, 32, 33, 34, 35, 36, 37, + 38, 0, 0, 0, 156, 32, 33, 34, 35, 36, + 37, 38, 0, 0, 0, 157, 32, 33, 34, 35, + 36, 37, 38, 0, 0, 0, 158, 32, 33, 34, + 35, 36, 37, 38, 0, 0, 0, 159, 32, 33, + 34, 35, 36, 37, 38, 0, 0, 0, 161, 32, + 33, 34, 35, 36, 37, 38, 0, 0, 50, 32, + 33, 34, 35, 36, 37, 38, 0, 0, 71, 32, + 33, 34, 35, 36, 37, 38, 0, 0, 100, 32, + 33, 34, 35, 36, 37, 38, 0, 88, 32, 33, + 34, 35, 36, 37, 38, 112, 113, 114, 115, 116 +}; + +static const short int yycheck[] = +{ + 1, 4, 5, 3, 4, 32, 6, 5, 17, 10, + 11, 12, 6, 21, 22, 23, 24, 25, 26, 27, + 20, 3, 4, 5, 24, 34, 31, 28, 35, 29, + 38, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 29, 0, 24, 29, 3, 4, 30, 29, 7, 8, + 3, 4, 11, 3, 4, 31, 9, 10, 5, 18, + 19, 24, 25, 26, 27, 24, 34, 68, 69, 70, + 29, 24, 73, 74, 24, 29, 29, 29, 37, 29, + 81, 29, 3, 4, 33, 86, 87, 88, 9, 90, + 3, 4, 3, 4, 26, 27, 9, 31, 9, 29, + 101, 102, 103, 24, 3, 4, 3, 4, 29, 31, + 9, 24, 9, 24, 30, 30, 29, 31, 29, 120, + 121, 122, 123, 124, 30, 24, 30, 24, 129, 32, + 29, 31, 29, 31, 76, 31, 31, 138, 139, 140, + 141, 142, 143, 144, 33, 38, 21, 22, 23, 24, + 25, 26, 27, 31, 155, 156, 157, 158, 159, 160, + 161, 162, 37, 164, 21, 22, 23, 24, 25, 26, + 27, 21, 22, 23, 24, 25, 26, 27, 68, 36, + 22, 23, 24, 25, 26, 27, 36, 21, 22, 23, + 24, 25, 26, 27, 23, 24, 25, 26, 27, 43, + 34, 21, 22, 23, 24, 25, 26, 27, 81, 118, + -1, 31, 21, 22, 23, 24, 25, 26, 27, 164, + 88, -1, 31, 21, 22, 23, 24, 25, 26, 27, + -1, -1, -1, 31, 21, 22, 23, 24, 25, 26, + 27, -1, -1, -1, 31, 21, 22, 23, 24, 25, + 26, 27, -1, -1, -1, 31, 21, 22, 23, 24, + 25, 26, 27, -1, -1, -1, 31, 21, 22, 23, + 24, 25, 26, 27, -1, -1, -1, 31, 21, 22, + 23, 24, 25, 26, 27, -1, -1, -1, 31, 21, + 22, 23, 24, 25, 26, 27, -1, -1, -1, 31, + 21, 22, 23, 24, 25, 26, 27, -1, -1, -1, + 31, 21, 22, 23, 24, 25, 26, 27, -1, -1, + -1, 31, 21, 22, 23, 24, 25, 26, 27, -1, + -1, -1, 31, 21, 22, 23, 24, 25, 26, 27, + -1, -1, -1, 31, 21, 22, 23, 24, 25, 26, + 27, -1, -1, -1, 31, 21, 22, 23, 24, 25, + 26, 27, -1, -1, -1, 31, 21, 22, 23, 24, + 25, 26, 27, -1, -1, -1, 31, 21, 22, 23, + 24, 25, 26, 27, -1, -1, -1, 31, 21, 22, + 23, 24, 25, 26, 27, -1, -1, -1, 31, 21, + 22, 23, 24, 25, 26, 27, -1, -1, 30, 21, + 22, 23, 24, 25, 26, 27, -1, -1, 30, 21, + 22, 23, 24, 25, 26, 27, -1, -1, 30, 21, + 22, 23, 24, 25, 26, 27, -1, 29, 21, 22, + 23, 24, 25, 26, 27, 12, 13, 14, 15, 16 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const unsigned char yystos[] = +{ + 0, 41, 0, 3, 4, 7, 8, 11, 18, 19, + 24, 29, 37, 40, 42, 43, 46, 47, 48, 52, + 57, 58, 5, 6, 40, 53, 54, 32, 29, 40, + 40, 40, 21, 22, 23, 24, 25, 26, 27, 34, + 29, 36, 35, 31, 49, 6, 20, 40, 44, 45, + 30, 38, 40, 40, 40, 40, 40, 40, 40, 40, + 40, 4, 5, 53, 5, 50, 51, 30, 31, 29, + 31, 30, 55, 29, 34, 33, 31, 44, 40, 5, + 40, 29, 40, 56, 40, 50, 31, 29, 29, 56, + 31, 30, 40, 9, 10, 40, 66, 66, 30, 40, + 30, 31, 31, 31, 30, 30, 32, 9, 40, 40, + 9, 40, 12, 13, 14, 15, 16, 59, 60, 61, + 31, 31, 31, 31, 31, 33, 59, 17, 34, 62, + 40, 40, 40, 40, 9, 40, 40, 63, 31, 31, + 31, 31, 31, 31, 37, 40, 40, 40, 40, 40, + 9, 40, 40, 64, 65, 31, 31, 31, 31, 31, + 31, 31, 36, 38, 31, 40, 40, 40, 40, 40, + 40, 9, 40, 40, 64 +}; #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) -#define YYEMPTY -2 +#define YYEMPTY (-2) #define YYEOF 0 + #define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrlab1 -/* Like YYERROR except do call yyerror. - This remains here temporarily to ease the - transition to the new meaning of YYERROR, for GCC. +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. Once GCC version 2 has supplanted version 1, this can go. */ + #define YYFAIL goto yyerrlab + #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(token, value) \ + +#define YYBACKUP(Token, Value) \ do \ if (yychar == YYEMPTY && yylen == 1) \ - { yychar = (token), yylval = (value); \ - yychar1 = YYTRANSLATE (yychar); \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK; \ goto yybackup; \ } \ else \ - { yyerror ("syntax error: cannot back up"); YYERROR; } \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ while (0) + #define YYTERROR 1 #define YYERRCODE 256 -#ifndef YYPURE -#define YYLEX yylex() + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (0) #endif -#ifdef YYPURE -#ifdef YYLSP_NEEDED + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ + #ifdef YYLEX_PARAM -#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM) +# define YYLEX yylex (YYLEX_PARAM) #else -#define YYLEX yylex(&yylval, &yylloc) +# define YYLEX yylex () #endif -#else /* not YYLSP_NEEDED */ -#ifdef YYLEX_PARAM -#define YYLEX yylex(&yylval, YYLEX_PARAM) + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yysymprint (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yy_stack_print (short int *bottom, short int *top) #else -#define YYLEX yylex(&yylval) +static void +yy_stack_print (bottom, top) + short int *bottom; + short int *top; #endif -#endif /* not YYLSP_NEEDED */ +{ + YYFPRINTF (stderr, "Stack now"); + for (/* Nothing. */; bottom <= top; ++bottom) + YYFPRINTF (stderr, " %d", *bottom); + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yy_reduce_print (int yyrule) +#else +static void +yy_reduce_print (yyrule) + int yyrule; #endif +{ + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ", + yyrule - 1, yylno); + /* Print the symbols being reduced, and their result. */ + for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) + YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); + YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]); +} -/* If nonreentrant, generate the variables here */ +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (Rule); \ +} while (0) -#ifndef YYPURE +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ -int yychar; /* the lookahead symbol */ -YYSTYPE yylval; /* the semantic value of the */ - /* lookahead symbol */ - -#ifdef YYLSP_NEEDED -YYLTYPE yylloc; /* location data for the lookahead */ - /* symbol */ -#endif - -int yynerrs; /* number of parse errors so far */ -#endif /* not YYPURE */ - -#if YYDEBUG != 0 -int yydebug; /* nonzero means print parse trace */ -/* Since this is uninitialized, it does not stop multiple parsers - from coexisting. */ -#endif - -/* YYINITDEPTH indicates the initial size of the parser's stacks */ +/* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH -#define YYINITDEPTH 200 +# define YYINITDEPTH 200 #endif -/* YYMAXDEPTH is the maximum size the stacks can grow to - (effective only if the built-in stack extension method is used). */ +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). -#if YYMAXDEPTH == 0 -#undef YYMAXDEPTH -#endif + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH -#define YYMAXDEPTH 10000 +# define YYMAXDEPTH 10000 #endif + -/* Define __yy_memcpy. Note that the size argument - should be passed with type unsigned int, because that is what the non-GCC - definitions require. With GCC, __builtin_memcpy takes an arg - of type size_t, but it can handle unsigned int. */ -#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ -#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT) -#else /* not GNU C or C++ */ -#ifndef __cplusplus +#if YYERROR_VERBOSE -/* This is the most reliable way to avoid incompatibilities - in available built-in functions on various systems. */ -static void -__yy_memcpy (to, from, count) - char *to; - char *from; - unsigned int count; +# ifndef yystrlen +# if defined (__GLIBC__) && defined (_STRING_H) +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +static YYSIZE_T +# if defined (__STDC__) || defined (__cplusplus) +yystrlen (const char *yystr) +# else +yystrlen (yystr) + const char *yystr; +# endif { - register char *f = from; - register char *t = to; - register int i = count; + const char *yys = yystr; - while (i-- > 0) - *t++ = *f++; + while (*yys++ != '\0') + continue; + + return yys - yystr - 1; } +# endif +# endif -#else /* __cplusplus */ - -/* This is the most reliable way to avoid incompatibilities - in available built-in functions on various systems. */ -static void -__yy_memcpy (char *to, char *from, unsigned int count) +# ifndef yystpcpy +# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +# if defined (__STDC__) || defined (__cplusplus) +yystpcpy (char *yydest, const char *yysrc) +# else +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +# endif { - register char *t = to; - register char *f = from; - register int i = count; + char *yyd = yydest; + const char *yys = yysrc; - while (i-- > 0) - *t++ = *f++; + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; } +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + size_t yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +#endif /* YYERROR_VERBOSE */ -#endif -#endif -#line 217 "/usr/local/share/bison.simple" -/* The user can define YYPARSE_PARAM as the name of an argument to be passed - into yyparse. The argument should have type void *. - It should actually point to an object. - Grammar actions can access the variable by casting it - to the proper pointer type. */ +#if YYDEBUG +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ -#ifdef YYPARSE_PARAM -#ifdef __cplusplus -#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM -#define YYPARSE_PARAM_DECL -#else /* not __cplusplus */ -#define YYPARSE_PARAM_ARG YYPARSE_PARAM -#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; -#endif /* not __cplusplus */ -#else /* not YYPARSE_PARAM */ -#define YYPARSE_PARAM_ARG -#define YYPARSE_PARAM_DECL -#endif /* not YYPARSE_PARAM */ - -/* Prevent warning if -Wstrict-prototypes. */ -#ifdef __GNUC__ -#ifdef YYPARSE_PARAM -int yyparse (void *); +#if defined (__STDC__) || defined (__cplusplus) +static void +yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) #else +static void +yysymprint (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# endif + switch (yytype) + { + default: + break; + } + YYFPRINTF (yyoutput, ")"); +} + +#endif /* ! YYDEBUG */ +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +#else +static void +yydestruct (yymsg, yytype, yyvaluep) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + + +/* Prevent warnings from -Wmissing-prototypes. */ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +int yyparse (void *YYPARSE_PARAM); +# else +int yyparse (); +# endif +#else /* ! YYPARSE_PARAM */ +#if defined (__STDC__) || defined (__cplusplus) int yyparse (void); -#endif -#endif - -int -yyparse(YYPARSE_PARAM_ARG) - YYPARSE_PARAM_DECL -{ - register int yystate; - register int yyn; - register short *yyssp; - register YYSTYPE *yyvsp; - int yyerrstatus; /* number of tokens to shift before error messages enabled */ - int yychar1 = 0; /* lookahead token as an internal (translated) token number */ - - short yyssa[YYINITDEPTH]; /* the state stack */ - YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */ - - short *yyss = yyssa; /* refer to the stacks thru separate pointers */ - YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */ - -#ifdef YYLSP_NEEDED - YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ - YYLTYPE *yyls = yylsa; - YYLTYPE *yylsp; - -#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) #else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + + +/* The look-ahead symbol. */ +int yychar; + +/* The semantic value of the look-ahead symbol. */ +YYSTYPE yylval; + +/* Number of syntax errors so far. */ +int yynerrs; + + + +/*----------. +| yyparse. | +`----------*/ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +int yyparse (void *YYPARSE_PARAM) +# else +int yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +# endif +#else /* ! YYPARSE_PARAM */ +#if defined (__STDC__) || defined (__cplusplus) +int +yyparse (void) +#else +int +yyparse () + ; +#endif +#endif +{ + + int yystate; + int yyn; + int yyresult; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + /* Look-ahead token as an internal (translated) token number. */ + int yytoken = 0; + + /* Three stacks and their tools: + `yyss': related to states, + `yyvs': related to semantic values, + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + short int yyssa[YYINITDEPTH]; + short int *yyss = yyssa; + short int *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp; + + + #define YYPOPSTACK (yyvsp--, yyssp--) -#endif - int yystacksize = YYINITDEPTH; - int yyfree_stacks = 0; + YYSIZE_T yystacksize = YYINITDEPTH; -#ifdef YYPURE - int yychar; - YYSTYPE yylval; - int yynerrs; -#ifdef YYLSP_NEEDED - YYLTYPE yylloc; -#endif -#endif + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; - YYSTYPE yyval; /* the variable used to return */ - /* semantic values from the action */ - /* routines */ + /* When reducing, the number of symbols on the RHS of the reduced + rule. */ int yylen; -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Starting parse\n"); -#endif + YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; @@ -711,358 +1214,332 @@ yyparse(YYPARSE_PARAM_ARG) so that they stay on the same level as the state stack. The wasted elements are never initialized. */ - yyssp = yyss - 1; + yyssp = yyss; yyvsp = yyvs; -#ifdef YYLSP_NEEDED - yylsp = yyls; -#endif -/* Push a new state, which is found in yystate . */ -/* In all cases, when you get here, the value and location stacks - have just been pushed. so pushing a state here evens the stacks. */ -yynewstate: + goto yysetstate; - *++yyssp = yystate; +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. so pushing a state here evens the stacks. + */ + yyssp++; - if (yyssp >= yyss + yystacksize - 1) + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) { - /* Give user a chance to reallocate the stack */ - /* Use copies of these so that the &'s don't force the real ones into memory. */ - YYSTYPE *yyvs1 = yyvs; - short *yyss1 = yyss; -#ifdef YYLSP_NEEDED - YYLTYPE *yyls1 = yyls; -#endif - /* Get the current used size of the three stacks, in elements. */ - int size = yyssp - yyss + 1; + YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow - /* Each stack pointer address is followed by the size of - the data in use in that stack, in bytes. */ -#ifdef YYLSP_NEEDED - /* This used to be a conditional around just the two extra args, - but that might be undefined if yyoverflow is a macro. */ - yyoverflow("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yyls1, size * sizeof (*yylsp), - &yystacksize); -#else - yyoverflow("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yystacksize); -#endif + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + short int *yyss1 = yyss; - yyss = yyss1; yyvs = yyvs1; -#ifdef YYLSP_NEEDED - yyls = yyls1; -#endif + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } #else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else /* Extend the stack our own way. */ - if (yystacksize >= YYMAXDEPTH) - { - yyerror("parser stack overflow"); - if (yyfree_stacks) - { - free (yyss); - free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif - } - return 2; - } + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; yystacksize *= 2; - if (yystacksize > YYMAXDEPTH) + if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; -#ifndef YYSTACK_USE_ALLOCA - yyfree_stacks = 1; -#endif - yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp)); - __yy_memcpy ((char *)yyss, (char *)yyss1, - size * (unsigned int) sizeof (*yyssp)); - yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp)); - __yy_memcpy ((char *)yyvs, (char *)yyvs1, - size * (unsigned int) sizeof (*yyvsp)); -#ifdef YYLSP_NEEDED - yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp)); - __yy_memcpy ((char *)yyls, (char *)yyls1, - size * (unsigned int) sizeof (*yylsp)); -#endif + + { + short int *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss); + YYSTACK_RELOCATE (yyvs); + +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif #endif /* no yyoverflow */ - yyssp = yyss + size - 1; - yyvsp = yyvs + size - 1; -#ifdef YYLSP_NEEDED - yylsp = yyls + size - 1; -#endif + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Stack size increased to %d\n", yystacksize); -#endif - if (yyssp >= yyss + yystacksize - 1) + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) YYABORT; } -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Entering state %d\n", yystate); -#endif + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); goto yybackup; - yybackup: + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: /* Do appropriate processing given the current state. */ -/* Read a lookahead token if we need one and don't already have one. */ +/* Read a look-ahead token if we need one and don't already have one. */ /* yyresume: */ - /* First try to decide what to do without reference to lookahead token. */ + /* First try to decide what to do without reference to look-ahead token. */ yyn = yypact[yystate]; - if (yyn == YYFLAG) + if (yyn == YYPACT_NINF) goto yydefault; - /* Not known => get a lookahead token if don't already have one. */ - - /* yychar is either YYEMPTY or YYEOF - or a valid token in external form. */ + /* Not known => get a look-ahead token if don't already have one. */ + /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ if (yychar == YYEMPTY) { -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Reading a token: "); -#endif + YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; } - /* Convert token to internal form (in yychar1) for indexing tables with */ - - if (yychar <= 0) /* This means end of input. */ + if (yychar <= YYEOF) { - yychar1 = 0; - yychar = YYEOF; /* Don't call YYLEX any more */ - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Now at end of input.\n"); -#endif + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); } else { - yychar1 = YYTRANSLATE(yychar); - -#if YYDEBUG != 0 - if (yydebug) - { - fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); - /* Give the individual parser a way to print the precise meaning - of a token, for further debugging info. */ -#ifdef YYPRINT - YYPRINT (stderr, yychar, yylval); -#endif - fprintf (stderr, ")\n"); - } -#endif + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } - yyn += yychar1; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; - yyn = yytable[yyn]; - - /* yyn is what to do for this token type in this state. - Negative => reduce, -yyn is rule number. - Positive => shift, yyn is new state. - New state is final state => don't bother to shift, - just return success. - 0, or most negative number => error. */ - - if (yyn < 0) + if (yyn <= 0) { - if (yyn == YYFLAG) + if (yyn == 0 || yyn == YYTABLE_NINF) goto yyerrlab; yyn = -yyn; goto yyreduce; } - else if (yyn == 0) - goto yyerrlab; if (yyn == YYFINAL) YYACCEPT; - /* Shift the lookahead token. */ - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); -#endif + /* Shift the look-ahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the token being shifted unless it is eof. */ if (yychar != YYEOF) yychar = YYEMPTY; *++yyvsp = yylval; -#ifdef YYLSP_NEEDED - *++yylsp = yylloc; -#endif - /* count tokens shifted since error; after three, turn off error status. */ - if (yyerrstatus) yyerrstatus--; + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; yystate = yyn; goto yynewstate; -/* Do the default action for the current state. */ -yydefault: +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; + goto yyreduce; -/* Do a reduction. yyn is the number of a rule to reduce with. */ + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ yyreduce: + /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; - if (yylen > 0) - yyval = yyvsp[1-yylen]; /* implement default value of the action */ -#if YYDEBUG != 0 - if (yydebug) + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) { - int i; - - fprintf (stderr, "Reducing via rule %d (line %d), ", - yyn, yyrline[yyn]); - - /* Print the symbols being reduced, and their result. */ - for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) - fprintf (stderr, "%s ", yytname[yyrhs[i]]); - fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); - } -#endif - - - switch (yyn) { - -case 2: + case 3: #line 117 "xlat-parse.y" -{ yyval.val = yyvsp[0].symval->Value; ; - break;} -case 3: + { (yyval.val) = (yyvsp[0].symval)->Value; ;} + break; + + case 4: #line 118 "xlat-parse.y" -{ yyval.val = yyvsp[-2].val + yyvsp[0].val; ; - break;} -case 4: + { (yyval.val) = (yyvsp[-2].val) + (yyvsp[0].val); ;} + break; + + case 5: #line 119 "xlat-parse.y" -{ yyval.val = yyvsp[-2].val - yyvsp[0].val; ; - break;} -case 5: + { (yyval.val) = (yyvsp[-2].val) - (yyvsp[0].val); ;} + break; + + case 6: #line 120 "xlat-parse.y" -{ yyval.val = yyvsp[-2].val * yyvsp[0].val; ; - break;} -case 6: + { (yyval.val) = (yyvsp[-2].val) * (yyvsp[0].val); ;} + break; + + case 7: #line 121 "xlat-parse.y" -{ yyval.val = yyvsp[-2].val / yyvsp[0].val; ; - break;} -case 7: + { (yyval.val) = (yyvsp[-2].val) / (yyvsp[0].val); ;} + break; + + case 8: #line 122 "xlat-parse.y" -{ yyval.val = yyvsp[-2].val | yyvsp[0].val; ; - break;} -case 8: + { (yyval.val) = (yyvsp[-2].val) | (yyvsp[0].val); ;} + break; + + case 9: #line 123 "xlat-parse.y" -{ yyval.val = yyvsp[-2].val & yyvsp[0].val; ; - break;} -case 9: + { (yyval.val) = (yyvsp[-2].val) & (yyvsp[0].val); ;} + break; + + case 10: #line 124 "xlat-parse.y" -{ yyval.val = yyvsp[-2].val ^ yyvsp[0].val; ; - break;} -case 10: + { (yyval.val) = (yyvsp[-2].val) ^ (yyvsp[0].val); ;} + break; + + case 11: #line 125 "xlat-parse.y" -{ yyval.val = -yyvsp[0].val ; - break;} -case 11: + { (yyval.val) = -(yyvsp[0].val) ;} + break; + + case 12: #line 126 "xlat-parse.y" -{ yyval.val = yyvsp[-1].val; ; - break;} -case 21: + { (yyval.val) = (yyvsp[-1].val); ;} + break; + + case 22: #line 145 "xlat-parse.y" -{ + { printf ("\n"); - ; - break;} -case 25: + ;} + break; + + case 26: #line 157 "xlat-parse.y" -{ printf ("%s", yyvsp[0].string); ; - break;} -case 26: + { printf ("%s", (yyvsp[0].string)); ;} + break; + + case 27: #line 158 "xlat-parse.y" -{ printf ("%d", yyvsp[0].val); ; - break;} -case 27: + { printf ("%d", (yyvsp[0].val)); ;} + break; + + case 28: #line 159 "xlat-parse.y" -{ printf ("\n"); ; - break;} -case 28: + { printf ("\n"); ;} + break; + + case 29: #line 163 "xlat-parse.y" -{ AddSym (yyvsp[-3].sym, yyvsp[-1].val); ; - break;} -case 29: + { AddSym ((yyvsp[-3].sym), (yyvsp[-1].val)); ;} + break; + + case 30: #line 167 "xlat-parse.y" -{ IncludeFile (yyvsp[0].string); ; - break;} -case 30: + { IncludeFile ((yyvsp[0].string)); ;} + break; + + case 31: #line 171 "xlat-parse.y" -{ EnumVal = 0; ; - break;} -case 35: + { EnumVal = 0; ;} + break; + + case 36: #line 181 "xlat-parse.y" -{ AddSym (yyvsp[0].sym, EnumVal++); ; - break;} -case 36: + { AddSym ((yyvsp[0].sym), EnumVal++); ;} + break; + + case 37: #line 182 "xlat-parse.y" -{ AddSym (yyvsp[-2].sym, EnumVal = yyvsp[0].val); ; - break;} -case 41: + { AddSym ((yyvsp[-2].sym), EnumVal = (yyvsp[0].val)); ;} + break; + + case 42: #line 199 "xlat-parse.y" -{ AddSym (yyvsp[-3].sym, yyvsp[-5].val); ; - break;} -case 42: + { AddSym ((yyvsp[-3].sym), (yyvsp[-5].val)); ;} + break; + + case 43: #line 201 "xlat-parse.y" -{ printf ("%s, line %d: %s is already defined\n", SourceName, SourceLine, yyvsp[0].symval->Sym); ; - break;} -case 44: + { printf ("%s, line %d: %s is already defined\n", SourceName, SourceLine, (yyvsp[0].symval)->Sym); ;} + break; + + case 45: #line 206 "xlat-parse.y" -{ yyval.val = 0; ; - break;} -case 47: + { (yyval.val) = 0; ;} + break; + + case 48: #line 213 "xlat-parse.y" -{ - Simple[yyvsp[-7].val].NewSpecial = yyvsp[-3].val; - Simple[yyvsp[-7].val].Flags = yyvsp[-5].val | yyvsp[-1].args.addflags; - Simple[yyvsp[-7].val].Args[0] = yyvsp[-1].args.args[0]; - Simple[yyvsp[-7].val].Args[1] = yyvsp[-1].args.args[1]; - Simple[yyvsp[-7].val].Args[2] = yyvsp[-1].args.args[2]; - Simple[yyvsp[-7].val].Args[3] = yyvsp[-1].args.args[3]; - Simple[yyvsp[-7].val].Args[4] = yyvsp[-1].args.args[4]; - ; - break;} -case 48: + { + Simple[(yyvsp[-7].val)].NewSpecial = (yyvsp[-3].val); + Simple[(yyvsp[-7].val)].Flags = (yyvsp[-5].val) | (yyvsp[-1].args).addflags; + Simple[(yyvsp[-7].val)].Args[0] = (yyvsp[-1].args).args[0]; + Simple[(yyvsp[-7].val)].Args[1] = (yyvsp[-1].args).args[1]; + Simple[(yyvsp[-7].val)].Args[2] = (yyvsp[-1].args).args[2]; + Simple[(yyvsp[-7].val)].Args[3] = (yyvsp[-1].args).args[3]; + Simple[(yyvsp[-7].val)].Args[4] = (yyvsp[-1].args).args[4]; + ;} + break; + + case 49: #line 223 "xlat-parse.y" -{ - printf ("%s, line %d: %s is undefined\n", SourceName, SourceLine, yyvsp[-3].sym); - ; - break;} -case 49: + { + printf ("%s, line %d: %s is undefined\n", SourceName, SourceLine, (yyvsp[-3].sym)); + ;} + break; + + case 50: #line 230 "xlat-parse.y" -{ + { if (NumBoomish == MAX_BOOMISH) { - MoreLines *probe = yyvsp[-1].boomlines; + MoreLines *probe = (yyvsp[-1].boomlines); while (probe != NULL) { @@ -1077,11 +1554,11 @@ case 49: int i; MoreLines *probe; - Boomish[NumBoomish].FirstLinetype = yyvsp[-6].val; - Boomish[NumBoomish].LastLinetype = yyvsp[-4].val; - Boomish[NumBoomish].NewSpecial = yyvsp[-9].val; + Boomish[NumBoomish].FirstLinetype = (yyvsp[-6].val); + Boomish[NumBoomish].LastLinetype = (yyvsp[-4].val); + Boomish[NumBoomish].NewSpecial = (yyvsp[-9].val); - for (i = 0, probe = yyvsp[-1].boomlines; probe != NULL; i++) + for (i = 0, probe = (yyvsp[-1].boomlines); probe != NULL; i++) { MoreLines *next = probe->next;; if (i < MAX_BOOMISH_EXEC) @@ -1101,44 +1578,47 @@ case 49: } NumBoomish++; } - ; - break;} -case 50: -#line 277 "xlat-parse.y" -{ - yyval.boomlines = NULL; - ; - break;} -case 51: -#line 281 "xlat-parse.y" -{ - yyval.boomlines = malloc (sizeof(MoreLines)); - yyval.boomlines->next = yyvsp[0].boomlines; - yyval.boomlines->arg = yyvsp[-1].boomline; - ; - break;} -case 52: -#line 290 "xlat-parse.y" -{ - yyval.boomline.bDefined = 1; - yyval.boomline.bOrExisting = (yyvsp[-1].val == OR_EQUAL); - yyval.boomline.bUseConstant = (yyvsp[0].boomarg.filters == NULL); - yyval.boomline.ArgNum = yyvsp[-2].val; - yyval.boomline.ConstantValue = yyvsp[0].boomarg.constant; - yyval.boomline.AndValue = yyvsp[0].boomarg.mask; + ;} + break; - if (yyvsp[0].boomarg.filters != NULL) + case 51: +#line 277 "xlat-parse.y" + { + (yyval.boomlines) = NULL; + ;} + break; + + case 52: +#line 281 "xlat-parse.y" + { + (yyval.boomlines) = malloc (sizeof(MoreLines)); + (yyval.boomlines)->next = (yyvsp[0].boomlines); + (yyval.boomlines)->arg = (yyvsp[-1].boomline); + ;} + break; + + case 53: +#line 290 "xlat-parse.y" + { + (yyval.boomline).bDefined = 1; + (yyval.boomline).bOrExisting = ((yyvsp[-1].val) == OR_EQUAL); + (yyval.boomline).bUseConstant = ((yyvsp[0].boomarg).filters == NULL); + (yyval.boomline).ArgNum = (yyvsp[-2].val); + (yyval.boomline).ConstantValue = (yyvsp[0].boomarg).constant; + (yyval.boomline).AndValue = (yyvsp[0].boomarg).mask; + + if ((yyvsp[0].boomarg).filters != NULL) { int i; MoreFilters *probe; - for (i = 0, probe = yyvsp[0].boomarg.filters; probe != NULL; i++) + for (i = 0, probe = (yyvsp[0].boomarg).filters; probe != NULL; i++) { MoreFilters *next = probe->next; if (i < 15) { - yyval.boomline.ResultFilter[i] = probe->filter.filter; - yyval.boomline.ResultValue[i] = probe->filter.value; + (yyval.boomline).ResultFilter[i] = probe->filter.filter; + (yyval.boomline).ResultValue[i] = probe->filter.value; } else if (i == 15) { @@ -1147,608 +1627,702 @@ case 52: free (probe); probe = next; } - yyval.boomline.ListSize = i > 15 ? 15 : i; + (yyval.boomline).ListSize = i > 15 ? 15 : i; } - ; - break;} -case 53: + ;} + break; + + case 54: #line 324 "xlat-parse.y" -{ yyval.val = 4; ; - break;} -case 54: + { (yyval.val) = 4; ;} + break; + + case 55: #line 325 "xlat-parse.y" -{ yyval.val = 0; ; - break;} -case 55: + { (yyval.val) = 0; ;} + break; + + case 56: #line 326 "xlat-parse.y" -{ yyval.val = 1; ; - break;} -case 56: + { (yyval.val) = 1; ;} + break; + + case 57: #line 327 "xlat-parse.y" -{ yyval.val = 2; ; - break;} -case 57: + { (yyval.val) = 2; ;} + break; + + case 58: #line 328 "xlat-parse.y" -{ yyval.val = 3; ; - break;} -case 58: + { (yyval.val) = 3; ;} + break; + + case 59: #line 332 "xlat-parse.y" -{ yyval.val = '='; ; - break;} -case 59: + { (yyval.val) = '='; ;} + break; + + case 60: #line 333 "xlat-parse.y" -{ yyval.val = OR_EQUAL; ; - break;} -case 60: + { (yyval.val) = OR_EQUAL; ;} + break; + + case 61: #line 338 "xlat-parse.y" -{ - yyval.boomarg.constant = yyvsp[0].val; - yyval.boomarg.filters = NULL; - ; - break;} -case 61: + { + (yyval.boomarg).constant = (yyvsp[0].val); + (yyval.boomarg).filters = NULL; + ;} + break; + + case 62: #line 343 "xlat-parse.y" -{ - yyval.boomarg.mask = yyvsp[-3].val; - yyval.boomarg.filters = yyvsp[-1].filter_p; - ; - break;} -case 62: + { + (yyval.boomarg).mask = (yyvsp[-3].val); + (yyval.boomarg).filters = (yyvsp[-1].filter_p); + ;} + break; + + case 63: #line 351 "xlat-parse.y" -{ - yyval.filter_p = malloc (sizeof (MoreFilters)); - yyval.filter_p->next = NULL; - yyval.filter_p->filter = yyvsp[0].filter; - ; - break;} -case 63: + { + (yyval.filter_p) = malloc (sizeof (MoreFilters)); + (yyval.filter_p)->next = NULL; + (yyval.filter_p)->filter = (yyvsp[0].filter); + ;} + break; + + case 64: #line 357 "xlat-parse.y" -{ - yyval.filter_p = malloc (sizeof (MoreFilters)); - yyval.filter_p->next = yyvsp[0].filter_p; - yyval.filter_p->filter = yyvsp[-2].filter; - ; - break;} -case 64: + { + (yyval.filter_p) = malloc (sizeof (MoreFilters)); + (yyval.filter_p)->next = (yyvsp[0].filter_p); + (yyval.filter_p)->filter = (yyvsp[-2].filter); + ;} + break; + + case 65: #line 365 "xlat-parse.y" -{ yyval.filter.filter = yyvsp[-2].val; yyval.filter.value = yyvsp[0].val; ; - break;} -case 65: + { (yyval.filter).filter = (yyvsp[-2].val); (yyval.filter).value = (yyvsp[0].val); ;} + break; + + case 66: #line 370 "xlat-parse.y" -{ - yyval.args.addflags = 0; - memset (yyval.args.args, 0, 5); - ; - break;} -case 66: + { + (yyval.args).addflags = 0; + memset ((yyval.args).args, 0, 5); + ;} + break; + + case 67: #line 375 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT1; - memset (yyval.args.args, 0, 5); - ; - break;} -case 67: + { + (yyval.args).addflags = SIMPLE_HASTAGAT1; + memset ((yyval.args).args, 0, 5); + ;} + break; + + case 68: #line 380 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT1; - yyval.args.args[0] = 0; - yyval.args.args[1] = yyvsp[0].val; - yyval.args.args[2] = 0; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 68: + { + (yyval.args).addflags = SIMPLE_HASTAGAT1; + (yyval.args).args[0] = 0; + (yyval.args).args[1] = (yyvsp[0].val); + (yyval.args).args[2] = 0; + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 69: #line 389 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT1; - yyval.args.args[0] = 0; - yyval.args.args[1] = yyvsp[-2].val; - yyval.args.args[2] = yyvsp[0].val; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 69: + { + (yyval.args).addflags = SIMPLE_HASTAGAT1; + (yyval.args).args[0] = 0; + (yyval.args).args[1] = (yyvsp[-2].val); + (yyval.args).args[2] = (yyvsp[0].val); + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 70: #line 398 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT1; - yyval.args.args[0] = 0; - yyval.args.args[1] = yyvsp[-4].val; - yyval.args.args[2] = yyvsp[-2].val; - yyval.args.args[3] = yyvsp[0].val; - yyval.args.args[4] = 0; - ; - break;} -case 70: + { + (yyval.args).addflags = SIMPLE_HASTAGAT1; + (yyval.args).args[0] = 0; + (yyval.args).args[1] = (yyvsp[-4].val); + (yyval.args).args[2] = (yyvsp[-2].val); + (yyval.args).args[3] = (yyvsp[0].val); + (yyval.args).args[4] = 0; + ;} + break; + + case 71: #line 407 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT1; - yyval.args.args[0] = 0; - yyval.args.args[1] = yyvsp[-6].val; - yyval.args.args[2] = yyvsp[-4].val; - yyval.args.args[3] = yyvsp[-2].val; - yyval.args.args[4] = yyvsp[0].val; - ; - break;} -case 71: + { + (yyval.args).addflags = SIMPLE_HASTAGAT1; + (yyval.args).args[0] = 0; + (yyval.args).args[1] = (yyvsp[-6].val); + (yyval.args).args[2] = (yyvsp[-4].val); + (yyval.args).args[3] = (yyvsp[-2].val); + (yyval.args).args[4] = (yyvsp[0].val); + ;} + break; + + case 72: #line 417 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HAS2TAGS; - yyval.args.args[0] = yyval.args.args[1] = 0; - yyval.args.args[2] = 0; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 72: + { + (yyval.args).addflags = SIMPLE_HAS2TAGS; + (yyval.args).args[0] = (yyval.args).args[1] = 0; + (yyval.args).args[2] = 0; + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 73: #line 425 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HAS2TAGS; - yyval.args.args[0] = yyval.args.args[1] = 0; - yyval.args.args[2] = yyvsp[0].val; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 73: + { + (yyval.args).addflags = SIMPLE_HAS2TAGS; + (yyval.args).args[0] = (yyval.args).args[1] = 0; + (yyval.args).args[2] = (yyvsp[0].val); + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 74: #line 433 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HAS2TAGS; - yyval.args.args[0] = yyval.args.args[1] = 0; - yyval.args.args[2] = yyvsp[-2].val; - yyval.args.args[3] = yyvsp[0].val; - yyval.args.args[4] = 0; - ; - break;} -case 74: + { + (yyval.args).addflags = SIMPLE_HAS2TAGS; + (yyval.args).args[0] = (yyval.args).args[1] = 0; + (yyval.args).args[2] = (yyvsp[-2].val); + (yyval.args).args[3] = (yyvsp[0].val); + (yyval.args).args[4] = 0; + ;} + break; + + case 75: #line 441 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HAS2TAGS; - yyval.args.args[0] = yyval.args.args[1] = 0; - yyval.args.args[2] = yyvsp[-4].val; - yyval.args.args[3] = yyvsp[-2].val; - yyval.args.args[4] = yyvsp[0].val; - ; - break;} -case 75: + { + (yyval.args).addflags = SIMPLE_HAS2TAGS; + (yyval.args).args[0] = (yyval.args).args[1] = 0; + (yyval.args).args[2] = (yyvsp[-4].val); + (yyval.args).args[3] = (yyvsp[-2].val); + (yyval.args).args[4] = (yyvsp[0].val); + ;} + break; + + case 76: #line 450 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASLINEID; - memset (yyval.args.args, 0, 5); - ; - break;} -case 76: + { + (yyval.args).addflags = SIMPLE_HASLINEID; + memset ((yyval.args).args, 0, 5); + ;} + break; + + case 77: #line 455 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASLINEID; - yyval.args.args[0] = 0; - yyval.args.args[1] = yyvsp[0].val; - yyval.args.args[2] = 0; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 77: + { + (yyval.args).addflags = SIMPLE_HASLINEID; + (yyval.args).args[0] = 0; + (yyval.args).args[1] = (yyvsp[0].val); + (yyval.args).args[2] = 0; + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 78: #line 464 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASLINEID; - yyval.args.args[0] = 0; - yyval.args.args[1] = yyvsp[-2].val; - yyval.args.args[2] = yyvsp[0].val; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 78: + { + (yyval.args).addflags = SIMPLE_HASLINEID; + (yyval.args).args[0] = 0; + (yyval.args).args[1] = (yyvsp[-2].val); + (yyval.args).args[2] = (yyvsp[0].val); + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 79: #line 473 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASLINEID; - yyval.args.args[0] = 0; - yyval.args.args[1] = yyvsp[-4].val; - yyval.args.args[2] = yyvsp[-2].val; - yyval.args.args[3] = yyvsp[0].val; - yyval.args.args[4] = 0; - ; - break;} -case 79: + { + (yyval.args).addflags = SIMPLE_HASLINEID; + (yyval.args).args[0] = 0; + (yyval.args).args[1] = (yyvsp[-4].val); + (yyval.args).args[2] = (yyvsp[-2].val); + (yyval.args).args[3] = (yyvsp[0].val); + (yyval.args).args[4] = 0; + ;} + break; + + case 80: #line 482 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASLINEID; - yyval.args.args[0] = 0; - yyval.args.args[1] = yyvsp[-6].val; - yyval.args.args[2] = yyvsp[-4].val; - yyval.args.args[3] = yyvsp[-2].val; - yyval.args.args[4] = yyvsp[0].val; - ; - break;} -case 80: + { + (yyval.args).addflags = SIMPLE_HASLINEID; + (yyval.args).args[0] = 0; + (yyval.args).args[1] = (yyvsp[-6].val); + (yyval.args).args[2] = (yyvsp[-4].val); + (yyval.args).args[3] = (yyvsp[-2].val); + (yyval.args).args[4] = (yyvsp[0].val); + ;} + break; + + case 81: #line 492 "xlat-parse.y" -{ - yyval.args.addflags = 0; - yyval.args.args[0] = yyvsp[0].val; - yyval.args.args[1] = 0; - yyval.args.args[2] = 0; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 81: + { + (yyval.args).addflags = 0; + (yyval.args).args[0] = (yyvsp[0].val); + (yyval.args).args[1] = 0; + (yyval.args).args[2] = 0; + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 82: #line 501 "xlat-parse.y" -{ - yyval.args.addflags = 0; - yyval.args.args[0] = yyvsp[-2].val; - yyval.args.args[1] = yyvsp[0].val; - yyval.args.args[2] = 0; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 82: + { + (yyval.args).addflags = 0; + (yyval.args).args[0] = (yyvsp[-2].val); + (yyval.args).args[1] = (yyvsp[0].val); + (yyval.args).args[2] = 0; + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 83: #line 510 "xlat-parse.y" -{ - yyval.args.addflags = 0; - yyval.args.args[0] = yyvsp[-4].val; - yyval.args.args[1] = yyvsp[-2].val; - yyval.args.args[2] = yyvsp[0].val; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 83: + { + (yyval.args).addflags = 0; + (yyval.args).args[0] = (yyvsp[-4].val); + (yyval.args).args[1] = (yyvsp[-2].val); + (yyval.args).args[2] = (yyvsp[0].val); + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 84: #line 519 "xlat-parse.y" -{ - yyval.args.addflags = 0; - yyval.args.args[0] = yyvsp[-6].val; - yyval.args.args[1] = yyvsp[-4].val; - yyval.args.args[2] = yyvsp[-2].val; - yyval.args.args[3] = yyvsp[0].val; - yyval.args.args[4] = 0; - ; - break;} -case 84: + { + (yyval.args).addflags = 0; + (yyval.args).args[0] = (yyvsp[-6].val); + (yyval.args).args[1] = (yyvsp[-4].val); + (yyval.args).args[2] = (yyvsp[-2].val); + (yyval.args).args[3] = (yyvsp[0].val); + (yyval.args).args[4] = 0; + ;} + break; + + case 85: #line 528 "xlat-parse.y" -{ - yyval.args.addflags = 0; - yyval.args.args[0] = yyvsp[-8].val; - yyval.args.args[1] = yyvsp[-6].val; - yyval.args.args[2] = yyvsp[-4].val; - yyval.args.args[3] = yyvsp[-2].val; - yyval.args.args[4] = yyvsp[0].val; - ; - break;} -case 85: + { + (yyval.args).addflags = 0; + (yyval.args).args[0] = (yyvsp[-8].val); + (yyval.args).args[1] = (yyvsp[-6].val); + (yyval.args).args[2] = (yyvsp[-4].val); + (yyval.args).args[3] = (yyvsp[-2].val); + (yyval.args).args[4] = (yyvsp[0].val); + ;} + break; + + case 86: #line 538 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT2; - yyval.args.args[0] = yyvsp[-2].val; - yyval.args.args[1] = 0; - yyval.args.args[2] = 0; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 86: + { + (yyval.args).addflags = SIMPLE_HASTAGAT2; + (yyval.args).args[0] = (yyvsp[-2].val); + (yyval.args).args[1] = 0; + (yyval.args).args[2] = 0; + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 87: #line 547 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT2; - yyval.args.args[0] = yyvsp[-4].val; - yyval.args.args[1] = 0; - yyval.args.args[2] = yyvsp[0].val; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 87: + { + (yyval.args).addflags = SIMPLE_HASTAGAT2; + (yyval.args).args[0] = (yyvsp[-4].val); + (yyval.args).args[1] = 0; + (yyval.args).args[2] = (yyvsp[0].val); + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 88: #line 556 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT2; - yyval.args.args[0] = yyvsp[-6].val; - yyval.args.args[1] = 0; - yyval.args.args[2] = yyvsp[-2].val; - yyval.args.args[3] = yyvsp[0].val; - yyval.args.args[4] = 0; - ; - break;} -case 88: + { + (yyval.args).addflags = SIMPLE_HASTAGAT2; + (yyval.args).args[0] = (yyvsp[-6].val); + (yyval.args).args[1] = 0; + (yyval.args).args[2] = (yyvsp[-2].val); + (yyval.args).args[3] = (yyvsp[0].val); + (yyval.args).args[4] = 0; + ;} + break; + + case 89: #line 565 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT2; - yyval.args.args[0] = yyvsp[-8].val; - yyval.args.args[1] = 0; - yyval.args.args[2] = yyvsp[-4].val; - yyval.args.args[3] = yyvsp[-2].val; - yyval.args.args[4] = yyvsp[0].val; - ; - break;} -case 89: + { + (yyval.args).addflags = SIMPLE_HASTAGAT2; + (yyval.args).args[0] = (yyvsp[-8].val); + (yyval.args).args[1] = 0; + (yyval.args).args[2] = (yyvsp[-4].val); + (yyval.args).args[3] = (yyvsp[-2].val); + (yyval.args).args[4] = (yyvsp[0].val); + ;} + break; + + case 90: #line 575 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT3; - yyval.args.args[0] = yyvsp[-4].val; - yyval.args.args[1] = yyvsp[-2].val; - yyval.args.args[2] = 0; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 90: + { + (yyval.args).addflags = SIMPLE_HASTAGAT3; + (yyval.args).args[0] = (yyvsp[-4].val); + (yyval.args).args[1] = (yyvsp[-2].val); + (yyval.args).args[2] = 0; + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 91: #line 584 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT3; - yyval.args.args[0] = yyvsp[-6].val; - yyval.args.args[1] = yyvsp[-4].val; - yyval.args.args[2] = 0; - yyval.args.args[3] = yyvsp[0].val; - yyval.args.args[4] = 0; - ; - break;} -case 91: + { + (yyval.args).addflags = SIMPLE_HASTAGAT3; + (yyval.args).args[0] = (yyvsp[-6].val); + (yyval.args).args[1] = (yyvsp[-4].val); + (yyval.args).args[2] = 0; + (yyval.args).args[3] = (yyvsp[0].val); + (yyval.args).args[4] = 0; + ;} + break; + + case 92: #line 593 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT3; - yyval.args.args[0] = yyvsp[-8].val; - yyval.args.args[1] = yyvsp[-6].val; - yyval.args.args[2] = 0; - yyval.args.args[3] = yyvsp[-2].val; - yyval.args.args[4] = yyvsp[0].val; - ; - break;} -case 92: + { + (yyval.args).addflags = SIMPLE_HASTAGAT3; + (yyval.args).args[0] = (yyvsp[-8].val); + (yyval.args).args[1] = (yyvsp[-6].val); + (yyval.args).args[2] = 0; + (yyval.args).args[3] = (yyvsp[-2].val); + (yyval.args).args[4] = (yyvsp[0].val); + ;} + break; + + case 93: #line 603 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT4; - yyval.args.args[0] = yyvsp[-6].val; - yyval.args.args[1] = yyvsp[-4].val; - yyval.args.args[2] = yyvsp[-2].val; - yyval.args.args[3] = 0; - yyval.args.args[4] = 0; - ; - break;} -case 93: + { + (yyval.args).addflags = SIMPLE_HASTAGAT4; + (yyval.args).args[0] = (yyvsp[-6].val); + (yyval.args).args[1] = (yyvsp[-4].val); + (yyval.args).args[2] = (yyvsp[-2].val); + (yyval.args).args[3] = 0; + (yyval.args).args[4] = 0; + ;} + break; + + case 94: #line 612 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT4; - yyval.args.args[0] = yyvsp[-8].val; - yyval.args.args[1] = yyvsp[-6].val; - yyval.args.args[2] = yyvsp[-4].val; - yyval.args.args[3] = 0; - yyval.args.args[4] = yyvsp[0].val; - ; - break;} -case 94: + { + (yyval.args).addflags = SIMPLE_HASTAGAT4; + (yyval.args).args[0] = (yyvsp[-8].val); + (yyval.args).args[1] = (yyvsp[-6].val); + (yyval.args).args[2] = (yyvsp[-4].val); + (yyval.args).args[3] = 0; + (yyval.args).args[4] = (yyvsp[0].val); + ;} + break; + + case 95: #line 622 "xlat-parse.y" -{ - yyval.args.addflags = SIMPLE_HASTAGAT5; - yyval.args.args[0] = yyvsp[-8].val; - yyval.args.args[1] = yyvsp[-6].val; - yyval.args.args[2] = yyvsp[-4].val; - yyval.args.args[3] = yyvsp[-2].val; - yyval.args.args[4] = 0; - ; - break;} -} - /* the action file gets copied in in place of this dollarsign */ -#line 543 "/usr/local/share/bison.simple" + { + (yyval.args).addflags = SIMPLE_HASTAGAT5; + (yyval.args).args[0] = (yyvsp[-8].val); + (yyval.args).args[1] = (yyvsp[-6].val); + (yyval.args).args[2] = (yyvsp[-4].val); + (yyval.args).args[3] = (yyvsp[-2].val); + (yyval.args).args[4] = 0; + ;} + break; + + + default: break; + } + +/* Line 1126 of yacc.c. */ +#line 2059 "xlat-parse.tab.c" yyvsp -= yylen; yyssp -= yylen; -#ifdef YYLSP_NEEDED - yylsp -= yylen; -#endif -#if YYDEBUG != 0 - if (yydebug) - { - short *ssp1 = yyss - 1; - fprintf (stderr, "state stack now"); - while (ssp1 != yyssp) - fprintf (stderr, " %d", *++ssp1); - fprintf (stderr, "\n"); - } -#endif + + YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; -#ifdef YYLSP_NEEDED - yylsp++; - if (yylen == 0) - { - yylsp->first_line = yylloc.first_line; - yylsp->first_column = yylloc.first_column; - yylsp->last_line = (yylsp-1)->last_line; - yylsp->last_column = (yylsp-1)->last_column; - yylsp->text = 0; - } - else - { - yylsp->last_line = (yylsp+yylen-1)->last_line; - yylsp->last_column = (yylsp+yylen-1)->last_column; - } -#endif - /* Now "shift" the result of the reduction. - Determine what state that goes to, - based on the state we popped back to - and the rule number reduced by. */ + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ yyn = yyr1[yyn]; - yystate = yypgoto[yyn - YYNTBASE] + *yyssp; - if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else - yystate = yydefgoto[yyn - YYNTBASE]; + yystate = yydefgoto[yyn - YYNTOKENS]; goto yynewstate; -yyerrlab: /* here on detecting error */ - if (! yyerrstatus) - /* If not already recovering from an error, report this error. */ +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) { ++yynerrs; - -#ifdef YYERROR_VERBOSE +#if YYERROR_VERBOSE yyn = yypact[yystate]; - if (yyn > YYFLAG && yyn < YYLAST) + if (YYPACT_NINF < yyn && yyn < YYLAST) { - int size = 0; - char *msg; - int x, count; + int yytype = YYTRANSLATE (yychar); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + char *yymsg = 0; +# define YYERROR_VERBOSE_ARGS_MAXIMUM 5 + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; - count = 0; - /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ - for (x = (yyn < 0 ? -yyn : 0); - x < (sizeof(yytname) / sizeof(char *)); x++) - if (yycheck[x + yyn] == x) - size += strlen(yytname[x]) + 15, count++; - msg = (char *) malloc(size + 15); - if (msg != 0) +#if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +#endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= yysize1 < yysize; + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= yysize1 < yysize; + yysize = yysize1; + + if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM) + yymsg = (char *) YYSTACK_ALLOC (yysize); + if (yymsg) { - strcpy(msg, "parse error"); - - if (count < 5) + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yymsg; + int yyi = 0; + while ((*yyp = *yyf)) { - count = 0; - for (x = (yyn < 0 ? -yyn : 0); - x < (sizeof(yytname) / sizeof(char *)); x++) - if (yycheck[x + yyn] == x) - { - strcat(msg, count == 0 ? ", expecting `" : " or `"); - strcat(msg, yytname[x]); - strcat(msg, "'"); - count++; - } + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } } - yyerror(msg); - free(msg); + yyerror (yymsg); + YYSTACK_FREE (yymsg); } else - yyerror ("parse error; also virtual memory exceeded"); + { + yyerror (YY_("syntax error")); + goto yyexhaustedlab; + } } else #endif /* YYERROR_VERBOSE */ - yyerror("parse error"); + yyerror (YY_("syntax error")); } - goto yyerrlab1; -yyerrlab1: /* here on error raised explicitly by an action */ + if (yyerrstatus == 3) { - /* if just tried and failed to reuse lookahead token after an error, discard it. */ + /* If just tried and failed to reuse look-ahead token after an + error, discard it. */ - /* return failure if at end of input */ - if (yychar == YYEOF) + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse look-ahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (0) + goto yyerrorlab; + +yyvsp -= yylen; + yyssp -= yylen; + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) YYABORT; -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); -#endif - yychar = YYEMPTY; + yydestruct ("Error: popping", yystos[yystate], yyvsp); + YYPOPSTACK; + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); } - /* Else will try to reuse lookahead token - after shifting the error token. */ - - yyerrstatus = 3; /* Each real token shifted decrements this */ - - goto yyerrhandle; - -yyerrdefault: /* current state does not do anything special for the error token. */ - -#if 0 - /* This is wrong; only states that explicitly want error tokens - should shift them. */ - yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/ - if (yyn) goto yydefault; -#endif - -yyerrpop: /* pop the current state because it cannot handle the error token */ - - if (yyssp == yyss) YYABORT; - yyvsp--; - yystate = *--yyssp; -#ifdef YYLSP_NEEDED - yylsp--; -#endif - -#if YYDEBUG != 0 - if (yydebug) - { - short *ssp1 = yyss - 1; - fprintf (stderr, "Error: state stack now"); - while (ssp1 != yyssp) - fprintf (stderr, " %d", *++ssp1); - fprintf (stderr, "\n"); - } -#endif - -yyerrhandle: - - yyn = yypact[yystate]; - if (yyn == YYFLAG) - goto yyerrdefault; - - yyn += YYTERROR; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) - goto yyerrdefault; - - yyn = yytable[yyn]; - if (yyn < 0) - { - if (yyn == YYFLAG) - goto yyerrpop; - yyn = -yyn; - goto yyreduce; - } - else if (yyn == 0) - goto yyerrpop; - if (yyn == YYFINAL) YYACCEPT; -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Shifting error token, "); -#endif - *++yyvsp = yylval; -#ifdef YYLSP_NEEDED - *++yylsp = yylloc; -#endif + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; - yyacceptlab: - /* YYACCEPT comes here. */ - if (yyfree_stacks) - { - free (yyss); - free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif - } - return 0; - yyabortlab: - /* YYABORT comes here. */ - if (yyfree_stacks) - { - free (yyss); - free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#ifndef yyoverflow +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ #endif + +yyreturn: + if (yychar != YYEOF && yychar != YYEMPTY) + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp); + YYPOPSTACK; } - return 1; +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif + return yyresult; } + + #line 632 "xlat-parse.y" @@ -1970,3 +2544,5 @@ int yyerror (char *s) printf ("%s\n", s); return 0; } + +