adding CExpr

This commit is contained in:
tengel 2024-03-20 09:28:18 -05:00
parent 930fad877a
commit 9c91ee36d2
30 changed files with 10941 additions and 0 deletions

85
CExpr/CEXPR.CNT Normal file
View file

@ -0,0 +1,85 @@
:Base cexpr.hlp
1 Introduction
2 Introduction=topic0
2 Data file manipulation=topic1
2 Availability and location of CExpr=topic2
1 CExpr compilation
2 CExpr compilation=topic3
1 Bugs and future developments
2 Bugs and future developments=topic4
2 Bugs=topic5
2 Future developments=topic6
1 Tutorial
2 Tutorial=topic7
1 Class reference
2 Class reference=topic8
2 CExpr
3 CExpr=topic9
3 CExpr::CExpr=topic10
3 CExpr::~CExpr=topic11
3 CExpr::AddAttributeValue=topic12
3 CExpr::AddAttributeValueString=topic13
3 CExpr::AddAttributeValueStringList=topic14
3 CExpr::AddAttributeValueWord=topic15
3 CExpr::Append=topic16
3 CExpr::Arg=arg
3 CExpr::AttributeValue=topic17
3 CExpr::Copy=topic18
3 CExpr::DeleteAttributeValue
4 CExpr::DeleteAttributeValue=topic19
3 CExpr::Functor
4 CExpr::Functor=topic20
3 CExpr::GetAttributeValue
4 CExpr::GetAttributeValue=topic21
3 CExpr::GetAttributeValueStringList
4 CExpr::GetAttributeValueStringList=topic22
3 CExpr::GetClientData
4 CExpr::GetClientData=topic23
3 CExpr::GetFirst
4 CExpr::GetFirst=getfirst
3 CExpr::GetLast
4 CExpr::GetLast=getlast
3 CExpr::GetNext
4 CExpr::GetNext=getnext
3 CExpr::Insert
4 CExpr::Insert=topic24
3 CExpr::IntegerValue
4 CExpr::IntegerValue=topic25
3 CExpr::Nth
4 CExpr::Nth=nth
3 CExpr::RealValue
4 CExpr::RealValue=topic26
3 CExpr::SetClientData
4 CExpr::SetClientData=topic27
3 CExpr::StringValue
4 CExpr::StringValue=topic28
3 CExpr::Type
4 CExpr::Type=topic29
3 CExpr::WordValue
4 CExpr::WordValue=topic30
3 CExpr::WriteLispExpr
4 CExpr::WriteLispExpr=topic31
3 CExpr::WriteClause
4 CExpr::WriteClause=topic32
3 CExpr::WriteExpr
4 CExpr::WriteExpr=topic33
2 CExprDatabase: public wxList
3 CExprDatabase: public wxList=topic34
3 CExprDatabase::CExprDatabase=topic35
3 CExprDatabase::~CExprDatabase=topic36
3 CExprDatabase::Append=topic37
3 CExprDatabase::BeginFind=topic38
3 CExprDatabase::ClearDatabase=topic39
3 CExprDatabase::FindClause=topic40
3 CExprDatabase::FindClauseByFunctor=topic41
3 CExprDatabase::GetErrorCount=geterrorcount
3 CExprDatabase::HashFind=topic42
3 CExprDatabase::Read=databaseread
3 CExprDatabase::ReadFromString=topic43
3 CExprDatabase::Write=databasewrite
3 CExprDatabase::WriteLisp
4 CExprDatabase::WriteLisp=topic44
2 Macros
3 Macros=topic45
1 Change log
2 Change log=topic46

BIN
CExpr/CEXPR.HLP Normal file

Binary file not shown.

1229
CExpr/Cexpr.cpp Normal file

File diff suppressed because it is too large Load diff

134
CExpr/Cexpr.dsp Normal file
View file

@ -0,0 +1,134 @@
# Microsoft Developer Studio Project File - Name="cexpr" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 5.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=cexpr - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Cexpr.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Cexpr.mak" CFG="cexpr - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "cexpr - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "cexpr - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
!IF "$(CFG)" == "cexpr - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 1
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "USE_DEFINE" /D "YY_USE_PROTOS" /D "_MBCS" /FD /c
# SUBTRACT CPP /YX
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "cexpr - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\cexpr___"
# PROP BASE Intermediate_Dir ".\cexpr___"
# PROP BASE Target_Dir ""
# PROP Use_MFC 1
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "USE_DEFINE" /D "YY_USE_PROTOS" /D "_MBCS" /FD /c
# SUBTRACT CPP /YX
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "cexpr - Win32 Release"
# Name "cexpr - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\cexpr.cpp
# End Source File
# Begin Source File
SOURCE=.\wx_hash.cpp
# End Source File
# Begin Source File
SOURCE=.\wx_list.cpp
# End Source File
# Begin Source File
SOURCE=.\Y_tab.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
# Begin Source File
SOURCE=.\cexpr.h
# End Source File
# Begin Source File
SOURCE=.\expr.h
# End Source File
# Begin Source File
SOURCE=.\stdafx.h
# End Source File
# Begin Source File
SOURCE=.\wx_hash.h
# End Source File
# Begin Source File
SOURCE=.\wx_list.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# End Group
# Begin Source File
SOURCE=.\Lex_yy.c
# PROP BASE Exclude_From_Build 1
# PROP Exclude_From_Build 1
# End Source File
# End Target
# End Project

29
CExpr/Cexpr.dsw Normal file
View file

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 5.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "cexpr"=.\Cexpr.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

246
CExpr/Cexpr.h Normal file
View file

@ -0,0 +1,246 @@
/*
* File: cexpr.h
* Purpose: Prolog-like file I/O
* Author: Julian Smart
* Created: 1997
* Updated:
* Copyright: (c) 1997, Julian Smart
*/
/* sccsid[] = "%W% %G%" */
#ifndef __CEXPRH__
#define __CEXPRH__
#include <stdio.h>
#include <iostream.h>
#include "wx_list.h"
#include "wx_hash.h"
#include "expr.h"
// Error types
#define CEXPR_ERROR_GENERAL 1
#define CEXPR_ERROR_SYNTAX 2
// Error handler function definition. If app returns TRUE,
// carry on processing.
typedef BOOL (*CExprErrorHandler) (int errorType, char *msg);
extern CExprErrorHandler currentCExprErrorHandler;
extern "C" FILE *yyin;
//#ifndef __WATCOMC__
extern "C"
//#endif
int yyparse(void);
typedef enum {
CExprNull,
CExprInteger,
CExprReal,
CExprWord,
CExprString,
CExprList
} CExprType;
class CExprDatabase;
class ClipsTemplate;
class ClipsTemplateSlot;
class CExpr
{
public:
CObject *client_data;
CExprType type;
union {
long integer;
char *word;
char *string;
float real;
CExpr *first; // If is a list expr, points to the first node
} value;
CExpr *next; // If this is a node in a list, points to the next node
CExpr *last; // If is a list expr, points to the last node
CExpr(CExprType the_type, char *word_or_string, BOOL allocate);
CExpr(const CString& functor); // Assume this is a new clause - pass functor
CExpr(CExprType the_type, const CString& word_or_string = "");
CExpr(long the_integer);
CExpr(float the_real);
CExpr(wxList *the_list);
~CExpr(void);
inline CExprType Type(void) { return type; }
inline long IntegerValue(void)
{
if (type == CExprInteger)
return value.integer;
else if (type == CExprReal)
return (long)value.real;
else return 0;
}
inline float RealValue(void) {
if (type == CExprReal)
return value.real;
else if (type == CExprInteger)
return (float)value.integer;
else return (float)0.0;
}
inline CString WordValue(void) {
if (type == CExprWord)
return value.word;
else if (type == CExprString)
return CString(value.string);
else return CString("");
}
inline CString StringValue(void) {
if (type == CExprString)
return CString(value.string);
else if (type == CExprWord)
return CString(value.word);
else return CString("");
}
// Get nth arg of clause (starting from 1)
CExpr *Arg(CExprType type, int arg);
// Return nth argument of a list expression (starting from zero)
CExpr *Nth(int arg);
// Returns the number of elements in a list expression
int Number(void);
CExpr *Copy(void);
CExpr *GetAttributeValueNode(const CString& word); // Use only for a clause or list
CExpr *AttributeValue(const CString& word); // Use only for a clause
CString Functor(void); // Only for a clause
BOOL IsFunctor(const CString& s); // Only for a clause
void WriteClause(ostream& stream); // Write this expression as a top-level clause
void WriteExpr(ostream& stream); // Write as any other subexpression
void WriteLispExpr(ostream& stream);
void WriteClipsClause(ostream& stream, BOOL filtering = FALSE,
CExprDatabase *database = NULL);
void WriteClipsSlot(ostream& stream, ClipsTemplate *temp);
void WriteClipsList(ostream& stream);
// Append an expression to a list
void Append(CExpr *expr);
// Insert at beginning of list
void Insert(CExpr *expr);
// Get first expr in list
inline CExpr *GetFirst(void) { return ((type == CExprList) ? value.first : NULL); }
// Get next expr if this is a node in a list
inline CExpr *GetNext(void) { return next; }
// Get last expr in list
inline CExpr *GetLast(void) { return ((type == CExprList) ? last : NULL); }
// This should really be called SetAttributeValue since any existing
// attribute-value is deleted first.
void AddAttributeValue(const CString& attribute, long value);
void AddAttributeValue(const CString& attribute, float value);
void AddAttributeValueWord(const CString& attribute, const CString& value);
void AddAttributeValueString(const CString& attribute, const CString& value);
void AddAttributeValue(const CString& attribute, wxList *value);
void AddAttributeValue(const CString& attribute, CExpr *value);
void AddAttributeValueStringList(const CString& attribute, wxList *string_list);
void DeleteAttributeValue(const CString& attribute);
BOOL GetAttributeValue(const CString& att, int& var);
BOOL GetAttributeValue(const CString& att, long& var);
BOOL GetAttributeValue(const CString& att, float& var);
BOOL GetAttributeValue(const CString& att, CString& var); // Word OR string -> string
BOOL GetAttributeValue(const CString& att, CExpr **var);
// Add string items to list if the list attribute exists
BOOL GetAttributeValueStringList(const CString& att, wxList *var);
// Associate other data with this expression, e.g. when reading in a
// number of linked items - store C++ object pointer with the expression
// so we can index into the CExpr database and fish out the pointer.
inline void SetClientData(CObject *data) { client_data = data; }
inline CObject *GetClientData(void) { return client_data; }
};
class CExprDatabase: public wxList
{
DECLARE_DYNAMIC(CExprDatabase)
private:
wxNode *position; // Where we are in a search
wxHashTable *hash_table;
CString attribute_to_hash;
public:
int noErrors;
CExprDatabase(CExprErrorHandler handler = 0);
// Use hashing on both the functor, and the attribute of
// specified type (CExprString or CExprInteger) and name.
// So to find node 45
// (i.e. match the clause node(id=45, ...))
// it usually requires 1 look-up: the keys for functor and attribute
// are added together.
// Obviously if the attribute was missing in a clause, it would
// fail to be found by this method, but could be retrieved by a
// linear search using BeginFind and FindClauseByFunctor,
// or just searching through the list as per usual.
CExprDatabase(CExprType type, const CString& attribute, int size = 500,
CExprErrorHandler handler = 0);
~CExprDatabase(void);
int GetItemCount(void); // get count of possible items
void BeginFind(void); // Initialise a search
CExpr *FindClause(long id); // Find a term based on an integer id attribute
// e.g. node(id=23, type=rectangle, ....).
// Find on basis of attribute/value pairs, e.g. type=rectangle
// This doesn't use hashing; it's a linear search.
CExpr *FindClause(const CString& word, const CString& value);
CExpr *FindClause(const CString& word, long value);
CExpr *FindClause(const CString& word, float value);
CExpr *FindClauseByFunctor(const CString& functor);
CExpr *HashFind(const CString& functor, const CString& value);
CExpr *HashFind(const CString& functor, long value);
void Append(CExpr *expr); // Does cleverer things if hashing is on
void ClearDatabase(void);
inline int GetErrorCount() { return noErrors; }
BOOL Read(const CString& filename);
BOOL ReadFromString(const CString& buffer);
BOOL Write(const CString& fileName);
BOOL Write(ostream& stream);
void WriteLisp(ostream& stream);
};
// Function call-style interface - some more convenience wrappers/unwrappers
// Make a call
CExpr *CExprMakeCall(const CString& functor ...);
#define CExprMakeInteger(x) (new CExpr((long)x))
#define CExprMakeReal(x) (new CExpr((float)x))
#define CExprMakeString(x) (new CExpr(CExprString, x))
#define CExprMakeWord(x) (new CExpr(CExprWord, x))
#define CExprMake(x) (new CExpr(x))
// Checks functor
BOOL CExprIsFunctor(CExpr *expr, const CString& functor);
// Temporary variable for communicating between read.cc and YACC/LEX
extern CExprDatabase *theCExprDatabase;
// YACC/LEX can leave memory lying around...
extern "C" CExprCleanUp();
#endif

234
CExpr/Cexpr.mak Normal file
View file

@ -0,0 +1,234 @@
# Microsoft Developer Studio Generated NMAKE File, Format Version 4.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
!IF "$(CFG)" == ""
CFG=cexpr - Win32 Debug
!MESSAGE No configuration specified. Defaulting to cexpr - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "cexpr - Win32 Release" && "$(CFG)" != "cexpr - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE on this makefile
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Cexpr.mak" CFG="cexpr - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "cexpr - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "cexpr - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
################################################################################
# Begin Project
# PROP Target_Last_Scanned "cexpr - Win32 Debug"
CPP=cl.exe
!IF "$(CFG)" == "cexpr - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 2
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
OUTDIR=.\Release
INTDIR=.\Release
ALL : "$(OUTDIR)\Cexpr.lib"
CLEAN :
-@erase ".\Release\Cexpr.lib"
-@erase ".\Release\wx_hash.obj"
-@erase ".\Release\cexpr.obj"
-@erase ".\Release\wx_list.obj"
-@erase ".\Release\Y_tab.obj"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "USE_DEFINE" /D "YY_USE_PROTOS" /D "_AFXDLL" /D "_MBCS" /c
# SUBTRACT CPP /YX
CPP_PROJ=/nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D\
"USE_DEFINE" /D "YY_USE_PROTOS" /D "_AFXDLL" /D "_MBCS" /Fo"$(INTDIR)/" /c
CPP_OBJS=.\Release/
CPP_SBRS=
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
BSC32_FLAGS=/nologo /o"$(OUTDIR)/Cexpr.bsc"
BSC32_SBRS=
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
LIB32_FLAGS=/nologo /out:"$(OUTDIR)/Cexpr.lib"
LIB32_OBJS= \
"$(INTDIR)/wx_hash.obj" \
"$(INTDIR)/cexpr.obj" \
"$(INTDIR)/wx_list.obj" \
"$(INTDIR)/Y_tab.obj"
"$(OUTDIR)\Cexpr.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
$(LIB32) @<<
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
<<
!ELSEIF "$(CFG)" == "cexpr - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "cexpr___"
# PROP BASE Intermediate_Dir "cexpr___"
# PROP BASE Target_Dir ""
# PROP Use_MFC 2
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
OUTDIR=.\Debug
INTDIR=.\Debug
ALL : "$(OUTDIR)\Cexpr.lib"
CLEAN :
-@erase ".\Debug\Cexpr.lib"
-@erase ".\Debug\wx_list.obj"
-@erase ".\Debug\cexpr.obj"
-@erase ".\Debug\wx_hash.obj"
-@erase ".\Debug\Y_tab.obj"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MDd /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "USE_DEFINE" /D "YY_USE_PROTOS" /D "_AFXDLL" /D "_MBCS" /c
# SUBTRACT CPP /YX
CPP_PROJ=/nologo /MDd /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D\
"USE_DEFINE" /D "YY_USE_PROTOS" /D "_AFXDLL" /D "_MBCS" /Fo"$(INTDIR)/" /c
CPP_OBJS=.\Debug/
CPP_SBRS=
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
BSC32_FLAGS=/nologo /o"$(OUTDIR)/Cexpr.bsc"
BSC32_SBRS=
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
LIB32_FLAGS=/nologo /out:"$(OUTDIR)/Cexpr.lib"
LIB32_OBJS= \
"$(INTDIR)/wx_list.obj" \
"$(INTDIR)/cexpr.obj" \
"$(INTDIR)/wx_hash.obj" \
"$(INTDIR)/Y_tab.obj"
"$(OUTDIR)\Cexpr.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
$(LIB32) @<<
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
<<
!ENDIF
.c{$(CPP_OBJS)}.obj:
$(CPP) $(CPP_PROJ) $<
.cpp{$(CPP_OBJS)}.obj:
$(CPP) $(CPP_PROJ) $<
.cxx{$(CPP_OBJS)}.obj:
$(CPP) $(CPP_PROJ) $<
.c{$(CPP_SBRS)}.sbr:
$(CPP) $(CPP_PROJ) $<
.cpp{$(CPP_SBRS)}.sbr:
$(CPP) $(CPP_PROJ) $<
.cxx{$(CPP_SBRS)}.sbr:
$(CPP) $(CPP_PROJ) $<
################################################################################
# Begin Target
# Name "cexpr - Win32 Release"
# Name "cexpr - Win32 Debug"
!IF "$(CFG)" == "cexpr - Win32 Release"
!ELSEIF "$(CFG)" == "cexpr - Win32 Debug"
!ENDIF
################################################################################
# Begin Source File
SOURCE=.\wx_hash.cpp
DEP_CPP_WX_HA=\
".\stdafx.h"\
".\wx_list.h"\
".\wx_hash.h"\
"$(INTDIR)\wx_hash.obj" : $(SOURCE) $(DEP_CPP_WX_HA) "$(INTDIR)"
# End Source File
################################################################################
# Begin Source File
SOURCE=.\wx_list.cpp
DEP_CPP_WX_LI=\
".\stdafx.h"\
".\wx_list.h"\
"$(INTDIR)\wx_list.obj" : $(SOURCE) $(DEP_CPP_WX_LI) "$(INTDIR)"
# End Source File
################################################################################
# Begin Source File
SOURCE=.\cexpr.cpp
DEP_CPP_CEXPR=\
".\stdafx.h"\
".\expr.h"\
".\cexpr.h"\
".\wx_list.h"\
".\wx_hash.h"\
"$(INTDIR)\cexpr.obj" : $(SOURCE) $(DEP_CPP_CEXPR) "$(INTDIR)"
# End Source File
################################################################################
# Begin Source File
SOURCE=.\Y_tab.c
DEP_CPP_Y_TAB=\
".\expr.h"\
".\Lex_yy.c"\
"$(INTDIR)\Y_tab.obj" : $(SOURCE) $(DEP_CPP_Y_TAB) "$(INTDIR)" ".\Lex_yy.c"
# End Source File
# End Target
# End Project
################################################################################

BIN
CExpr/Cexpr.mdp Normal file

Binary file not shown.

BIN
CExpr/Cexpr.opt Normal file

Binary file not shown.

35
CExpr/Cexpr.plg Normal file
View file

@ -0,0 +1,35 @@
--------------------Configuration: cexpr - Win32 Release--------------------
Begining build with project "D:\Code\cexpr\Cexpr.dsp", at root.
Active configuration is Win32 (x86) Static Library (based on Win32 (x86) Static Library)
Project's tools are:
"32-bit C/C++ Compiler for 80x86" with flags "/nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "USE_DEFINE" /D "YY_USE_PROTOS" /D "_MBCS" /Fo".\Release/" /Fd".\Release/" /FD /c "
"Browser Database Maker" with flags "/nologo /o".\Release/Cexpr.bsc" "
"Library Manager" with flags "/nologo /out:".\Release\Cexpr.lib" "
"Custom Build" with flags ""
"<Component 0xa>" with flags ""
Creating temp file "E:\TEMP\RSPC.tmp" with contents </nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "USE_DEFINE" /D "YY_USE_PROTOS" /D "_MBCS" /Fo".\Release/" /Fd".\Release/" /FD /c
"D:\Code\cexpr\cexpr.cpp"
"D:\Code\cexpr\wx_hash.cpp"
"D:\Code\cexpr\wx_list.cpp"
"D:\Code\cexpr\Y_tab.c"
>
Creating command line "cl.exe @E:\TEMP\RSPC.tmp"
Creating command line "link.exe -lib /nologo /out:".\Release\Cexpr.lib" .\Release\cexpr.obj .\Release\wx_hash.obj .\Release\wx_list.obj .\Release\Y_tab.obj"
Compiling...
cexpr.cpp
wx_hash.cpp
wx_list.cpp
Generating Code...
Compiling...
Y_tab.c
lexer.l(277) : warning C4013: 'read' undefined; assuming extern returning int
y_tab.c(516) : warning C4102: 'yyerrlab' : unreferenced label
y_tab.c(516) : warning C4102: 'yynewerror' : unreferenced label
Generating Code...
Creating library...
Cexpr.lib - 0 error(s), 3 warning(s)

1208
CExpr/DOSLEX.C Normal file

File diff suppressed because it is too large Load diff

516
CExpr/DOSYACC.C Normal file
View file

@ -0,0 +1,516 @@
#ifndef lint
static char yysccsid[] = "@(#)yaccpar 1.7 (Berkeley) 09/09/90";
#endif
#define YYBYACC 1
#line 2 "parser.y"
#include "string.h"
#include "expr.h"
#ifndef __EXTERN_C__
#define __EXTERN_C__ 1
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
extern "C" {
#endif
#endif
int yylex(void);
int yylook(void);
int yywrap(void);
int yyback(int *, int);
/* You may need to put /DLEX_SCANNER in your makefile
* if you're using LEX!
*/
#ifdef LEX_SCANNER
/* int yyoutput(int); */
void yyoutput(int);
#else
void yyoutput(int);
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
}
#endif
#endif
#line 36 "parser.y"
typedef union {
char *s;
/* struct pexpr *expr; */
} YYSTYPE;
#line 44 "y_tab.c"
#define INTEGER 1
#define WORD 2
#define STRING 3
#define PERIOD 13
#define OPEN 4
#define CLOSE 5
#define COMMA 6
#define NEWLINE 7
#define ERROR 8
#define OPEN_SQUARE 9
#define CLOSE_SQUARE 10
#define EQUALS 11
#define EXP 14
#define YYERRCODE 256
short yylhs[] = { -1,
0, 0, 1, 1, 1, 2, 2, 2, 3, 3,
3, 4, 4, 5, 5, 5, 5, 5, 5, 5,
};
short yylen[] = { 2,
0, 2, 2, 2, 2, 4, 2, 3, 0, 1,
3, 3, 1, 1, 1, 1, 3, 3, 5, 1,
};
short yydefred[] = { 1,
0, 0, 0, 0, 2, 0, 5, 3, 0, 0,
0, 15, 7, 20, 0, 0, 13, 4, 0, 0,
0, 0, 8, 0, 6, 0, 18, 0, 12, 11,
0, 19,
};
short yydgoto[] = { 1,
5, 14, 15, 16, 17,
};
short yysindex[] = { 0,
-2, 9, 2, 1, 0, 10, 0, 0, 11, -5,
17, 0, 0, 0, 14, -1, 0, 0, 33, 38,
41, 16, 0, 11, 0, 29, 0, 40, 0, 0,
44, 0,
};
short yyrindex[] = { 0,
0, 0, 0, 0, 0, 0, 0, 0, 42, 21,
24, 0, 0, 0, 0, 30, 0, 0, 0, 0,
0, 0, 0, 31, 0, 27, 0, 24, 0, 0,
0, 0,
};
short yygindex[] = { 0,
0, 45, -8, 0, 26,
};
#define YYTABLESIZE 254
short yytable[] = { 3,
19, 10, 11, 12, 24, 9, 4, 20, 21, 4,
13, 10, 11, 12, 8, 30, 10, 28, 12, 4,
9, 7, 18, 23, 4, 16, 16, 22, 14, 14,
16, 17, 17, 14, 10, 9, 17, 25, 26, 10,
9, 27, 31, 9, 32, 6, 9, 29, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 2,
};
short yycheck[] = { 2,
9, 1, 2, 3, 6, 4, 9, 13, 14, 9,
10, 1, 2, 3, 13, 24, 1, 2, 3, 9,
4, 13, 13, 10, 9, 5, 6, 11, 5, 6,
10, 5, 6, 10, 5, 5, 10, 5, 1, 10,
10, 1, 14, 4, 1, 1, 5, 22, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 256,
};
#define YYFINAL 1
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 14
#if YYDEBUG
char *yyname[] = {
"end-of-file","INTEGER","WORD","STRING","OPEN","CLOSE","COMMA","NEWLINE",
"ERROR","OPEN_SQUARE","CLOSE_SQUARE","EQUALS",0,"PERIOD","EXP",
};
char *yyrule[] = {
"$accept : commands",
"commands :",
"commands : commands command",
"command : WORD PERIOD",
"command : expr PERIOD",
"command : error PERIOD",
"expr : WORD OPEN arglist CLOSE",
"expr : OPEN_SQUARE CLOSE_SQUARE",
"expr : OPEN_SQUARE arglist CLOSE_SQUARE",
"arglist :",
"arglist : arg",
"arglist : arg COMMA arglist",
"arg : WORD EQUALS arg1",
"arg : arg1",
"arg1 : WORD",
"arg1 : STRING",
"arg1 : INTEGER",
"arg1 : INTEGER PERIOD INTEGER",
"arg1 : INTEGER EXP INTEGER",
"arg1 : INTEGER PERIOD INTEGER EXP INTEGER",
"arg1 : expr",
};
#endif
#define yyclearin (yychar=(-1))
#define yyerrok (yyerrflag=0)
#ifdef YYSTACKSIZE
#ifndef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#endif
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 600
#define YYMAXDEPTH 600
#endif
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
short yyss[YYSTACKSIZE];
YYSTYPE yyvs[YYSTACKSIZE];
#define yystacksize YYSTACKSIZE
#line 118 "parser.y"
#include "lex_yy.c"
/*
void yyerror(s)
char *s;
{
syntax_error(s);
}
*/
/* Ansi prototype. If this doesn't work for you... uncomment
the above instead.
*/
void yyerror(char *s)
{
syntax_error(s);
}
/*
* Unfortunately, my DOS version of FLEX
* requires yywrap to be #def'ed, whereas
* the UNIX flex expects a proper function.
*/
/* Not sure if __SC__ is the appropriate thing
* to test
*/
#ifndef __SC__
#ifdef USE_DEFINE
#ifndef yywrap
#define yywrap() 1
#endif
#else
int yywrap() { return 1; }
#endif
#endif
#line 247 "y_tab.c"
#define YYABORT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse()
{
register int yym, yyn, yystate;
#if YYDEBUG
register char *yys;
extern char *getenv();
if (yys = getenv("YYDEBUG"))
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
yynerrs = 0;
yyerrflag = 0;
yychar = (-1);
yyssp = yyss;
yyvsp = yyvs;
*yyssp = yystate = 0;
yyloop:
if (yyn = yydefred[yystate]) goto yyreduce;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, reading %d (%s)\n", yystate,
yychar, yys);
}
#endif
}
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, shifting to state %d\n",
yystate, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
yychar = (-1);
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
yyn = yytable[yyn];
goto yyreduce;
}
if (yyerrflag) goto yyinrecovery;
#ifdef lint
goto yynewerror;
#endif
yynewerror:
yyerror("syntax error");
#ifdef lint
goto yyerrlab;
#endif
yyerrlab:
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, error recovery shifting\
to state %d\n", *yyssp, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
printf("yydebug: error recovery discarding state %d\n",
*yyssp);
#endif
if (yyssp <= yyss) goto yyabort;
--yyssp;
--yyvsp;
}
}
}
else
{
if (yychar == 0) goto yyabort;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, error recovery discards token %d (%s)\n",
yystate, yychar, yys);
}
#endif
yychar = (-1);
goto yyloop;
}
yyreduce:
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, reducing by rule %d (%s)\n",
yystate, yyn, yyrule[yyn]);
#endif
yym = yylen[yyn];
yyval = yyvsp[1-yym];
switch (yyn)
{
case 3:
#line 68 "parser.y"
{process_command(cexpr_cons(make_word(yyvsp[-1].s), NULL)); free(yyvsp[-1].s);}
break;
case 4:
#line 70 "parser.y"
{process_command(yyvsp[-1].s);}
break;
case 5:
#line 72 "parser.y"
{syntax_error("Unrecognized command.");}
break;
case 6:
#line 76 "parser.y"
{yyval.s = cexpr_cons(make_word(yyvsp[-3].s), yyvsp[-1].s); free(yyvsp[-3].s);}
break;
case 7:
#line 78 "parser.y"
{yyval.s = cexpr_cons(NULL, NULL);}
break;
case 8:
#line 80 "parser.y"
{yyval.s = yyvsp[-1].s; }
break;
case 9:
#line 84 "parser.y"
{yyval.s = NULL;}
break;
case 10:
#line 86 "parser.y"
{yyval.s = cexpr_cons(yyvsp[0].s, NULL);}
break;
case 11:
#line 89 "parser.y"
{yyval.s = cexpr_cons(yyvsp[-2].s, yyvsp[0].s);}
break;
case 12:
#line 93 "parser.y"
{yyval.s = cexpr_cons(make_word("="), cexpr_cons(make_word(yyvsp[-2].s), cexpr_cons(yyvsp[0].s, NULL)));
free(yyvsp[-2].s); }
break;
case 13:
#line 96 "parser.y"
{yyval.s = yyvsp[0].s; }
break;
case 14:
#line 99 "parser.y"
{yyval.s = make_word(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 15:
#line 101 "parser.y"
{yyval.s = make_string(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 16:
#line 103 "parser.y"
{yyval.s = make_integer(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 17:
#line 105 "parser.y"
{yyval.s = make_real(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); }
break;
case 18:
#line 107 "parser.y"
{yyval.s = make_exp(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); }
break;
case 19:
#line 110 "parser.y"
{yyval.s = make_exp2(yyvsp[-4].s, yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-4].s); free(yyvsp[-2].s);
free(yyvsp[0].s); }
break;
case 20:
#line 114 "parser.y"
{yyval.s = yyvsp[0].s;}
break;
#line 461 "y_tab.c"
}
yyssp -= yym;
yystate = *yyssp;
yyvsp -= yym;
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: after reduction, shifting from state 0 to\
state %d\n", YYFINAL);
#endif
yystate = YYFINAL;
*++yyssp = YYFINAL;
*++yyvsp = yyval;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, reading %d (%s)\n",
YYFINAL, yychar, yys);
}
#endif
}
if (yychar == 0) goto yyaccept;
goto yyloop;
}
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
yystate = yytable[yyn];
else
yystate = yydgoto[yym];
#if YYDEBUG
if (yydebug)
printf("yydebug: after reduction, shifting from state %d \
to state %d\n", *yyssp, yystate);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate;
*++yyvsp = yyval;
goto yyloop;
yyoverflow:
yyerror("yacc stack overflow");
yyabort:
return (1);
yyaccept:
return (0);
}

0
CExpr/Debug/empty.dir Normal file
View file

124
CExpr/EXPR.H Normal file
View file

@ -0,0 +1,124 @@
/*
* File: expr.h
* Purpose:
* Author: Julian Smart
* Created: 1993
* Updated:
* Copyright: (c) 1993
*/
/* sccsid[] = "%W% %G%" */
#ifndef __EXPRH__
#define __EXPRH__
#include <math.h>
#include <stdlib.h>
/* Rename all YACC/LEX stuff or we'll conflict with other
* applications
*/
#define yyback CExpr_yyback
#define yylook CExpr_yylook
#define yywrap CExpr_yywrap
#define yyoutput CExpr_yyoutput
#define yylex CExpr_yylex
#define yyerror CExpr_yyerror
#define input CExpr_input
#define unput CExpr_unput
#define yyleng CExpr_yyleng
#define yytext CExpr_yytext
#define yymorfg CExpr_yymorfg
#define yylineno CExpr_yylineno
#define yytchar CExpr_yytchar
#define yyin CExpr_yyin
#define yyout CExpr_yyout
#define yysvf CExpr_yysvf
#define yyestate CExpr_yyestate
#define yysvec CExpr_yysvec
#define yybgin CExpr_yybgin
#define yyprevious CExpr_yyprevious
#define yylhs CExpr_yylhs
#define yylen CExpr_yylen
#define yydefred CExpr_yydefred
#define yydgoto CExpr_yydgoto
#define yysindex CExpr_yysindex
#define yyrindex CExpr_yyrindex
#define yygindex CExpr_yygindex
#define yytable CExpr_yytable
#define yycheck CExpr_yycheck
#define yyname CExpr_yyname
#define yyrule CExpr_yyrule
#define yydebug CExpr_yydebug
#define yynerrs CExpr_yynerrs
#define yyerrflag CExpr_yyerrflag
#define yychar CExpr_yychar
#define yyvsp CExpr_yyvsp
#define yyssp CExpr_yyssp
#define yyval CExpr_yyval
#define yylval CExpr_yylval
#define yyss CExpr_yyss
#define yyvs CExpr_yyvs
#define yyparse CExpr_yyparse
/* +++steve162e: more defines necessary */
#define yy_init_buffer CExpr_yy_init_buffer
#define yy_create_buffer CExpr_yy_create_buffer
#define yy_load_buffer_state CExpr_yy_load_buffer_state
#define yyrestart CExpr_yyrestart
#define yy_switch_to_buffer CExpr_yy_switch_to_buffer
#define yy_delete_buffer CExpr_yy_delete_buffer
/* ---steve162e */
/* WG 1/96: still more for flex 2.5 */
#define yy_scan_buffer CExpr_scan_buffer
#define yy_scan_string CExpr_scan_string
#define yy_scan_bytes CExpr_scan_bytes
#define yy_flex_debug CExpr_flex_debug
#define yy_flush_buffer CExpr_flush_buffer
#define yyleng CExpr_yyleng
#define yytext CExpr_yytext
#ifdef __cplusplus
extern "C" {
char *cexpr_cons(char *, char *);
char * make_integer(char *);
char * make_word(char *);
char * make_string(char *);
char * make_real(char *, char *);
char * make_exp(char *, char *);
char * make_exp2(char *, char *, char*);
void add_expr(char *);
void process_command(char *);
void syntax_error(char *);
}
#else
#if __BORLANDC__
char *cexpr_cons(char *, char *);
char * make_integer(char *);
char * make_word(char *);
char * make_string(char *);
char * make_real(char *, char *);
char * make_exp(char *, char *);
char * make_exp2(char *, char *, char*);
void add_expr(char *);
void process_command(char *);
void syntax_error(char *);
#else
char *cexpr_cons();
char * make_integer();
char * make_word();
char * make_string();
char * make_real();
char * make_exp();
char * make_exp2();
void add_expr();
void process_command();
void syntax_error();
#endif
#endif
#endif

1213
CExpr/LEX_YY.C Normal file

File diff suppressed because it is too large Load diff

193
CExpr/Lexer.l Normal file
View file

@ -0,0 +1,193 @@
SIGN [+-]
DIGIT [0-9]
ALPHA [a-zA-Z_]
ALPHADIGIT [a-zA-Z_0-9]
STRINGCHAR [^"\\]
WORDCHAR [^'\\]
%{
/*
* File: lexer.l
* Description: Lexical analyser for PROLOGIO; can be used with
* either lex and flex.
*/
#include <string.h>
/* +++steve162e: added, otherwise, CExpr_input will be undefined (at least under LINUX)
please check, if this is also TRUE under other UNIXes.
*/
#if defined(FLEX_SCANNER) && defined(_LINUX)
#define CExpr_input my_input
#endif
/* ---steve162e */
#include "expr.h"
#ifdef wx_x
extern char *malloc();
#endif
#define Return(x) return x;
#if defined(VMS) && !defined(strdup)
#define strdup(s) (strcpy((char *)malloc(strlen(s)+1), s));
#endif
static size_t lex_buffer_length = 0;
static const char *lex_buffer = NULL;
static size_t lex_string_ptr = 0;
static int lex_read_from_string = 0;
static int my_input(void);
static int my_unput(char);
#ifdef FLEX_SCANNER
#undef YY_INPUT
# define YY_INPUT(buf,result,max_size) \
if (lex_read_from_string) \
{ int c = my_input(); result = (c == 0) ? YY_NULL : ((buf)[0]=(c), 1); } \
else \
if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
YY_FATAL_ERROR( "read() in flex scanner failed" );
#else
# undef unput
# define unput(_c) my_unput(_c)
#endif
%}
%%
{SIGN}?{DIGIT}+ {yylval.s = strdup(yytext); Return(INTEGER);}
"e" Return(EXP);
{ALPHA}{ALPHADIGIT}* {yylval.s = strdup(yytext); Return(WORD);}
"'"{WORDCHAR}*"'" {int len = strlen(yytext);
yytext[len-1] = 0;
yylval.s = strdup(yytext+1);
Return(WORD);}
\"({STRINGCHAR}|\\\"|\|\\\\|\\)*\" {yylval.s = strdup(yytext); Return(STRING);}
"(" Return(OPEN);
")" Return(CLOSE);
"," Return(COMMA);
"[" Return(OPEN_SQUARE);
"]" Return(CLOSE_SQUARE);
"=" Return(EQUALS);
"." Return(PERIOD);
[ \t] ;
\n ;
"/*" { loop:
#ifdef __cplusplus
while (yyinput() != '*');
switch (yyinput())
#else
while (input() != '*');
switch (input())
#endif
{
case '/': break;
case '*': unput('*');
default: goto loop;
}
}
. Return(ERROR);
%%
#ifdef FLEX_SCANNER
static int lex_input() {
return input();
}
#else /* BSD/AT&T lex */
#ifndef input
# error "Sorry, but need either flex or AT&T lex"
#endif
static int lex_input() {
return input();
}
/* # undef unput
# define unput(_c) my_unput(_c)
*/
# undef input
# define input() my_input()
static int my_unput(char c)
{
if (lex_read_from_string) {
/* Make sure we have something */
if (lex_string_ptr) {
if (c == '\n') yylineno--;
lex_string_ptr--;
}
} else {
yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;
/* unput(c); Causes infinite recursion! */
}
return c;
}
#endif
/* Public */
void LexFromFile(FILE *fd)
{
lex_read_from_string = 0;
yyin = fd;
/* Don't know why this is necessary, but otherwise
* lex only works _once_!
*/
#ifdef FLEX_SCANNER
yy_init = 1;
#endif
}
void LexFromString(char *buffer)
{
lex_read_from_string = 1;
lex_buffer = buffer;
lex_buffer_length = strlen(buffer);
lex_string_ptr = 0;
/* Don't know why this is necessary, but otherwise
* lex only works _once_!
*/
#ifdef FLEX_SCANNER
yy_init = 1;
#endif
}
static int my_input( void )
{
if (lex_read_from_string) {
if (lex_string_ptr == lex_buffer_length)
return 0;
else {
char c = lex_buffer[lex_string_ptr++];
#ifndef FLEX_SCANNER
if (c == '\n') yylineno++;
#endif
return c;
}
} else {
return lex_input();
}
}
void CExprCleanUp()
{
if (yy_current_buffer)
yy_delete_buffer(yy_current_buffer);
}

157
CExpr/PARSER.Y Normal file
View file

@ -0,0 +1,157 @@
%{
#include "string.h"
#include "expr.h"
#ifndef __EXTERN_C__
#define __EXTERN_C__ 1
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
extern "C" {
#endif
#endif
int yylex(void);
int yylook(void);
int yywrap(void);
int yyback(int *, int);
void yyerror(char *);
/* You may need to put /DLEX_SCANNER in your makefile
* if you're using LEX!
*/
#ifdef LEX_SCANNER
/* int yyoutput(int); */
void yyoutput(int);
#else
void yyoutput(int);
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
}
#endif
#endif
%}
%union {
char *s;
/* struct pexpr *expr; */
}
%start commands
%token <s> INTEGER 1
%token <s> WORD 2
%token <s> STRING 3
%token <s> PERIOD 13
%token OPEN 4
%token CLOSE 5
%token COMMA 6
%token NEWLINE 7
%token ERROR 8
%token OPEN_SQUARE 9
%token CLOSE_SQUARE 10
%token EQUALS 11
%token EXP 14
/* %type <expr> command expr arglist arg arg1 */
%type <s> command expr arglist arg arg1
%%
commands : /* empty */
| commands command
;
command : WORD PERIOD
{process_command(cexpr_cons(make_word($1), NULL)); free($1);}
| expr PERIOD
{process_command($1);}
| error PERIOD
{syntax_error("Unrecognized command.");}
;
expr : WORD OPEN arglist CLOSE
{$$ = cexpr_cons(make_word($1), $3); free($1);}
| OPEN_SQUARE CLOSE_SQUARE
{$$ = cexpr_cons(NULL, NULL);}
| OPEN_SQUARE arglist CLOSE_SQUARE
{$$ = $2; }
;
arglist :
{$$ = NULL;}
| arg
{$$ = cexpr_cons($1, NULL);}
|
arg COMMA arglist
{$$ = cexpr_cons($1, $3);}
;
arg : WORD EQUALS arg1
{$$ = cexpr_cons(make_word("="), cexpr_cons(make_word($1), cexpr_cons($3, NULL)));
free($1); }
| arg1
{$$ = $1; }
arg1 : WORD
{$$ = make_word($1); free($1);}
| STRING
{$$ = make_string($1); free($1);}
| INTEGER
{$$ = make_integer($1); free($1);}
| INTEGER PERIOD INTEGER
{$$ = make_real($1, $3); free($1); free($3); }
| INTEGER EXP INTEGER
{$$ = make_exp($1, $3); free($1); free($3); }
|
INTEGER PERIOD INTEGER EXP INTEGER
{$$ = make_exp2($1, $3, $5); free($1); free($3);
free($5); }
| expr
{$$ = $1;}
;
%%
#include "lex_yy.c"
/*
void yyerror(s)
char *s;
{
syntax_error(s);
}
*/
/* Ansi prototype. If this doesn't work for you... uncomment
the above instead.
*/
void yyerror(char *s)
{
syntax_error(s);
}
/*
* Unfortunately, my DOS version of FLEX
* requires yywrap to be #def'ed, whereas
* the UNIX flex expects a proper function.
*/
/* Not sure if __SC__ is the appropriate thing
* to test
*/
#ifndef __SC__
#ifdef USE_DEFINE
#ifndef yywrap
#define yywrap() 1
#endif
#else if !defined(__alpha) && !defined(__ultrix)
int yywrap() { return 1; }
#endif
#endif

0
CExpr/Release/empty.dir Normal file
View file

16
CExpr/STDAFX.H Normal file
View file

@ -0,0 +1,16 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows 95 Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

350
CExpr/WX_HASH.CPP Normal file
View file

@ -0,0 +1,350 @@
/*
* File: wb_hash.cc
* Purpose: Hash table implementation
* Author: Julian Smart
* Created: 1993
* Updated: August 1994
* RCS_ID: $Id: wb_hash.cc,v 1.3 1994/08/14 21:34:01 edz Exp $
* Copyright: (c) 1993, AIAI, University of Edinburgh
*/
/* static const char sccsid[] = "@(#)wb_hash.cc 1.2 5/9/94"; */
#ifdef __GNUG__
#pragma implementation "wx_hash.h"
#endif
#include "stdafx.h"
#include "wx_list.h"
#include "wx_hash.h"
#include <string.h>
#include <stdarg.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(wxHashTable, CObject)
wxHashTable::wxHashTable (int the_key_type, int size)
{
n = size;
current_position = -1;
current_node = NULL;
key_type = the_key_type;
hash_table = new wxList *[size];
int i;
for (i = 0; i < size; i++)
hash_table[i] = NULL;
}
wxHashTable::~wxHashTable (void)
{
int i;
for (i = 0; i < n; i++)
if (hash_table[i])
delete hash_table[i];
delete[] hash_table;
}
BOOL wxHashTable::Create(int the_key_type, int size)
{
n = size;
current_position = -1;
current_node = NULL;
key_type = the_key_type;
if (hash_table)
delete[] hash_table;
hash_table = new wxList *[size];
int i;
for (i = 0; i < size; i++)
hash_table[i] = NULL;
return TRUE;
}
void wxHashTable::Put (long key, long value, CObject * object)
{
// Should NEVER be
if (key < 0)
key = -key;
int position = (int) (key % n);
if (!hash_table[position])
hash_table[position] = new wxList (wxKEY_INTEGER);
hash_table[position]->Append (value, object);
}
void wxHashTable::Put (long key, char *value, CObject * object)
{
// Should NEVER be
if (key < 0)
key = -key;
int position = (int) (key % n);
if (!hash_table[position])
hash_table[position] = new wxList (wxKEY_INTEGER);
hash_table[position]->Append (value, object);
}
void wxHashTable::Put (long key, CObject * object)
{
// Should NEVER be
if (key < 0)
key = -key;
int position = (int) (key % n);
if (!hash_table[position])
hash_table[position] = new wxList (wxKEY_INTEGER);
hash_table[position]->Append (key, object);
}
void wxHashTable::Put (const char *key, CObject * object)
{
int position = (int) (MakeKey (key) % n);
if (!hash_table[position])
hash_table[position] = new wxList (wxKEY_STRING);
hash_table[position]->Append (key, object);
}
CObject *wxHashTable::Get (long key, long value)
{
// Should NEVER be
if (key < 0)
key = -key;
int position = (int) (key % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (value);
if (node)
return node->Data ();
else
return NULL;
}
}
CObject *wxHashTable::Get (long key, char *value)
{
// Should NEVER be
if (key < 0)
key = -key;
int position = (int) (key % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (value);
if (node)
return node->Data ();
else
return NULL;
}
}
CObject *wxHashTable::Get (long key)
{
// Should NEVER be
if (key < 0)
key = -key;
int position = (int) (key % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (key);
return node ? node->Data () : NULL;
}
}
CObject *wxHashTable::Get (const char *key)
{
int position = (int) (MakeKey (key) % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (key);
return node ? node->Data () : NULL;
}
}
CObject *wxHashTable::Delete (long key)
{
// Should NEVER be
if (key < 0)
key = -key;
int position = (int) (key % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (key);
if (node)
{
CObject *data = node->Data ();
delete node;
return data;
}
else
return NULL;
}
}
CObject *wxHashTable::Delete (const char *key)
{
int position = (int) (MakeKey (key) % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (key);
if (node)
{
CObject *data = node->Data ();
delete node;
return data;
}
else
return NULL;
}
}
CObject *wxHashTable::Delete (long key, int value)
{
// Should NEVER be
if (key < 0)
key = -key;
int position = (int) (key % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (value);
if (node)
{
CObject *data = node->Data ();
delete node;
return data;
}
else
return NULL;
}
}
CObject *wxHashTable::Delete (long key, char *value)
{
/*
// Should NEVER be
if (key < 0)
key = -key;
*/
int position = (int) (key % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (value);
if (node)
{
CObject *data = node->Data ();
delete node;
return data;
}
else
return NULL;
}
}
long wxHashTable::MakeKey (const char *string)
{
long int_key = 0;
while (*string)
int_key += (unsigned char) *string++;
/* // Don't need this since int_key >= 0)
if (int_key < 0)
int_key = -int_key;
*/
return int_key;
}
void wxHashTable::BeginFind (void)
{
current_position = -1;
current_node = NULL;
}
wxNode *wxHashTable::Next (void)
{
wxNode *found = NULL;
BOOL end = FALSE;
while (!end && !found)
{
if (!current_node)
{
current_position++;
if (current_position >= n)
{
current_position = -1;
current_node = NULL;
end = TRUE;
}
else
{
if (hash_table[current_position])
{
current_node = hash_table[current_position]->First ();
found = current_node;
}
}
}
else
{
current_node = current_node->Next ();
found = current_node;
}
}
return found;
}
void wxHashTable::DeleteContents (BOOL flag)
{
int i;
for (i = 0; i < n; i++)
{
if (hash_table[i])
hash_table[i]->DeleteContents (flag);
}
}
void wxHashTable::Clear (void)
{
int i;
for (i = 0; i < n; i++)
{
if (hash_table[i])
hash_table[i]->Clear ();
}
}

100
CExpr/WX_HASH.H Normal file
View file

@ -0,0 +1,100 @@
/*
* File: wx_hash.h
* Purpose: Basic hash table implementation
* Author: Julian Smart
* Created: 1993
* Updated:
* Copyright: (c) 1993
*/
/* sccsid[] = "@(#)wx_hash.h 1.2 5/9/94" */
#ifndef wxb_hashh
#define wxb_hashh
#ifdef __GNUG__
#pragma interface
#endif
#include "wx_list.h"
/*
* A hash table is an array of user-definable size with lists
* of data items hanging off the array positions. Usually there'll
* be a hit, so no search is required; otherwise we'll have to run down
* the list to find the desired item.
*/
#ifdef IN_CPROTO
typedef void *wxHashTable ;
#else
class wxHashTable: public CObject
{
DECLARE_DYNAMIC(wxHashTable)
public:
int n;
int current_position;
wxNode *current_node;
unsigned int key_type;
wxList **hash_table;
wxHashTable(int the_key_type = wxKEY_INTEGER, int size = 1000);
~wxHashTable(void);
BOOL Create(int the_key_type = wxKEY_INTEGER, int size = 1000);
// Note that there are 2 forms of Put, Get.
// With a key and a value, the *value* will be checked
// when a collision is detected. Otherwise, if there are
// 2 items with a different value but the same key,
// we'll retrieve the WRONG ONE. So where possible,
// supply the required value along with the key.
// In fact, the value-only versions make a key, and still store
// the value. The use of an explicit key might be required
// e.g. when combining several values into one key.
// When doing that, it's highly likely we'll get a collision,
// e.g. 1 + 2 = 3, 2 + 1 = 3.
// key and value are NOT necessarily the same
void Put(long key, long value, CObject *object);
void Put(long key, char *value, CObject *object);
// key and value are the same
void Put(long value, CObject *object);
void Put(const char *value, CObject *object);
// key and value not the same
CObject *Get(long key, long value);
CObject *Get(long key, char *value);
// key and value are the same
CObject *Get(long value);
CObject *Get(const char *value);
// Deletes entry and returns data if found
CObject *Delete(long key);
CObject *Delete(const char *key);
CObject *Delete(long key, int value);
CObject *Delete(long key, char *value);
// Construct your own integer key from a string, e.g. in case
// you need to combine it with something
long MakeKey(const char *string);
// Way of iterating through whole hash table (e.g. to delete everything)
// Not necessary, of course, if you're only storing pointers to
// objects maintained separately
void BeginFind(void);
wxNode *Next(void);
void DeleteContents(BOOL flag);
void Clear(void);
};
#endif // IN_CPROTO
#endif // wxb_hashh

598
CExpr/Wx_list.cpp Normal file
View file

@ -0,0 +1,598 @@
/*
* File: wb_list.cc
* Purpose: List implementation
* Author: Julian Smart
* Created: 1993
* Updated: August 1994
* RCS_ID: $Id: wb_list.cc,v 1.3 1994/08/14 21:34:01 edz Exp $
* Copyright: (c) 1993, AIAI, University of Edinburgh
*/
/* static const char sccsid[] = "@(#)wb_list.cc 1.2 5/9/94"; */
#ifdef __GNUG__
#pragma implementation "wx_list.h"
#endif
#include "stdafx.h"
#include "wx_list.h"
#include <stdarg.h>
#include <stdlib.h>
IMPLEMENT_DYNAMIC(wxNode, CObject)
IMPLEMENT_DYNAMIC(wxList, CObject)
IMPLEMENT_DYNAMIC(wxStringList, wxList)
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
wxNode::wxNode (wxList * the_list, wxNode * last_one, wxNode * next_one,
CObject * object)
{
data = object;
previous = last_one;
next = next_one;
list = the_list;
key.string = NULL;
if (previous)
previous->next = this;
if (next)
next->previous = this;
}
// Keyed constructor
wxNode::wxNode (wxList * the_list, wxNode * last_one, wxNode * next_one,
CObject * object, long the_key)
{
data = object;
previous = last_one;
next = next_one;
list = the_list;
key.integer = the_key;
if (previous)
previous->next = this;
if (next)
next->previous = this;
}
wxNode::wxNode (wxList * the_list, wxNode * last_one, wxNode * next_one,
CObject * object, const char *the_key)
{
data = object;
previous = last_one;
next = next_one;
list = the_list;
key.string = copystring (the_key);
if (previous)
previous->next = this;
if (next)
next->previous = this;
}
wxNode::~wxNode (void)
{
if (list)
list->n--;
if (list && list->destroy_data)
delete data;
if (list && list->key_type == wxKEY_STRING && key.string)
delete[]key.string;
// Make next node point back to the previous node from here
if (next)
next->previous = previous;
else if (list)
// If there's a new end of list (deleting the last one)
// make sure the list knows about it.
list->last_node = previous;
// Make the previous node point to the next node from here
if (previous)
previous->next = next;
// Or if no previous node (start of list), make sure list points at
// the next node which becomes the first!.
else if (list)
list->first_node = next;
}
wxList::wxList (void)
{
first_node = NULL;
last_node = NULL;
n = 0;
destroy_data = 0;
key_type = wxKEY_NONE;
}
wxList::wxList (int N, CObject * Objects[])
{
wxNode *last = NULL;
int i;
for (i = 0; i < N; i++)
{
wxNode *next = new wxNode (this, last, NULL, Objects[i]);
last = next;
if (i == 0)
first_node = next;
}
last_node = last;
n = N;
key_type = wxKEY_NONE;
}
wxList::wxList (unsigned int the_key_type)
{
n = 0;
destroy_data = 0;
first_node = NULL;
last_node = NULL;
key_type = the_key_type;
}
// Variable argument list, terminated by a zero
wxList::wxList (CObject * first_one...)
{
// #ifndef __sgi
va_list ap;
va_start (ap, first_one);
wxNode *last = new wxNode (this, NULL, NULL, first_one);
first_node = last;
n = 1;
for (;;)
{
CObject *object = va_arg (ap, CObject *);
// if (object == NULL) // Doesn't work in Windows -- segment is non-zero for NULL!
#ifdef wx_msw
if ((int) object == 0)
#else
if ((long) object == 0)
#endif
break;
else
{
wxNode *node = new wxNode (this, last, NULL, object);
last = node;
n++;
}
}
last_node = last;
va_end (ap);
destroy_data = 0;
key_type = wxKEY_NONE;
/*
#else
fprintf (stderr, "Error: cannot use variable-argument functions on SGI!\n");
#endif
*/
}
wxList::~wxList (void)
{
wxNode *each = first_node;
while (each)
{
wxNode *next = each->Next ();
delete each;
each = next;
}
}
wxNode *wxList::Nth (int i)
{
int j = 0;
for (wxNode * current = First (); current; current = current->Next ())
{
if (j++ == i)
return current;
}
return NULL; // No such element
}
wxNode *wxList::Find (long key)
{
wxNode *current = First();
while (current)
{
if (current->key.integer == key)
return current;
current = current->Next();
}
return NULL; // Not found!
}
wxNode *wxList::Find (const char *key)
{
wxNode *current = First();
while (current)
{
if (!current->key.string)
{
// wxFatalError ("wxList: string key not present, probably did not Append correctly!");
break;
}
if (strcmp (current->key.string, key) == 0)
return current;
current = current->Next();
}
return NULL; // Not found!
}
wxNode *wxList::Member (CObject * object)
{
for (wxNode * current = First (); current; current = current->Next ())
{
CObject *each = current->Data ();
if (each == object)
return current;
}
return NULL;
}
BOOL wxList::DeleteNode (wxNode * node)
{
if (node)
{
delete node;
return TRUE;
}
return FALSE;
}
BOOL wxList::DeleteObject (CObject * object)
{
// Search list for object
for (wxNode * current = first_node; current; current = current->Next ())
{
if (current->Data () == object)
{
delete current;
return TRUE;
}
}
return FALSE; // Did not find the object
}
// Insert new node at front of list
wxNode *wxList::Insert (CObject * object)
{
wxNode *node = new wxNode (this, NULL, First (), object);
first_node = node;
if (!(node->Next ()))
last_node = node;
n++;
return node;
}
// Insert new node before given node.
wxNode *wxList::Insert (wxNode * position, CObject * object)
{
wxNode *prev = NULL;
if (position)
prev = position->Previous ();
wxNode *node = new wxNode (this, prev, position, object);
if (!first_node)
{
first_node = node;
last_node = node;
}
if (!prev)
first_node = node;
n++;
return node;
}
// Keyed append
wxNode *wxList::Append (long key, CObject * object)
{
wxNode *node = new wxNode (this, last_node, NULL, object, key);
if (!first_node)
first_node = node;
last_node = node;
n++;
return node;
}
wxNode *wxList::Append (const char *key, CObject * object)
{
wxNode *node = new wxNode (this, last_node, NULL, object, key);
if (!first_node)
first_node = node;
last_node = node;
n++;
return node;
}
void wxList::Clear (void)
{
wxNode *current = first_node;
while (current)
{
wxNode *next = current->Next ();
delete current;
current = next;
}
first_node = NULL;
last_node = NULL;
n = 0;
}
//Executes function F with all items present in the list
void wxList::ForEach(void (*F)(CObject *O))
{
wxNode *each = first_node;
while (each)
{ (*F)( each->Data ());
each = each->Next();
}
}
// Returns a pointer to the item which returns TRUE with function F
// or NULL if no such item found
CObject *wxList::FirstThat(int (*F)(CObject *O))
{
wxNode *each = first_node;
while (each)
{ if ((*F)( each->Data ())) return each->Data();
each = each->Next();
}
return NULL;
}
// Like FirstThat, but proceeds from the end backward
/*
CObject *wxList::LastThat(int (*F)(CObject *O))
{
wxNode *each = last_node;
while (each)
{ if ((*F)( each->Data ())) return each->Data();
each = each->Previous();
}
return NULL;
}
*/
// (stefan.hammes@urz.uni-heidelberg.de)
//
// function for sorting lists. the concept is borrowed from 'qsort'.
// by giving a sort function, arbitrary lists can be sorted.
// method:
// - put CObject pointers into an array
// - sort the array with qsort
// - put back the sorted CObject pointers into the list
//
// CAVE: the sort function receives pointers to CObject pointers (CObject **),
// so dereference right!
// EXAMPLE:
// int listcompare(const void *arg1, const void *arg2)
// {
// return(compare(**(wxString **)arg1,
// **(wxString **)arg2));
// }
//
// void main()
// {
// wxList list;
//
// list.Append(new wxString("DEF"));
// list.Append(new wxString("GHI"));
// list.Append(new wxString("ABC"));
// list.Sort(listcompare);
// }
void wxList::Sort(wxSortCompareFunction compfunc)
{
// allocate an array for the CObject pointers of the list
const size_t num = Number();
CObject **objArray = new CObject *[num];
CObject **objPtr = objArray;
// go through the list and put the pointers into the array
wxNode *node = First();
while(node!=NULL){
*objPtr++ = node->Data();
node = node->Next();
}
// sort the array
qsort((void *)objArray,num,sizeof(CObject *),compfunc);
// put the sorted pointers back into the list
objPtr = objArray;
node = First();
while(node!=NULL){
node->SetData(*objPtr++);
node = node->Next();
}
// free the array
delete[] objArray;
}
/*
* String list
*
*/
wxStringList::wxStringList (void):
wxList ()
{
}
// Variable argument list, terminated by a zero
// Makes new storage for the strings
wxStringList::wxStringList (char *first...)
{
// #ifndef __sgi
n = 0;
destroy_data = 0;
key_type = wxKEY_NONE;
first_node = NULL;
last_node = NULL;
if (!first)
return;
va_list ap;
va_start (ap, first);
wxNode *last = new wxNode (this, NULL, NULL, (CObject *) copystring (first));
first_node = last;
n = 1;
for (;;)
{
char *s = va_arg (ap, char *);
// if (s == NULL)
#ifdef wx_msw
if ((int) s == 0)
#else
if ((long) s == 0)
#endif
break;
else
{
wxNode *node = new wxNode (this, last, NULL, (CObject *) copystring (s));
last = node;
n++;
}
}
last_node = last;
va_end (ap);
/*
#else
fprintf (stderr, "Error: cannot use variable-argument functions on SGI!\n");
#endif
*/
}
wxStringList::~wxStringList (void)
{
wxNode *each = first_node;
while (each)
{
char *s = (char *) each->Data ();
delete[]s;
wxNode *next = each->Next ();
delete each;
each = next;
}
}
wxNode *wxStringList::Add (const char *s)
{
return Append ((CObject *) (copystring (s)));
}
void wxStringList::Delete (const char *s)
{
for (wxNode * node = First (); node; node = node->Next ())
{
char *string = (char *) node->Data ();
if (string == s || strcmp (string, s) == 0)
{
delete[]string;
delete node;
break; // Done!
}
} // for
}
// Only makes new strings if arg is TRUE
char **wxStringList::ListToArray (BOOL new_copies)
{
char **string_array = new char *[Number ()];
wxNode *node = First ();
int i;
for (i = 0; i < n; i++)
{
char *s = (char *) node->Data ();
if (new_copies)
string_array[i] = copystring (s);
else
string_array[i] = s;
node = node->Next ();
}
return string_array;
}
static int
wx_comparestrings (const void *arg1, const void *arg2)
{
char **s1 = (char **) arg1;
char **s2 = (char **) arg2;
return strcmp (*s1, *s2);
}
// Sort a list of strings - deallocates old nodes, allocates new
void wxStringList::Sort (void)
{
size_t N = n;
char **array = new char *[N];
size_t i = 0;
for (wxNode * node = First (); node; node = node->Next ())
array[i++] = (char *) node->Data ();
qsort (array, N, sizeof (char *), wx_comparestrings);
Clear ();
for (i = 0; i < N; i++)
Append ((CObject *) (array[i]));
delete[]array;
}
// Checks whether s is a member of the list
BOOL wxStringList::Member (const char *s)
{
for (wxNode * node = First (); node; node = node->Next ())
{
const char *s1 = (const char *) node->Data ();
if (s == s1 || strcmp (s, s1) == 0)
return TRUE;
}
return FALSE;
}
char *
copystring (const char *s)
{
if (s == NULL) s = "";
size_t len = strlen (s) + 1;
char *news = new char[len];
memcpy (news, s, len); // Should be the fastest
return news;
}

155
CExpr/Wx_list.h Normal file
View file

@ -0,0 +1,155 @@
/*
* File: wx_list.h
* Purpose: wxList implementation much used in wxWindows
* Author: Julian Smart
* Created: 1993
* Updated:
* Copyright:
*/
/* sccsid[] = "@(#)wx_list.h 1.2 5/9/94" */
#ifndef wxb_listh
#define wxb_listh
#ifdef __GNUG__
#pragma interface
#endif
#ifdef IN_CPROTO
typedef void *wxList ;
typedef void *wxNode;
typedef void *wxStringList;
#else
class wxList;
#define wxKEY_NONE 0
#define wxKEY_INTEGER 1
#define wxKEY_STRING 2
class wxNode: public CObject
{
DECLARE_DYNAMIC(wxNode)
private:
CObject *data;
wxNode *next;
wxNode *previous;
public:
wxList *list;
// Optional key stuff
union
{
long integer;
char *string;
} key;
wxNode(wxList *the_list = NULL, wxNode *last_one = NULL, wxNode *next_one = NULL, CObject *object = NULL);
wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
CObject *object, long the_key);
wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
CObject *object, const char *the_key);
~wxNode(void);
inline wxNode *Next(void) { return next; }
inline wxNode *Previous(void) { return previous; }
inline CObject *Data(void) { return data; }
inline void SetData(CObject *the_data) { data = the_data; }
};
// type of compare function for list sort operation (as in 'qsort')
typedef int (*wxSortCompareFunction)(const void *elem1, const void *elem2);
class wxList: public CObject
{
DECLARE_DYNAMIC(wxList)
public:
int n;
int destroy_data;
wxNode *first_node;
wxNode *last_node;
unsigned int key_type;
wxList(void);
wxList(unsigned int the_key_type);
wxList(int N, CObject *Objects[]);
wxList(CObject *object, ...);
~wxList(void);
inline int Number(void) { return n; }
// Append to end of list
inline wxNode *Append(CObject *object)
{
wxNode *node = new wxNode(this, last_node, NULL, object);
if (!first_node)
first_node = node;
last_node = node;
n ++;
return node;
}
// Insert at front of list
wxNode *Insert(CObject *object);
// Insert before given node
wxNode *Insert(wxNode *position, CObject *object);
// Keyed append
wxNode *Append(long key, CObject *object);
wxNode *Append(const char *key, CObject *object);
BOOL DeleteNode(wxNode *node);
BOOL DeleteObject(CObject *object); // Finds object pointer and
// deletes node (and object if
// DeleteContents is on)
void Clear(void); // Delete all nodes
inline wxNode *First(void) { return first_node; }
inline wxNode *Last(void) { return last_node; }
wxNode *Nth(int i); // nth node counting from 0
// Keyed search
wxNode *Find(long key);
wxNode *Find(const char *key);
wxNode *Member(CObject *object);
inline void DeleteContents(int destroy) { destroy_data = destroy; }
// Instruct it to destroy user data
// when deleting nodes
// this function allows the sorting of arbitrary lists by giving
// a function to compare two list elements.
void Sort(wxSortCompareFunction compfunc);
CObject *FirstThat(int (*F)(CObject *O));
void ForEach(void (*F)(CObject *O));
//CObject *LastThat(int (*F)(CObject *O));
};
// String list class. N.B. this always copies strings
// with Add and deletes them itself.
class wxStringList: public wxList
{
DECLARE_DYNAMIC(wxStringList)
public:
wxStringList(void);
wxStringList(char *first ...);
~wxStringList(void);
virtual wxNode *Add(const char *s);
virtual void Delete(const char *s);
virtual char **ListToArray(BOOL new_copies = FALSE);
virtual void Sort(void);
virtual BOOL Member(const char *s);
};
// Make a copy of this string using 'new'
extern char *copystring(const char *s);
#endif // IN_CPROTO
#endif // wxb_listh

516
CExpr/Y_TAB.C Normal file
View file

@ -0,0 +1,516 @@
#ifndef lint
static char yysccsid[] = "@(#)yaccpar 1.7 (Berkeley) 09/09/90";
#endif
#define YYBYACC 1
#line 2 "parser.y"
#include "string.h"
#include "expr.h"
#ifndef __EXTERN_C__
#define __EXTERN_C__ 1
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
extern "C" {
#endif
#endif
int yylex(void);
int yylook(void);
int yywrap(void);
int yyback(int *, int);
/* You may need to put /DLEX_SCANNER in your makefile
* if you're using LEX!
*/
#ifdef LEX_SCANNER
/* int yyoutput(int); */
void yyoutput(int);
#else
void yyoutput(int);
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
}
#endif
#endif
#line 36 "parser.y"
typedef union {
char *s;
/* struct pexpr *expr; */
} YYSTYPE;
#line 44 "y_tab.c"
#define INTEGER 1
#define WORD 2
#define STRING 3
#define PERIOD 13
#define OPEN 4
#define CLOSE 5
#define COMMA 6
#define NEWLINE 7
#define ERROR 8
#define OPEN_SQUARE 9
#define CLOSE_SQUARE 10
#define EQUALS 11
#define EXP 14
#define YYERRCODE 256
short yylhs[] = { -1,
0, 0, 1, 1, 1, 2, 2, 2, 3, 3,
3, 4, 4, 5, 5, 5, 5, 5, 5, 5,
};
short yylen[] = { 2,
0, 2, 2, 2, 2, 4, 2, 3, 0, 1,
3, 3, 1, 1, 1, 1, 3, 3, 5, 1,
};
short yydefred[] = { 1,
0, 0, 0, 0, 2, 0, 5, 3, 0, 0,
0, 15, 7, 20, 0, 0, 13, 4, 0, 0,
0, 0, 8, 0, 6, 0, 18, 0, 12, 11,
0, 19,
};
short yydgoto[] = { 1,
5, 14, 15, 16, 17,
};
short yysindex[] = { 0,
-2, 9, 2, 1, 0, 10, 0, 0, 11, -5,
17, 0, 0, 0, 14, -1, 0, 0, 33, 38,
41, 16, 0, 11, 0, 29, 0, 40, 0, 0,
44, 0,
};
short yyrindex[] = { 0,
0, 0, 0, 0, 0, 0, 0, 0, 42, 21,
24, 0, 0, 0, 0, 30, 0, 0, 0, 0,
0, 0, 0, 31, 0, 27, 0, 24, 0, 0,
0, 0,
};
short yygindex[] = { 0,
0, 45, -8, 0, 26,
};
#define YYTABLESIZE 254
short yytable[] = { 3,
19, 10, 11, 12, 24, 9, 4, 20, 21, 4,
13, 10, 11, 12, 8, 30, 10, 28, 12, 4,
9, 7, 18, 23, 4, 16, 16, 22, 14, 14,
16, 17, 17, 14, 10, 9, 17, 25, 26, 10,
9, 27, 31, 9, 32, 6, 9, 29, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 2,
};
short yycheck[] = { 2,
9, 1, 2, 3, 6, 4, 9, 13, 14, 9,
10, 1, 2, 3, 13, 24, 1, 2, 3, 9,
4, 13, 13, 10, 9, 5, 6, 11, 5, 6,
10, 5, 6, 10, 5, 5, 10, 5, 1, 10,
10, 1, 14, 4, 1, 1, 5, 22, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 256,
};
#define YYFINAL 1
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 14
#if YYDEBUG
char *yyname[] = {
"end-of-file","INTEGER","WORD","STRING","OPEN","CLOSE","COMMA","NEWLINE",
"ERROR","OPEN_SQUARE","CLOSE_SQUARE","EQUALS",0,"PERIOD","EXP",
};
char *yyrule[] = {
"$accept : commands",
"commands :",
"commands : commands command",
"command : WORD PERIOD",
"command : expr PERIOD",
"command : error PERIOD",
"expr : WORD OPEN arglist CLOSE",
"expr : OPEN_SQUARE CLOSE_SQUARE",
"expr : OPEN_SQUARE arglist CLOSE_SQUARE",
"arglist :",
"arglist : arg",
"arglist : arg COMMA arglist",
"arg : WORD EQUALS arg1",
"arg : arg1",
"arg1 : WORD",
"arg1 : STRING",
"arg1 : INTEGER",
"arg1 : INTEGER PERIOD INTEGER",
"arg1 : INTEGER EXP INTEGER",
"arg1 : INTEGER PERIOD INTEGER EXP INTEGER",
"arg1 : expr",
};
#endif
#define yyclearin (yychar=(-1))
#define yyerrok (yyerrflag=0)
#ifdef YYSTACKSIZE
#ifndef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#endif
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 600
#define YYMAXDEPTH 600
#endif
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
short yyss[YYSTACKSIZE];
YYSTYPE yyvs[YYSTACKSIZE];
#define yystacksize YYSTACKSIZE
#line 118 "parser.y"
#include "lex_yy.c"
/*
void yyerror(s)
char *s;
{
syntax_error(s);
}
*/
/* Ansi prototype. If this doesn't work for you... uncomment
the above instead.
*/
void yyerror(char *s)
{
syntax_error(s);
}
/*
* Unfortunately, my DOS version of FLEX
* requires yywrap to be #def'ed, whereas
* the UNIX flex expects a proper function.
*/
/* Not sure if __SC__ is the appropriate thing
* to test
*/
#ifndef __SC__
#ifdef USE_DEFINE
#ifndef yywrap
#define yywrap() 1
#endif
#else
int yywrap() { return 1; }
#endif
#endif
#line 247 "y_tab.c"
#define YYABORT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse()
{
register int yym, yyn, yystate;
#if YYDEBUG
register char *yys;
extern char *getenv();
if (yys = getenv("YYDEBUG"))
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
yynerrs = 0;
yyerrflag = 0;
yychar = (-1);
yyssp = yyss;
yyvsp = yyvs;
*yyssp = yystate = 0;
yyloop:
if (yyn = yydefred[yystate]) goto yyreduce;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, reading %d (%s)\n", yystate,
yychar, yys);
}
#endif
}
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, shifting to state %d\n",
yystate, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
yychar = (-1);
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
yyn = yytable[yyn];
goto yyreduce;
}
if (yyerrflag) goto yyinrecovery;
#ifdef lint
goto yynewerror;
#endif
yynewerror:
yyerror("syntax error");
#ifdef lint
goto yyerrlab;
#endif
yyerrlab:
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, error recovery shifting\
to state %d\n", *yyssp, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
printf("yydebug: error recovery discarding state %d\n",
*yyssp);
#endif
if (yyssp <= yyss) goto yyabort;
--yyssp;
--yyvsp;
}
}
}
else
{
if (yychar == 0) goto yyabort;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, error recovery discards token %d (%s)\n",
yystate, yychar, yys);
}
#endif
yychar = (-1);
goto yyloop;
}
yyreduce:
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, reducing by rule %d (%s)\n",
yystate, yyn, yyrule[yyn]);
#endif
yym = yylen[yyn];
yyval = yyvsp[1-yym];
switch (yyn)
{
case 3:
#line 68 "parser.y"
{process_command(cexpr_cons(make_word(yyvsp[-1].s), NULL)); free(yyvsp[-1].s);}
break;
case 4:
#line 70 "parser.y"
{process_command(yyvsp[-1].s);}
break;
case 5:
#line 72 "parser.y"
{syntax_error("Unrecognized command.");}
break;
case 6:
#line 76 "parser.y"
{yyval.s = cexpr_cons(make_word(yyvsp[-3].s), yyvsp[-1].s); free(yyvsp[-3].s);}
break;
case 7:
#line 78 "parser.y"
{yyval.s = cexpr_cons(NULL, NULL);}
break;
case 8:
#line 80 "parser.y"
{yyval.s = yyvsp[-1].s; }
break;
case 9:
#line 84 "parser.y"
{yyval.s = NULL;}
break;
case 10:
#line 86 "parser.y"
{yyval.s = cexpr_cons(yyvsp[0].s, NULL);}
break;
case 11:
#line 89 "parser.y"
{yyval.s = cexpr_cons(yyvsp[-2].s, yyvsp[0].s);}
break;
case 12:
#line 93 "parser.y"
{yyval.s = cexpr_cons(make_word("="), cexpr_cons(make_word(yyvsp[-2].s), cexpr_cons(yyvsp[0].s, NULL)));
free(yyvsp[-2].s); }
break;
case 13:
#line 96 "parser.y"
{yyval.s = yyvsp[0].s; }
break;
case 14:
#line 99 "parser.y"
{yyval.s = make_word(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 15:
#line 101 "parser.y"
{yyval.s = make_string(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 16:
#line 103 "parser.y"
{yyval.s = make_integer(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 17:
#line 105 "parser.y"
{yyval.s = make_real(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); }
break;
case 18:
#line 107 "parser.y"
{yyval.s = make_exp(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); }
break;
case 19:
#line 110 "parser.y"
{yyval.s = make_exp2(yyvsp[-4].s, yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-4].s); free(yyvsp[-2].s);
free(yyvsp[0].s); }
break;
case 20:
#line 114 "parser.y"
{yyval.s = yyvsp[0].s;}
break;
#line 461 "y_tab.c"
}
yyssp -= yym;
yystate = *yyssp;
yyvsp -= yym;
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: after reduction, shifting from state 0 to\
state %d\n", YYFINAL);
#endif
yystate = YYFINAL;
*++yyssp = YYFINAL;
*++yyvsp = yyval;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, reading %d (%s)\n",
YYFINAL, yychar, yys);
}
#endif
}
if (yychar == 0) goto yyaccept;
goto yyloop;
}
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
yystate = yytable[yyn];
else
yystate = yydgoto[yym];
#if YYDEBUG
if (yydebug)
printf("yydebug: after reduction, shifting from state %d \
to state %d\n", *yyssp, yystate);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate;
*++yyvsp = yyval;
goto yyloop;
yyoverflow:
yyerror("yacc stack overflow");
yyabort:
return (1);
yyaccept:
return (0);
}

1208
CExpr/old/DOSLEX.C Normal file

File diff suppressed because it is too large Load diff

516
CExpr/old/DOSYACC.C Normal file
View file

@ -0,0 +1,516 @@
#ifndef lint
static char yysccsid[] = "@(#)yaccpar 1.7 (Berkeley) 09/09/90";
#endif
#define YYBYACC 1
#line 2 "parser.y"
#include "string.h"
#include "expr.h"
#ifndef __EXTERN_C__
#define __EXTERN_C__ 1
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
extern "C" {
#endif
#endif
int yylex(void);
int yylook(void);
int yywrap(void);
int yyback(int *, int);
/* You may need to put /DLEX_SCANNER in your makefile
* if you're using LEX!
*/
#ifdef LEX_SCANNER
/* int yyoutput(int); */
void yyoutput(int);
#else
void yyoutput(int);
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
}
#endif
#endif
#line 36 "parser.y"
typedef union {
char *s;
/* struct pexpr *expr; */
} YYSTYPE;
#line 44 "y_tab.c"
#define INTEGER 1
#define WORD 2
#define STRING 3
#define PERIOD 13
#define OPEN 4
#define CLOSE 5
#define COMMA 6
#define NEWLINE 7
#define ERROR 8
#define OPEN_SQUARE 9
#define CLOSE_SQUARE 10
#define EQUALS 11
#define EXP 14
#define YYERRCODE 256
short yylhs[] = { -1,
0, 0, 1, 1, 1, 2, 2, 2, 3, 3,
3, 4, 4, 5, 5, 5, 5, 5, 5, 5,
};
short yylen[] = { 2,
0, 2, 2, 2, 2, 4, 2, 3, 0, 1,
3, 3, 1, 1, 1, 1, 3, 3, 5, 1,
};
short yydefred[] = { 1,
0, 0, 0, 0, 2, 0, 5, 3, 0, 0,
0, 15, 7, 20, 0, 0, 13, 4, 0, 0,
0, 0, 8, 0, 6, 0, 18, 0, 12, 11,
0, 19,
};
short yydgoto[] = { 1,
5, 14, 15, 16, 17,
};
short yysindex[] = { 0,
-2, 9, 2, 1, 0, 10, 0, 0, 11, -5,
17, 0, 0, 0, 14, -1, 0, 0, 33, 38,
41, 16, 0, 11, 0, 29, 0, 40, 0, 0,
44, 0,
};
short yyrindex[] = { 0,
0, 0, 0, 0, 0, 0, 0, 0, 42, 21,
24, 0, 0, 0, 0, 30, 0, 0, 0, 0,
0, 0, 0, 31, 0, 27, 0, 24, 0, 0,
0, 0,
};
short yygindex[] = { 0,
0, 45, -8, 0, 26,
};
#define YYTABLESIZE 254
short yytable[] = { 3,
19, 10, 11, 12, 24, 9, 4, 20, 21, 4,
13, 10, 11, 12, 8, 30, 10, 28, 12, 4,
9, 7, 18, 23, 4, 16, 16, 22, 14, 14,
16, 17, 17, 14, 10, 9, 17, 25, 26, 10,
9, 27, 31, 9, 32, 6, 9, 29, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 2,
};
short yycheck[] = { 2,
9, 1, 2, 3, 6, 4, 9, 13, 14, 9,
10, 1, 2, 3, 13, 24, 1, 2, 3, 9,
4, 13, 13, 10, 9, 5, 6, 11, 5, 6,
10, 5, 6, 10, 5, 5, 10, 5, 1, 10,
10, 1, 14, 4, 1, 1, 5, 22, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 256,
};
#define YYFINAL 1
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 14
#if YYDEBUG
char *yyname[] = {
"end-of-file","INTEGER","WORD","STRING","OPEN","CLOSE","COMMA","NEWLINE",
"ERROR","OPEN_SQUARE","CLOSE_SQUARE","EQUALS",0,"PERIOD","EXP",
};
char *yyrule[] = {
"$accept : commands",
"commands :",
"commands : commands command",
"command : WORD PERIOD",
"command : expr PERIOD",
"command : error PERIOD",
"expr : WORD OPEN arglist CLOSE",
"expr : OPEN_SQUARE CLOSE_SQUARE",
"expr : OPEN_SQUARE arglist CLOSE_SQUARE",
"arglist :",
"arglist : arg",
"arglist : arg COMMA arglist",
"arg : WORD EQUALS arg1",
"arg : arg1",
"arg1 : WORD",
"arg1 : STRING",
"arg1 : INTEGER",
"arg1 : INTEGER PERIOD INTEGER",
"arg1 : INTEGER EXP INTEGER",
"arg1 : INTEGER PERIOD INTEGER EXP INTEGER",
"arg1 : expr",
};
#endif
#define yyclearin (yychar=(-1))
#define yyerrok (yyerrflag=0)
#ifdef YYSTACKSIZE
#ifndef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#endif
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 600
#define YYMAXDEPTH 600
#endif
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
short yyss[YYSTACKSIZE];
YYSTYPE yyvs[YYSTACKSIZE];
#define yystacksize YYSTACKSIZE
#line 118 "parser.y"
#include "lex_yy.c"
/*
void yyerror(s)
char *s;
{
syntax_error(s);
}
*/
/* Ansi prototype. If this doesn't work for you... uncomment
the above instead.
*/
void yyerror(char *s)
{
syntax_error(s);
}
/*
* Unfortunately, my DOS version of FLEX
* requires yywrap to be #def'ed, whereas
* the UNIX flex expects a proper function.
*/
/* Not sure if __SC__ is the appropriate thing
* to test
*/
#ifndef __SC__
#ifdef USE_DEFINE
#ifndef yywrap
#define yywrap() 1
#endif
#else
int yywrap() { return 1; }
#endif
#endif
#line 247 "y_tab.c"
#define YYABORT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse()
{
register int yym, yyn, yystate;
#if YYDEBUG
register char *yys;
extern char *getenv();
if (yys = getenv("YYDEBUG"))
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
yynerrs = 0;
yyerrflag = 0;
yychar = (-1);
yyssp = yyss;
yyvsp = yyvs;
*yyssp = yystate = 0;
yyloop:
if (yyn = yydefred[yystate]) goto yyreduce;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, reading %d (%s)\n", yystate,
yychar, yys);
}
#endif
}
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, shifting to state %d\n",
yystate, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
yychar = (-1);
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
yyn = yytable[yyn];
goto yyreduce;
}
if (yyerrflag) goto yyinrecovery;
#ifdef lint
goto yynewerror;
#endif
yynewerror:
yyerror("syntax error");
#ifdef lint
goto yyerrlab;
#endif
yyerrlab:
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, error recovery shifting\
to state %d\n", *yyssp, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
printf("yydebug: error recovery discarding state %d\n",
*yyssp);
#endif
if (yyssp <= yyss) goto yyabort;
--yyssp;
--yyvsp;
}
}
}
else
{
if (yychar == 0) goto yyabort;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, error recovery discards token %d (%s)\n",
yystate, yychar, yys);
}
#endif
yychar = (-1);
goto yyloop;
}
yyreduce:
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, reducing by rule %d (%s)\n",
yystate, yyn, yyrule[yyn]);
#endif
yym = yylen[yyn];
yyval = yyvsp[1-yym];
switch (yyn)
{
case 3:
#line 68 "parser.y"
{process_command(cexpr_cons(make_word(yyvsp[-1].s), NULL)); free(yyvsp[-1].s);}
break;
case 4:
#line 70 "parser.y"
{process_command(yyvsp[-1].s);}
break;
case 5:
#line 72 "parser.y"
{syntax_error("Unrecognized command.");}
break;
case 6:
#line 76 "parser.y"
{yyval.s = cexpr_cons(make_word(yyvsp[-3].s), yyvsp[-1].s); free(yyvsp[-3].s);}
break;
case 7:
#line 78 "parser.y"
{yyval.s = cexpr_cons(NULL, NULL);}
break;
case 8:
#line 80 "parser.y"
{yyval.s = yyvsp[-1].s; }
break;
case 9:
#line 84 "parser.y"
{yyval.s = NULL;}
break;
case 10:
#line 86 "parser.y"
{yyval.s = cexpr_cons(yyvsp[0].s, NULL);}
break;
case 11:
#line 89 "parser.y"
{yyval.s = cexpr_cons(yyvsp[-2].s, yyvsp[0].s);}
break;
case 12:
#line 93 "parser.y"
{yyval.s = cexpr_cons(make_word("="), cexpr_cons(make_word(yyvsp[-2].s), cexpr_cons(yyvsp[0].s, NULL)));
free(yyvsp[-2].s); }
break;
case 13:
#line 96 "parser.y"
{yyval.s = yyvsp[0].s; }
break;
case 14:
#line 99 "parser.y"
{yyval.s = make_word(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 15:
#line 101 "parser.y"
{yyval.s = make_string(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 16:
#line 103 "parser.y"
{yyval.s = make_integer(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 17:
#line 105 "parser.y"
{yyval.s = make_real(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); }
break;
case 18:
#line 107 "parser.y"
{yyval.s = make_exp(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); }
break;
case 19:
#line 110 "parser.y"
{yyval.s = make_exp2(yyvsp[-4].s, yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-4].s); free(yyvsp[-2].s);
free(yyvsp[0].s); }
break;
case 20:
#line 114 "parser.y"
{yyval.s = yyvsp[0].s;}
break;
#line 461 "y_tab.c"
}
yyssp -= yym;
yystate = *yyssp;
yyvsp -= yym;
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: after reduction, shifting from state 0 to\
state %d\n", YYFINAL);
#endif
yystate = YYFINAL;
*++yyssp = YYFINAL;
*++yyvsp = yyval;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, reading %d (%s)\n",
YYFINAL, yychar, yys);
}
#endif
}
if (yychar == 0) goto yyaccept;
goto yyloop;
}
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
yystate = yytable[yyn];
else
yystate = yydgoto[yym];
#if YYDEBUG
if (yydebug)
printf("yydebug: after reduction, shifting from state %d \
to state %d\n", *yyssp, yystate);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate;
*++yyvsp = yyval;
goto yyloop;
yyoverflow:
yyerror("yacc stack overflow");
yyabort:
return (1);
yyaccept:
return (0);
}

193
CExpr/old/LEXER.L Normal file
View file

@ -0,0 +1,193 @@
SIGN [+-]
DIGIT [0-9]
ALPHA [a-zA-Z_]
ALPHADIGIT [a-zA-Z_0-9]
STRINGCHAR [^"\\]
WORDCHAR [^'\\]
%{
/*
* File: lexer.l
* Description: Lexical analyser for PROLOGIO; can be used with
* either lex and flex.
*/
#include <string.h>
/* +++steve162e: added, otherwise, CExpr_input will be undefined (at least under LINUX)
please check, if this is also TRUE under other UNIXes.
*/
#if defined(FLEX_SCANNER) && defined(_LINUX)
#define CExpr_input my_input
#endif
/* ---steve162e */
#include "expr.h"
#ifdef wx_x
extern char *malloc();
#endif
#define Return(x) return x;
#if defined(VMS) && !defined(strdup)
#define strdup(s) (strcpy((char *)malloc(strlen(s)+1), s));
#endif
static size_t lex_buffer_length = 0;
static const char *lex_buffer = NULL;
static size_t lex_string_ptr = 0;
static int lex_read_from_string = 0;
static int my_input(void);
static int my_unput(char);
#ifdef FLEX_SCANNER
#undef YY_INPUT
# define YY_INPUT(buf,result,max_size) \
if (lex_read_from_string) \
{ int c = my_input(); result = (c == 0) ? YY_NULL : ((buf)[0]=(c), 1); } \
else \
if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
YY_FATAL_ERROR( "read() in flex scanner failed" );
#else
# undef unput
# define unput(_c) my_unput(_c)
#endif
%}
%%
{SIGN}?{DIGIT}+ {yylval.s = strdup(yytext); Return(INTEGER);}
"e" Return(EXP);
{ALPHA}{ALPHADIGIT}* {yylval.s = strdup(yytext); Return(WORD);}
"'"{WORDCHAR}*"'" {int len = strlen(yytext);
yytext[len-1] = 0;
yylval.s = strdup(yytext+1);
Return(WORD);}
\"({STRINGCHAR}|\\\"|\|\\\\|\\)*\" {yylval.s = strdup(yytext); Return(STRING);}
"(" Return(OPEN);
")" Return(CLOSE);
"," Return(COMMA);
"[" Return(OPEN_SQUARE);
"]" Return(CLOSE_SQUARE);
"=" Return(EQUALS);
"." Return(PERIOD);
[ \t] ;
\n ;
"/*" { loop:
#ifdef __cplusplus
while (yyinput() != '*');
switch (yyinput())
#else
while (input() != '*');
switch (input())
#endif
{
case '/': break;
case '*': unput('*');
default: goto loop;
}
}
. Return(ERROR);
%%
#ifdef FLEX_SCANNER
static int lex_input() {
return input();
}
#else /* BSD/AT&T lex */
#ifndef input
# error "Sorry, but need either flex or AT&T lex"
#endif
static int lex_input() {
return input();
}
/* # undef unput
# define unput(_c) my_unput(_c)
*/
# undef input
# define input() my_input()
static int my_unput(char c)
{
if (lex_read_from_string) {
/* Make sure we have something */
if (lex_string_ptr) {
if (c == '\n') yylineno--;
lex_string_ptr--;
}
} else {
yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;
/* unput(c); Causes infinite recursion! */
}
return c;
}
#endif
/* Public */
void LexFromFile(FILE *fd)
{
lex_read_from_string = 0;
yyin = fd;
/* Don't know why this is necessary, but otherwise
* lex only works _once_!
*/
#ifdef FLEX_SCANNER
yy_init = 1;
#endif
}
void LexFromString(char *buffer)
{
lex_read_from_string = 1;
lex_buffer = buffer;
lex_buffer_length = strlen(buffer);
lex_string_ptr = 0;
/* Don't know why this is necessary, but otherwise
* lex only works _once_!
*/
#ifdef FLEX_SCANNER
yy_init = 1;
#endif
}
static int my_input( void )
{
if (lex_read_from_string) {
if (lex_string_ptr == lex_buffer_length)
return 0;
else {
char c = lex_buffer[lex_string_ptr++];
#ifndef FLEX_SCANNER
if (c == '\n') yylineno++;
#endif
return c;
}
} else {
return lex_input();
}
}
void CExprCleanUp()
{
if (yy_current_buffer)
yy_delete_buffer(yy_current_buffer);
}

1213
CExpr/old/LEX_YY.C Normal file

File diff suppressed because it is too large Load diff

157
CExpr/old/PARSER.Y Normal file
View file

@ -0,0 +1,157 @@
%{
#include "string.h"
#include "expr.h"
#ifndef __EXTERN_C__
#define __EXTERN_C__ 1
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
extern "C" {
#endif
#endif
int yylex(void);
int yylook(void);
int yywrap(void);
int yyback(int *, int);
void yyerror(char *);
/* You may need to put /DLEX_SCANNER in your makefile
* if you're using LEX!
*/
#ifdef LEX_SCANNER
/* int yyoutput(int); */
void yyoutput(int);
#else
void yyoutput(int);
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
}
#endif
#endif
%}
%union {
char *s;
/* struct pexpr *expr; */
}
%start commands
%token <s> INTEGER 1
%token <s> WORD 2
%token <s> STRING 3
%token <s> PERIOD 13
%token OPEN 4
%token CLOSE 5
%token COMMA 6
%token NEWLINE 7
%token ERROR 8
%token OPEN_SQUARE 9
%token CLOSE_SQUARE 10
%token EQUALS 11
%token EXP 14
/* %type <expr> command expr arglist arg arg1 */
%type <s> command expr arglist arg arg1
%%
commands : /* empty */
| commands command
;
command : WORD PERIOD
{process_command(cexpr_cons(make_word($1), NULL)); free($1);}
| expr PERIOD
{process_command($1);}
| error PERIOD
{syntax_error("Unrecognized command.");}
;
expr : WORD OPEN arglist CLOSE
{$$ = cexpr_cons(make_word($1), $3); free($1);}
| OPEN_SQUARE CLOSE_SQUARE
{$$ = cexpr_cons(NULL, NULL);}
| OPEN_SQUARE arglist CLOSE_SQUARE
{$$ = $2; }
;
arglist :
{$$ = NULL;}
| arg
{$$ = cexpr_cons($1, NULL);}
|
arg COMMA arglist
{$$ = cexpr_cons($1, $3);}
;
arg : WORD EQUALS arg1
{$$ = cexpr_cons(make_word("="), cexpr_cons(make_word($1), cexpr_cons($3, NULL)));
free($1); }
| arg1
{$$ = $1; }
arg1 : WORD
{$$ = make_word($1); free($1);}
| STRING
{$$ = make_string($1); free($1);}
| INTEGER
{$$ = make_integer($1); free($1);}
| INTEGER PERIOD INTEGER
{$$ = make_real($1, $3); free($1); free($3); }
| INTEGER EXP INTEGER
{$$ = make_exp($1, $3); free($1); free($3); }
|
INTEGER PERIOD INTEGER EXP INTEGER
{$$ = make_exp2($1, $3, $5); free($1); free($3);
free($5); }
| expr
{$$ = $1;}
;
%%
#include "lex_yy.c"
/*
void yyerror(s)
char *s;
{
syntax_error(s);
}
*/
/* Ansi prototype. If this doesn't work for you... uncomment
the above instead.
*/
void yyerror(char *s)
{
syntax_error(s);
}
/*
* Unfortunately, my DOS version of FLEX
* requires yywrap to be #def'ed, whereas
* the UNIX flex expects a proper function.
*/
/* Not sure if __SC__ is the appropriate thing
* to test
*/
#ifndef __SC__
#ifdef USE_DEFINE
#ifndef yywrap
#define yywrap() 1
#endif
#else if !defined(__alpha) && !defined(__ultrix)
int yywrap() { return 1; }
#endif
#endif

516
CExpr/old/Y_TAB.C Normal file
View file

@ -0,0 +1,516 @@
#ifndef lint
static char yysccsid[] = "@(#)yaccpar 1.7 (Berkeley) 09/09/90";
#endif
#define YYBYACC 1
#line 2 "parser.y"
#include "string.h"
#include "expr.h"
#ifndef __EXTERN_C__
#define __EXTERN_C__ 1
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
extern "C" {
#endif
#endif
int yylex(void);
int yylook(void);
int yywrap(void);
int yyback(int *, int);
/* You may need to put /DLEX_SCANNER in your makefile
* if you're using LEX!
*/
#ifdef LEX_SCANNER
/* int yyoutput(int); */
void yyoutput(int);
#else
void yyoutput(int);
#endif
#if defined(__cplusplus) || defined(__STDC__)
#if defined(__cplusplus) && defined(__EXTERN_C__)
}
#endif
#endif
#line 36 "parser.y"
typedef union {
char *s;
/* struct pexpr *expr; */
} YYSTYPE;
#line 44 "y_tab.c"
#define INTEGER 1
#define WORD 2
#define STRING 3
#define PERIOD 13
#define OPEN 4
#define CLOSE 5
#define COMMA 6
#define NEWLINE 7
#define ERROR 8
#define OPEN_SQUARE 9
#define CLOSE_SQUARE 10
#define EQUALS 11
#define EXP 14
#define YYERRCODE 256
short yylhs[] = { -1,
0, 0, 1, 1, 1, 2, 2, 2, 3, 3,
3, 4, 4, 5, 5, 5, 5, 5, 5, 5,
};
short yylen[] = { 2,
0, 2, 2, 2, 2, 4, 2, 3, 0, 1,
3, 3, 1, 1, 1, 1, 3, 3, 5, 1,
};
short yydefred[] = { 1,
0, 0, 0, 0, 2, 0, 5, 3, 0, 0,
0, 15, 7, 20, 0, 0, 13, 4, 0, 0,
0, 0, 8, 0, 6, 0, 18, 0, 12, 11,
0, 19,
};
short yydgoto[] = { 1,
5, 14, 15, 16, 17,
};
short yysindex[] = { 0,
-2, 9, 2, 1, 0, 10, 0, 0, 11, -5,
17, 0, 0, 0, 14, -1, 0, 0, 33, 38,
41, 16, 0, 11, 0, 29, 0, 40, 0, 0,
44, 0,
};
short yyrindex[] = { 0,
0, 0, 0, 0, 0, 0, 0, 0, 42, 21,
24, 0, 0, 0, 0, 30, 0, 0, 0, 0,
0, 0, 0, 31, 0, 27, 0, 24, 0, 0,
0, 0,
};
short yygindex[] = { 0,
0, 45, -8, 0, 26,
};
#define YYTABLESIZE 254
short yytable[] = { 3,
19, 10, 11, 12, 24, 9, 4, 20, 21, 4,
13, 10, 11, 12, 8, 30, 10, 28, 12, 4,
9, 7, 18, 23, 4, 16, 16, 22, 14, 14,
16, 17, 17, 14, 10, 9, 17, 25, 26, 10,
9, 27, 31, 9, 32, 6, 9, 29, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 2,
};
short yycheck[] = { 2,
9, 1, 2, 3, 6, 4, 9, 13, 14, 9,
10, 1, 2, 3, 13, 24, 1, 2, 3, 9,
4, 13, 13, 10, 9, 5, 6, 11, 5, 6,
10, 5, 6, 10, 5, 5, 10, 5, 1, 10,
10, 1, 14, 4, 1, 1, 5, 22, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 256,
};
#define YYFINAL 1
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 14
#if YYDEBUG
char *yyname[] = {
"end-of-file","INTEGER","WORD","STRING","OPEN","CLOSE","COMMA","NEWLINE",
"ERROR","OPEN_SQUARE","CLOSE_SQUARE","EQUALS",0,"PERIOD","EXP",
};
char *yyrule[] = {
"$accept : commands",
"commands :",
"commands : commands command",
"command : WORD PERIOD",
"command : expr PERIOD",
"command : error PERIOD",
"expr : WORD OPEN arglist CLOSE",
"expr : OPEN_SQUARE CLOSE_SQUARE",
"expr : OPEN_SQUARE arglist CLOSE_SQUARE",
"arglist :",
"arglist : arg",
"arglist : arg COMMA arglist",
"arg : WORD EQUALS arg1",
"arg : arg1",
"arg1 : WORD",
"arg1 : STRING",
"arg1 : INTEGER",
"arg1 : INTEGER PERIOD INTEGER",
"arg1 : INTEGER EXP INTEGER",
"arg1 : INTEGER PERIOD INTEGER EXP INTEGER",
"arg1 : expr",
};
#endif
#define yyclearin (yychar=(-1))
#define yyerrok (yyerrflag=0)
#ifdef YYSTACKSIZE
#ifndef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#endif
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 600
#define YYMAXDEPTH 600
#endif
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
short yyss[YYSTACKSIZE];
YYSTYPE yyvs[YYSTACKSIZE];
#define yystacksize YYSTACKSIZE
#line 118 "parser.y"
#include "lex_yy.c"
/*
void yyerror(s)
char *s;
{
syntax_error(s);
}
*/
/* Ansi prototype. If this doesn't work for you... uncomment
the above instead.
*/
void yyerror(char *s)
{
syntax_error(s);
}
/*
* Unfortunately, my DOS version of FLEX
* requires yywrap to be #def'ed, whereas
* the UNIX flex expects a proper function.
*/
/* Not sure if __SC__ is the appropriate thing
* to test
*/
#ifndef __SC__
#ifdef USE_DEFINE
#ifndef yywrap
#define yywrap() 1
#endif
#else
int yywrap() { return 1; }
#endif
#endif
#line 247 "y_tab.c"
#define YYABORT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse()
{
register int yym, yyn, yystate;
#if YYDEBUG
register char *yys;
extern char *getenv();
if (yys = getenv("YYDEBUG"))
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
yynerrs = 0;
yyerrflag = 0;
yychar = (-1);
yyssp = yyss;
yyvsp = yyvs;
*yyssp = yystate = 0;
yyloop:
if (yyn = yydefred[yystate]) goto yyreduce;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, reading %d (%s)\n", yystate,
yychar, yys);
}
#endif
}
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, shifting to state %d\n",
yystate, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
yychar = (-1);
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
yyn = yytable[yyn];
goto yyreduce;
}
if (yyerrflag) goto yyinrecovery;
#ifdef lint
goto yynewerror;
#endif
yynewerror:
yyerror("syntax error");
#ifdef lint
goto yyerrlab;
#endif
yyerrlab:
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, error recovery shifting\
to state %d\n", *yyssp, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
printf("yydebug: error recovery discarding state %d\n",
*yyssp);
#endif
if (yyssp <= yyss) goto yyabort;
--yyssp;
--yyvsp;
}
}
}
else
{
if (yychar == 0) goto yyabort;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, error recovery discards token %d (%s)\n",
yystate, yychar, yys);
}
#endif
yychar = (-1);
goto yyloop;
}
yyreduce:
#if YYDEBUG
if (yydebug)
printf("yydebug: state %d, reducing by rule %d (%s)\n",
yystate, yyn, yyrule[yyn]);
#endif
yym = yylen[yyn];
yyval = yyvsp[1-yym];
switch (yyn)
{
case 3:
#line 68 "parser.y"
{process_command(cexpr_cons(make_word(yyvsp[-1].s), NULL)); free(yyvsp[-1].s);}
break;
case 4:
#line 70 "parser.y"
{process_command(yyvsp[-1].s);}
break;
case 5:
#line 72 "parser.y"
{syntax_error("Unrecognized command.");}
break;
case 6:
#line 76 "parser.y"
{yyval.s = cexpr_cons(make_word(yyvsp[-3].s), yyvsp[-1].s); free(yyvsp[-3].s);}
break;
case 7:
#line 78 "parser.y"
{yyval.s = cexpr_cons(NULL, NULL);}
break;
case 8:
#line 80 "parser.y"
{yyval.s = yyvsp[-1].s; }
break;
case 9:
#line 84 "parser.y"
{yyval.s = NULL;}
break;
case 10:
#line 86 "parser.y"
{yyval.s = cexpr_cons(yyvsp[0].s, NULL);}
break;
case 11:
#line 89 "parser.y"
{yyval.s = cexpr_cons(yyvsp[-2].s, yyvsp[0].s);}
break;
case 12:
#line 93 "parser.y"
{yyval.s = cexpr_cons(make_word("="), cexpr_cons(make_word(yyvsp[-2].s), cexpr_cons(yyvsp[0].s, NULL)));
free(yyvsp[-2].s); }
break;
case 13:
#line 96 "parser.y"
{yyval.s = yyvsp[0].s; }
break;
case 14:
#line 99 "parser.y"
{yyval.s = make_word(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 15:
#line 101 "parser.y"
{yyval.s = make_string(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 16:
#line 103 "parser.y"
{yyval.s = make_integer(yyvsp[0].s); free(yyvsp[0].s);}
break;
case 17:
#line 105 "parser.y"
{yyval.s = make_real(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); }
break;
case 18:
#line 107 "parser.y"
{yyval.s = make_exp(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); }
break;
case 19:
#line 110 "parser.y"
{yyval.s = make_exp2(yyvsp[-4].s, yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-4].s); free(yyvsp[-2].s);
free(yyvsp[0].s); }
break;
case 20:
#line 114 "parser.y"
{yyval.s = yyvsp[0].s;}
break;
#line 461 "y_tab.c"
}
yyssp -= yym;
yystate = *yyssp;
yyvsp -= yym;
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
printf("yydebug: after reduction, shifting from state 0 to\
state %d\n", YYFINAL);
#endif
yystate = YYFINAL;
*++yyssp = YYFINAL;
*++yyvsp = yyval;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("yydebug: state %d, reading %d (%s)\n",
YYFINAL, yychar, yys);
}
#endif
}
if (yychar == 0) goto yyaccept;
goto yyloop;
}
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
yystate = yytable[yyn];
else
yystate = yydgoto[yym];
#if YYDEBUG
if (yydebug)
printf("yydebug: after reduction, shifting from state %d \
to state %d\n", *yyssp, yystate);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate;
*++yyvsp = yyval;
goto yyloop;
yyoverflow:
yyerror("yacc stack overflow");
yyabort:
return (1);
yyaccept:
return (0);
}