mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2025-01-18 13:11:37 +00:00
- 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)
This commit is contained in:
parent
3aa1c6c361
commit
43abfba723
67 changed files with 18740 additions and 22425 deletions
|
@ -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
|
||||
|
||||
|
|
27
ccdv-win32.c
27
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++;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<FBaseCVar *> &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<FBaseCVar *> &cvars, DWORD filter);
|
||||
|
||||
void C_DeinitConsole();
|
||||
|
||||
class FBoolCVar : public FBaseCVar
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -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;
|
||||
|
|
198
src/x64inlines.h
Normal file
198
src/x64inlines.h
Normal file
|
@ -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);
|
||||
}
|
|
@ -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 $@ $<
|
||||
|
|
568
tools/dehsupp/dehsupp.c
Normal file
568
tools/dehsupp/dehsupp.c
Normal file
|
@ -0,0 +1,568 @@
|
|||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <search.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#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 <infile> <outfile>\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);
|
||||
}
|
||||
}
|
124
tools/dehsupp/dehsupp.h
Normal file
124
tools/dehsupp/dehsupp.h
Normal file
|
@ -0,0 +1,124 @@
|
|||
#include <stdio.h>
|
||||
#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);
|
||||
|
|
@ -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)""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="0"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
DisableSpecificWarnings="4996"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/dehsupp.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="copy "$(TargetPath)" "$(ProjectDir)\$(TargetFileName)""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|x64"
|
||||
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
|
@ -206,7 +128,7 @@
|
|||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
|
@ -257,6 +179,85 @@
|
|||
CommandLine="copy "$(TargetPath)" "$(ProjectDir)\$(TargetFileName)""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="1"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
DisableSpecificWarnings="4996"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/dehsupp.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="copy "$(TargetPath)" "$(ProjectDir)\$(TargetFileName)""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|x64"
|
||||
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
|
@ -283,8 +284,9 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="1"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="0"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
|
@ -341,42 +343,30 @@
|
|||
</References>
|
||||
<Files>
|
||||
<File
|
||||
RelativePath=".\parse.tab.c"
|
||||
RelativePath=".\dehsupp.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dehsupp.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\parse.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="__STDC__=0"
|
||||
CompileAs="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="__STDC__=0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="__STDC__=0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="__STDC__=0"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\parse.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\parse.y"
|
||||
>
|
||||
|
@ -385,8 +375,9 @@
|
|||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="bison parse.y
"
|
||||
Outputs="parse.tab.c"
|
||||
Description="Creating parse.c from parse.y"
|
||||
CommandLine="..\lemon\lemon.exe -m -s "$(InputFileName)""
|
||||
Outputs="$(InputDir)parse.c"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
|
@ -394,8 +385,77 @@
|
|||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="bison parse.y
"
|
||||
Outputs="parse.tab.c"
|
||||
Description="Creating parse.c from parse.y"
|
||||
CommandLine="..\lemon\lemon.exe -m -s "$(InputFileName)""
|
||||
Outputs="$(InputDir)parse.c"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="Creating parse.c from parse.y"
|
||||
CommandLine="..\lemon\lemon.exe -s "$(InputFileName)""
|
||||
Outputs="$(InputDir)parse.c"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="Creating parse.c from parse.y"
|
||||
CommandLine="..\lemon\lemon.exe -m -s "$(InputFileName)""
|
||||
Outputs="$(InputDir)parse.c"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\scanner.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\scanner.re"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="Creating scanner.c from scanner.re"
|
||||
CommandLine="..\re2c\re2c -s -o "scanner.c" "$(InputFileName)""
|
||||
Outputs="$(InputDir)scanner.c"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="Creating scanner.c from scanner.re"
|
||||
CommandLine="..\re2c\re2c -s -o "scanner.c" "$(InputFileName)""
|
||||
Outputs="$(InputDir)scanner.c"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="Creating scanner.c from scanner.re"
|
||||
CommandLine="..\re2c\re2c -s -o "scanner.c" "$(InputFileName)""
|
||||
Outputs="$(InputDir)scanner.c"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="Creating scanner.c from scanner.re"
|
||||
CommandLine="..\re2c\re2c -s -o "scanner.c" "$(InputFileName)""
|
||||
Outputs="$(InputDir)scanner.c"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
|
|
1258
tools/dehsupp/parse.c
Normal file
1258
tools/dehsupp/parse.c
Normal file
File diff suppressed because it is too large
Load diff
34
tools/dehsupp/parse.h
Normal file
34
tools/dehsupp/parse.h
Normal file
|
@ -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
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
1085
tools/dehsupp/scanner.c
Normal file
1085
tools/dehsupp/scanner.c
Normal file
File diff suppressed because it is too large
Load diff
176
tools/dehsupp/scanner.re
Normal file
176
tools/dehsupp/scanner.re
Normal file
|
@ -0,0 +1,176 @@
|
|||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
9343
tools/lemon/lemon.c
9343
tools/lemon/lemon.c
File diff suppressed because it is too large
Load diff
|
@ -43,15 +43,16 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="1"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="0"
|
||||
RuntimeLibrary="2"
|
||||
RuntimeLibrary="3"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="0"
|
||||
DebugInformationFormat="4"
|
||||
CallingConvention="0"
|
||||
CompileAs="1"
|
||||
DisableSpecificWarnings="4996"
|
||||
|
@ -68,94 +69,11 @@
|
|||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/lemon.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="false"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="."
|
||||
IntermediateDirectory="Build"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="1"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="0"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="0"
|
||||
CallingConvention="0"
|
||||
CompileAs="1"
|
||||
DisableSpecificWarnings="4996"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/lemon.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeReferences="0"
|
||||
EnableCOMDATFolding="0"
|
||||
OptimizeForWindows98="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
|
@ -268,6 +186,89 @@
|
|||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="."
|
||||
IntermediateDirectory="Build"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="1"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="0"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="0"
|
||||
CallingConvention="0"
|
||||
CompileAs="1"
|
||||
DisableSpecificWarnings="4996"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/lemon.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|x64"
|
||||
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
|
@ -356,92 +357,74 @@
|
|||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
<File
|
||||
RelativePath=".\lemon.c"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\lemon.c"
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
DisableSpecificWarnings="4996"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lempar.c"
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
DisableSpecificWarnings="4996"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lemon.html"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lempar.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
/* First off, code is include which follows the "include" declaration
|
||||
** in the input file. */
|
||||
#include <stdio.h>
|
||||
#ifndef NDEBUG
|
||||
#include <string.h>
|
||||
#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);
|
||||
}
|
||||
|
|
141
tools/re2c/CHANGELOG
Normal file
141
tools/re2c/CHANGELOG
Normal file
|
@ -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 <max>\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.
|
||||
|
|
@ -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
|
|
@ -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:
|
|
@ -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 <packagedir>/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 <release>
|
||||
rpm -Uhv <packagedir>/re2c-0.9.3-<release>.rpm
|
||||
rpm -Uhv <packagedir>/re2c-0.10.3-<release>.rpm
|
||||
|
||||
Here <realease> should be a number like 1. And <packagedir> 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
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,165 +0,0 @@
|
|||
re2c Version @PACKAGE_VERSION@
|
||||
------------------
|
||||
|
||||
Originally written by Peter Bumbulis (peter@csg.uwaterloo.ca)
|
||||
|
||||
Currently maintained by:
|
||||
Dan Nuffer <nuffer at users.sourceforge.net>
|
||||
Marcus Boerger <helly at users.sourceforge.net>
|
||||
Hartmut Kaiser <hkaiser at users.sourceforge.net>
|
||||
|
||||
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 <release>
|
||||
rpm -Uhv <packagedir>/re2c-@PACKAGE_VERSION@-<release>.rpm
|
||||
|
||||
Here <realease> should be a number like 1. And <packagedir> 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.
|
||||
|
157
tools/re2c/aclocal.m4
vendored
157
tools/re2c/aclocal.m4
vendored
|
@ -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>>, <<[^ ]>>, <<>>), <<>>,
|
||||
<<test -z "<<$>>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>,
|
||||
<<am_indx=1
|
||||
for am_file in <<$1>>; 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([,]))])
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -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
|
||||
|
|
1713
tools/re2c/code.cc
1713
tools/re2c/code.cc
File diff suppressed because it is too large
Load diff
53
tools/re2c/code.h
Normal file
53
tools/re2c/code.h
Normal file
|
@ -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
|
|
@ -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 <inttypes.h> 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 <memory.h> 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 <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> 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 <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> 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 <unistd.h> 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 <sys/types.h> 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
|
|
@ -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 <inttypes.h> 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 <sys/types.h>
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> 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 <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
@ -35,7 +36,7 @@
|
|||
#define HAVE_STRDUP 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
@ -46,41 +47,29 @@
|
|||
/* Define to 1 if you have the <sys/types.h> 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 <unistd.h> 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 <sys/types.h> 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 */
|
7415
tools/re2c/configure
vendored
7415
tools/re2c/configure
vendored
File diff suppressed because it is too large
Load diff
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
386
tools/re2c/dfa.h
386
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 <iosfwd>
|
||||
#include <map>
|
||||
#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<uint, State*> 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
|
||||
|
|
340
tools/re2c/examples/push.re
Normal file
340
tools/re2c/examples/push.re
Normal file
|
@ -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 <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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<tokenNameSize ? 20 : tokenNameSize);
|
||||
for(size_t i=0; i<padSize; ++i) putchar(' ');
|
||||
printf(" : ---->");
|
||||
|
||||
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<maxFill)
|
||||
{
|
||||
eof = true;
|
||||
input = null;
|
||||
inputSize = sizeof(null);
|
||||
memset(null, 0, sizeof(null));
|
||||
}
|
||||
|
||||
/*
|
||||
* When we get here, we have a partially
|
||||
* consumed buffer which is in the following state:
|
||||
* last valid char last valid buffer spot
|
||||
* v v
|
||||
* +-------------------+-------------+---------------+-------------+----------------------+
|
||||
* ^ ^ ^ ^ ^ ^
|
||||
* buffer start marker cursor limit bufferEnd
|
||||
*
|
||||
* We need to stretch the buffer and concatenate the new chunk of input to it
|
||||
*
|
||||
*/
|
||||
size_t used = limit-buffer;
|
||||
size_t needed = used+inputSize;
|
||||
size_t allocated = bufferEnd-buffer;
|
||||
if(allocated<needed)
|
||||
{
|
||||
size_t limitOffset = limit-buffer;
|
||||
size_t startOffset = start-buffer;
|
||||
size_t markerOffset = marker-buffer;
|
||||
size_t cursorOffset = cursor-buffer;
|
||||
|
||||
buffer = (uint8_t*)realloc(buffer, needed);
|
||||
bufferEnd = needed+buffer;
|
||||
|
||||
marker = markerOffset + buffer;
|
||||
cursor = cursorOffset + buffer;
|
||||
start = buffer + startOffset;
|
||||
limit = limitOffset + buffer;
|
||||
}
|
||||
memcpy(limit, input, inputSize);
|
||||
limit += inputSize;
|
||||
|
||||
// The scanner starts here
|
||||
#define YYLIMIT limit
|
||||
#define YYCURSOR cursor
|
||||
#define YYMARKER marker
|
||||
#define YYCTYPE uint8_t
|
||||
|
||||
#define SKIP(x) { start = cursor; goto yy0; }
|
||||
#define SEND(x) { send(x); SKIP(); }
|
||||
#define YYFILL(n) { goto fill; }
|
||||
|
||||
#define YYGETSTATE() state
|
||||
#define YYSETSTATE(x) { state = (x); }
|
||||
|
||||
start:
|
||||
|
||||
/*!re2c
|
||||
|
||||
eol = "\n";
|
||||
eof = "\000";
|
||||
digit = [0-9];
|
||||
integer = digit+;
|
||||
alpha = [A-Za-z_];
|
||||
any = [\000-\0377];
|
||||
space = [ \h\t\v\f\r];
|
||||
|
||||
"if" { SEND(kIf); }
|
||||
"for" { SEND(kFor); }
|
||||
"else" { SEND(kElse); }
|
||||
"goto" { SEND(kGoto); }
|
||||
"break" { SEND(kBreak); }
|
||||
"while" { SEND(kWhile); }
|
||||
"return" { SEND(kReturn); }
|
||||
alpha (alpha|digit)* { SEND(kIdentifier); }
|
||||
integer { SEND(kDecimalConstant);}
|
||||
|
||||
"=" { SEND(kEqual); }
|
||||
"(" { SEND(kLeftParen); }
|
||||
")" { SEND(kRightParen); }
|
||||
"-" { SEND(kMinus); }
|
||||
"+" { SEND(kPlus); }
|
||||
"*" { SEND(kStar); }
|
||||
"/" { SEND(kSlash); }
|
||||
|
||||
eol { SKIP(); }
|
||||
space { SKIP(); }
|
||||
eof { send(kEOF); return 1; }
|
||||
any { SEND(kUnknown); }
|
||||
*/
|
||||
|
||||
fill:
|
||||
ssize_t unfinishedSize = cursor-start;
|
||||
printf(
|
||||
"scanner needs a refill. Exiting for now with:\n"
|
||||
" saved fill state = %d\n"
|
||||
" unfinished token size = %d\n",
|
||||
state,
|
||||
unfinishedSize
|
||||
);
|
||||
|
||||
if(0<unfinishedSize && start<limit)
|
||||
{
|
||||
printf(" unfinished token is :");
|
||||
fwrite(start, 1, cursor-start, stdout);
|
||||
putchar('\n');
|
||||
}
|
||||
putchar('\n');
|
||||
|
||||
/*
|
||||
* Once we get here, we can get rid of
|
||||
* everything before start and after limit.
|
||||
*/
|
||||
if(eof==true) goto start;
|
||||
if(buffer<start)
|
||||
{
|
||||
size_t startOffset = start-buffer;
|
||||
memmove(buffer, start, limit-start);
|
||||
marker -= startOffset;
|
||||
cursor -= startOffset;
|
||||
limit -= startOffset;
|
||||
start -= startOffset;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
int main(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
{
|
||||
// Parse cmd line
|
||||
int input = 0;
|
||||
if(1<argc)
|
||||
{
|
||||
input = open(argv[1], O_RDONLY | O_BINARY);
|
||||
if(input<0)
|
||||
{
|
||||
fprintf(
|
||||
stderr,
|
||||
"could not open file %s\n",
|
||||
argv[1]
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tokenize input file by pushing batches
|
||||
* of data one by one into the scanner.
|
||||
*/
|
||||
const size_t batchSize = 256;
|
||||
uint8_t buffer[batchSize];
|
||||
PushScanner scanner;
|
||||
while(1)
|
||||
{
|
||||
ssize_t n = read(input, buffer, batchSize);
|
||||
scanner.push(buffer, n);
|
||||
if(n<batchSize) break;
|
||||
}
|
||||
scanner.push(0, -1);
|
||||
close(input);
|
||||
|
||||
// Done
|
||||
return 0;
|
||||
}
|
||||
|
44
tools/re2c/examples/repeater.re
Normal file
44
tools/re2c/examples/repeater.re
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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");
|
||||
}
|
|
@ -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 <set>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#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<uint> 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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 <fstream>
|
||||
|
@ -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<uint> 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 = "<stdin>";
|
||||
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 = "<stdin>";
|
||||
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 = "<stdout>";
|
||||
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;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
#! /bin/sh
|
||||
|
||||
# $Id: makerpm.in,v 1.7 2004/04/19 23:31:34 helly Exp $
|
||||
# M.Boerger <re2c@somabo.de>
|
||||
|
||||
PREFIX="@PACKAGE_NAME@"
|
||||
VERSION="@PACKAGE_VERSION@"
|
||||
TARDIR="`basename \`pwd\``"
|
||||
RELEASE=${1:-1}
|
||||
|
||||
echo "Usage:"
|
||||
echo "$0 <release>"
|
||||
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}
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
Author: Marcus Boerger <helly@users.sourceforge.net>
|
||||
Author: Marcus Boerger <helly@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
/* $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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -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 -<arg> <val> or in the form -<arg><val> */
|
||||
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
|
||||
|
||||
|
|
|
@ -1,16 +1,34 @@
|
|||
/*
|
||||
Author: Marcus Boerger <helly@users.sourceforge.net>
|
||||
Author: Marcus Boerger <helly@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
/* $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
|
||||
|
||||
|
|
|
@ -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 <pinard@iro.umontreal.ca>, 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
|
|
@ -1,40 +0,0 @@
|
|||
#! /bin/sh
|
||||
# mkinstalldirs --- make directory hierarchy
|
||||
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
|
||||
# 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
|
File diff suppressed because it is too large
Load diff
|
@ -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 <iosfwd>
|
||||
#include <map>
|
||||
|
||||
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<std::string, Symbol*> 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
|
||||
|
|
|
@ -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 <op> CLOSE
|
||||
%type <op> close
|
||||
|
@ -67,6 +75,8 @@ static char* strdup(const char* s)
|
|||
%type <token> CODE
|
||||
%type <regexp> RANGE STRING
|
||||
%type <regexp> rule look expr diff term factor primary
|
||||
%type <str> CONFIG VALUE
|
||||
%type <number> 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( "<stdin>" );
|
||||
}
|
||||
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
|
||||
|
|
537
tools/re2c/re.h
537
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 <iostream>
|
||||
#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
|
||||
|
|
|
@ -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 <n>" 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
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<<EOF>>\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 <helly@users.sourceforge.net>
|
|||
.P
|
||||
Hartmut Kaiser <hkaiser@users.sourceforge.net>
|
||||
.P
|
||||
Emmanuel Mogenet <mgix@mgix.com> 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
|
||||
|
|
|
@ -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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#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<<EOF>>\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 <peter@csg.uwaterloo.ca>
|
||||
.P
|
||||
Brian Young <bayoung@acm.org>
|
||||
.P
|
||||
Dan Nuffer <nuffer@users.sourceforge.net>
|
||||
.P
|
||||
Marcus Boerger <helly@users.sourceforge.net>
|
||||
.P
|
||||
Hartmut Kaiser <hkaiser@users.sourceforge.net>
|
||||
.P
|
||||
.PD 1
|
||||
|
||||
.SH VERSION INFORMATION
|
||||
This manpage describes \fBre2c\fP, version @PACKAGE_VERSION@.
|
||||
|
||||
.fi
|
|
@ -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 <re2c@somabo.de>
|
||||
- Initial version.
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
%{_bindir}/re2c
|
||||
%{_mandir}/man1/re2c.1*
|
||||
|
||||
%doc README examples doc/*
|
|
@ -100,88 +100,6 @@
|
|||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="."
|
||||
IntermediateDirectory="Build"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="1"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="1"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="0"
|
||||
CallingConvention="0"
|
||||
DisableSpecificWarnings="4996"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/re2c.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|x64"
|
||||
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
|
@ -265,6 +183,88 @@
|
|||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="."
|
||||
IntermediateDirectory="Build"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="1"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="1"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="0"
|
||||
CallingConvention="0"
|
||||
DisableSpecificWarnings="4996"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/re2c.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|x64"
|
||||
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
|
@ -382,38 +382,86 @@
|
|||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\scanner.cc"
|
||||
RelativePath=".\parser.y"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
DisableSpecificWarnings="4101;4102"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
DisableSpecificWarnings="4101;4102"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
DisableSpecificWarnings="4101;4102"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
DisableSpecificWarnings="4101;4102"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\scanner.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\scanner.re"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
|
@ -435,6 +483,14 @@
|
|||
RelativePath=".\basics.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\code.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\config_w32.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dfa.h"
|
||||
>
|
||||
|
@ -463,6 +519,10 @@
|
|||
RelativePath=".\scanner.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stream_lc.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\substr.h"
|
||||
>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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 <iosfwd>
|
||||
#include <string>
|
||||
#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
|
||||
|
|
|
@ -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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#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
|
||||
|
||||
|
|
425
tools/re2c/stream_lc.h
Normal file
425
tools/re2c/stream_lc.h
Normal file
|
@ -0,0 +1,425 @@
|
|||
/*
|
||||
Author: Marcus Boerger <helly@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
/* $Id: stream_lc.h,v 1.10 2006/02/26 20:36:09 helly Exp $ */
|
||||
|
||||
#ifndef _stream_lc_h
|
||||
#define _stream_lc_h
|
||||
|
||||
#include <iosfwd>
|
||||
#include <fstream>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace re2c
|
||||
{
|
||||
|
||||
template<class _E, class _Tr = std::char_traits<_E> >
|
||||
class basic_null_streambuf
|
||||
: public std::basic_streambuf<_E, _Tr>
|
||||
{
|
||||
public:
|
||||
basic_null_streambuf()
|
||||
: std::basic_streambuf<_E, _Tr>()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
typedef basic_null_streambuf<char> null_streambuf;
|
||||
|
||||
template<class _E, class _Tr = std::char_traits<_E> >
|
||||
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<char> null_stream;
|
||||
|
||||
class line_number
|
||||
{
|
||||
public:
|
||||
virtual ~line_number()
|
||||
{
|
||||
}
|
||||
|
||||
virtual uint get_line() const = 0;
|
||||
};
|
||||
|
||||
template<class _E, class _Tr = std::char_traits<_E> >
|
||||
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<char> 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 _E, class _Tr = std::char_traits<_E> >
|
||||
class basic_ofstream_lc
|
||||
: public basic_fstream_lc<_E, std::basic_ostream<_E, _Tr>, std::ios_base::out, _Tr>
|
||||
{
|
||||
};
|
||||
|
||||
typedef basic_ofstream_lc<char> ofstream_lc;
|
||||
|
||||
template<class _E, class _Tr = std::char_traits<_E> >
|
||||
class basic_ifstream_lc
|
||||
: public basic_fstream_lc<_E, std::basic_istream<_E, _Tr>, std::ios_base::in, _Tr>
|
||||
{
|
||||
};
|
||||
|
||||
typedef basic_ifstream_lc<char> 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<std::string*>(&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 */
|
|
@ -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 <string.h>
|
||||
#include <stdlib.h>
|
||||
#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
|
||||
|
|
|
@ -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 <iostream>
|
||||
#include <string>
|
||||
#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
|
||||
|
|
|
@ -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"
|
|
@ -1,6 +0,0 @@
|
|||
/*!re2c
|
||||
digits = [0-9];
|
||||
|
||||
(digits+ | digits* "." digits+) ([dDeE] [+-]? digits+)? { return true; }
|
||||
[\000-\377] { return false; }
|
||||
*/
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue