-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Copyright and license notices. Updated automake to 2.0 standards. Enhanced the 'generateGrammars' and 'runtests' bash scripts for testing builds. Fixed a memory initialization bug in CppDemo/CppDemoCallbacks.cpp, CppDemo::vDefineAstNodes().
- Loading branch information
Lowell D. Thomas
committed
Dec 4, 2014
0 parents
commit f7b2e37
Showing
125 changed files
with
61,888 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
*~ | ||
.* | ||
!.gitignore | ||
**/documentation | ||
**/build | ||
**/autom4te.cache | ||
**/Debug | ||
**/Release | ||
**/RemoteSystemsTempFiles | ||
*.o | ||
*.out | ||
*.zip | ||
*.gz | ||
WideCharacters.html | ||
cmsg | ||
doxygen_sqlite3.db | ||
# | ||
# automake files NOT included | ||
config.h | ||
config.log | ||
config.status | ||
stamp-h1 | ||
# | ||
# automake files included | ||
#aclocal.m4 | ||
#compile | ||
#config.h.in | ||
#configure | ||
#configure.ac | ||
#depcomp | ||
#install-sh | ||
#Makefile.am | ||
#Makefile.in | ||
#missing | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/******************************************************************************* | ||
APG Version 6.3 | ||
Copyright (C) 2005 - 2012 Lowell D. Thomas, all rights reserved | ||
author: Lowell D. Thomas | ||
email: [email protected] | ||
website: http://www.coasttocoastresearch.com | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see | ||
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html> | ||
or write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*******************************************************************************/ | ||
|
||
#include "Apg.h" | ||
#include "Private.h" | ||
|
||
#define AASSERT(cond) if(!(cond)){spCtx->spParserCtx->pfnAlertHandler(__LINE__, __FILE__);} | ||
|
||
void vAstCtor(APG_PARSER_CTX* spParserCtx){ | ||
if(!spParserCtx->vpAstCtx){ | ||
apg_uint uiMaxRecords = 20 * (spParserCtx->uiRuleCount + spParserCtx->uiUdtCount); | ||
apg_uint uiSize, uiNodeCount, i; | ||
|
||
// context | ||
APG_AST_CTX* spCtx = (APG_AST_CTX*)vpMemAlloc(spParserCtx->vpMemCtx, sizeof(APG_AST_CTX)); | ||
if(!spCtx){spParserCtx->pfnAlertHandler(__LINE__, __FILE__);} | ||
memset((void*)spCtx, 0, sizeof(APG_AST_CTX)); | ||
|
||
// AST nodes | ||
uiNodeCount = spParserCtx->uiRuleCount +spParserCtx->uiUdtCount; | ||
uiSize = sizeof(apg_uint) * uiNodeCount; | ||
spCtx->uipNodes = (apg_uint*)vpMemAlloc(spParserCtx->vpMemCtx, uiSize); | ||
AASSERT(spCtx->uipNodes); | ||
memset((void*)spCtx->uipNodes, 0, uiSize); | ||
|
||
// AST callbacks | ||
uiSize = uiNodeCount * sizeof(APG_CALLBACK); | ||
spCtx->pfnCallbacks = (APG_CALLBACK*)vpMemAlloc(spParserCtx->vpMemCtx, uiSize); | ||
AASSERT(spCtx->pfnCallbacks); | ||
memset((void*)spCtx->pfnCallbacks, 0, uiSize); | ||
|
||
// AST records | ||
uiSize = sizeof(APG_AST_RECORD) * uiMaxRecords; | ||
spCtx->spRecords = (APG_AST_RECORD*)vpMemAlloc(spParserCtx->vpMemCtx, uiSize); | ||
AASSERT(spCtx->spRecords); | ||
memset((void*)spCtx->spRecords, 0, uiSize); | ||
spCtx->uiRecordEnd = uiMaxRecords; | ||
spCtx->uiRecordCount = 0; | ||
|
||
// default disables all nodes | ||
for(i = 0; i < spCtx->uiNodeCount; i++){ | ||
spCtx->uipNodes[i] = APG_FALSE; | ||
spCtx->pfnCallbacks[i] = NULL; | ||
} | ||
|
||
// admin data | ||
spCtx->vpMemCtx = spParserCtx->vpMemCtx; | ||
spCtx->uiNodeCount = uiNodeCount; | ||
spCtx->uiRuleCount = spParserCtx->uiRuleCount; | ||
spCtx->uiUdtCount = spParserCtx->uiUdtCount; | ||
|
||
// success | ||
spParserCtx->vpAstCtx = (void*)spCtx; | ||
} | ||
vAstClear(spParserCtx); | ||
} | ||
|
||
void vAstDtor(APG_PARSER_CTX* spParserCtx){ | ||
if(spParserCtx->vpAstCtx){ | ||
APG_AST_CTX* spCtx = (APG_AST_CTX*)spParserCtx->vpAstCtx; | ||
vMemFree(spParserCtx->vpMemCtx, (void*)spCtx->spRecords); | ||
vMemFree(spParserCtx->vpMemCtx, (void*)spCtx->uipNodes); | ||
vMemFree(spParserCtx->vpMemCtx, (void*)spCtx->pfnCallbacks); | ||
memset((void*)spCtx, 0, sizeof(APG_AST_CTX)); | ||
vMemFree(spParserCtx->vpMemCtx, (void*)spCtx); | ||
spParserCtx->vpAstCtx = NULL; | ||
} | ||
} | ||
|
||
void vAstClear(APG_PARSER_CTX* spParserCtx){ | ||
if(spParserCtx->vpAstCtx){ | ||
APG_AST_CTX* spCtx = (APG_AST_CTX*)spParserCtx->vpAstCtx; | ||
spCtx->uiRecordCount = 0; | ||
spCtx->uiIgnoreRecords = 0; | ||
} | ||
} | ||
|
||
//#include <stdio.h> | ||
// traverses the AST nodes for which records have been previously defined by uiParserSyntaxAnalysis(); | ||
// calls any callback functions which may have been assigned to the nodes | ||
// pfnRuleCallbacks - an array of override rule callback functions | ||
// - array must be of at lease RuleCount in length | ||
// - array members must be NULL or point to a valid callback function | ||
// - may be NULL which would be the same as providing an all-NULL array | ||
// pfnUdtCallbacks - ditto for UDT override callback functions | ||
// return - the number of callback functions defined for which no AST node records have been collected | ||
// - if non-zero, this is a warning user may want to re-define some of the callback functions | ||
apg_uint uiAstTraverse(APG_AST_CTX* spCtx, APG_CALLBACK* pfnRuleCallbacks, APG_CALLBACK* pfnUdtCallbacks, APG_CBDATA* spData){ | ||
apg_uint uiRet = 0; | ||
APG_AST_RECORD* spRecord = spCtx->spRecords; | ||
APG_AST_RECORD* spRecordEnd = spRecord + spCtx->uiRecordCount; | ||
APG_CALLBACK pfnaCallbacks[spCtx->uiNodeCount]; | ||
apg_uint i; | ||
|
||
for(i = 0; i < spCtx->uiNodeCount; i++){pfnaCallbacks[i] = NULL;} | ||
if(pfnRuleCallbacks){ | ||
for(i = 0; i < spCtx->uiRuleCount; i++){ | ||
pfnaCallbacks[i] = pfnRuleCallbacks[i]; // override all rule callbacks | ||
if(pfnRuleCallbacks[i] && !spCtx->pfnCallbacks[i]){uiRet++;} | ||
} | ||
} else{ | ||
for(i = 0; i < spCtx->uiRuleCount; i++){ | ||
pfnaCallbacks[i] = spCtx->pfnCallbacks[i]; // use previously defined rule callbacks | ||
} | ||
} | ||
if(spCtx->uiUdtCount){ | ||
if(pfnUdtCallbacks){ | ||
for(i = 0; i < spCtx->uiUdtCount; i++){ | ||
pfnaCallbacks[i + spCtx->uiRuleCount] = pfnUdtCallbacks[i]; // override all UDT callbacks | ||
if(pfnRuleCallbacks[i + spCtx->uiRuleCount] && !spCtx->pfnCallbacks[i + spCtx->uiRuleCount]){uiRet++;} | ||
} | ||
} else{ | ||
for(i = 0; i < spCtx->uiUdtCount; i++){ | ||
pfnaCallbacks[i + spCtx->uiRuleCount] = spCtx->pfnCallbacks[i + spCtx->uiRuleCount]; // use previously defined UDT callbacks | ||
} | ||
} | ||
} | ||
|
||
for(; spRecord < spRecordEnd; spRecord++){ | ||
if(pfnaCallbacks[spRecord->uiId]){ | ||
spData->uiPhraseOffset = spRecord->uiPhraseOffset; | ||
spData->uiPhraseLength = spRecord->uiPhraseLength; | ||
spData->uiState = spRecord->uiState; | ||
if(spRecord->uiState == PRE_AST){pfnaCallbacks[spRecord->uiId](spData);} | ||
else if(spRecord->uiState == POST_AST){pfnaCallbacks[spRecord->uiId](spData);} | ||
} | ||
} | ||
return uiRet; | ||
} | ||
|
||
void vAstGrow(APG_AST_CTX* spCtx){ | ||
apg_uint uiNewRecordEnd = spCtx->uiRecordEnd * 3; | ||
APG_AST_RECORD* spOldRecords = spCtx->spRecords; | ||
APG_AST_RECORD* spNewRecords = (APG_AST_RECORD*)vpMemAlloc(spCtx->vpMemCtx, sizeof(APG_AST_RECORD) * uiNewRecordEnd); | ||
AASSERT(spNewRecords); | ||
memcpy((void*)spNewRecords, (void*)spOldRecords, sizeof(APG_AST_RECORD) * spCtx->uiRecordEnd); | ||
spCtx->spRecords = spNewRecords; | ||
spCtx->uiRecordEnd = uiNewRecordEnd; | ||
vMemFree(spCtx->vpMemCtx, (void*)spOldRecords); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/******************************************************************************* | ||
APG Version 6.3 | ||
Copyright (C) 2005 - 2012 Lowell D. Thomas, all rights reserved | ||
author: Lowell D. Thomas | ||
email: [email protected] | ||
website: http://www.coasttocoastresearch.com | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see | ||
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html> | ||
or write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*******************************************************************************/ | ||
|
||
#ifndef GRAMMAR_H_6_3_ | ||
#define GRAMMAR_H_6_3_ | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// GENERATOR GRAMMAR DEFINITION TYPES, DEFINES AND VALUES | ||
// To be shared with Generator and Parser. | ||
// These data definitions are meant to be used by both the generator to create the grammar data, | ||
// and the parser to initialize using the generated data. | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
typedef unsigned long int G_UINT; | ||
//typedef unsigned int G_UINT; | ||
// opcode types | ||
#define G_TYPE_RNM 10 | ||
#define G_TYPE_UDT 20 | ||
#define G_TYPE_REP 30 | ||
#define G_TYPE_ALT 40 | ||
#define G_TYPE_CAT 41 | ||
#define G_TYPE_AND 50 | ||
#define G_TYPE_NOT 60 | ||
#define G_TYPE_TLS 70 | ||
#define G_TYPE_TBS 80 | ||
#define G_TYPE_TRG 90 | ||
|
||
typedef struct{ | ||
G_UINT uiMinSizeofACharMax; // sizeof(apg_achar) <= uiMinSizeofACharMax | ||
G_UINT uiMinSizeofUintMax; // sizeof(apg_uint) <= uiMinSizeofUintMax | ||
G_UINT uiSizeInBytes; // total size, in bytes, of the grammar data, including this header | ||
G_UINT uiACharMin; // minimum alphabet character code | ||
G_UINT uiACharMax; // maximum alphabet character code (caution when writing UDTs!) | ||
G_UINT uiUintMax; // maximum integer used | ||
G_UINT uiVersionOffset; // offset to the version number | ||
G_UINT uiVersionLen; // length in bytes of the version length | ||
G_UINT uiCharTableOffset; // offset to the character table | ||
G_UINT uiCharTableLen; // length in bytes of the character table | ||
G_UINT uiACharTableOffset; // offset to the alphabet character table | ||
G_UINT uiACharTableLen; // number of characters iln the alphabet character table | ||
G_UINT uiChildListOffset; // offset to the child list | ||
G_UINT uiChildListLen; // number of indexes in the chile list | ||
G_UINT uiRulesOffset; // offset to the rule list | ||
G_UINT uiRulesLen; // number of rules | ||
G_UINT uiUdtsOffset; // offset to the UDT list | ||
G_UINT uiUdtsLen; // number of UDTs | ||
G_UINT uiOpcodesOffset; // offset to the opcode list | ||
G_UINT uiOpcodesLen; // number of opcodes | ||
} G_HDR; | ||
|
||
typedef struct{ | ||
G_UINT uiGrammarLineNo; | ||
G_UINT uiGrammarPhraseOffset; | ||
G_UINT uiGrammarPhraseLength; | ||
G_UINT uiNameOffset; | ||
G_UINT uiNameLen; | ||
G_UINT uiRuleIndex; | ||
G_UINT uiChildOffset; | ||
G_UINT uiChildCount; | ||
} G_RULE; | ||
|
||
typedef struct{ | ||
G_UINT uiGrammarLineNo; | ||
G_UINT uiGrammarPhraseOffset; | ||
G_UINT uiGrammarPhraseLength; | ||
G_UINT uiNameOffset; | ||
G_UINT uiNameLen; | ||
G_UINT uiUdtIndex; | ||
G_UINT uiEmpty; | ||
} G_UDT; | ||
|
||
typedef struct{ | ||
// G_UINT uiType; | ||
G_UINT uiChildOffset; | ||
G_UINT uiRuleIndex; | ||
} G_RNMOP; | ||
|
||
typedef struct{ | ||
// G_UINT uiType; | ||
G_UINT uiEmpty; | ||
G_UINT uiUdtIndex; | ||
} G_UDTOP; | ||
|
||
typedef struct{ | ||
// G_UINT uiType; | ||
G_UINT uiChildListOffset; | ||
G_UINT uiChildCount; | ||
} G_ALTOP; | ||
|
||
typedef struct{ | ||
// G_UINT uiType; | ||
G_UINT uiChildListOffset; | ||
G_UINT uiChildCount; | ||
} G_CATOP; | ||
|
||
typedef struct{ | ||
// G_UINT uiType; | ||
G_UINT uiChildOffset; | ||
G_UINT uiMin; | ||
G_UINT uiMax; | ||
} G_REPOP; | ||
|
||
typedef struct{ | ||
// G_UINT uiType; | ||
G_UINT uiChildOffset; | ||
} G_ANDOP; | ||
|
||
typedef struct{ | ||
// G_UINT uiType; | ||
G_UINT uiChildOffset; | ||
} G_NOTOP; | ||
|
||
typedef struct{ | ||
// G_UINT uiType; | ||
G_UINT uiMin; | ||
G_UINT uiMax; | ||
} G_TRGOP; | ||
|
||
typedef struct{ | ||
// G_UINT uiType; | ||
G_UINT uiOffset; | ||
G_UINT uiLen; | ||
} G_TBSOP; | ||
|
||
typedef struct{ | ||
// G_UINT uiType; | ||
G_UINT uiOffset; | ||
G_UINT uiLen; | ||
} G_TLSOP; | ||
|
||
typedef union{ | ||
G_RNMOP sRnm; | ||
G_UDTOP sUdt; | ||
G_REPOP sRep; | ||
G_ALTOP sAlt; | ||
G_CATOP sCat; | ||
G_ANDOP sAnd; | ||
G_NOTOP sNot; | ||
G_TRGOP sTrg; | ||
G_TBSOP sTbs; | ||
G_TLSOP sTls; | ||
} G_OPUNION; | ||
|
||
typedef struct{ | ||
G_UINT uiType; | ||
G_UINT uiGrammarLineNo; | ||
G_UINT uiGrammarPhraseOffset; | ||
G_UINT uiGrammarPhraseLength; | ||
G_OPUNION sOpType; | ||
} G_OPCODE; | ||
|
||
void vGrammarSetHash(G_HDR* spHdr); | ||
G_UINT uiGrammarValidateHash(G_HDR* spHdr); | ||
|
||
#endif /* GRAMMAR_H_6_3_ */ |
Oops, something went wrong.