void deempty() { /* eliminate references to the empty symol */ /* handles used in list traversals */ PSYMBOL s; PPRODUCTION p; if (emptypt == NULL) { errormsg( "EMPTY SYMBOL MUST BE DEFINED", -1 ); return; /* quit if no analysis possible */ } /* apply initial markings on all symbols */ for (s = symlist; s != NULL; s = s->next) { if (TERMINAL(s)) { /* most terminals are nonempty */ s->state = NONEMPTY; } else { /* nonterminals and rules are empty until proven not */ s->state = ISEMPTY; for (p = s->data; p != NULL; p = p->next) { p->state = ISEMPTY; } } } /* the distinguished empty symbol is the exceptional terminal */ emptypt->state = ISEMPTY; do { /* keep trying until no change is made to the grammar */ change = false; for (s = symlist; s != NULL; s = s->next) if (NONTERMINAL(s)) { /* for each nonterminal symbol s */ checkempty( s ); } } while (change); /* now use the markup to rewrite rules accounting for emptyness */ for (s = symlist; s != NULL; s = s->next) if (NONTERMINAL(s)) { /* for each nonterminal symbol s */ cleanempty( s ); } /* finally, deal with possible empty distinguished symbol */ if (head->state == ISEMPTY) { /* eliminate the distinguished symbol and the empty symbol! */ head = NULL; emptypt = NULL; } else if (head->state == CANBEEMPTY) { /* we eliminated a bit too much, put it back! */ p = NEWPRODUCTION; p->data = NEWELEMENT; p->data->next = NULL; p->data->data = emptypt; p->next = head->data; head->data = p; /* do not eliminate the empty symbol! */ } else /* head->state == NONEMPTY */ { /* eliminate the empty symbol! */ emptypt = NULL; } }
void finishline(Line * l) { int i; int quick1=false; int quick2=false; l->on=false; //printwholegrid(); switch (l->dir) { case DOWN: // falls through. case UP: markgrid(l->geom.x,l->geom.y,l->geom.w,l->geom.h,'|'); SDL_FillRect(screen,&l->geom,SDL_MapRGB(screen->format, 0x00, 0x40, 0x80)); soil(l->geom); // scan along edges to quickly determine if this // is going to be complicated. quick1=true; quick2=true; for (i=l->geom.y+BLOCKHEIGHT/2;i<l->geom.y+l->geom.h;i++) { if (grid[l->geom.x-1][i] != ' ' && grid[l->geom.x-1][i] != '*') quick1=false; if (grid[l->geom.x+BLOCKWIDTH][i] != ' ' && grid[l->geom.x+BLOCKWIDTH][i] != '*') quick2=false; } checkempty(l->geom.x-BLOCKWIDTH/2,l->geom.y+BLOCKHEIGHT/2); checkempty(l->geom.x+BLOCKWIDTH+BLOCKWIDTH/2/2,l->geom.y+BLOCKHEIGHT/2); if (!quick1) for (i=l->geom.y+BLOCKHEIGHT/2+BLOCKHEIGHT;i<l->geom.y+l->geom.h;i+=BLOCKHEIGHT) checkempty(l->geom.x-BLOCKWIDTH/2,i); if (!quick2) for (i=l->geom.y+BLOCKHEIGHT/2+BLOCKHEIGHT;i<l->geom.y+l->geom.h;i+=BLOCKHEIGHT) checkempty(l->geom.x+BLOCKWIDTH+BLOCKWIDTH/2,i); break; case RIGHT: // falls through case LEFT: markgrid(l->geom.x,l->geom.y,l->geom.w,l->geom.h,'-'); SDL_FillRect(screen,&l->geom,SDL_MapRGB(screen->format, 0x00, 0x40, 0x80)); soil(l->geom); // scan along edges to quickly determine if this // is going to be complicated. quick1=true; quick2=true; for (i=l->geom.x+BLOCKWIDTH/2;i<l->geom.x+l->geom.w;i++) { if (grid[i][l->geom.y-1] != ' ' && grid[i][l->geom.y-1] != '*') quick1=false; if (grid[i][l->geom.y+BLOCKHEIGHT] != ' ' && grid[i][l->geom.y+BLOCKHEIGHT] != '*') quick2=false; } checkempty(l->geom.x+BLOCKWIDTH/2,l->geom.y-BLOCKHEIGHT/2); checkempty(l->geom.x+BLOCKWIDTH/2,l->geom.y+BLOCKHEIGHT+BLOCKHEIGHT/2); if (!quick1) for (i=l->geom.x+BLOCKWIDTH/2+BLOCKWIDTH;i<l->geom.x+l->geom.w;i+=BLOCKWIDTH) checkempty(i,l->geom.y-BLOCKHEIGHT/2); if (!quick2) for (i=l->geom.x+BLOCKWIDTH/2+BLOCKWIDTH;i<l->geom.x+l->geom.w;i+=BLOCKWIDTH) checkempty(i,l->geom.y+BLOCKHEIGHT+BLOCKHEIGHT/2); break; } }
QSet& uniq(QSet& qs) { // doesn't clear qseen! result to be passed to subsetId SDL_DETERMINIZE_ASSERT(checkempty()); removeShrink(qs, removeDup(seenq)); return qs; }