mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-30 16:00:55 +00:00
Lemon update 2010-01-07 03:53:04 on branch trunk
- Another attempt at fixing the table generator in lemon. Again, this does not effect the SQLite grammar. (user: drh)
This commit is contained in:
parent
961188bc81
commit
7e8b9219a8
1 changed files with 42 additions and 14 deletions
|
@ -412,7 +412,23 @@ char *arg;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** The state of the yy_action table under construction is an instance of
|
** The state of the yy_action table under construction is an instance of
|
||||||
** the following structure
|
** the following structure.
|
||||||
|
**
|
||||||
|
** The yy_action table maps the pair (state_number, lookahead) into an
|
||||||
|
** action_number. The table is an array of integers pairs. The state_number
|
||||||
|
** determines an initial offset into the yy_action array. The lookahead
|
||||||
|
** value is then added to this initial offset to get an index X into the
|
||||||
|
** yy_action array. If the aAction[X].lookahead equals the value of the
|
||||||
|
** of the lookahead input, then the value of the action_number output is
|
||||||
|
** aAction[X].action. If the lookaheads do not match then the
|
||||||
|
** default action for the state_number is returned.
|
||||||
|
**
|
||||||
|
** All actions associated with a single state_number are first entered
|
||||||
|
** into aLookahead[] using multiple calls to acttab_action(). Then the
|
||||||
|
** actions for that single state_number are placed into the aAction[]
|
||||||
|
** array with a single call to acttab_insert(). The acttab_insert() call
|
||||||
|
** also resets the aLookahead[] array in preparation for the next
|
||||||
|
** state number.
|
||||||
*/
|
*/
|
||||||
typedef struct acttab acttab;
|
typedef struct acttab acttab;
|
||||||
struct acttab {
|
struct acttab {
|
||||||
|
@ -458,7 +474,10 @@ acttab *acttab_alloc(void){
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a new action to the current transaction set
|
/* Add a new action to the current transaction set.
|
||||||
|
**
|
||||||
|
** This routine is called once for each lookahead for a particular
|
||||||
|
** state.
|
||||||
*/
|
*/
|
||||||
void acttab_action(acttab *p, int lookahead, int action){
|
void acttab_action(acttab *p, int lookahead, int action){
|
||||||
if( p->nLookahead>=p->nLookaheadAlloc ){
|
if( p->nLookahead>=p->nLookaheadAlloc ){
|
||||||
|
@ -495,7 +514,6 @@ void acttab_action(acttab *p, int lookahead, int action){
|
||||||
*/
|
*/
|
||||||
int acttab_insert(acttab *p){
|
int acttab_insert(acttab *p){
|
||||||
int i, j, k, n;
|
int i, j, k, n;
|
||||||
int nActtab; /* Number of slots in the p->aAction[] table */
|
|
||||||
assert( p->nLookahead>0 );
|
assert( p->nLookahead>0 );
|
||||||
|
|
||||||
/* Make sure we have enough space to hold the expanded action table
|
/* Make sure we have enough space to hold the expanded action table
|
||||||
|
@ -503,8 +521,7 @@ int acttab_insert(acttab *p){
|
||||||
** must be appended to the current action table
|
** must be appended to the current action table
|
||||||
*/
|
*/
|
||||||
n = p->mxLookahead + 1;
|
n = p->mxLookahead + 1;
|
||||||
nActtab = p->nAction + n;
|
if( p->nAction + n >= p->nActionAlloc ){
|
||||||
if( nActtab >= p->nActionAlloc ){
|
|
||||||
int oldAlloc = p->nActionAlloc;
|
int oldAlloc = p->nActionAlloc;
|
||||||
p->nActionAlloc = p->nAction + n + p->nActionAlloc + 20;
|
p->nActionAlloc = p->nAction + n + p->nActionAlloc + 20;
|
||||||
p->aAction = realloc( p->aAction,
|
p->aAction = realloc( p->aAction,
|
||||||
|
@ -519,16 +536,16 @@ int acttab_insert(acttab *p){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scan the existing action table looking for an offset where we can
|
/* Scan the existing action table looking for an offset that is a
|
||||||
** insert the current transaction set. Fall out of the loop when that
|
** duplicate of the current transaction set. Fall out of the loop
|
||||||
** offset is found. In the worst case, we fall out of the loop when
|
** if and when the duplicate is found.
|
||||||
** i reaches nActtab, which means we append the new transaction set.
|
|
||||||
**
|
**
|
||||||
** i is the index in p->aAction[] where p->mnLookahead is inserted.
|
** i is the index in p->aAction[] where p->mnLookahead is inserted.
|
||||||
*/
|
*/
|
||||||
for(i=nActtab-1; i>=0; i--){
|
for(i=p->nAction-1; i>=0; i--){
|
||||||
/* First look for an existing action table entry that can be reused */
|
|
||||||
if( p->aAction[i].lookahead==p->mnLookahead ){
|
if( p->aAction[i].lookahead==p->mnLookahead ){
|
||||||
|
/* All lookaheads and actions in the aLookahead[] transaction
|
||||||
|
** must match against the candidate aAction[i] entry. */
|
||||||
if( p->aAction[i].action!=p->mnAction ) continue;
|
if( p->aAction[i].action!=p->mnAction ) continue;
|
||||||
for(j=0; j<p->nLookahead; j++){
|
for(j=0; j<p->nLookahead; j++){
|
||||||
k = p->aLookahead[j].lookahead - p->mnLookahead + i;
|
k = p->aLookahead[j].lookahead - p->mnLookahead + i;
|
||||||
|
@ -537,19 +554,30 @@ int acttab_insert(acttab *p){
|
||||||
if( p->aLookahead[j].action!=p->aAction[k].action ) break;
|
if( p->aLookahead[j].action!=p->aAction[k].action ) break;
|
||||||
}
|
}
|
||||||
if( j<p->nLookahead ) continue;
|
if( j<p->nLookahead ) continue;
|
||||||
|
|
||||||
|
/* No possible lookahead value that is not in the aLookahead[]
|
||||||
|
** transaction is allowed to match aAction[i] */
|
||||||
n = 0;
|
n = 0;
|
||||||
for(j=0; j<p->nAction; j++){
|
for(j=0; j<p->nAction; j++){
|
||||||
if( p->aAction[j].lookahead<0 ) continue;
|
if( p->aAction[j].lookahead<0 ) continue;
|
||||||
if( p->aAction[j].lookahead==j+p->mnLookahead-i ) n++;
|
if( p->aAction[j].lookahead==j+p->mnLookahead-i ) n++;
|
||||||
}
|
}
|
||||||
if( n==p->nLookahead ){
|
if( n==p->nLookahead ){
|
||||||
break; /* Same as a prior transaction set */
|
break; /* An exact match is found at offset i */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If no existing offsets exactly match the current transaction, find an
|
||||||
|
** an empty offset in the aAction[] table in which we can add the
|
||||||
|
** aLookahead[] transaction.
|
||||||
|
*/
|
||||||
if( i<0 ){
|
if( i<0 ){
|
||||||
/* If no reusable entry is found, look for an empty slot */
|
/* Look for holes in the aAction[] table that fit the current
|
||||||
for(i=0; i<nActtab; i++){
|
** aLookahead[] transaction. Leave i set to the offset of the hole.
|
||||||
|
** If no holes are found, i is left at p->nAction, which means the
|
||||||
|
** transaction will be appended. */
|
||||||
|
for(i=0; i<p->nActionAlloc - p->mxLookahead; i++){
|
||||||
if( p->aAction[i].lookahead<0 ){
|
if( p->aAction[i].lookahead<0 ){
|
||||||
for(j=0; j<p->nLookahead; j++){
|
for(j=0; j<p->nLookahead; j++){
|
||||||
k = p->aLookahead[j].lookahead - p->mnLookahead + i;
|
k = p->aLookahead[j].lookahead - p->mnLookahead + i;
|
||||||
|
|
Loading…
Reference in a new issue