diff --git a/CExpr/CEXPR.CNT b/CExpr/CEXPR.CNT new file mode 100644 index 0000000..08d838a --- /dev/null +++ b/CExpr/CEXPR.CNT @@ -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 diff --git a/CExpr/CEXPR.HLP b/CExpr/CEXPR.HLP new file mode 100644 index 0000000..d973bf1 Binary files /dev/null and b/CExpr/CEXPR.HLP differ diff --git a/CExpr/Cexpr.cpp b/CExpr/Cexpr.cpp new file mode 100644 index 0000000..098e24d --- /dev/null +++ b/CExpr/Cexpr.cpp @@ -0,0 +1,1229 @@ +/* + * File: cexpr.cpp + * Purpose: Prolog-like file I/O + * Author: Julian Smart + * Created: 1993 + * Updated: + * Copyright: (c) 1993 + */ + +static const char sccsid[] = "%W% %G%"; + +#include "stdafx.h" +#include +#include +#include + +#include "expr.h" +#include "cexpr.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +extern "C" void add_expr(char *); +extern "C" void LexFromFile(FILE *fd); +extern "C" void LexFromString(char *buf); + +CExprDatabase *theCExprDatabase = NULL; +CExprErrorHandler currentCExprErrorHandler; + +IMPLEMENT_DYNAMIC(CExprDatabase, wxList) + +CExpr::CExpr(const CString& functor) +{ + type = CExprList; + next = NULL; + last = NULL; + value.first = NULL; + + CExpr *pfunctor = new CExpr(CExprWord, functor); + Append(pfunctor); + client_data = NULL; +} + +CExpr::CExpr(CExprType the_type, const CString& word_or_string) +{ + type = the_type; + + switch (the_type) + { + case CExprWord: + value.word = copystring((const char *)word_or_string); + break; + case CExprString: + value.string = copystring((const char *)word_or_string); + break; + case CExprList: + last = NULL; + value.first = NULL; + break; + case CExprReal: + case CExprInteger: + case CExprNull: + break; + } + client_data = NULL; + next = NULL; +} + +CExpr::CExpr(CExprType the_type, char *word_or_string, BOOL allocate) +{ + type = the_type; + + switch (the_type) + { + case CExprWord: + value.word = allocate ? copystring(word_or_string) : word_or_string; + break; + case CExprString: + value.string = allocate ? copystring(word_or_string) : word_or_string; + break; + case CExprList: + last = NULL; + value.first = NULL; + break; + case CExprReal: + case CExprInteger: + case CExprNull: + break; + } + client_data = NULL; + next = NULL; +} + +CExpr::CExpr(long the_integer) +{ + type = CExprInteger; + value.integer = the_integer; + client_data = NULL; + next = NULL; +} + +CExpr::CExpr(float the_real) +{ + type = CExprReal; + value.real = the_real; + client_data = NULL; + next = NULL; +} + +CExpr::CExpr(wxList *the_list) +{ + type = CExprList; + client_data = NULL; + last = NULL; + value.first = NULL; + + CExpr *listExpr = new CExpr(CExprList); + + wxNode *node = the_list->First(); + while (node) + { + CExpr *expr = (CExpr *)node->Data(); + listExpr->Append(expr); + node = node->Next(); + } + Append(listExpr); + + delete the_list; +} + +CExpr::~CExpr(void) +{ + switch (type) + { + case CExprInteger: + case CExprReal: + { + break; + } + case CExprString: + { + delete[] value.string; + break; + } + case CExprWord: + { + delete[] value.word; + break; + } + case CExprList: + { + CExpr *expr = value.first; + while (expr) + { + CExpr *expr1 = expr->next; + + delete expr; + expr = expr1; + } + break; + } + case CExprNull: break; + } +} + +void CExpr::Append(CExpr *expr) +{ + if (!value.first) + value.first = expr; + + if (last) + last->next = expr; + last = expr; +} + +void CExpr::Insert(CExpr *expr) +{ + expr->next = value.first; + value.first = expr; + + if (!last) + last = expr; +} + +CExpr *CExpr::Copy(void) +{ + // This seems to get round an optimizer bug when + // using Watcom C++ 10a in WIN32 compilation mode. + // If these lines not present, the type seems to be + // interpreted wrongly as an integer. + // I don't want to turn optimization off since it's needed + // for reading in files quickly. +#if defined(__WATCOMC__) + char buf[2]; + sprintf(buf, ""); +#endif + + switch (type) + { + case CExprInteger: + return new CExpr(value.integer); + case CExprReal: + return new CExpr(value.real); + case CExprString: + return new CExpr(CExprString, CString(value.string)); + case CExprWord: + return new CExpr(CExprWord, CString(value.word)); + case CExprList: + { + CExpr *expr = value.first; + CExpr *new_list = new CExpr(CExprList); + while (expr) + { + CExpr *expr2 = expr->Copy(); + new_list->Append(expr2); + expr = expr->next; + } + return new_list; + } + case CExprNull: + break; + } + return NULL; +} + + +// Get the CExpr (containing (= CExpr Value) form) for the given word +// or string, assuming that we have Attribute=Value, ... +CExpr *CExpr::GetAttributeValueNode(const CString& word) // Use only for a clause or list +{ + if (type != CExprList) + return NULL; + + CExpr *expr = value.first; + while (expr) + { + if (expr->type == CExprList) + { + CExpr *firstNode = expr->value.first; + if ((firstNode->type == CExprWord) && (firstNode->value.word[0] == '=')) + { + CExpr *secondNode = firstNode->next; + if ((secondNode->type == CExprWord) && + (strcmp((const char *)word, secondNode->value.word) == 0)) + { + return expr; + } + } + } + expr = expr->next; + } + return NULL; +} + +// Get the value (in CExpr form) for the given word or string, assuming +// that we have Attribute=Value, ... +CExpr *CExpr::AttributeValue(const CString& word) // Use only for a clause or list +{ + if (type != CExprList) + return NULL; + + CExpr *attExpr = GetAttributeValueNode(word); + if (attExpr && attExpr->value.first && attExpr->value.first->next) + return attExpr->value.first->next->next; + else return NULL; +} + +CString CExpr::Functor(void) // Use only for a clause +{ + if ((type != CExprList) || !value.first) + return CString(""); + + if (value.first->type == CExprWord) + return CString(value.first->value.word); + else + return CString(""); +} + +BOOL CExpr::IsFunctor(const CString& f) // Use only for a clause +{ + if ((type != CExprList) || !value.first) + return FALSE; + + return (value.first->type == CExprWord && + (strcmp((const char *)f, value.first->value.word) == 0)); +} + +// Return nth argument of a clause (starting from 1) +CExpr *CExpr::Arg(CExprType theType, int arg) +{ + CExpr *expr = value.first; + int i; + for (i = 1; i < arg; i++) + if (expr) + expr = expr->next; + + if (expr && (expr->type == theType)) + return expr; + else + return NULL; +} + +// Return nth argument of a list expression (starting from zero) +CExpr *CExpr::Nth(int arg) +{ + if (type != CExprList) + return NULL; + + CExpr *expr = value.first; + int i; + for (i = 0; i < arg; i++) + if (expr) + expr = expr->next; + else return NULL; + + if (expr) + return expr; + else + return NULL; +} + + // Returns the number of elements in a list expression +int CExpr::Number(void) +{ + if (type != CExprList) + return 0; + + int i = 0; + CExpr *expr = value.first; + while (expr) + { + expr = expr->next; + i ++; + } + return i; +} + +void CExpr::DeleteAttributeValue(const CString& attribute) +{ + if (type != CExprList) + return; + + CExpr *expr = value.first; + CExpr *lastExpr = this; + while (expr) + { + if (expr->type == CExprList) + { + CExpr *firstNode = expr->value.first; + if ((firstNode->type == CExprWord) && (firstNode->value.word[0] == '=')) + { + CExpr *secondNode = firstNode->next; + if ((secondNode->type == CExprWord) && + (strcmp((const char *)attribute, secondNode->value.word) == 0)) + { + CExpr *nextExpr = expr->next; + delete expr; + + lastExpr->next = nextExpr; + + if (last == expr) + last = lastExpr; + + return; + } + } + } + lastExpr = expr; + expr = expr->next; + } + return; +} + +void CExpr::AddAttributeValue(const CString& attribute, CExpr *val) +{ + if (type != CExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist CExpr expression\n"; + return; + } + // Warning - existing code may assume that any existing value + // is deleted first. For efficiency, we leave this to the application. +// DeleteAttributeValue(attribute); + + CExpr *patt = new CExpr(CExprWord, attribute); + CExpr *pequals = new CExpr(CExprWord, "="); + + CExpr *listExpr = new CExpr(CExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(val); + + Append(listExpr); +} + +void CExpr::AddAttributeValue(const CString& attribute, long val) +{ + if (type != CExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist CExpr expression\n"; + return; + } + // Warning - existing code may assume that any existing value + // is deleted first. For efficiency, we leave this to the application. +// DeleteAttributeValue(attribute); + + CExpr *patt = new CExpr(CExprWord, attribute); + CExpr *pval = new CExpr(val); + CExpr *pequals = new CExpr(CExprWord, "="); + + CExpr *listExpr = new CExpr(CExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(pval); + + Append(listExpr); +} + +void CExpr::AddAttributeValue(const CString& attribute, float val) +{ + if (type != CExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist CExpr expression\n"; + return; + } + +// DeleteAttributeValue(attribute); + CExpr *patt = new CExpr(CExprWord, attribute); + CExpr *pval = new CExpr(val); + CExpr *pequals = new CExpr(CExprWord, "="); + + CExpr *listExpr = new CExpr(CExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(pval); + + Append(listExpr); +} + +void CExpr::AddAttributeValueString(const CString& attribute, const CString& val) +{ + if (type != CExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist CExpr expression\n"; + return; + } + +// DeleteAttributeValue(attribute); + + CExpr *patt = new CExpr(CExprWord, attribute); + CExpr *pval = new CExpr(CExprString, val); + CExpr *pequals = new CExpr(CExprWord, "="); + + CExpr *listExpr = new CExpr(CExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(pval); + + Append(listExpr); +} + +void CExpr::AddAttributeValueWord(const CString& attribute, const CString& val) +{ + if (type != CExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist CExpr expression\n"; + return; + } + +// DeleteAttributeValue(attribute); + + CExpr *patt = new CExpr(CExprWord, attribute); + CExpr *pval = new CExpr(CExprWord, val); + CExpr *pequals = new CExpr(CExprWord, "="); + + CExpr *listExpr = new CExpr(CExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(pval); + + Append(listExpr); +} + +void CExpr::AddAttributeValue(const CString& attribute, wxList *val) +{ + if (type != CExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist CExpr expression\n"; + return; + } + if (!val) + return; + +// DeleteAttributeValue(attribute); + + CExpr *patt = new CExpr(CExprWord, attribute); + CExpr *pval = new CExpr(val); + CExpr *pequals = new CExpr(CExprWord, "="); + + CExpr *listExpr = new CExpr(CExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(pval); + + Append(listExpr); +} + +void CExpr::AddAttributeValueStringList(const CString& attribute, wxList *string_list) +{ + if (type != CExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist CExpr expression\n"; + return; + } + if (!string_list) + return; + +// DeleteAttributeValue(attribute); + + // First make a list of CExpr strings + CExpr *listExpr = new CExpr(CExprList); + wxNode *node = string_list->First(); + while (node) + { + char *string = (char *)node->Data(); + CExpr *expr = new CExpr(CExprString, CString(string)); + listExpr->Append(expr); + node = node->Next(); + } + + // Now make an (=, Att, Value) triple + CExpr *patt = new CExpr(CExprWord, attribute); + CExpr *pequals = new CExpr(CExprWord, "="); + + CExpr *listExpr2 = new CExpr(CExprList); + + listExpr2->Append(pequals); + listExpr2->Append(patt); + listExpr2->Append(listExpr); + + Append(listExpr2); +} + +BOOL CExpr::GetAttributeValue(const CString& att, int& var) +{ + CExpr *expr = AttributeValue(att); + + if (expr && (expr->Type() == CExprInteger || expr->Type() == CExprReal)) + { + var = (int)(expr->IntegerValue()); + return TRUE; + } + else + return FALSE; +} + +BOOL CExpr::GetAttributeValue(const CString& att, long& var) +{ + CExpr *expr = AttributeValue(att); + + if (expr && (expr->Type() == CExprInteger || expr->Type() == CExprReal)) + { + var = expr->IntegerValue(); + return TRUE; + } + else + return FALSE; +} + +BOOL CExpr::GetAttributeValue(const CString& att, float& var) +{ + CExpr *expr = AttributeValue(att); + if (expr && (expr->Type() == CExprInteger || expr->Type() == CExprReal)) + { + var = expr->RealValue(); + return TRUE; + } + else + return FALSE; +} + +BOOL CExpr::GetAttributeValue(const CString& att, CString& var) // Word OR string -> string +{ + CExpr *expr = AttributeValue(att); + if (expr && expr->Type() == CExprWord) + { + var = expr->WordValue(); + return TRUE; + } + else if (expr && expr->Type() == CExprString) + { + var = expr->StringValue(); + return TRUE; + } + else + return FALSE; +} + +BOOL CExpr::GetAttributeValue(const CString& att, CExpr **var) +{ + CExpr *expr = AttributeValue(att); + if (expr) + { + *var = expr; + return TRUE; + } + else + return FALSE; +} + +BOOL CExpr::GetAttributeValueStringList(const CString& att, wxList *var) +{ + CExpr *expr = AttributeValue(att); + if (expr && expr->Type() == CExprList) + { + CExpr *string_expr = expr->value.first; + while (string_expr) + { + if (string_expr->Type() == CExprString) + var->Append((CObject *)copystring(string_expr->StringValue())); + + string_expr = string_expr->next; + } + return TRUE; + } + else + return FALSE; +} + +void CExpr::WriteClause(ostream& stream) // Write this expression as a top-level clause +{ + if (type != CExprList) + return; + + CExpr *node = value.first; + if (node) + { + node->WriteExpr(stream); + stream << "("; + node = node->next; + BOOL first = TRUE; + while (node) + { + if (!first) + stream << " "; + node->WriteExpr(stream); + node = node->next; + if (node) stream << ",\n"; + first = FALSE; + } + stream << ").\n\n"; + } +} + +void CExpr::WriteExpr(ostream& stream) // Write as any other subexpression +{ + // This seems to get round an optimizer bug when + // using Watcom C++ 10a in WIN32 compilation mode. + // If these lines not present, the type seems to be + // interpreted wrongly as an integer. + // I don't want to turn optimization off since it's needed + // for reading in files quickly. +#if defined(__WATCOMC__) + char buf[2]; + sprintf(buf, ""); +#endif + + switch (type) + { + case CExprInteger: + { + stream << value.integer; + break; + } + case CExprReal: + { + float f = value.real; +/* Now the parser can cope with this. + // Prevent printing in 'e' notation. Any better way? + if (fabs(f) < 0.00001) + f = 0.0; +*/ + char buf[40]; + sprintf(buf, "%.6g", f); + stream << buf; + break; + } + case CExprString: + { + stream << "\""; + int i; + int len = strlen(value.string); + for (i = 0; i < len; i++) + { + char ch = value.string[i]; + if (ch == '"' || ch == '\\') + stream << "\\"; + stream << ch; + } + + stream << "\""; + break; + } + case CExprWord: + { + BOOL quote_it = FALSE; + int len = strlen(value.word); + if ((len == 0) || (len > 0 && (value.word[0] > 64 && value.word[0] < 91))) + quote_it = TRUE; + else + { + int i; + for (i = 0; i < len; i++) + if ((!isalpha(value.word[i])) && (!isdigit(value.word[i])) && + (value.word[i] != '_')) + { quote_it = TRUE; i = len; } + } + + if (quote_it) + stream << "'"; + + stream << value.word; + + if (quote_it) + stream << "'"; + + break; + } + case CExprList: + { + if (!value.first) + stream << "[]"; + else + { + CExpr *expr = value.first; + + if ((expr->Type() == CExprWord) && (strcmp(expr->WordValue(), "=") == 0)) + { + CExpr *arg1 = expr->next; + CExpr *arg2 = arg1->next; + arg1->WriteExpr(stream); + stream << " = "; + arg2->WriteExpr(stream); + } + else + { + stream << "["; + while (expr) + { + expr->WriteExpr(stream); + expr = expr->next; + if (expr) stream << ", "; + } + stream << "]"; + } + } + break; + } + case CExprNull: break; + } +} + +void CExpr::WriteLispExpr(ostream& stream) +{ + switch (type) + { + case CExprInteger: + { + stream << value.integer; + break; + } + case CExprReal: + { + stream << value.real; + break; + } + case CExprString: + { + stream << "\"" << value.string << "\""; + break; + } + case CExprWord: + { + stream << value.word; + break; + } + case CExprList: + { + CExpr *expr = value.first; + + stream << "("; + while (expr) + { + expr->WriteLispExpr(stream); + expr = expr->next; + if (expr) stream << " "; + } + + stream << ")"; + break; + } + case CExprNull: break; + } +} + +// CExpr 'database' (list of expressions) +CExprDatabase::CExprDatabase(CExprErrorHandler handler) +{ + position = NULL; + hash_table = NULL; + currentCExprErrorHandler = handler; + noErrors = 0; +} + +CExprDatabase::CExprDatabase(CExprType type, const CString& attribute, int size, + CExprErrorHandler handler) +{ + position = NULL; + attribute_to_hash = attribute; + if (type == CExprString) + hash_table = new wxHashTable(wxKEY_STRING, size); + else if (type == CExprInteger) + hash_table = new wxHashTable(wxKEY_INTEGER, size); + else hash_table = NULL; + + currentCExprErrorHandler = handler; + noErrors = 0; +} + +CExprDatabase::~CExprDatabase(void) +{ + ClearDatabase(); + if (hash_table) + delete hash_table; +} + +int CExprDatabase::GetItemCount(void) // get count of possible items +{ + int z = 0; + wxNode *node = First(); + while (node) + { + z++; + node = node->Next(); + } + return z; +} + +void CExprDatabase::BeginFind(void) // Initialise a search +{ + position = First(); +} + +CExpr *CExprDatabase::FindClause(long id) // Find a term based on an integer id attribute + // e.g. node(id=23, type=rectangle, ....). +{ + CExpr *found = NULL; + while (position && !found) + { + CExpr *term = (CExpr *)position->Data(); + + if (term->Type() == CExprList) + { + CExpr *value = term->AttributeValue("id"); + if (value->Type() == CExprInteger && value->IntegerValue() == id) + found = term; + } + position = position->Next(); + } + return found; +} + +// Find on basis of attribute/value pairs, e.g. type=rectangle +CExpr *CExprDatabase::FindClause(const CString& word, const CString& val) +{ + CExpr *found = NULL; + while (position && !found) + { + CExpr *term = (CExpr *)position->Data(); + + if (term->Type() == CExprList) + { + CExpr *value = term->AttributeValue(word); + if ((value->Type() == CExprWord && value->WordValue() == val) || + (value->Type() == CExprString && value->StringValue() == val)) + found = term; + } + position = position->Next(); + } + return found; +} + +CExpr *CExprDatabase::FindClause(const CString& word, long val) +{ + CExpr *found = NULL; + while (position && !found) + { + CExpr *term = (CExpr *)position->Data(); + + if (term->Type() == CExprList) + { + CExpr *value = term->AttributeValue(word); + if ((value->Type() == CExprInteger) && (value->IntegerValue() == val)) + found = term; + } + position = position->Next(); + } + return found; +} + +CExpr *CExprDatabase::FindClause(const CString& word, float val) +{ + CExpr *found = NULL; + while (position && !found) + { + CExpr *term = (CExpr *)position->Data(); + + if (term->Type() == CExprList) + { + CExpr *value = term->AttributeValue(word); + if ((value->Type() == CExprReal) && (value->RealValue() == val)) + found = term; + } + position = position->Next(); + } + return found; +} + +CExpr *CExprDatabase::FindClauseByFunctor(const CString& functor) +{ + CExpr *found = NULL; + while (position && !found) + { + CExpr *term = (CExpr *)position->Data(); + + if (term->Type() == CExprList) + { + if (term->Functor() == functor) + found = term; + } + position = position->Next(); + } + return found; +} + +// If hashing is on, must store in hash table too +void CExprDatabase::Append(CExpr *clause) +{ + wxList::Append((CObject *)clause); + if (hash_table) + { + CString functor(clause->Functor()); + CExpr *expr = clause->AttributeValue(attribute_to_hash); + if (expr) + { + long functor_key = hash_table->MakeKey((char *)(const char *)functor); + long value_key = 0; + if (expr && expr->Type() == CExprString) + { + value_key = hash_table->MakeKey((char *)(const char *)expr->StringValue()); + hash_table->Put(functor_key + value_key, (char *)(const char *)expr->StringValue(), (CObject *)clause); + } + else if (expr && expr->Type() == CExprInteger) + { + value_key = expr->IntegerValue(); + hash_table->Put(functor_key + value_key, expr->IntegerValue(), (CObject *)clause); + } + + } + } +} + +CExpr *CExprDatabase::HashFind(const CString& functor, long value) +{ + long key = hash_table->MakeKey((char *)(const char *)functor) + value; + + // The key alone isn't guaranteed to be unique: + // must supply value too. Let's assume the value of the + // id is going to be reasonably unique. + return (CExpr *)hash_table->Get(key, value); +} + +CExpr *CExprDatabase::HashFind(const CString& functor, const CString& value) +{ + long key = hash_table->MakeKey((char *)(const char *)functor) + hash_table->MakeKey((char *)(const char *)value); + return (CExpr *)hash_table->Get(key, (char *)(const char *)value); +} + +void CExprDatabase::ClearDatabase(void) +{ + noErrors = 0; + wxNode *node = First(); + while (node) + { + CExpr *expr = (CExpr *)node->Data(); + delete expr; + delete node; + node = First(); + } + + if (hash_table) + hash_table->Clear(); +} + +BOOL CExprDatabase::Read(const CString& filename) +{ + noErrors = 0; + + FILE *f = fopen((const char *)filename, "r"); + if (f) + { + theCExprDatabase = this; + + LexFromFile(f); + yyparse(); + fclose(f); + + CExprCleanUp(); + return (noErrors == 0); + } + else + { + return FALSE; + } +} + +BOOL CExprDatabase::ReadFromString(const CString& buffer) +{ + noErrors = 0; + theCExprDatabase = this; + + LexFromString((char *)(const char *)buffer); + yyparse(); + CExprCleanUp(); + return (noErrors == 0); +} + +BOOL CExprDatabase::Write(const CString& fileName) +{ + ofstream str((char *)(const char *)fileName); + if (str.bad()) + return FALSE; + return Write(str); +} + +BOOL CExprDatabase::Write(ostream& stream) +{ + noErrors = 0; + wxNode *node = First(); + while (node) + { + CExpr *expr = (CExpr *)node->Data(); + expr->WriteClause(stream); + node = node->Next(); + } + return (noErrors == 0); +} + +void CExprDatabase::WriteLisp(ostream& stream) +{ + noErrors = 0; + wxNode *node = First(); + while (node) + { + CExpr *expr = (CExpr *)node->Data(); + expr->WriteLispExpr(stream); + stream << "\n\n"; + node = node->Next(); + } +} + +void add_expr(CExpr * expr) +{ + theCExprDatabase->Append(expr); +} + +// Checks functor +BOOL CExprIsFunctor(CExpr *expr, const CString& functor) +{ + if (expr && (expr->Type() == CExprList)) + { + CExpr *first_expr = expr->value.first; + + if (first_expr && (first_expr->Type() == CExprWord) && + (first_expr->WordValue() == functor)) + return TRUE; + else + return FALSE; + } + else + return FALSE; +} + +/* + * Called from parser + * + */ + +char *make_integer(char *str) +{ + CExpr *x = new CExpr(atol(str)); + + return (char *)x; +} + +char *make_real(char *str1, char *str2) +{ + char buf[50]; + + sprintf(buf, "%s.%s", str1, str2); + float f = (float)atof(buf); + CExpr *x = new CExpr(f); + + return (char *)x; +} + +// extern "C" double exp10(double); + +char *make_exp(char *str1, char *str2) +{ + double mantissa = (double)atoi(str1); + double exponent = (double)atoi(str2); + + double d = mantissa * pow(10.0, exponent); + + CExpr *x = new CExpr((float)d); + + return (char *)x; +} + +char *make_exp2(char *str1, char *str2, char *str3) +{ + char buf[50]; + + sprintf(buf, "%s.%s", str1, str2); + double mantissa = (double)atof(buf); + double exponent = (double)atoi(str3); + + double d = mantissa * pow(10.0, exponent); + + CExpr *x = new CExpr((float)d); + + return (char *)x; +} + +char *make_word(char *str) +{ + CExpr *x = new CExpr(CExprWord, str); + return (char *)x; +} + +char *make_string(char *str) +{ + char *s, *t; + int len, i; + + str++; /* skip leading quote */ + len = strlen(str) - 1; /* ignore trailing quote */ + + s = new char[len + 1]; + + t = s; + for(i=0; iInsert(car); + return (char *)cdr; +} + +void process_command(char * cexpr) +{ + CExpr *expr = (CExpr *)cexpr; + add_expr(expr); +} + +void syntax_error(char *s) +{ + if (currentCExprErrorHandler) + (void)(*(currentCExprErrorHandler))(CEXPR_ERROR_SYNTAX, "syntax error"); + if (theCExprDatabase) theCExprDatabase->noErrors += 1; +} + +#ifdef _WINDLL +char *__cdecl strdup(const char *s) +{ + int len = strlen(s); + char *new_s = (char *)malloc(sizeof(char)*(len+1)); + strcpy(new_s, s); + return new_s; +} +#endif diff --git a/CExpr/Cexpr.dsp b/CExpr/Cexpr.dsp new file mode 100644 index 0000000..a207677 --- /dev/null +++ b/CExpr/Cexpr.dsp @@ -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 diff --git a/CExpr/Cexpr.dsw b/CExpr/Cexpr.dsw new file mode 100644 index 0000000..0b754e5 --- /dev/null +++ b/CExpr/Cexpr.dsw @@ -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> +{{{ +}}} + +############################################################################### + diff --git a/CExpr/Cexpr.h b/CExpr/Cexpr.h new file mode 100644 index 0000000..dd2bff3 --- /dev/null +++ b/CExpr/Cexpr.h @@ -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 +#include +#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 + diff --git a/CExpr/Cexpr.mak b/CExpr/Cexpr.mak new file mode 100644 index 0000000..1f81da4 --- /dev/null +++ b/CExpr/Cexpr.mak @@ -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 +################################################################################ diff --git a/CExpr/Cexpr.mdp b/CExpr/Cexpr.mdp new file mode 100644 index 0000000..b439e1f Binary files /dev/null and b/CExpr/Cexpr.mdp differ diff --git a/CExpr/Cexpr.opt b/CExpr/Cexpr.opt new file mode 100644 index 0000000..b5f313e Binary files /dev/null and b/CExpr/Cexpr.opt differ diff --git a/CExpr/Cexpr.plg b/CExpr/Cexpr.plg new file mode 100644 index 0000000..3fca8a2 --- /dev/null +++ b/CExpr/Cexpr.plg @@ -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 "" + "" with flags "" + +Creating temp file "E:\TEMP\RSPC.tmp" with contents +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) diff --git a/CExpr/DOSLEX.C b/CExpr/DOSLEX.C new file mode 100644 index 0000000..60a57fd --- /dev/null +++ b/CExpr/DOSLEX.C @@ -0,0 +1,1208 @@ +/* A lexical scanner generated by flex */ + +/* scanner skeleton version: + * $Header: /usr/fsys/odin/a/vern/flex/RCS/flex.skel,v 2.16 90/08/03 14:09:36 vern Exp $ + */ + +#define FLEX_SCANNER + +#include + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include +#include + +/* use prototypes in function declarations */ +#define YY_USE_PROTOS + +/* the "const" storage-class-modifier is valid */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#ifdef __STDC__ + +#ifdef __GNUC__ +#include +#else +#include +#endif /* __GNUC__ */ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + + +#ifdef __TURBOC__ +#define YY_USE_CONST +#endif + + +#ifndef YY_USE_CONST +#define const +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +/* we can't get here if it's an ANSI C compiler, or a C++ compiler, + * so it's got to be a K&R compiler, and therefore there's no standard + * place from which to include these definitions + */ +/* +char *malloc(); +int free(); +*/ + +int read(); +#endif + + +/* amount of stuff to slurp up with each read */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* returned upon end-of-file */ +#define YY_END_TOK 0 + +/* copy whatever the last rule matched to the standard output */ + +/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */ +/* this used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite() + */ +#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout ) + +/* gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#define YY_INPUT(buf,result,max_size) \ + if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "read() in flex scanner failed" ); +#define YY_NULL 0 + +/* no semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#define yyterminate() return ( YY_NULL ) + +/* report a fatal error */ + +/* The funky do-while is used to turn this macro definition into + * a single C statement (which needs a semi-colon terminator). + * This avoids problems with code like: + * + * if ( something_happens ) + * YY_FATAL_ERROR( "oops, the something happened" ); + * else + * everything_okay(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the YY_FATAL_ERROR() call. + */ + +#define YY_FATAL_ERROR(msg) \ + do \ + { \ + (void) fputs( msg, stderr ); \ + (void) putc( '\n', stderr ); \ + exit( 1 ); \ + } \ + while ( 0 ) + +/* default yywrap function - always treat EOF as an EOF */ +int yywrap(void) { return 1; } + + +/* enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN + */ +#define BEGIN yy_start = 1 + 2 * + +/* action number for EOF rule of a given start state */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* special action meaning "start processing a new file" */ +#define YY_NEW_FILE \ + do \ + { \ + yy_init_buffer( yy_current_buffer, yyin ); \ + yy_load_buffer_state(); \ + } \ + while ( 0 ) + +/* default declaration of generated scanner - a define so the user can + * easily add parameters + */ +#define YY_DECL int yylex YY_PROTO(( void )) + +/* code executed at the end of each rule */ +#define YY_BREAK break; + +#define YY_END_OF_BUFFER_CHAR 0 + +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */ +#endif + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +#define YY_CHAR unsigned char +# line 1 "lexer.l" +#define INITIAL 0 +# line 9 "lexer.l" +/* + * File: lexer.l + * Description: Lexical analyser for PROLOGIO; can be used with + * either lex and flex. + */ +#include + +/* +++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 + +# line 58 "lexer.l" + +/* done after the current pattern has been matched and before the + * corresponding action - sets up yytext + */ +#define YY_DO_BEFORE_ACTION \ + yytext = yy_bp; \ + yyleng = yy_cp - yy_bp; \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* return all but the first 'n' matched characters back to the input stream */ +#define yyless(n) \ + do \ + { \ + /* undo effects of setting up yytext */ \ + *yy_cp = yy_hold_char; \ + yy_c_buf_p = yy_cp = yy_bp + n; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#undef unput +#define unput(c) yyunput( c, yytext ) + + +struct yy_buffer_state + { + FILE *yy_input_file; + + YY_CHAR *yy_ch_buf; /* input buffer */ + YY_CHAR *yy_buf_pos; /* current position in input buffer */ + + /* size of input buffer in bytes, not including room for EOB characters*/ + int yy_buf_size; + + /* number of characters read into yy_ch_buf, not including EOB characters */ + int yy_n_chars; + + int yy_eof_status; /* whether we've seen an EOF on this buffer */ +#define EOF_NOT_SEEN 0 + /* "pending" happens when the EOF has been seen but there's still + * some text process + */ +#define EOF_PENDING 1 +#define EOF_DONE 2 + }; + +static YY_BUFFER_STATE yy_current_buffer; + +/* we provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state" + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed */ +static YY_CHAR yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + + +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +#ifndef YY_USER_INIT +#define YY_USER_INIT +#endif + +extern YY_CHAR *yytext; +extern int yyleng; +extern FILE *yyin, *yyout; + +YY_CHAR *yytext; +int yyleng; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +#define YY_END_OF_BUFFER 18 +typedef int yy_state_type; +static const short int yy_accept[34] = + { 0, + 0, 0, 18, 16, 13, 14, 16, 16, 6, 7, + 16, 8, 12, 16, 1, 11, 3, 9, 10, 2, + 0, 5, 0, 0, 0, 4, 1, 15, 3, 5, + 0, 0, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 1, 1, 1, 1, 5, 6, + 7, 8, 9, 10, 9, 11, 12, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 1, 1, 1, + 14, 1, 1, 1, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 16, 17, 18, 1, 15, 1, 15, 15, 15, 15, + + 19, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 1, 20, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[21] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 1, 2, 1, 3, 1, 2, 1 + } ; + +static const short int yy_base[37] = + { 0, + 0, 0, 48, 55, 55, 55, 17, 42, 55, 55, + 19, 55, 55, 23, 17, 55, 0, 55, 55, 0, + 18, 55, 19, 23, 21, 55, 12, 55, 0, 24, + 25, 29, 55, 49, 52, 22 + } ; + +static const short int yy_def[37] = + { 0, + 33, 1, 33, 33, 33, 33, 34, 35, 33, 33, + 33, 33, 33, 33, 33, 33, 36, 33, 33, 36, + 34, 33, 34, 34, 35, 33, 33, 33, 36, 34, + 34, 34, 0, 33, 33, 33 + } ; + +static const short int yy_nxt[76] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 4, 11, 12, + 13, 14, 15, 16, 17, 18, 4, 19, 20, 4, + 22, 22, 30, 29, 27, 26, 22, 22, 30, 27, + 28, 27, 30, 23, 23, 23, 24, 24, 24, 31, + 23, 32, 24, 24, 24, 23, 26, 33, 24, 21, + 21, 21, 25, 25, 3, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static const short int yy_chk[76] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 7, 21, 23, 36, 27, 25, 24, 30, 31, 15, + 14, 11, 32, 7, 21, 23, 7, 21, 23, 24, + 30, 31, 24, 30, 31, 32, 8, 3, 32, 34, + 34, 34, 35, 35, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static yy_state_type yy_last_accepting_state; +static YY_CHAR *yy_last_accepting_cpos; + +/* the intent behind this definition is that it'll catch + * any uses of REJECT which flex missed + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 + +/* these variables are all declared out here so that section 3 code can + * manipulate them + */ +/* points to current character in buffer */ +static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr )); +void yyrestart YY_PROTO(( FILE *input_file )); +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); + +#define yy_new_buffer yy_create_buffer + +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif + +YY_DECL + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp, *yy_bp; + register int yy_act; + + + + + if ( yy_init ) + { + YY_USER_INIT; + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( yy_current_buffer ) + yy_init_buffer( yy_current_buffer, yyin ); + else + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + + yy_init = 0; + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; + + /* support of yytext */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of the + * current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[*yy_cp]; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_current_state != 33 ); + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + YY_USER_ACTION; + +do_action: /* this label is used only to access EOF actions */ + + + switch ( yy_act ) + { + case 0: /* must backtrack */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + +case 1: +# line 60 "lexer.l" +{yylval.s = strdup(yytext); Return(INTEGER);} + YY_BREAK +case 2: +# line 62 "lexer.l" +Return(EXP); + YY_BREAK +case 3: +# line 64 "lexer.l" +{yylval.s = strdup(yytext); Return(WORD);} + YY_BREAK +case 4: +# line 66 "lexer.l" +{int len = strlen(yytext); + yytext[len-1] = 0; + yylval.s = strdup(yytext+1); + Return(WORD);} + YY_BREAK +case 5: +# line 71 "lexer.l" +{yylval.s = strdup(yytext); Return(STRING);} + YY_BREAK +case 6: +# line 73 "lexer.l" +Return(OPEN); + YY_BREAK +case 7: +# line 75 "lexer.l" +Return(CLOSE); + YY_BREAK +case 8: +# line 77 "lexer.l" +Return(COMMA); + YY_BREAK +case 9: +# line 79 "lexer.l" +Return(OPEN_SQUARE); + YY_BREAK +case 10: +# line 81 "lexer.l" +Return(CLOSE_SQUARE); + YY_BREAK +case 11: +# line 83 "lexer.l" +Return(EQUALS); + YY_BREAK +case 12: +# line 85 "lexer.l" +Return(PERIOD); + YY_BREAK +case 13: +# line 87 "lexer.l" +; + YY_BREAK +case 14: +# line 89 "lexer.l" +; + YY_BREAK +case 15: +# line 91 "lexer.l" +{ loop: +#ifdef __cplusplus + while (yyinput() != '*'); + switch (yyinput()) +#else + while (input() != '*'); + switch (input()) +#endif + { + case '/': break; + case '*': unput('*'); + default: goto loop; + } + } + YY_BREAK +case 16: +# line 106 "lexer.l" +Return(ERROR); + YY_BREAK +case 17: +# line 108 "lexer.l" +ECHO; + YY_BREAK +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* amount of text matched not including the EOB char */ + int yy_amount_of_matched_text = yy_cp - yytext - 1; + + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + + /* note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the end- + * of-buffer state). Contrast this with the test in yyinput(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + { + yy_state_type yy_next_state; + + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* okay, we're now positioned to make the + * NUL transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we + * don't want to build jamming into it because + * then it will run more slowly) + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* consume the NUL */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* note: because we've taken care in + * yy_get_next_buffer() to have set up yytext, + * we can now set up yy_c_buf_p so that if some + * total hoser (like flex itself) wants + * to call the scanner after we return the + * YY_NULL, it'll still work - another YY_NULL + * will get returned. + */ + yy_c_buf_p = yytext + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF((yy_start - 1) / 2); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: +#ifdef FLEX_DEBUG + printf( "action # %d\n", yy_act ); +#endif + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } + } + } + + +/* yy_get_next_buffer - try to read in a new buffer + * + * synopsis + * int yy_get_next_buffer(); + * + * returns a code representing an action + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + + { + register YY_CHAR *dest = yy_current_buffer->yy_ch_buf; + register YY_CHAR *source = yytext - 1; /* copy prev. char, too */ + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + /* try to read more data */ + + /* first move last chars to start of buffer */ + number_to_move = yy_c_buf_p - yytext; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_n_chars = 0; + + else + { + int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1; + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + else if ( num_to_read <= 0 ) + YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); + + /* read in more data */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == 1 ) + { + ret_val = EOB_ACT_END_OF_FILE; + yy_current_buffer->yy_eof_status = EOF_DONE; + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_eof_status = EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + /* yytext begins at the second character in yy_ch_buf; the first + * character is the one which preceded it before reading in the latest + * buffer; it needs to be kept around in case it's a newline, so + * yy_get_previous_state() will have with '^' rules active + */ + + yytext = &yy_current_buffer->yy_ch_buf[1]; + + return ( ret_val ); + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached + * + * synopsis + * yy_state_type yy_get_previous_state(); + */ + +static yy_state_type yy_get_previous_state() + + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp; + + yy_current_state = yy_start; + + for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1); + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return ( yy_current_state ); + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +register yy_state_type yy_current_state; +#endif + + { + register int yy_is_jam; + register YY_CHAR *yy_cp = yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 33); + + return ( yy_is_jam ? 0 : yy_current_state ); + } + + +#ifdef YY_USE_PROTOS +static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp ) +#else +static void yyunput( c, yy_bp ) +YY_CHAR c; +register YY_CHAR *yy_bp; +#endif + + { + register YY_CHAR *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */ + register YY_CHAR *dest = + &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2]; + register YY_CHAR *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += dest - source; + yy_bp += dest - source; + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + if ( yy_cp > yy_bp && yy_cp[-1] == '\n' ) + yy_cp[-2] = '\n'; + + *--yy_cp = c; + + /* note: the formal parameter *must* be called "yy_bp" for this + * macro to now work correctly + */ + YY_DO_BEFORE_ACTION; /* set up yytext again */ + } + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + + { + int c; + YY_CHAR *yy_cp = yy_c_buf_p; + + *yy_cp = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + yytext = yy_c_buf_p; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + { + yy_c_buf_p = yytext + YY_MORE_ADJ; + return ( EOF ); + } + + YY_NEW_FILE; + +#ifdef __cplusplus + return ( yyinput() ); +#else + return ( input() ); +#endif + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + YY_MORE_ADJ; + break; + + case EOB_ACT_LAST_MATCH: +#ifdef __cplusplus + YY_FATAL_ERROR( "unexpected last match in yyinput()" ); +#else + YY_FATAL_ERROR( "unexpected last match in input()" ); +#endif + } + } + } + + c = *yy_c_buf_p; + yy_hold_char = *++yy_c_buf_p; + + return ( c ); + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + + { + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* flush out information for old buffer */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* we don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) ); + + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) ); + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + yy_init_buffer( b, file ); + + return ( b ); + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + free( (char *) b->yy_ch_buf ); + free( (char *) b ); + } + + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + { + b->yy_input_file = file; + + /* we put in the '\n' and start reading from [1] so that an + * initial match-at-newline will be true. + */ + + b->yy_ch_buf[0] = '\n'; + b->yy_n_chars = 1; + + /* we always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[1]; + + b->yy_eof_status = EOF_NOT_SEEN; + } +# line 108 "lexer.l" + + + +#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(); + } +} + diff --git a/CExpr/DOSYACC.C b/CExpr/DOSYACC.C new file mode 100644 index 0000000..03f7726 --- /dev/null +++ b/CExpr/DOSYACC.C @@ -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); +} diff --git a/CExpr/Debug/empty.dir b/CExpr/Debug/empty.dir new file mode 100644 index 0000000..e69de29 diff --git a/CExpr/EXPR.H b/CExpr/EXPR.H new file mode 100644 index 0000000..aa1b2a7 --- /dev/null +++ b/CExpr/EXPR.H @@ -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 +#include + +/* 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 diff --git a/CExpr/LEX_YY.C b/CExpr/LEX_YY.C new file mode 100644 index 0000000..7cb9405 --- /dev/null +++ b/CExpr/LEX_YY.C @@ -0,0 +1,1213 @@ +/* A lexical scanner generated by flex */ + +/* scanner skeleton version: + * $Header: /usr/fsys/odin/a/vern/flex/RCS/flex.skel,v 2.16 90/08/03 14:09:36 vern Exp $ + */ + +#define FLEX_SCANNER + +#include + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include +#include + +/* use prototypes in function declarations */ +#define YY_USE_PROTOS + +/* the "const" storage-class-modifier is valid */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#ifdef __STDC__ + +#ifdef __GNUC__ +#include +#else +#include +#endif /* __GNUC__ */ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + + +#ifdef __TURBOC__ +#define YY_USE_CONST +#endif + + +#ifndef YY_USE_CONST +#define const +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +/* we can't get here if it's an ANSI C compiler, or a C++ compiler, + * so it's got to be a K&R compiler, and therefore there's no standard + * place from which to include these definitions + */ +/* +char *malloc(); +int free(); +*/ + +int read(); +#endif + + +/* amount of stuff to slurp up with each read */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* returned upon end-of-file */ +#define YY_END_TOK 0 + +/* copy whatever the last rule matched to the standard output */ + +/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */ +/* this used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite() + */ +#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout ) + +/* gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#define YY_INPUT(buf,result,max_size) \ + if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "read() in flex scanner failed" ); +#define YY_NULL 0 + +/* no semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#define yyterminate() return ( YY_NULL ) + +/* report a fatal error */ + +/* The funky do-while is used to turn this macro definition into + * a single C statement (which needs a semi-colon terminator). + * This avoids problems with code like: + * + * if ( something_happens ) + * YY_FATAL_ERROR( "oops, the something happened" ); + * else + * everything_okay(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the YY_FATAL_ERROR() call. + */ + +#define YY_FATAL_ERROR(msg) \ + do \ + { \ + (void) fputs( msg, stderr ); \ + (void) putc( '\n', stderr ); \ + exit( 1 ); \ + } \ + while ( 0 ) + +/* default yywrap function - always treat EOF as an EOF */ +int yywrap(void) { return 1; } + + +/* enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN + */ +#define BEGIN yy_start = 1 + 2 * + +/* action number for EOF rule of a given start state */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* special action meaning "start processing a new file" */ +#define YY_NEW_FILE \ + do \ + { \ + yy_init_buffer( yy_current_buffer, yyin ); \ + yy_load_buffer_state(); \ + } \ + while ( 0 ) + +/* default declaration of generated scanner - a define so the user can + * easily add parameters + */ +#define YY_DECL int yylex YY_PROTO(( void )) + +/* code executed at the end of each rule */ +#define YY_BREAK break; + +#define YY_END_OF_BUFFER_CHAR 0 + +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */ +#endif + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +#define YY_CHAR unsigned char +# line 1 "lexer.l" +#define INITIAL 0 +# line 9 "lexer.l" +/* + * File: lexer.l + * Description: Lexical analyser for PROLOGIO; can be used with + * either lex and flex. + */ +#include + +/* +++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 + +# line 58 "lexer.l" + +/* done after the current pattern has been matched and before the + * corresponding action - sets up yytext + */ +#define YY_DO_BEFORE_ACTION \ + yytext = yy_bp; \ + yyleng = yy_cp - yy_bp; \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* return all but the first 'n' matched characters back to the input stream */ +#define yyless(n) \ + do \ + { \ + /* undo effects of setting up yytext */ \ + *yy_cp = yy_hold_char; \ + yy_c_buf_p = yy_cp = yy_bp + n; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#undef unput +#define unput(c) yyunput( c, yytext ) + + +struct yy_buffer_state + { + FILE *yy_input_file; + + YY_CHAR *yy_ch_buf; /* input buffer */ + YY_CHAR *yy_buf_pos; /* current position in input buffer */ + + /* size of input buffer in bytes, not including room for EOB characters*/ + int yy_buf_size; + + /* number of characters read into yy_ch_buf, not including EOB characters */ + int yy_n_chars; + + int yy_eof_status; /* whether we've seen an EOF on this buffer */ +#define EOF_NOT_SEEN 0 + /* "pending" happens when the EOF has been seen but there's still + * some text process + */ +#define EOF_PENDING 1 +#define EOF_DONE 2 + }; + +static YY_BUFFER_STATE yy_current_buffer; + +/* we provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state" + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed */ +static YY_CHAR yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + + +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +#ifndef YY_USER_INIT +#define YY_USER_INIT +#endif + +extern YY_CHAR *yytext; +extern int yyleng; +extern FILE *yyin, *yyout; + +YY_CHAR *yytext; +int yyleng; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +#define YY_END_OF_BUFFER 18 +typedef int yy_state_type; +static const short int yy_accept[34] = + { 0, + 0, 0, 18, 16, 13, 14, 16, 16, 6, 7, + 16, 8, 12, 16, 1, 11, 3, 9, 10, 2, + 0, 5, 0, 0, 0, 4, 1, 15, 3, 5, + 0, 0, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 1, 1, 1, 1, 5, 6, + 7, 8, 9, 10, 9, 11, 12, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 1, 1, 1, + 14, 1, 1, 1, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 16, 17, 18, 1, 15, 1, 15, 15, 15, 15, + + 19, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 1, 20, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[21] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 1, 2, 1, 3, 1, 2, 1 + } ; + +static const short int yy_base[37] = + { 0, + 0, 0, 48, 55, 55, 55, 17, 42, 55, 55, + 19, 55, 55, 23, 17, 55, 0, 55, 55, 0, + 18, 55, 19, 23, 21, 55, 12, 55, 0, 24, + 25, 29, 55, 49, 52, 22 + } ; + +static const short int yy_def[37] = + { 0, + 33, 1, 33, 33, 33, 33, 34, 35, 33, 33, + 33, 33, 33, 33, 33, 33, 36, 33, 33, 36, + 34, 33, 34, 34, 35, 33, 33, 33, 36, 34, + 34, 34, 0, 33, 33, 33 + } ; + +static const short int yy_nxt[76] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 4, 11, 12, + 13, 14, 15, 16, 17, 18, 4, 19, 20, 4, + 22, 22, 30, 29, 27, 26, 22, 22, 30, 27, + 28, 27, 30, 23, 23, 23, 24, 24, 24, 31, + 23, 32, 24, 24, 24, 23, 26, 33, 24, 21, + 21, 21, 25, 25, 3, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static const short int yy_chk[76] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 7, 21, 23, 36, 27, 25, 24, 30, 31, 15, + 14, 11, 32, 7, 21, 23, 7, 21, 23, 24, + 30, 31, 24, 30, 31, 32, 8, 3, 32, 34, + 34, 34, 35, 35, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static yy_state_type yy_last_accepting_state; +static YY_CHAR *yy_last_accepting_cpos; + +/* the intent behind this definition is that it'll catch + * any uses of REJECT which flex missed + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 + +/* these variables are all declared out here so that section 3 code can + * manipulate them + */ +/* points to current character in buffer */ +static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr )); +void yyrestart YY_PROTO(( FILE *input_file )); +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); + +#define yy_new_buffer yy_create_buffer + +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif + +YY_DECL + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp, *yy_bp; + register int yy_act; + + + + + if ( yy_init ) + { + YY_USER_INIT; + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( yy_current_buffer ) + yy_init_buffer( yy_current_buffer, yyin ); + else + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + + yy_init = 0; + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; + + /* support of yytext */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of the + * current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[*yy_cp]; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_current_state != 33 ); + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + YY_USER_ACTION; + +do_action: /* this label is used only to access EOF actions */ + + + switch ( yy_act ) + { + case 0: /* must backtrack */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + +case 1: +# line 60 "lexer.l" +{yylval.s = strdup(yytext); Return(INTEGER);} + YY_BREAK +case 2: +# line 62 "lexer.l" +Return(EXP); + YY_BREAK +case 3: +# line 64 "lexer.l" +{yylval.s = strdup(yytext); Return(WORD);} + YY_BREAK +case 4: +# line 66 "lexer.l" +{int len = strlen(yytext); + yytext[len-1] = 0; + yylval.s = strdup(yytext+1); + Return(WORD);} + YY_BREAK +case 5: +# line 71 "lexer.l" +{yylval.s = strdup(yytext); Return(STRING);} + YY_BREAK +case 6: +# line 73 "lexer.l" +Return(OPEN); + YY_BREAK +case 7: +# line 75 "lexer.l" +Return(CLOSE); + YY_BREAK +case 8: +# line 77 "lexer.l" +Return(COMMA); + YY_BREAK +case 9: +# line 79 "lexer.l" +Return(OPEN_SQUARE); + YY_BREAK +case 10: +# line 81 "lexer.l" +Return(CLOSE_SQUARE); + YY_BREAK +case 11: +# line 83 "lexer.l" +Return(EQUALS); + YY_BREAK +case 12: +# line 85 "lexer.l" +Return(PERIOD); + YY_BREAK +case 13: +# line 87 "lexer.l" +; + YY_BREAK +case 14: +# line 89 "lexer.l" +; + YY_BREAK +case 15: +# line 91 "lexer.l" +{ loop: +#ifdef __cplusplus + while (yyinput() != '*'); + switch (yyinput()) +#else + while (input() != '*'); + switch (input()) +#endif + { + case '/': break; + case '*': unput('*'); + default: goto loop; + } + } + YY_BREAK +case 16: +# line 106 "lexer.l" +Return(ERROR); + YY_BREAK +case 17: +# line 108 "lexer.l" +ECHO; + YY_BREAK +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* amount of text matched not including the EOB char */ + int yy_amount_of_matched_text = yy_cp - yytext - 1; + + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + + /* note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the end- + * of-buffer state). Contrast this with the test in yyinput(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + { + yy_state_type yy_next_state; + + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* okay, we're now positioned to make the + * NUL transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we + * don't want to build jamming into it because + * then it will run more slowly) + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* consume the NUL */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* note: because we've taken care in + * yy_get_next_buffer() to have set up yytext, + * we can now set up yy_c_buf_p so that if some + * total hoser (like flex itself) wants + * to call the scanner after we return the + * YY_NULL, it'll still work - another YY_NULL + * will get returned. + */ + yy_c_buf_p = yytext + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF((yy_start - 1) / 2); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: +#ifdef FLEX_DEBUG + printf( "action # %d\n", yy_act ); +#endif + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } + } + } + + +/* yy_get_next_buffer - try to read in a new buffer + * + * synopsis + * int yy_get_next_buffer(); + * + * returns a code representing an action + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + + { + register YY_CHAR *dest = yy_current_buffer->yy_ch_buf; + register YY_CHAR *source = yytext - 1; /* copy prev. char, too */ + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + /* try to read more data */ + + /* first move last chars to start of buffer */ + number_to_move = yy_c_buf_p - yytext; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_n_chars = 0; + + else + { + int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1; + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + else if ( num_to_read <= 0 ) + YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); + + /* read in more data */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == 1 ) + { + ret_val = EOB_ACT_END_OF_FILE; + yy_current_buffer->yy_eof_status = EOF_DONE; + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_eof_status = EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + /* yytext begins at the second character in yy_ch_buf; the first + * character is the one which preceded it before reading in the latest + * buffer; it needs to be kept around in case it's a newline, so + * yy_get_previous_state() will have with '^' rules active + */ + + yytext = &yy_current_buffer->yy_ch_buf[1]; + + return ( ret_val ); + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached + * + * synopsis + * yy_state_type yy_get_previous_state(); + */ + +static yy_state_type yy_get_previous_state() + + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp; + + yy_current_state = yy_start; + + for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1); + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return ( yy_current_state ); + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +register yy_state_type yy_current_state; +#endif + + { + register int yy_is_jam; + register YY_CHAR *yy_cp = yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 33); + + return ( yy_is_jam ? 0 : yy_current_state ); + } + + +#ifdef YY_USE_PROTOS +static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp ) +#else +static void yyunput( c, yy_bp ) +YY_CHAR c; +register YY_CHAR *yy_bp; +#endif + + { + register YY_CHAR *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */ + register YY_CHAR *dest = + &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2]; + register YY_CHAR *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += dest - source; + yy_bp += dest - source; + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + if ( yy_cp > yy_bp && yy_cp[-1] == '\n' ) + yy_cp[-2] = '\n'; + + *--yy_cp = c; + + /* note: the formal parameter *must* be called "yy_bp" for this + * macro to now work correctly + */ + YY_DO_BEFORE_ACTION; /* set up yytext again */ + } + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + + { + int c; + YY_CHAR *yy_cp = yy_c_buf_p; + + *yy_cp = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + yytext = yy_c_buf_p; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + { + yy_c_buf_p = yytext + YY_MORE_ADJ; + return ( EOF ); + } + + YY_NEW_FILE; + +#ifdef __cplusplus + return ( yyinput() ); +#else + return ( input() ); +#endif + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + YY_MORE_ADJ; + break; + + case EOB_ACT_LAST_MATCH: +#ifdef __cplusplus + YY_FATAL_ERROR( "unexpected last match in yyinput()" ); +#else + YY_FATAL_ERROR( "unexpected last match in input()" ); +#endif + } + } + } + + c = *yy_c_buf_p; + yy_hold_char = *++yy_c_buf_p; + + return ( c ); + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + + { + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* flush out information for old buffer */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* we don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) ); + + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) ); + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + yy_init_buffer( b, file ); + + return ( b ); + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + free( (char *) b->yy_ch_buf ); + free( (char *) b ); + } + + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + { + b->yy_input_file = file; + + /* we put in the '\n' and start reading from [1] so that an + * initial match-at-newline will be true. + */ + + b->yy_ch_buf[0] = '\n'; + b->yy_n_chars = 1; + + /* we always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[1]; + + b->yy_eof_status = EOF_NOT_SEEN; + } +# line 108 "lexer.l" + + + +#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); +} diff --git a/CExpr/Lexer.l b/CExpr/Lexer.l new file mode 100644 index 0000000..8635661 --- /dev/null +++ b/CExpr/Lexer.l @@ -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 + +/* +++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); +} diff --git a/CExpr/PARSER.Y b/CExpr/PARSER.Y new file mode 100644 index 0000000..7ede7ec --- /dev/null +++ b/CExpr/PARSER.Y @@ -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 INTEGER 1 +%token WORD 2 +%token STRING 3 +%token 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 command expr arglist arg arg1 */ +%type 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 diff --git a/CExpr/Release/empty.dir b/CExpr/Release/empty.dir new file mode 100644 index 0000000..e69de29 diff --git a/CExpr/STDAFX.H b/CExpr/STDAFX.H new file mode 100644 index 0000000..8a137a0 --- /dev/null +++ b/CExpr/STDAFX.H @@ -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 // MFC core and standard components +#include // MFC extensions +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC support for Windows 95 Common Controls +#endif // _AFX_NO_AFXCMN_SUPPORT + + + + diff --git a/CExpr/WX_HASH.CPP b/CExpr/WX_HASH.CPP new file mode 100644 index 0000000..723d70b --- /dev/null +++ b/CExpr/WX_HASH.CPP @@ -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 +#include + +#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 (); + } +} + + diff --git a/CExpr/WX_HASH.H b/CExpr/WX_HASH.H new file mode 100644 index 0000000..5925ea0 --- /dev/null +++ b/CExpr/WX_HASH.H @@ -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 diff --git a/CExpr/Wx_list.cpp b/CExpr/Wx_list.cpp new file mode 100644 index 0000000..a5266ec --- /dev/null +++ b/CExpr/Wx_list.cpp @@ -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 +#include + +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; +} diff --git a/CExpr/Wx_list.h b/CExpr/Wx_list.h new file mode 100644 index 0000000..4affb0e --- /dev/null +++ b/CExpr/Wx_list.h @@ -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 diff --git a/CExpr/Y_TAB.C b/CExpr/Y_TAB.C new file mode 100644 index 0000000..03f7726 --- /dev/null +++ b/CExpr/Y_TAB.C @@ -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); +} diff --git a/CExpr/old/DOSLEX.C b/CExpr/old/DOSLEX.C new file mode 100644 index 0000000..60a57fd --- /dev/null +++ b/CExpr/old/DOSLEX.C @@ -0,0 +1,1208 @@ +/* A lexical scanner generated by flex */ + +/* scanner skeleton version: + * $Header: /usr/fsys/odin/a/vern/flex/RCS/flex.skel,v 2.16 90/08/03 14:09:36 vern Exp $ + */ + +#define FLEX_SCANNER + +#include + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include +#include + +/* use prototypes in function declarations */ +#define YY_USE_PROTOS + +/* the "const" storage-class-modifier is valid */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#ifdef __STDC__ + +#ifdef __GNUC__ +#include +#else +#include +#endif /* __GNUC__ */ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + + +#ifdef __TURBOC__ +#define YY_USE_CONST +#endif + + +#ifndef YY_USE_CONST +#define const +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +/* we can't get here if it's an ANSI C compiler, or a C++ compiler, + * so it's got to be a K&R compiler, and therefore there's no standard + * place from which to include these definitions + */ +/* +char *malloc(); +int free(); +*/ + +int read(); +#endif + + +/* amount of stuff to slurp up with each read */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* returned upon end-of-file */ +#define YY_END_TOK 0 + +/* copy whatever the last rule matched to the standard output */ + +/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */ +/* this used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite() + */ +#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout ) + +/* gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#define YY_INPUT(buf,result,max_size) \ + if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "read() in flex scanner failed" ); +#define YY_NULL 0 + +/* no semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#define yyterminate() return ( YY_NULL ) + +/* report a fatal error */ + +/* The funky do-while is used to turn this macro definition into + * a single C statement (which needs a semi-colon terminator). + * This avoids problems with code like: + * + * if ( something_happens ) + * YY_FATAL_ERROR( "oops, the something happened" ); + * else + * everything_okay(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the YY_FATAL_ERROR() call. + */ + +#define YY_FATAL_ERROR(msg) \ + do \ + { \ + (void) fputs( msg, stderr ); \ + (void) putc( '\n', stderr ); \ + exit( 1 ); \ + } \ + while ( 0 ) + +/* default yywrap function - always treat EOF as an EOF */ +int yywrap(void) { return 1; } + + +/* enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN + */ +#define BEGIN yy_start = 1 + 2 * + +/* action number for EOF rule of a given start state */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* special action meaning "start processing a new file" */ +#define YY_NEW_FILE \ + do \ + { \ + yy_init_buffer( yy_current_buffer, yyin ); \ + yy_load_buffer_state(); \ + } \ + while ( 0 ) + +/* default declaration of generated scanner - a define so the user can + * easily add parameters + */ +#define YY_DECL int yylex YY_PROTO(( void )) + +/* code executed at the end of each rule */ +#define YY_BREAK break; + +#define YY_END_OF_BUFFER_CHAR 0 + +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */ +#endif + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +#define YY_CHAR unsigned char +# line 1 "lexer.l" +#define INITIAL 0 +# line 9 "lexer.l" +/* + * File: lexer.l + * Description: Lexical analyser for PROLOGIO; can be used with + * either lex and flex. + */ +#include + +/* +++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 + +# line 58 "lexer.l" + +/* done after the current pattern has been matched and before the + * corresponding action - sets up yytext + */ +#define YY_DO_BEFORE_ACTION \ + yytext = yy_bp; \ + yyleng = yy_cp - yy_bp; \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* return all but the first 'n' matched characters back to the input stream */ +#define yyless(n) \ + do \ + { \ + /* undo effects of setting up yytext */ \ + *yy_cp = yy_hold_char; \ + yy_c_buf_p = yy_cp = yy_bp + n; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#undef unput +#define unput(c) yyunput( c, yytext ) + + +struct yy_buffer_state + { + FILE *yy_input_file; + + YY_CHAR *yy_ch_buf; /* input buffer */ + YY_CHAR *yy_buf_pos; /* current position in input buffer */ + + /* size of input buffer in bytes, not including room for EOB characters*/ + int yy_buf_size; + + /* number of characters read into yy_ch_buf, not including EOB characters */ + int yy_n_chars; + + int yy_eof_status; /* whether we've seen an EOF on this buffer */ +#define EOF_NOT_SEEN 0 + /* "pending" happens when the EOF has been seen but there's still + * some text process + */ +#define EOF_PENDING 1 +#define EOF_DONE 2 + }; + +static YY_BUFFER_STATE yy_current_buffer; + +/* we provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state" + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed */ +static YY_CHAR yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + + +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +#ifndef YY_USER_INIT +#define YY_USER_INIT +#endif + +extern YY_CHAR *yytext; +extern int yyleng; +extern FILE *yyin, *yyout; + +YY_CHAR *yytext; +int yyleng; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +#define YY_END_OF_BUFFER 18 +typedef int yy_state_type; +static const short int yy_accept[34] = + { 0, + 0, 0, 18, 16, 13, 14, 16, 16, 6, 7, + 16, 8, 12, 16, 1, 11, 3, 9, 10, 2, + 0, 5, 0, 0, 0, 4, 1, 15, 3, 5, + 0, 0, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 1, 1, 1, 1, 5, 6, + 7, 8, 9, 10, 9, 11, 12, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 1, 1, 1, + 14, 1, 1, 1, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 16, 17, 18, 1, 15, 1, 15, 15, 15, 15, + + 19, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 1, 20, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[21] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 1, 2, 1, 3, 1, 2, 1 + } ; + +static const short int yy_base[37] = + { 0, + 0, 0, 48, 55, 55, 55, 17, 42, 55, 55, + 19, 55, 55, 23, 17, 55, 0, 55, 55, 0, + 18, 55, 19, 23, 21, 55, 12, 55, 0, 24, + 25, 29, 55, 49, 52, 22 + } ; + +static const short int yy_def[37] = + { 0, + 33, 1, 33, 33, 33, 33, 34, 35, 33, 33, + 33, 33, 33, 33, 33, 33, 36, 33, 33, 36, + 34, 33, 34, 34, 35, 33, 33, 33, 36, 34, + 34, 34, 0, 33, 33, 33 + } ; + +static const short int yy_nxt[76] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 4, 11, 12, + 13, 14, 15, 16, 17, 18, 4, 19, 20, 4, + 22, 22, 30, 29, 27, 26, 22, 22, 30, 27, + 28, 27, 30, 23, 23, 23, 24, 24, 24, 31, + 23, 32, 24, 24, 24, 23, 26, 33, 24, 21, + 21, 21, 25, 25, 3, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static const short int yy_chk[76] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 7, 21, 23, 36, 27, 25, 24, 30, 31, 15, + 14, 11, 32, 7, 21, 23, 7, 21, 23, 24, + 30, 31, 24, 30, 31, 32, 8, 3, 32, 34, + 34, 34, 35, 35, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static yy_state_type yy_last_accepting_state; +static YY_CHAR *yy_last_accepting_cpos; + +/* the intent behind this definition is that it'll catch + * any uses of REJECT which flex missed + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 + +/* these variables are all declared out here so that section 3 code can + * manipulate them + */ +/* points to current character in buffer */ +static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr )); +void yyrestart YY_PROTO(( FILE *input_file )); +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); + +#define yy_new_buffer yy_create_buffer + +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif + +YY_DECL + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp, *yy_bp; + register int yy_act; + + + + + if ( yy_init ) + { + YY_USER_INIT; + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( yy_current_buffer ) + yy_init_buffer( yy_current_buffer, yyin ); + else + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + + yy_init = 0; + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; + + /* support of yytext */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of the + * current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[*yy_cp]; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_current_state != 33 ); + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + YY_USER_ACTION; + +do_action: /* this label is used only to access EOF actions */ + + + switch ( yy_act ) + { + case 0: /* must backtrack */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + +case 1: +# line 60 "lexer.l" +{yylval.s = strdup(yytext); Return(INTEGER);} + YY_BREAK +case 2: +# line 62 "lexer.l" +Return(EXP); + YY_BREAK +case 3: +# line 64 "lexer.l" +{yylval.s = strdup(yytext); Return(WORD);} + YY_BREAK +case 4: +# line 66 "lexer.l" +{int len = strlen(yytext); + yytext[len-1] = 0; + yylval.s = strdup(yytext+1); + Return(WORD);} + YY_BREAK +case 5: +# line 71 "lexer.l" +{yylval.s = strdup(yytext); Return(STRING);} + YY_BREAK +case 6: +# line 73 "lexer.l" +Return(OPEN); + YY_BREAK +case 7: +# line 75 "lexer.l" +Return(CLOSE); + YY_BREAK +case 8: +# line 77 "lexer.l" +Return(COMMA); + YY_BREAK +case 9: +# line 79 "lexer.l" +Return(OPEN_SQUARE); + YY_BREAK +case 10: +# line 81 "lexer.l" +Return(CLOSE_SQUARE); + YY_BREAK +case 11: +# line 83 "lexer.l" +Return(EQUALS); + YY_BREAK +case 12: +# line 85 "lexer.l" +Return(PERIOD); + YY_BREAK +case 13: +# line 87 "lexer.l" +; + YY_BREAK +case 14: +# line 89 "lexer.l" +; + YY_BREAK +case 15: +# line 91 "lexer.l" +{ loop: +#ifdef __cplusplus + while (yyinput() != '*'); + switch (yyinput()) +#else + while (input() != '*'); + switch (input()) +#endif + { + case '/': break; + case '*': unput('*'); + default: goto loop; + } + } + YY_BREAK +case 16: +# line 106 "lexer.l" +Return(ERROR); + YY_BREAK +case 17: +# line 108 "lexer.l" +ECHO; + YY_BREAK +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* amount of text matched not including the EOB char */ + int yy_amount_of_matched_text = yy_cp - yytext - 1; + + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + + /* note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the end- + * of-buffer state). Contrast this with the test in yyinput(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + { + yy_state_type yy_next_state; + + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* okay, we're now positioned to make the + * NUL transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we + * don't want to build jamming into it because + * then it will run more slowly) + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* consume the NUL */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* note: because we've taken care in + * yy_get_next_buffer() to have set up yytext, + * we can now set up yy_c_buf_p so that if some + * total hoser (like flex itself) wants + * to call the scanner after we return the + * YY_NULL, it'll still work - another YY_NULL + * will get returned. + */ + yy_c_buf_p = yytext + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF((yy_start - 1) / 2); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: +#ifdef FLEX_DEBUG + printf( "action # %d\n", yy_act ); +#endif + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } + } + } + + +/* yy_get_next_buffer - try to read in a new buffer + * + * synopsis + * int yy_get_next_buffer(); + * + * returns a code representing an action + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + + { + register YY_CHAR *dest = yy_current_buffer->yy_ch_buf; + register YY_CHAR *source = yytext - 1; /* copy prev. char, too */ + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + /* try to read more data */ + + /* first move last chars to start of buffer */ + number_to_move = yy_c_buf_p - yytext; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_n_chars = 0; + + else + { + int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1; + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + else if ( num_to_read <= 0 ) + YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); + + /* read in more data */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == 1 ) + { + ret_val = EOB_ACT_END_OF_FILE; + yy_current_buffer->yy_eof_status = EOF_DONE; + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_eof_status = EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + /* yytext begins at the second character in yy_ch_buf; the first + * character is the one which preceded it before reading in the latest + * buffer; it needs to be kept around in case it's a newline, so + * yy_get_previous_state() will have with '^' rules active + */ + + yytext = &yy_current_buffer->yy_ch_buf[1]; + + return ( ret_val ); + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached + * + * synopsis + * yy_state_type yy_get_previous_state(); + */ + +static yy_state_type yy_get_previous_state() + + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp; + + yy_current_state = yy_start; + + for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1); + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return ( yy_current_state ); + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +register yy_state_type yy_current_state; +#endif + + { + register int yy_is_jam; + register YY_CHAR *yy_cp = yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 33); + + return ( yy_is_jam ? 0 : yy_current_state ); + } + + +#ifdef YY_USE_PROTOS +static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp ) +#else +static void yyunput( c, yy_bp ) +YY_CHAR c; +register YY_CHAR *yy_bp; +#endif + + { + register YY_CHAR *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */ + register YY_CHAR *dest = + &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2]; + register YY_CHAR *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += dest - source; + yy_bp += dest - source; + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + if ( yy_cp > yy_bp && yy_cp[-1] == '\n' ) + yy_cp[-2] = '\n'; + + *--yy_cp = c; + + /* note: the formal parameter *must* be called "yy_bp" for this + * macro to now work correctly + */ + YY_DO_BEFORE_ACTION; /* set up yytext again */ + } + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + + { + int c; + YY_CHAR *yy_cp = yy_c_buf_p; + + *yy_cp = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + yytext = yy_c_buf_p; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + { + yy_c_buf_p = yytext + YY_MORE_ADJ; + return ( EOF ); + } + + YY_NEW_FILE; + +#ifdef __cplusplus + return ( yyinput() ); +#else + return ( input() ); +#endif + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + YY_MORE_ADJ; + break; + + case EOB_ACT_LAST_MATCH: +#ifdef __cplusplus + YY_FATAL_ERROR( "unexpected last match in yyinput()" ); +#else + YY_FATAL_ERROR( "unexpected last match in input()" ); +#endif + } + } + } + + c = *yy_c_buf_p; + yy_hold_char = *++yy_c_buf_p; + + return ( c ); + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + + { + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* flush out information for old buffer */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* we don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) ); + + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) ); + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + yy_init_buffer( b, file ); + + return ( b ); + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + free( (char *) b->yy_ch_buf ); + free( (char *) b ); + } + + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + { + b->yy_input_file = file; + + /* we put in the '\n' and start reading from [1] so that an + * initial match-at-newline will be true. + */ + + b->yy_ch_buf[0] = '\n'; + b->yy_n_chars = 1; + + /* we always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[1]; + + b->yy_eof_status = EOF_NOT_SEEN; + } +# line 108 "lexer.l" + + + +#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(); + } +} + diff --git a/CExpr/old/DOSYACC.C b/CExpr/old/DOSYACC.C new file mode 100644 index 0000000..03f7726 --- /dev/null +++ b/CExpr/old/DOSYACC.C @@ -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); +} diff --git a/CExpr/old/LEXER.L b/CExpr/old/LEXER.L new file mode 100644 index 0000000..8635661 --- /dev/null +++ b/CExpr/old/LEXER.L @@ -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 + +/* +++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); +} diff --git a/CExpr/old/LEX_YY.C b/CExpr/old/LEX_YY.C new file mode 100644 index 0000000..7cb9405 --- /dev/null +++ b/CExpr/old/LEX_YY.C @@ -0,0 +1,1213 @@ +/* A lexical scanner generated by flex */ + +/* scanner skeleton version: + * $Header: /usr/fsys/odin/a/vern/flex/RCS/flex.skel,v 2.16 90/08/03 14:09:36 vern Exp $ + */ + +#define FLEX_SCANNER + +#include + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include +#include + +/* use prototypes in function declarations */ +#define YY_USE_PROTOS + +/* the "const" storage-class-modifier is valid */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#ifdef __STDC__ + +#ifdef __GNUC__ +#include +#else +#include +#endif /* __GNUC__ */ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + + +#ifdef __TURBOC__ +#define YY_USE_CONST +#endif + + +#ifndef YY_USE_CONST +#define const +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +/* we can't get here if it's an ANSI C compiler, or a C++ compiler, + * so it's got to be a K&R compiler, and therefore there's no standard + * place from which to include these definitions + */ +/* +char *malloc(); +int free(); +*/ + +int read(); +#endif + + +/* amount of stuff to slurp up with each read */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* returned upon end-of-file */ +#define YY_END_TOK 0 + +/* copy whatever the last rule matched to the standard output */ + +/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */ +/* this used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite() + */ +#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout ) + +/* gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#define YY_INPUT(buf,result,max_size) \ + if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "read() in flex scanner failed" ); +#define YY_NULL 0 + +/* no semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#define yyterminate() return ( YY_NULL ) + +/* report a fatal error */ + +/* The funky do-while is used to turn this macro definition into + * a single C statement (which needs a semi-colon terminator). + * This avoids problems with code like: + * + * if ( something_happens ) + * YY_FATAL_ERROR( "oops, the something happened" ); + * else + * everything_okay(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the YY_FATAL_ERROR() call. + */ + +#define YY_FATAL_ERROR(msg) \ + do \ + { \ + (void) fputs( msg, stderr ); \ + (void) putc( '\n', stderr ); \ + exit( 1 ); \ + } \ + while ( 0 ) + +/* default yywrap function - always treat EOF as an EOF */ +int yywrap(void) { return 1; } + + +/* enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN + */ +#define BEGIN yy_start = 1 + 2 * + +/* action number for EOF rule of a given start state */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* special action meaning "start processing a new file" */ +#define YY_NEW_FILE \ + do \ + { \ + yy_init_buffer( yy_current_buffer, yyin ); \ + yy_load_buffer_state(); \ + } \ + while ( 0 ) + +/* default declaration of generated scanner - a define so the user can + * easily add parameters + */ +#define YY_DECL int yylex YY_PROTO(( void )) + +/* code executed at the end of each rule */ +#define YY_BREAK break; + +#define YY_END_OF_BUFFER_CHAR 0 + +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */ +#endif + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +#define YY_CHAR unsigned char +# line 1 "lexer.l" +#define INITIAL 0 +# line 9 "lexer.l" +/* + * File: lexer.l + * Description: Lexical analyser for PROLOGIO; can be used with + * either lex and flex. + */ +#include + +/* +++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 + +# line 58 "lexer.l" + +/* done after the current pattern has been matched and before the + * corresponding action - sets up yytext + */ +#define YY_DO_BEFORE_ACTION \ + yytext = yy_bp; \ + yyleng = yy_cp - yy_bp; \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* return all but the first 'n' matched characters back to the input stream */ +#define yyless(n) \ + do \ + { \ + /* undo effects of setting up yytext */ \ + *yy_cp = yy_hold_char; \ + yy_c_buf_p = yy_cp = yy_bp + n; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#undef unput +#define unput(c) yyunput( c, yytext ) + + +struct yy_buffer_state + { + FILE *yy_input_file; + + YY_CHAR *yy_ch_buf; /* input buffer */ + YY_CHAR *yy_buf_pos; /* current position in input buffer */ + + /* size of input buffer in bytes, not including room for EOB characters*/ + int yy_buf_size; + + /* number of characters read into yy_ch_buf, not including EOB characters */ + int yy_n_chars; + + int yy_eof_status; /* whether we've seen an EOF on this buffer */ +#define EOF_NOT_SEEN 0 + /* "pending" happens when the EOF has been seen but there's still + * some text process + */ +#define EOF_PENDING 1 +#define EOF_DONE 2 + }; + +static YY_BUFFER_STATE yy_current_buffer; + +/* we provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state" + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed */ +static YY_CHAR yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + + +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +#ifndef YY_USER_INIT +#define YY_USER_INIT +#endif + +extern YY_CHAR *yytext; +extern int yyleng; +extern FILE *yyin, *yyout; + +YY_CHAR *yytext; +int yyleng; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +#define YY_END_OF_BUFFER 18 +typedef int yy_state_type; +static const short int yy_accept[34] = + { 0, + 0, 0, 18, 16, 13, 14, 16, 16, 6, 7, + 16, 8, 12, 16, 1, 11, 3, 9, 10, 2, + 0, 5, 0, 0, 0, 4, 1, 15, 3, 5, + 0, 0, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 1, 1, 1, 1, 5, 6, + 7, 8, 9, 10, 9, 11, 12, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 1, 1, 1, + 14, 1, 1, 1, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 16, 17, 18, 1, 15, 1, 15, 15, 15, 15, + + 19, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 1, 20, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[21] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 1, 2, 1, 3, 1, 2, 1 + } ; + +static const short int yy_base[37] = + { 0, + 0, 0, 48, 55, 55, 55, 17, 42, 55, 55, + 19, 55, 55, 23, 17, 55, 0, 55, 55, 0, + 18, 55, 19, 23, 21, 55, 12, 55, 0, 24, + 25, 29, 55, 49, 52, 22 + } ; + +static const short int yy_def[37] = + { 0, + 33, 1, 33, 33, 33, 33, 34, 35, 33, 33, + 33, 33, 33, 33, 33, 33, 36, 33, 33, 36, + 34, 33, 34, 34, 35, 33, 33, 33, 36, 34, + 34, 34, 0, 33, 33, 33 + } ; + +static const short int yy_nxt[76] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 4, 11, 12, + 13, 14, 15, 16, 17, 18, 4, 19, 20, 4, + 22, 22, 30, 29, 27, 26, 22, 22, 30, 27, + 28, 27, 30, 23, 23, 23, 24, 24, 24, 31, + 23, 32, 24, 24, 24, 23, 26, 33, 24, 21, + 21, 21, 25, 25, 3, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static const short int yy_chk[76] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 7, 21, 23, 36, 27, 25, 24, 30, 31, 15, + 14, 11, 32, 7, 21, 23, 7, 21, 23, 24, + 30, 31, 24, 30, 31, 32, 8, 3, 32, 34, + 34, 34, 35, 35, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static yy_state_type yy_last_accepting_state; +static YY_CHAR *yy_last_accepting_cpos; + +/* the intent behind this definition is that it'll catch + * any uses of REJECT which flex missed + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 + +/* these variables are all declared out here so that section 3 code can + * manipulate them + */ +/* points to current character in buffer */ +static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr )); +void yyrestart YY_PROTO(( FILE *input_file )); +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); + +#define yy_new_buffer yy_create_buffer + +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif + +YY_DECL + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp, *yy_bp; + register int yy_act; + + + + + if ( yy_init ) + { + YY_USER_INIT; + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( yy_current_buffer ) + yy_init_buffer( yy_current_buffer, yyin ); + else + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + + yy_init = 0; + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; + + /* support of yytext */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of the + * current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[*yy_cp]; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_current_state != 33 ); + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + YY_USER_ACTION; + +do_action: /* this label is used only to access EOF actions */ + + + switch ( yy_act ) + { + case 0: /* must backtrack */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + +case 1: +# line 60 "lexer.l" +{yylval.s = strdup(yytext); Return(INTEGER);} + YY_BREAK +case 2: +# line 62 "lexer.l" +Return(EXP); + YY_BREAK +case 3: +# line 64 "lexer.l" +{yylval.s = strdup(yytext); Return(WORD);} + YY_BREAK +case 4: +# line 66 "lexer.l" +{int len = strlen(yytext); + yytext[len-1] = 0; + yylval.s = strdup(yytext+1); + Return(WORD);} + YY_BREAK +case 5: +# line 71 "lexer.l" +{yylval.s = strdup(yytext); Return(STRING);} + YY_BREAK +case 6: +# line 73 "lexer.l" +Return(OPEN); + YY_BREAK +case 7: +# line 75 "lexer.l" +Return(CLOSE); + YY_BREAK +case 8: +# line 77 "lexer.l" +Return(COMMA); + YY_BREAK +case 9: +# line 79 "lexer.l" +Return(OPEN_SQUARE); + YY_BREAK +case 10: +# line 81 "lexer.l" +Return(CLOSE_SQUARE); + YY_BREAK +case 11: +# line 83 "lexer.l" +Return(EQUALS); + YY_BREAK +case 12: +# line 85 "lexer.l" +Return(PERIOD); + YY_BREAK +case 13: +# line 87 "lexer.l" +; + YY_BREAK +case 14: +# line 89 "lexer.l" +; + YY_BREAK +case 15: +# line 91 "lexer.l" +{ loop: +#ifdef __cplusplus + while (yyinput() != '*'); + switch (yyinput()) +#else + while (input() != '*'); + switch (input()) +#endif + { + case '/': break; + case '*': unput('*'); + default: goto loop; + } + } + YY_BREAK +case 16: +# line 106 "lexer.l" +Return(ERROR); + YY_BREAK +case 17: +# line 108 "lexer.l" +ECHO; + YY_BREAK +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* amount of text matched not including the EOB char */ + int yy_amount_of_matched_text = yy_cp - yytext - 1; + + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + + /* note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the end- + * of-buffer state). Contrast this with the test in yyinput(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + { + yy_state_type yy_next_state; + + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* okay, we're now positioned to make the + * NUL transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we + * don't want to build jamming into it because + * then it will run more slowly) + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* consume the NUL */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* note: because we've taken care in + * yy_get_next_buffer() to have set up yytext, + * we can now set up yy_c_buf_p so that if some + * total hoser (like flex itself) wants + * to call the scanner after we return the + * YY_NULL, it'll still work - another YY_NULL + * will get returned. + */ + yy_c_buf_p = yytext + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF((yy_start - 1) / 2); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: +#ifdef FLEX_DEBUG + printf( "action # %d\n", yy_act ); +#endif + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } + } + } + + +/* yy_get_next_buffer - try to read in a new buffer + * + * synopsis + * int yy_get_next_buffer(); + * + * returns a code representing an action + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + + { + register YY_CHAR *dest = yy_current_buffer->yy_ch_buf; + register YY_CHAR *source = yytext - 1; /* copy prev. char, too */ + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + /* try to read more data */ + + /* first move last chars to start of buffer */ + number_to_move = yy_c_buf_p - yytext; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_n_chars = 0; + + else + { + int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1; + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + else if ( num_to_read <= 0 ) + YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); + + /* read in more data */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == 1 ) + { + ret_val = EOB_ACT_END_OF_FILE; + yy_current_buffer->yy_eof_status = EOF_DONE; + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_eof_status = EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + /* yytext begins at the second character in yy_ch_buf; the first + * character is the one which preceded it before reading in the latest + * buffer; it needs to be kept around in case it's a newline, so + * yy_get_previous_state() will have with '^' rules active + */ + + yytext = &yy_current_buffer->yy_ch_buf[1]; + + return ( ret_val ); + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached + * + * synopsis + * yy_state_type yy_get_previous_state(); + */ + +static yy_state_type yy_get_previous_state() + + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp; + + yy_current_state = yy_start; + + for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1); + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return ( yy_current_state ); + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +register yy_state_type yy_current_state; +#endif + + { + register int yy_is_jam; + register YY_CHAR *yy_cp = yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 33); + + return ( yy_is_jam ? 0 : yy_current_state ); + } + + +#ifdef YY_USE_PROTOS +static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp ) +#else +static void yyunput( c, yy_bp ) +YY_CHAR c; +register YY_CHAR *yy_bp; +#endif + + { + register YY_CHAR *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */ + register YY_CHAR *dest = + &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2]; + register YY_CHAR *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += dest - source; + yy_bp += dest - source; + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + if ( yy_cp > yy_bp && yy_cp[-1] == '\n' ) + yy_cp[-2] = '\n'; + + *--yy_cp = c; + + /* note: the formal parameter *must* be called "yy_bp" for this + * macro to now work correctly + */ + YY_DO_BEFORE_ACTION; /* set up yytext again */ + } + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + + { + int c; + YY_CHAR *yy_cp = yy_c_buf_p; + + *yy_cp = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + yytext = yy_c_buf_p; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + { + yy_c_buf_p = yytext + YY_MORE_ADJ; + return ( EOF ); + } + + YY_NEW_FILE; + +#ifdef __cplusplus + return ( yyinput() ); +#else + return ( input() ); +#endif + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + YY_MORE_ADJ; + break; + + case EOB_ACT_LAST_MATCH: +#ifdef __cplusplus + YY_FATAL_ERROR( "unexpected last match in yyinput()" ); +#else + YY_FATAL_ERROR( "unexpected last match in input()" ); +#endif + } + } + } + + c = *yy_c_buf_p; + yy_hold_char = *++yy_c_buf_p; + + return ( c ); + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + + { + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* flush out information for old buffer */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* we don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) ); + + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) ); + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + yy_init_buffer( b, file ); + + return ( b ); + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + free( (char *) b->yy_ch_buf ); + free( (char *) b ); + } + + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + { + b->yy_input_file = file; + + /* we put in the '\n' and start reading from [1] so that an + * initial match-at-newline will be true. + */ + + b->yy_ch_buf[0] = '\n'; + b->yy_n_chars = 1; + + /* we always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[1]; + + b->yy_eof_status = EOF_NOT_SEEN; + } +# line 108 "lexer.l" + + + +#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); +} diff --git a/CExpr/old/PARSER.Y b/CExpr/old/PARSER.Y new file mode 100644 index 0000000..7ede7ec --- /dev/null +++ b/CExpr/old/PARSER.Y @@ -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 INTEGER 1 +%token WORD 2 +%token STRING 3 +%token 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 command expr arglist arg arg1 */ +%type 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 diff --git a/CExpr/old/Y_TAB.C b/CExpr/old/Y_TAB.C new file mode 100644 index 0000000..03f7726 --- /dev/null +++ b/CExpr/old/Y_TAB.C @@ -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); +}