aboutsummaryrefslogtreecommitdiff
path: root/tool/lempar.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2002-02-23 19:39:46 +0000
committerdrh <drh@noemail.net>2002-02-23 19:39:46 +0000
commitb29b0a52275a8df96fecce1e7b3d3e5830fe13c9 (patch)
tree0812f55f507910e1fab7d86ef4b59079a43ccd50 /tool/lempar.c
parentb59499c73b044c66d4863a57e7f252030510939d (diff)
downloadsqlite-b29b0a52275a8df96fecce1e7b3d3e5830fe13c9.tar.gz
sqlite-b29b0a52275a8df96fecce1e7b3d3e5830fe13c9.zip
Modify lemon to use much less memory for its parser tables. This reduces
the size of the library by 50K, which is important for an embedded library. (CVS 389) FossilOrigin-Name: 67a135a051e7c96ddbfe85976539b4b8372c7026
Diffstat (limited to 'tool/lempar.c')
-rw-r--r--tool/lempar.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/tool/lempar.c b/tool/lempar.c
index a0b066f9d..6a2cd0874 100644
--- a/tool/lempar.c
+++ b/tool/lempar.c
@@ -76,8 +76,8 @@
*/
struct yyActionEntry {
YYCODETYPE lookahead; /* The value of the look-ahead token */
+ YYCODETYPE next; /* Next entry + 1. Zero at end of collision chain */
YYACTIONTYPE action; /* Action to take for this look-ahead */
- struct yyActionEntry *next; /* Next look-ahead with the same hash, or NULL */
};
static struct yyActionEntry yyActionTable[] = {
%%
@@ -89,15 +89,14 @@ static struct yyActionEntry yyActionTable[] = {
**
** + A pointer to the start of the action hash table in yyActionTable.
**
-** + A mask used to hash the look-ahead token. The mask is an integer
-** which is one less than the size of the hash table.
+** + The number of entries in the action hash table.
**
** + The default action. This is the action to take if no entry for
** the given look-ahead is found in the action hash table.
*/
struct yyStateEntry {
struct yyActionEntry *hashtbl; /* Start of the hash table in yyActionTable */
- int mask; /* Mask used for hashing the look-ahead */
+ YYCODETYPE nEntry; /* Number of entries in action hash table */
YYACTIONTYPE actionDefault; /* Default action if look-ahead not found */
};
static struct yyStateEntry yyStateTable[] = {
@@ -297,13 +296,16 @@ static int yy_find_parser_action(
/* if( pParser->idx<0 ) return YY_NO_ACTION; */
pState = &yyStateTable[pParser->top->stateno];
- if( iLookAhead!=YYNOCODE ){
- pAction = &pState->hashtbl[iLookAhead & pState->mask];
- while( pAction ){
+ if( pState->nEntry==0 ){
+ return pState->actionDefault;
+ }else if( iLookAhead!=YYNOCODE ){
+ pAction = &pState->hashtbl[iLookAhead % pState->nEntry];
+ while( 1 ){
if( pAction->lookahead==iLookAhead ) return pAction->action;
- pAction = pAction->next;
+ if( pAction->next==0 ) return pState->actionDefault;
+ pAction = &pState->hashtbl[pAction->next-1];
}
- }else if( pState->mask!=0 || pState->hashtbl->lookahead!=YYNOCODE ){
+ }else if( pState->hashtbl->lookahead!=YYNOCODE ){
return YY_NO_ACTION;
}
return pState->actionDefault;