Lines Matching +full:y +full:- +full:rp

107 int SetUnion(/* char *A,char *B */);    /* A <- A U B, thru element N */
109 #define SetFind(X,Y) (X[Y]) /* True if Y is in set X */ argument
129 int prec; /* Precedence if defined (-1 otherwise) */
136 char *firstset; /* First-set for all rules of this symbol */
151 struct symbol *lhs; /* Left-hand side of the rule */
168 ** Configurations also contain a follow-set which is a list of terminal
172 struct rule *rp; /* The rule upon which the configuration is based */ member
174 char *fws; /* Follow-set for this configuration only */
175 struct plink *fplp; /* Follow-set forward propagation links */
176 struct plink *bplp; /* Follow-set backwards propagation links */
188 struct symbol *sp; /* The look-ahead symbol */
201 struct rule *rp; /* The rule, if a reduce */ member
218 #define NO_OFFSET (-2147483647)
245 char *vartype; /* The default type of non-terminal symbols */
262 char *vardest; /* Code for the default non-terminal destructor */
263 int vardestln; /* Line number for default non-term destructor code*/
344 for(i=0; i<amt-1; i++) freelist[i].next = &freelist[i+1]; in Action_new()
345 freelist[amt-1].next = 0; in Action_new()
348 freelist = freelist->next; in Action_new()
358 rc = ap1->sp->index - ap2->sp->index;
359 if( rc==0 ) rc = (int)ap1->type - (int)ap2->type;
361 assert( ap1->type==REDUCE || ap1->type==RD_RESOLVED || ap1->type==CONFLICT);
362 assert( ap2->type==REDUCE || ap2->type==RD_RESOLVED || ap2->type==CONFLICT);
363 rc = ap1->x.rp->index - ap2->x.rp->index;
372 ap = (struct action *)msort((char *)ap,(char **)&ap->next,actioncmp);
384 new->next = *app;
386 new->type = type;
387 new->sp = sp;
389 new->x.stp = (struct state *)arg;
391 new->x.rp = (struct rule *)arg;
420 #define acttab_size(X) ((X)->nAction)
422 /* The value for the N-th entry in yy_action */
423 #define acttab_yyaction(X,N) ((X)->aAction[N].action)
425 /* The value for the N-th entry in yy_lookahead */
426 #define acttab_yylookahead(X,N) ((X)->aAction[N].lookahead)
430 free( p->aAction ); in acttab_free()
431 free( p->aLookahead ); in acttab_free()
449 if( p->nLookahead>=p->nLookaheadAlloc ){ in acttab_action()
450 p->nLookaheadAlloc += 25; in acttab_action()
451 p->aLookahead = realloc( p->aLookahead, in acttab_action()
452 sizeof(p->aLookahead[0])*p->nLookaheadAlloc ); in acttab_action()
453 if( p->aLookahead==0 ){ in acttab_action()
458 if( p->nLookahead==0 ){ in acttab_action()
459 p->mxLookahead = lookahead; in acttab_action()
460 p->mnLookahead = lookahead; in acttab_action()
461 p->mnAction = action; in acttab_action()
463 if( p->mxLookahead<lookahead ) p->mxLookahead = lookahead; in acttab_action()
464 if( p->mnLookahead>lookahead ){ in acttab_action()
465 p->mnLookahead = lookahead; in acttab_action()
466 p->mnAction = action; in acttab_action()
469 p->aLookahead[p->nLookahead].lookahead = lookahead; in acttab_action()
470 p->aLookahead[p->nLookahead].action = action; in acttab_action()
471 p->nLookahead++; in acttab_action()
483 assert( p->nLookahead>0 ); in acttab_insert()
489 n = p->mxLookahead + 1; in acttab_insert()
490 if( p->nAction + n >= p->nActionAlloc ){ in acttab_insert()
491 int oldAlloc = p->nActionAlloc; in acttab_insert()
492 p->nActionAlloc = p->nAction + n + p->nActionAlloc + 20; in acttab_insert()
493 p->aAction = realloc( p->aAction, in acttab_insert()
494 sizeof(p->aAction[0])*p->nActionAlloc); in acttab_insert()
495 if( p->aAction==0 ){ in acttab_insert()
499 for(i=oldAlloc; i<p->nActionAlloc; i++){ in acttab_insert()
500 p->aAction[i].lookahead = -1; in acttab_insert()
501 p->aAction[i].action = -1; in acttab_insert()
508 ** i reaches p->nAction, which means we append the new transaction set. in acttab_insert()
510 ** i is the index in p->aAction[] where p->mnLookahead is inserted. in acttab_insert()
512 for(i=0; i<p->nAction+p->mnLookahead; i++){ in acttab_insert()
513 if( p->aAction[i].lookahead<0 ){ in acttab_insert()
514 for(j=0; j<p->nLookahead; j++){ in acttab_insert()
515 k = p->aLookahead[j].lookahead - p->mnLookahead + i; in acttab_insert()
517 if( p->aAction[k].lookahead>=0 ) break; in acttab_insert()
519 if( j<p->nLookahead ) continue; in acttab_insert()
520 for(j=0; j<p->nAction; j++){ in acttab_insert()
521 if( p->aAction[j].lookahead==j+p->mnLookahead-i ) break; in acttab_insert()
523 if( j==p->nAction ){ in acttab_insert()
526 }else if( p->aAction[i].lookahead==p->mnLookahead ){ in acttab_insert()
527 if( p->aAction[i].action!=p->mnAction ) continue; in acttab_insert()
528 for(j=0; j<p->nLookahead; j++){ in acttab_insert()
529 k = p->aLookahead[j].lookahead - p->mnLookahead + i; in acttab_insert()
530 if( k<0 || k>=p->nAction ) break; in acttab_insert()
531 if( p->aLookahead[j].lookahead!=p->aAction[k].lookahead ) break; in acttab_insert()
532 if( p->aLookahead[j].action!=p->aAction[k].action ) break; in acttab_insert()
534 if( j<p->nLookahead ) continue; in acttab_insert()
536 for(j=0; j<p->nAction; j++){ in acttab_insert()
537 if( p->aAction[j].lookahead<0 ) continue; in acttab_insert()
538 if( p->aAction[j].lookahead==j+p->mnLookahead-i ) n++; in acttab_insert()
540 if( n==p->nLookahead ){ in acttab_insert()
546 for(j=0; j<p->nLookahead; j++){ in acttab_insert()
547 k = p->aLookahead[j].lookahead - p->mnLookahead + i; in acttab_insert()
548 p->aAction[k] = p->aLookahead[j]; in acttab_insert()
549 if( k>=p->nAction ) p->nAction = k+1; in acttab_insert()
551 p->nLookahead = 0; in acttab_insert()
555 return i - p->mnLookahead; in acttab_insert()
579 ** rp->precsym field filled. Other rules take as their precedence
587 struct rule *rp; local
588 for(rp=xp->rule; rp; rp=rp->next){
589 if( rp->precsym==0 ){
591 for(i=0; i<rp->nrhs; i++){
592 if( rp->rhs[i]->prec>=0 ){
593 rp->precsym = rp->rhs[i];
611 struct rule *rp; local
614 for(i=0; i<lemp->nsymbol; i++){
615 lemp->symbols[i]->lambda = B_FALSE;
617 for(i=lemp->nterminal; i<lemp->nsymbol; i++){
618 lemp->symbols[i]->firstset = SetNew();
624 for(rp=lemp->rule; rp; rp=rp->next){
625 if( rp->lhs->lambda ) continue;
626 for(i=0; i<rp->nrhs; i++){
627 if( rp->rhs[i]->lambda==B_FALSE ) break;
629 if( i==rp->nrhs ){
630 rp->lhs->lambda = B_TRUE;
640 for(rp=lemp->rule; rp; rp=rp->next){
641 s1 = rp->lhs;
642 for(i=0; i<rp->nrhs; i++){
643 s2 = rp->rhs[i];
644 if( s2->type==TERMINAL ){
645 progress += SetAdd(s1->firstset,s2->index);
648 if( s1->lambda==B_FALSE ) break;
650 progress += SetUnion(s1->firstset,s2->firstset);
651 if( s2->lambda==B_FALSE ) break;
668 struct rule *rp; local
673 if( lemp->start ){
674 sp = Symbol_find(lemp->start);
676 ErrorMsg(lemp->filename,0,
679 symbol instead.",lemp->start,lemp->rule->lhs->name);
680 lemp->errorcnt++;
681 sp = lemp->rule->lhs;
684 sp = lemp->rule->lhs;
687 /* Make sure the start symbol doesn't occur on the right-hand side of
690 for(rp=lemp->rule; rp; rp=rp->next){
692 for(i=0; i<rp->nrhs; i++){
693 if( rp->rhs[i]==sp ){
694 ErrorMsg(lemp->filename,0,
696 right-hand side of a rule. This will result in a parser which \
697 does not work properly.",sp->name);
698 lemp->errorcnt++;
705 ** left-hand side */
706 for(rp=sp->rule; rp; rp=rp->nextlhs){
708 newcfp = Configlist_addbasis(rp,0);
709 SetAdd(newcfp->fws,0);
737 /* A state with the same basis already exists! Copy all the follow-set
740 struct config *x, *y; local
741 for(x=bp, y=stp->bp; x && y; x=x->bp, y=y->bp){
742 Plink_copy(&y->bplp,x->bplp);
743 Plink_delete(x->fplp);
744 x->fplp = x->bplp = 0;
755 stp->bp = bp; /* Remember the configuration basis */
756 stp->cfp = cfp; /* Remember the configuration closure */
757 stp->index = lemp->nstate++; /* Every state gets a sequence number */
758 stp->ap = 0; /* No actions, yet. */
759 State_insert(stp,stp->bp); /* Add to the state table */
781 for(cfp=stp->cfp; cfp; cfp=cfp->next) cfp->status = INCOMPLETE;
784 for(cfp=stp->cfp; cfp; cfp=cfp->next){
785 if( cfp->status==COMPLETE ) continue; /* Already used by inner loop */
786 if( cfp->dot>=cfp->rp->nrhs ) continue; /* Can't shift this config */
788 sp = cfp->rp->rhs[cfp->dot]; /* Symbol after the dot */
793 for(bcfp=cfp; bcfp; bcfp=bcfp->next){
794 if( bcfp->status==COMPLETE ) continue; /* Already used */
795 if( bcfp->dot>=bcfp->rp->nrhs ) continue; /* Can't shift this one */
796 bsp = bcfp->rp->rhs[bcfp->dot]; /* Get symbol after dot */
798 bcfp->status = COMPLETE; /* Mark this config as used */
799 new = Configlist_addbasis(bcfp->rp,bcfp->dot+1);
800 Plink_add(&new->bplp,bcfp);
809 Action_add(&stp->ap,SHIFT,sp,(char *)newstp);
827 for(i=0; i<lemp->nstate; i++){
828 stp = lemp->sorted[i];
829 for(cfp=stp->cfp; cfp; cfp=cfp->next){
830 cfp->stp = stp;
835 ** links are used in the follow-set computation. */
836 for(i=0; i<lemp->nstate; i++){
837 stp = lemp->sorted[i];
838 for(cfp=stp->cfp; cfp; cfp=cfp->next){
839 for(plp=cfp->bplp; plp; plp=plp->next){
840 other = plp->cfp;
841 Plink_add(&other->fplp,cfp);
861 for(i=0; i<lemp->nstate; i++){
862 for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){
863 cfp->status = INCOMPLETE;
869 for(i=0; i<lemp->nstate; i++){
870 for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){
871 if( cfp->status==COMPLETE ) continue;
872 for(plp=cfp->fplp; plp; plp=plp->next){
873 change = SetUnion(plp->cfp->fws,cfp->fws);
875 plp->cfp->status = INCOMPLETE;
879 cfp->status = COMPLETE;
896 struct rule *rp; local
902 for(i=0; i<lemp->nstate; i++){ /* Loop over all states */
903 stp = lemp->sorted[i];
904 for(cfp=stp->cfp; cfp; cfp=cfp->next){ /* Loop over all configurations */
905 if( cfp->rp->nrhs==cfp->dot ){ /* Is dot at extreme right? */
906 for(j=0; j<lemp->nterminal; j++){
907 if( SetFind(cfp->fws,j) ){
909 ** rule "cfp->rp" if the lookahead symbol is "lemp->symbols[j]" */
910 Action_add(&stp->ap,REDUCE,lemp->symbols[j],(char *)cfp->rp);
918 if( lemp->start ){
919 sp = Symbol_find(lemp->start);
920 if( sp==0 ) sp = lemp->rule->lhs;
922 sp = lemp->rule->lhs;
927 Action_add(&lemp->sorted[0]->ap,ACCEPT,sp,0);
930 for(i=0; i<lemp->nstate; i++){
933 stp = lemp->sorted[i];
934 assert( stp->ap );
935 stp->ap = Action_sort(stp->ap);
936 for(ap=stp->ap; ap && ap->next; ap=ap->next){
937 for(nap=ap->next; nap && nap->sp==ap->sp; nap=nap->next){
940 lemp->nconflict += resolve_conflict(ap,nap,lemp->errsym);
946 for(rp=lemp->rule; rp; rp=rp->next) rp->canReduce = B_FALSE;
947 for(i=0; i<lemp->nstate; i++){
949 for(ap=lemp->sorted[i]->ap; ap; ap=ap->next){
950 if( ap->type==REDUCE ) ap->x.rp->canReduce = B_TRUE;
953 for(rp=lemp->rule; rp; rp=rp->next){
954 if( rp->canReduce ) continue;
955 ErrorMsg(lemp->filename,rp->ruleline,"This rule can not be reduced.\n");
956 lemp->errorcnt++;
961 ** conflict can't be resolve, return non-zero.
971 ** function won't work if apx->type==REDUCE and apy->type==SHIFT.
980 assert( apx->sp==apy->sp ); /* Otherwise there would be no conflict */
981 if( apx->type==SHIFT && apy->type==REDUCE ){
982 spx = apx->sp;
983 spy = apy->x.rp->precsym;
984 if( spy==0 || spx->prec<0 || spy->prec<0 ){
986 apy->type = CONFLICT;
988 }else if( spx->prec>spy->prec ){ /* Lower precedence wins */
989 apy->type = RD_RESOLVED;
990 }else if( spx->prec<spy->prec ){
991 apx->type = SH_RESOLVED;
992 }else if( spx->prec==spy->prec && spx->assoc==RIGHT ){ /* Use operator */
993 apy->type = RD_RESOLVED; /* associativity */
994 }else if( spx->prec==spy->prec && spx->assoc==LEFT ){ /* to break tie */
995 apx->type = SH_RESOLVED;
997 assert( spx->prec==spy->prec && spx->assoc==NONE );
998 apy->type = CONFLICT;
1001 }else if( apx->type==REDUCE && apy->type==REDUCE ){
1002 spx = apx->x.rp->precsym;
1003 spy = apy->x.rp->precsym;
1004 if( spx==0 || spy==0 || spx->prec<0 ||
1005 spy->prec<0 || spx->prec==spy->prec ){
1006 apy->type = CONFLICT;
1008 }else if( spx->prec>spy->prec ){
1009 apy->type = RD_RESOLVED;
1010 }else if( spx->prec<spy->prec ){
1011 apx->type = RD_RESOLVED;
1015 apx->type==SH_RESOLVED ||
1016 apx->type==RD_RESOLVED ||
1017 apx->type==CONFLICT ||
1018 apy->type==SH_RESOLVED ||
1019 apy->type==RD_RESOLVED ||
1020 apy->type==CONFLICT
1051 for(i=0; i<amt-1; i++) freelist[i].next = &freelist[i+1]; in newconfig()
1052 freelist[amt-1].next = 0; in newconfig()
1055 freelist = freelist->next; in newconfig()
1063 old->next = freelist;
1088 struct config *Configlist_add(rp,dot) in Configlist_add() argument
1089 struct rule *rp; /* The rule */ in Configlist_add()
1095 model.rp = rp;
1100 cfp->rp = rp;
1101 cfp->dot = dot;
1102 cfp->fws = SetNew();
1103 cfp->stp = 0;
1104 cfp->fplp = cfp->bplp = 0;
1105 cfp->next = 0;
1106 cfp->bp = 0;
1108 currentend = &cfp->next;
1115 struct config *Configlist_addbasis(rp,dot) in Configlist_addbasis() argument
1116 struct rule *rp; in Configlist_addbasis()
1123 model.rp = rp;
1128 cfp->rp = rp;
1129 cfp->dot = dot;
1130 cfp->fws = SetNew();
1131 cfp->stp = 0;
1132 cfp->fplp = cfp->bplp = 0;
1133 cfp->next = 0;
1134 cfp->bp = 0;
1136 currentend = &cfp->next;
1138 basisend = &cfp->bp;
1149 struct rule *rp, *newrp; local
1154 for(cfp=current; cfp; cfp=cfp->next){
1155 rp = cfp->rp;
1156 dot = cfp->dot;
1157 if( dot>=rp->nrhs ) continue;
1158 sp = rp->rhs[dot];
1159 if( sp->type==NONTERMINAL ){
1160 if( sp->rule==0 && sp!=lemp->errsym ){
1161 ErrorMsg(lemp->filename,rp->line,"Nonterminal \"%s\" has no rules.",
1162 sp->name);
1163 lemp->errorcnt++;
1165 for(newrp=sp->rule; newrp; newrp=newrp->nextlhs){
1167 for(i=dot+1; i<rp->nrhs; i++){
1168 xsp = rp->rhs[i];
1169 if( xsp->type==TERMINAL ){
1170 SetAdd(newcfp->fws,xsp->index);
1173 SetUnion(newcfp->fws,xsp->firstset);
1174 if( xsp->lambda==B_FALSE ) break;
1177 if( i==rp->nrhs ) Plink_add(&cfp->fplp,newcfp);
1186 current = (struct config *)msort((char *)current,(char **)&(current->next),Configcmp); in Configlist_sort()
1193 basis = (struct config *)msort((char *)current,(char **)&(current->bp),Configcmp); in Configlist_sortbasis()
1224 nextcfp = cfp->next;
1225 assert( cfp->fplp==0 );
1226 assert( cfp->bplp==0 );
1227 if( cfp->fws ) SetFree(cfp->fws);
1252 if( c=='-' && i<max-1 ) spot = i+1;
1278 sprintf(prefix,"%.*s:%d: ",PREFIXLIMIT-10,filename,lineno); in ErrorMsg()
1280 sprintf(prefix,"%.*s: ",PREFIXLIMIT-10,filename); in ErrorMsg()
1283 availablewidth = LINEWIDTH - prefixsize; in ErrorMsg()
1290 while( errmsgsize>0 && errmsg[errmsgsize-1]=='\n' ){ in ErrorMsg()
1291 errmsg[--errmsgsize] = 0; in ErrorMsg()
1309 /* Report an out-of-memory condition and abort. This function
1385 for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
1388 for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
1389 for(i=1; isupper(lem.symbols[i]->name[0]); i++);
1402 /* Compute the lambda-nonterminals and the first-sets for every
1406 /* Compute all LR(0) states. Also record follow-set propagation
1407 ** links so that the follow-set can be computed later */
1424 /* Generate a report of the parser generated. (the "y.output" file) */
1431 ** omitted if the "-m" option is used because makeheaders will
1437 lem.nterminal, lem.nsymbol - lem.nterminal, lem.nrule);
1449 ** A generic merge-sort program.
1453 ** a null-terminated list. Then to sort the list call:
1455 ** ptr = msort(ptr,&(ptr->next),cmpfnc);
1468 ** Merge-sort.
1478 ** a: A sorted, null-terminated linked list. (May be null).
1479 ** b: A sorted, null-terminated linked list. (May be null).
1531 ** list: Pointer to a singly-linked list of structures.
1552 offset = (unsigned long)next - (unsigned long)list;
1558 for(i=0; i<LISTSIZE-1 && set[i]!=0; i++){
1573 #define ISOPT(X) ((X)[0]=='-'||(X)[0]=='+'||strchr((X),'=')!=0)
1576 ** Print the command line with a carrot pointing to the k-th character
1577 ** of the n-th field.
1595 fprintf(err,"\n%*s^-- here\n",spcnt,"");
1597 fprintf(err,"\n%*shere --^\n",spcnt-7,"");
1602 ** Return the index of the N-th non-switch argument. Return -1
1614 n--;
1616 if( strcmp(argv[i],"--")==0 ) dashdash = 1;
1619 return -1;
1637 v = argv[i][0]=='-' ? 1 : 0;
1699 fprintf(err,"%sillegal character in floating-point argument.\n",emsg);
1700 errline(i,((unsigned long)end)-(unsigned long)argv[i],err);
1711 errline(i,((unsigned long)end)-(unsigned long)argv[i],err);
1760 if( argv[i][0]=='+' || argv[i][0]=='-' ){
1782 if( strcmp(argv[i],"--")==0 ) dashdash = 1; in OptNArgs()
1833 fprintf(errstream," -%-*s %s\n",max,op[i].label,op[i].message); in OptPrint()
1838 (int)(max-strlen(op[i].label)-9),"",op[i].message); in OptPrint()
1843 (int)(max-strlen(op[i].label)-6),"",op[i].message); in OptPrint()
1848 (int)(max-strlen(op[i].label)-8),"",op[i].message); in OptPrint()
1887 struct symbol *lhs; /* Left-hand side of current rule */
1889 int nrhs; /* Number of right-hand side symbols seen */
1907 x = Strsafe(psp->tokenstart); /* Save the token permanently */
1909 printf("%s:%d: Token=[%s] state=%d\n",psp->filename,psp->tokenlineno,
1910 x,psp->state);
1912 switch( psp->state ){
1914 psp->prevrule = 0;
1915 psp->preccounter = 0;
1916 psp->firstrule = psp->lastrule = 0;
1917 psp->gp->nrule = 0;
1921 psp->state = WAITING_FOR_DECL_KEYWORD;
1923 psp->lhs = Symbol_new(x);
1924 psp->nrhs = 0;
1925 psp->lhsalias = 0;
1926 psp->state = WAITING_FOR_ARROW;
1928 if( psp->prevrule==0 ){
1929 ErrorMsg(psp->filename,psp->tokenlineno,
1932 psp->errorcnt++;
1933 }else if( psp->prevrule->code!=0 ){
1934 ErrorMsg(psp->filename,psp->tokenlineno,
1937 psp->errorcnt++;
1939 psp->prevrule->line = psp->tokenlineno;
1940 psp->prevrule->code = &x[1];
1943 psp->state = PRECEDENCE_MARK_1;
1945 ErrorMsg(psp->filename,psp->tokenlineno,
1948 psp->errorcnt++;
1953 ErrorMsg(psp->filename,psp->tokenlineno,
1955 psp->errorcnt++;
1956 }else if( psp->prevrule==0 ){
1957 ErrorMsg(psp->filename,psp->tokenlineno,
1959 psp->errorcnt++;
1960 }else if( psp->prevrule->precsym!=0 ){
1961 ErrorMsg(psp->filename,psp->tokenlineno,
1964 psp->errorcnt++;
1966 psp->prevrule->precsym = Symbol_new(x);
1968 psp->state = PRECEDENCE_MARK_2;
1972 ErrorMsg(psp->filename,psp->tokenlineno,
1974 psp->errorcnt++;
1976 psp->state = WAITING_FOR_DECL_OR_RULE;
1980 psp->state = IN_RHS;
1982 psp->state = LHS_ALIAS_1;
1984 ErrorMsg(psp->filename,psp->tokenlineno,
1986 psp->lhs->name);
1987 psp->errorcnt++;
1988 psp->state = RESYNC_AFTER_RULE_ERROR;
1993 psp->lhsalias = x;
1994 psp->state = LHS_ALIAS_2;
1996 ErrorMsg(psp->filename,psp->tokenlineno,
1998 x,psp->lhs->name);
1999 psp->errorcnt++;
2000 psp->state = RESYNC_AFTER_RULE_ERROR;
2005 psp->state = LHS_ALIAS_3;
2007 ErrorMsg(psp->filename,psp->tokenlineno,
2008 "Missing \")\" following LHS alias name \"%s\".",psp->lhsalias);
2009 psp->errorcnt++;
2010 psp->state = RESYNC_AFTER_RULE_ERROR;
2015 psp->state = IN_RHS;
2017 ErrorMsg(psp->filename,psp->tokenlineno,
2018 "Missing \"->\" following: \"%s(%s)\".",
2019 psp->lhs->name,psp->lhsalias);
2020 psp->errorcnt++;
2021 psp->state = RESYNC_AFTER_RULE_ERROR;
2026 struct rule *rp; local
2027 rp = (struct rule *)malloc( sizeof(struct rule) +
2028 sizeof(struct symbol*)*psp->nrhs + sizeof(char*)*psp->nrhs );
2029 if( rp==0 ){
2030 ErrorMsg(psp->filename,psp->tokenlineno,
2032 psp->errorcnt++;
2033 psp->prevrule = 0;
2036 rp->ruleline = psp->tokenlineno;
2037 rp->rhs = (struct symbol**)&rp[1];
2038 rp->rhsalias = (char**)&(rp->rhs[psp->nrhs]);
2039 for(i=0; i<psp->nrhs; i++){
2040 rp->rhs[i] = psp->rhs[i];
2041 rp->rhsalias[i] = psp->alias[i];
2043 rp->lhs = psp->lhs;
2044 rp->lhsalias = psp->lhsalias;
2045 rp->nrhs = psp->nrhs;
2046 rp->code = 0;
2047 rp->precsym = 0;
2048 rp->index = psp->gp->nrule++;
2049 rp->nextlhs = rp->lhs->rule;
2050 rp->lhs->rule = rp;
2051 rp->next = 0;
2052 if( psp->firstrule==0 ){
2053 psp->firstrule = psp->lastrule = rp;
2055 psp->lastrule->next = rp;
2056 psp->lastrule = rp;
2058 psp->prevrule = rp;
2060 psp->state = WAITING_FOR_DECL_OR_RULE;
2062 if( psp->nrhs>=MAXRHS ){
2063 ErrorMsg(psp->filename,psp->tokenlineno,
2066 psp->errorcnt++;
2067 psp->state = RESYNC_AFTER_RULE_ERROR;
2069 psp->rhs[psp->nrhs] = Symbol_new(x);
2070 psp->alias[psp->nrhs] = 0;
2071 psp->nrhs++;
2073 }else if( x[0]=='(' && psp->nrhs>0 ){
2074 psp->state = RHS_ALIAS_1;
2076 ErrorMsg(psp->filename,psp->tokenlineno,
2078 psp->errorcnt++;
2079 psp->state = RESYNC_AFTER_RULE_ERROR;
2084 psp->alias[psp->nrhs-1] = x;
2085 psp->state = RHS_ALIAS_2;
2087 ErrorMsg(psp->filename,psp->tokenlineno,
2089 x,psp->rhs[psp->nrhs-1]->name);
2090 psp->errorcnt++;
2091 psp->state = RESYNC_AFTER_RULE_ERROR;
2096 psp->state = IN_RHS;
2098 ErrorMsg(psp->filename,psp->tokenlineno,
2099 "Missing \")\" following LHS alias name \"%s\".",psp->lhsalias);
2100 psp->errorcnt++;
2101 psp->state = RESYNC_AFTER_RULE_ERROR;
2106 psp->declkeyword = x;
2107 psp->declargslot = 0;
2108 psp->decllnslot = 0;
2109 psp->state = WAITING_FOR_DECL_ARG;
2111 psp->declargslot = &(psp->gp->name);
2113 psp->declargslot = &(psp->gp->include);
2114 psp->decllnslot = &psp->gp->includeln;
2116 psp->declargslot = &(psp->gp->extracode);
2117 psp->decllnslot = &psp->gp->extracodeln;
2119 psp->declargslot = &psp->gp->tokendest;
2120 psp->decllnslot = &psp->gp->tokendestln;
2122 psp->declargslot = &psp->gp->vardest;
2123 psp->decllnslot = &psp->gp->vardestln;
2125 psp->declargslot = &psp->gp->tokenprefix;
2127 psp->declargslot = &(psp->gp->error);
2128 psp->decllnslot = &psp->gp->errorln;
2130 psp->declargslot = &(psp->gp->accept);
2131 psp->decllnslot = &psp->gp->acceptln;
2133 psp->declargslot = &(psp->gp->failure);
2134 psp->decllnslot = &psp->gp->failureln;
2136 psp->declargslot = &(psp->gp->overflow);
2137 psp->decllnslot = &psp->gp->overflowln;
2139 psp->declargslot = &(psp->gp->arg);
2141 psp->declargslot = &(psp->gp->tokentype);
2143 psp->declargslot = &(psp->gp->vartype);
2145 psp->declargslot = &(psp->gp->stacksize);
2147 psp->declargslot = &(psp->gp->start);
2149 psp->preccounter++;
2150 psp->declassoc = LEFT;
2151 psp->state = WAITING_FOR_PRECEDENCE_SYMBOL;
2153 psp->preccounter++;
2154 psp->declassoc = RIGHT;
2155 psp->state = WAITING_FOR_PRECEDENCE_SYMBOL;
2157 psp->preccounter++;
2158 psp->declassoc = NONE;
2159 psp->state = WAITING_FOR_PRECEDENCE_SYMBOL;
2161 psp->state = WAITING_FOR_DESTRUCTOR_SYMBOL;
2163 psp->state = WAITING_FOR_DATATYPE_SYMBOL;
2165 psp->fallback = 0;
2166 psp->state = WAITING_FOR_FALLBACK_ID;
2168 ErrorMsg(psp->filename,psp->tokenlineno,
2170 psp->errorcnt++;
2171 psp->state = RESYNC_AFTER_DECL_ERROR;
2174 ErrorMsg(psp->filename,psp->tokenlineno,
2176 psp->errorcnt++;
2177 psp->state = RESYNC_AFTER_DECL_ERROR;
2182 ErrorMsg(psp->filename,psp->tokenlineno,
2184 psp->errorcnt++;
2185 psp->state = RESYNC_AFTER_DECL_ERROR;
2188 psp->declargslot = &sp->destructor;
2189 psp->decllnslot = &sp->destructorln;
2190 psp->state = WAITING_FOR_DECL_ARG;
2195 ErrorMsg(psp->filename,psp->tokenlineno,
2197 psp->errorcnt++;
2198 psp->state = RESYNC_AFTER_DECL_ERROR;
2201 psp->declargslot = &sp->datatype;
2202 psp->decllnslot = 0;
2203 psp->state = WAITING_FOR_DECL_ARG;
2208 psp->state = WAITING_FOR_DECL_OR_RULE;
2212 if( sp->prec>=0 ){
2213 ErrorMsg(psp->filename,psp->tokenlineno,
2215 psp->errorcnt++;
2217 sp->prec = psp->preccounter;
2218 sp->assoc = psp->declassoc;
2221 ErrorMsg(psp->filename,psp->tokenlineno,
2223 psp->errorcnt++;
2228 if( *(psp->declargslot)!=0 ){
2229 ErrorMsg(psp->filename,psp->tokenlineno,
2231 x[0]=='\"' ? &x[1] : x,psp->declkeyword);
2232 psp->errorcnt++;
2233 psp->state = RESYNC_AFTER_DECL_ERROR;
2235 *(psp->declargslot) = (x[0]=='\"' || x[0]=='{') ? &x[1] : x;
2236 if( psp->decllnslot ) *psp->decllnslot = psp->tokenlineno;
2237 psp->state = WAITING_FOR_DECL_OR_RULE;
2240 ErrorMsg(psp->filename,psp->tokenlineno,
2241 "Illegal argument to %%%s: %s",psp->declkeyword,x);
2242 psp->errorcnt++;
2243 psp->state = RESYNC_AFTER_DECL_ERROR;
2248 psp->state = WAITING_FOR_DECL_OR_RULE;
2250 ErrorMsg(psp->filename, psp->tokenlineno,
2252 psp->errorcnt++;
2255 if( psp->fallback==0 ){
2256 psp->fallback = sp;
2257 }else if( sp->fallback ){
2258 ErrorMsg(psp->filename, psp->tokenlineno,
2260 psp->errorcnt++;
2262 sp->fallback = psp->fallback;
2263 psp->gp->has_fallback = 1;
2268 /* if( x[0]=='.' ) psp->state = WAITING_FOR_DECL_OR_RULE;
2271 if( x[0]=='.' ) psp->state = WAITING_FOR_DECL_OR_RULE;
2272 if( x[0]=='%' ) psp->state = WAITING_FOR_DECL_KEYWORD;
2295 ps.filename = gp->filename;
2303 gp->errorcnt++;
2313 gp->errorcnt++;
2320 gp->errorcnt++;
2338 while( (c= *cp)!=0 && (c!='/' || cp[-1]!='*') ){
2367 else if( c=='}' ) level--;
2417 gp->rule = ps.firstrule;
2418 gp->errorcnt = ps.errorcnt;
2422 ** Routines processing configuration follow-set propagation links
2437 "Unable to allocate memory for a new follow-set propagation link.\n"); in Plink_new()
2440 for(i=0; i<amt-1; i++) plink_freelist[i].next = &plink_freelist[i+1]; in Plink_new()
2441 plink_freelist[amt-1].next = 0; in Plink_new()
2444 plink_freelist = plink_freelist->next; in Plink_new()
2455 new->next = *plpp;
2457 new->cfp = cfp;
2467 nextpl = from->next;
2468 from->next = *to;
2481 nextpl = plp->next;
2482 plp->next = plink_freelist;
2503 name = malloc( strlen(lemp->filename) + strlen(suffix) + 5 );
2508 strcpy(name,lemp->filename);
2525 if( lemp->outname ) free(lemp->outname);
2526 lemp->outname = file_makename(lemp, suffix);
2527 fp = fopen(lemp->outname,mode);
2529 fprintf(stderr,"Can't open file \"%s\".\n",lemp->outname);
2530 lemp->errorcnt++;
2541 struct rule *rp; local
2544 printf("// Reprint of input file \"%s\".\n// Symbols:\n",lemp->filename);
2546 for(i=0; i<lemp->nsymbol; i++){
2547 sp = lemp->symbols[i];
2548 len = strlen(sp->name);
2553 skip = (lemp->nsymbol + ncolumns - 1)/ncolumns;
2556 for(j=i; j<lemp->nsymbol; j+=skip){
2557 sp = lemp->symbols[j];
2558 assert( sp->index==j );
2559 printf(" %3d %-*.*s",j,maxlen,maxlen,sp->name);
2563 for(rp=lemp->rule; rp; rp=rp->next){
2564 printf("%s",rp->lhs->name);
2565 /* if( rp->lhsalias ) printf("(%s)",rp->lhsalias); */
2567 for(i=0; i<rp->nrhs; i++){
2568 printf(" %s",rp->rhs[i]->name);
2569 /* if( rp->rhsalias[i] ) printf("(%s)",rp->rhsalias[i]); */
2572 if( rp->precsym ) printf(" [%s]",rp->precsym->name);
2573 /* if( rp->code ) printf("\n %s",rp->code); */
2582 struct rule *rp; local
2584 rp = cfp->rp;
2585 fprintf(fp,"%s ::=",rp->lhs->name);
2586 for(i=0; i<=rp->nrhs; i++){
2587 if( i==cfp->dot ) fprintf(fp," *");
2588 if( i==rp->nrhs ) break;
2589 fprintf(fp," %s",rp->rhs[i]->name);
2605 for(i=0; i<lemp->nterminal; i++){
2607 fprintf(out,"%s%s",spacer,lemp->symbols[i]->name);
2621 fprintf(out,"%12s%s (state %2d) ","",tag,plp->cfp->stp->index);
2622 ConfigPrint(out,plp->cfp);
2624 plp = plp->next;
2634 switch( ap->type ){ in PrintAction()
2636 fprintf(fp,"%*s shift %d",indent,ap->sp->name,ap->x.stp->index); in PrintAction()
2639 fprintf(fp,"%*s reduce %d",indent,ap->sp->name,ap->x.rp->index); in PrintAction()
2642 fprintf(fp,"%*s accept",indent,ap->sp->name); in PrintAction()
2645 fprintf(fp,"%*s error",indent,ap->sp->name); in PrintAction()
2648 fprintf(fp,"%*s reduce %-3d ** Parsing conflict **", in PrintAction()
2649 indent,ap->sp->name,ap->x.rp->index); in PrintAction()
2660 /* Generate the "y.output" log file */
2673 for(i=0; i<lemp->nstate; i++){
2674 stp = lemp->sorted[i];
2675 fprintf(fp,"State %d:\n",stp->index);
2676 if( lemp->basisflag ) cfp=stp->bp;
2677 else cfp=stp->cfp;
2680 if( cfp->dot==cfp->rp->nrhs ){
2681 sprintf(buf,"(%d)",cfp->rp->index);
2689 SetPrint(fp,cfp->fws,lemp);
2690 PlinkPrint(fp,cfp->fplp,"To ");
2691 PlinkPrint(fp,cfp->bplp,"From");
2693 if( lemp->basisflag ) cfp=cfp->bp;
2694 else cfp=cfp->next;
2697 for(ap=stp->ap; ap; ap=ap->next){
2760 switch( ap->type ){
2761 case SHIFT: act = ap->x.stp->index; break;
2762 case REDUCE: act = ap->x.rp->index + lemp->nstate; break;
2763 case ERROR: act = lemp->nstate + lemp->nrule; break;
2764 case ACCEPT: act = lemp->nstate + lemp->nrule + 1; break;
2765 default: act = -1; break;
2794 && (i==0 || !isalpha(line[i-1]))
2796 if( i>iStart ) fprintf(out,"%.*s",i-iStart,&line[iStart]);
2818 cp = strrchr(lemp->filename,'.');
2820 sprintf(buf,"%.*s.lt",(int)(cp-lemp->filename),lemp->filename);
2822 sprintf(buf,"%s.lt",lemp->filename);
2829 tpltname = pathsearch(lemp->argv0,templatename,0);
2834 lemp->errorcnt++;
2840 lemp->errorcnt++;
2855 fprintf(out,"#line %d \"%s\"\n",strln,lemp->filename); (*lineno)++;
2861 fprintf(out,"\n#line %d \"%s\"\n",*lineno+2,lemp->outname); (*lineno)+=2;
2878 if( sp->type==TERMINAL ){
2879 cp = lemp->tokendest;
2881 fprintf(out,"#line %d \"%s\"\n{",lemp->tokendestln,lemp->filename);
2882 }else if( sp->destructor ){
2883 cp = sp->destructor;
2884 fprintf(out,"#line %d \"%s\"\n{",sp->destructorln,lemp->filename);
2885 }else if( lemp->vardest ){
2886 cp = lemp->vardest;
2888 fprintf(out,"#line %d \"%s\"\n{",lemp->vardestln,lemp->filename);
2894 fprintf(out,"(yypminor->yy%d)",sp->dtnum);
2902 fprintf(out,"}\n#line %d \"%s\"\n",*lineno,lemp->outname);
2907 ** Return TRUE (non-zero) if the given symbol has a destructor.
2914 if( sp->type==TERMINAL ){
2915 ret = lemp->tokendest!=0;
2917 ret = lemp->vardest!=0 || sp->destructor!=0;
2923 ** Generate code which executes when the rule "rp" is reduced. Write
2924 ** the code to "out". Make sure lineno stays up-to-date.
2926 PRIVATE void emit_code(out,rp,lemp,lineno) in emit_code() argument
2928 struct rule *rp;
2938 for(i=0; i<rp->nrhs; i++) used[i] = 0;
2942 if( rp->code ){
2943 fprintf(out,"#line %d \"%s\"\n{",rp->line,lemp->filename);
2944 for(cp=rp->code; *cp; cp++){
2945 if( isalpha(*cp) && (cp==rp->code || (!isalnum(cp[-1]) && cp[-1]!='_')) ){
2950 if( rp->lhsalias && strcmp(cp,rp->lhsalias)==0 ){
2951 fprintf(out,"yygotominor.yy%d",rp->lhs->dtnum);
2955 for(i=0; i<rp->nrhs; i++){
2956 if( rp->rhsalias[i] && strcmp(cp,rp->rhsalias[i])==0 ){
2957 fprintf(out,"yymsp[%d].minor.yy%d",i-rp->nrhs+1,rp->rhs[i]->dtnum);
2970 fprintf(out,"}\n#line %d \"%s\"\n",*lineno,lemp->outname);
2971 } /* End if( rp->code ) */
2974 if( rp->lhsalias && !lhsused ){
2975 ErrorMsg(lemp->filename,rp->ruleline,
2977 rp->lhsalias,rp->lhs->name,rp->lhsalias);
2978 lemp->errorcnt++;
2983 for(i=0; i<rp->nrhs; i++){
2984 if( rp->rhsalias[i] && !used[i] ){
2985 ErrorMsg(lemp->filename,rp->ruleline,
2987 rp->rhsalias[i],rp->rhs[i]->name,rp->rhsalias[i]);
2988 lemp->errorcnt++;
2989 }else if( rp->rhsalias[i]==0 ){
2990 if( has_destructor(rp->rhs[i],lemp) ){
2992 rp->rhs[i]->index,i-rp->nrhs+1); (*lineno)++;
2995 rp->rhs[i]->name);
3026 arraysize = lemp->nsymbol * 2;
3030 if( lemp->vartype ){
3031 maxdtlength = strlen(lemp->vartype);
3033 for(i=0; i<lemp->nsymbol; i++){
3035 struct symbol *sp = lemp->symbols[i];
3036 if( sp->datatype==0 ) continue;
3037 len = strlen(sp->datatype);
3052 for(i=0; i<lemp->nsymbol; i++){
3053 struct symbol *sp = lemp->symbols[i];
3055 if( sp==lemp->errsym ){
3056 sp->dtnum = arraysize+1;
3059 if( sp->type!=NONTERMINAL || (sp->datatype==0 && lemp->vartype==0) ){
3060 sp->dtnum = 0;
3063 cp = sp->datatype;
3064 if( cp==0 ) cp = lemp->vartype;
3068 while( j>0 && isspace(stddt[j-1]) ) j--;
3077 sp->dtnum = hash + 1;
3084 sp->dtnum = hash + 1;
3095 name = lemp->name ? lemp->name : "Parse";
3099 lemp->tokentype?lemp->tokentype:"void*"); lineno++;
3108 fprintf(out," int yy%d;\n",lemp->errsym->dtnum); lineno++;
3128 }else if( lwr>=-127 && upr<=127 ){ in minimum_size_type()
3130 }else if( lwr>=-32767 && upr<32767 ){ in minimum_size_type()
3145 int isTkn; /* True to use tokens. False for non-terminals */
3155 return p2->nAction - p1->nAction; in axset_compare()
3168 struct rule *rp; local
3184 tplt_xfer(lemp->name,in,out,&lineno);
3187 tplt_print(out,lemp,lemp->include,lemp->includeln,&lineno);
3193 tplt_xfer(lemp->name,in,out,&lineno);
3199 if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
3201 for(i=1; i<lemp->nterminal; i++){
3202 fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
3207 tplt_xfer(lemp->name,in,out,&lineno);
3212 minimum_size_type(0, lemp->nsymbol+5)); lineno++;
3213 fprintf(out,"#define YYNOCODE %d\n",lemp->nsymbol+1); lineno++;
3215 minimum_size_type(0, lemp->nstate+lemp->nrule+5)); lineno++;
3217 if( lemp->stacksize ){
3218 if( atoi(lemp->stacksize)<=0 ){
3219 ErrorMsg(lemp->filename,0,
3221 lemp->stacksize);
3222 lemp->errorcnt++;
3223 lemp->stacksize = "100";
3225 fprintf(out,"#define YYSTACKDEPTH %s\n",lemp->stacksize); lineno++;
3232 name = lemp->name ? lemp->name : "Parse";
3233 if( lemp->arg && lemp->arg[0] ){
3235 i = strlen(lemp->arg);
3236 while( i>=1 && isspace(lemp->arg[i-1]) ) i--;
3237 while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--;
3238 fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg); lineno++;
3239 fprintf(out,"#define %sARG_PDECL ,%s\n",name,lemp->arg); lineno++;
3240 fprintf(out,"#define %sARG_FETCH %s = yypParser->%s\n",
3241 name,lemp->arg,&lemp->arg[i]); lineno++;
3242 fprintf(out,"#define %sARG_STORE yypParser->%s = %s\n",
3243 name,&lemp->arg[i],&lemp->arg[i]); lineno++;
3253 fprintf(out,"#define YYNSTATE %d\n",lemp->nstate); lineno++;
3254 fprintf(out,"#define YYNRULE %d\n",lemp->nrule); lineno++;
3255 fprintf(out,"#define YYERRORSYMBOL %d\n",lemp->errsym->index); lineno++;
3256 fprintf(out,"#define YYERRSYMDT yy%d\n",lemp->errsym->dtnum); lineno++;
3257 if( lemp->has_fallback ){
3260 tplt_xfer(lemp->name,in,out,&lineno);
3270 ** shifting non-terminals after a reduce.
3275 ax = malloc( sizeof(ax[0])*lemp->nstate*2 );
3280 for(i=0; i<lemp->nstate; i++){
3281 stp = lemp->sorted[i];
3282 stp->nTknAct = stp->nNtAct = 0;
3283 stp->iDflt = lemp->nstate + lemp->nrule;
3284 stp->iTknOfst = NO_OFFSET;
3285 stp->iNtOfst = NO_OFFSET;
3286 for(ap=stp->ap; ap; ap=ap->next){
3288 if( ap->sp->index<lemp->nterminal ){
3289 stp->nTknAct++;
3290 }else if( ap->sp->index<lemp->nsymbol ){
3291 stp->nNtAct++;
3293 stp->iDflt = compute_action(lemp, ap);
3299 ax[i*2].nAction = stp->nTknAct;
3302 ax[i*2+1].nAction = stp->nNtAct;
3311 qsort(ax, lemp->nstate*2, sizeof(ax[0]), axset_compare);
3313 for(i=0; i<lemp->nstate*2 && ax[i].nAction>0; i++){
3316 for(ap=stp->ap; ap; ap=ap->next){
3318 if( ap->sp->index>=lemp->nterminal ) continue;
3321 acttab_action(pActtab, ap->sp->index, action);
3323 stp->iTknOfst = acttab_insert(pActtab);
3324 if( stp->iTknOfst<mnTknOfst ) mnTknOfst = stp->iTknOfst;
3325 if( stp->iTknOfst>mxTknOfst ) mxTknOfst = stp->iTknOfst;
3327 for(ap=stp->ap; ap; ap=ap->next){
3329 if( ap->sp->index<lemp->nterminal ) continue;
3330 if( ap->sp->index==lemp->nsymbol ) continue;
3333 acttab_action(pActtab, ap->sp->index, action);
3335 stp->iNtOfst = acttab_insert(pActtab);
3336 if( stp->iNtOfst<mnNtOfst ) mnNtOfst = stp->iNtOfst;
3337 if( stp->iNtOfst>mxNtOfst ) mxNtOfst = stp->iNtOfst;
3347 if( action<0 ) action = lemp->nsymbol + lemp->nrule + 2;
3350 if( j==9 || i==n-1 ){
3363 if( la<0 ) la = lemp->nsymbol;
3366 if( j==9 || i==n-1 ){
3376 fprintf(out, "#define YY_SHIFT_USE_DFLT (%d)\n", mnTknOfst-1); lineno++;
3378 minimum_size_type(mnTknOfst-1, mxTknOfst)); lineno++;
3379 n = lemp->nstate;
3382 stp = lemp->sorted[i];
3383 ofst = stp->iTknOfst;
3384 if( ofst==NO_OFFSET ) ofst = mnTknOfst - 1;
3387 if( j==9 || i==n-1 ){
3397 fprintf(out, "#define YY_REDUCE_USE_DFLT (%d)\n", mnNtOfst-1); lineno++;
3399 minimum_size_type(mnNtOfst-1, mxNtOfst)); lineno++;
3400 n = lemp->nstate;
3403 stp = lemp->sorted[i];
3404 ofst = stp->iNtOfst;
3405 if( ofst==NO_OFFSET ) ofst = mnNtOfst - 1;
3408 if( j==9 || i==n-1 ){
3419 n = lemp->nstate;
3421 stp = lemp->sorted[i];
3423 fprintf(out, " %4d,", stp->iDflt);
3424 if( j==9 || i==n-1 ){
3432 tplt_xfer(lemp->name,in,out,&lineno);
3436 if( lemp->has_fallback ){
3437 for(i=0; i<lemp->nterminal; i++){
3438 struct symbol *p = lemp->symbols[i];
3439 if( p->fallback==0 ){
3440 fprintf(out, " 0, /* %10s => nothing */\n", p->name);
3442 fprintf(out, " %3d, /* %10s => %s */\n", p->fallback->index,
3443 p->name, p->fallback->name);
3448 tplt_xfer(lemp->name, in, out, &lineno);
3452 for(i=0; i<lemp->nsymbol; i++){
3453 sprintf(line,"\"%s\",",lemp->symbols[i]->name);
3454 fprintf(out," %-15s",line);
3458 tplt_xfer(lemp->name,in,out,&lineno);
3464 for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){
3465 assert( rp->index==i );
3466 fprintf(out," /* %3d */ \"%s ::=", i, rp->lhs->name);
3467 for(j=0; j<rp->nrhs; j++) fprintf(out," %s",rp->rhs[j]->name);
3470 tplt_xfer(lemp->name,in,out,&lineno);
3476 if( lemp->tokendest ){
3477 for(i=0; i<lemp->nsymbol; i++){
3478 struct symbol *sp = lemp->symbols[i];
3479 if( sp==0 || sp->type!=TERMINAL ) continue;
3480 fprintf(out," case %d:\n",sp->index); lineno++;
3482 for(i=0; i<lemp->nsymbol && lemp->symbols[i]->type!=TERMINAL; i++);
3483 if( i<lemp->nsymbol ){
3484 emit_destructor_code(out,lemp->symbols[i],lemp,&lineno);
3488 for(i=0; i<lemp->nsymbol; i++){
3489 struct symbol *sp = lemp->symbols[i];
3490 if( sp==0 || sp->type==TERMINAL || sp->destructor==0 ) continue;
3491 fprintf(out," case %d:\n",sp->index); lineno++;
3492 emit_destructor_code(out,lemp->symbols[i],lemp,&lineno);
3495 if( lemp->vardest ){
3497 for(i=0; i<lemp->nsymbol; i++){
3498 struct symbol *sp = lemp->symbols[i];
3499 if( sp==0 || sp->type==TERMINAL ||
3500 sp->index<=0 || sp->destructor!=0 ) continue;
3501 fprintf(out," case %d:\n",sp->index); lineno++;
3509 tplt_xfer(lemp->name,in,out,&lineno);
3512 tplt_print(out,lemp,lemp->overflow,lemp->overflowln,&lineno);
3513 tplt_xfer(lemp->name,in,out,&lineno);
3520 for(rp=lemp->rule; rp; rp=rp->next){
3521 fprintf(out," { %d, %d },\n",rp->lhs->index,rp->nrhs); lineno++;
3523 tplt_xfer(lemp->name,in,out,&lineno);
3526 for(rp=lemp->rule; rp; rp=rp->next){
3527 fprintf(out," case %d:\n",rp->index); lineno++;
3528 emit_code(out,rp,lemp,&lineno);
3531 tplt_xfer(lemp->name,in,out,&lineno);
3534 tplt_print(out,lemp,lemp->failure,lemp->failureln,&lineno);
3535 tplt_xfer(lemp->name,in,out,&lineno);
3538 tplt_print(out,lemp,lemp->error,lemp->errorln,&lineno);
3539 tplt_xfer(lemp->name,in,out,&lineno);
3542 tplt_print(out,lemp,lemp->accept,lemp->acceptln,&lineno);
3543 tplt_xfer(lemp->name,in,out,&lineno);
3546 tplt_print(out,lemp,lemp->extracode,lemp->extracodeln,&lineno);
3563 if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
3567 for(i=1; i<lemp->nterminal && fgets(line,LINESIZE,in); i++){
3568 sprintf(pattern,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
3572 if( i==lemp->nterminal ){
3579 for(i=1; i<lemp->nterminal; i++){
3580 fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
3598 struct rule *rp, *rp2, *rbest; local
3602 for(i=0; i<lemp->nstate; i++){
3603 stp = lemp->sorted[i];
3607 for(ap=stp->ap; ap; ap=ap->next){
3608 if( ap->type!=REDUCE ) continue;
3609 rp = ap->x.rp;
3610 if( rp==rbest ) continue;
3612 for(ap2=ap->next; ap2; ap2=ap2->next){
3613 if( ap2->type!=REDUCE ) continue;
3614 rp2 = ap2->x.rp;
3616 if( rp2==rp ) n++;
3620 rbest = rp;
3630 for(ap=stp->ap; ap; ap=ap->next){
3631 if( ap->type==REDUCE && ap->x.rp==rbest ) break;
3634 ap->sp = Symbol_new("{default}");
3635 for(ap=ap->next; ap; ap=ap->next){
3636 if( ap->type==REDUCE && ap->x.rp==rbest ) ap->type = NOT_USED;
3638 stp->ap = Action_sort(stp->ap);
3729 char *Strsafe(y) in Strsafe() argument
3730 char *y; in Strsafe()
3734 z = Strsafe_find(y);
3735 if( z==0 && (z=malloc( strlen(y)+1 ))!=0 ){
3736 strcpy(z,y);
3772 x1a->size = 1024; in Strsafe_init()
3773 x1a->count = 0; in Strsafe_init()
3774 x1a->tbl = (x1node*)malloc( in Strsafe_init()
3776 if( x1a->tbl==0 ){ in Strsafe_init()
3781 x1a->ht = (x1node**)&(x1a->tbl[1024]); in Strsafe_init()
3782 for(i=0; i<1024; i++) x1a->ht[i] = 0; in Strsafe_init()
3797 h = ph & (x1a->size-1);
3798 np = x1a->ht[h];
3800 if( strcmp(np->data,data)==0 ){
3805 np = np->next;
3807 if( x1a->count>=x1a->size ){
3811 array.size = size = x1a->size*2;
3812 array.count = x1a->count;
3818 for(i=0; i<x1a->count; i++){
3820 oldnp = &(x1a->tbl[i]);
3821 h = strhash(oldnp->data) & (size-1);
3823 if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
3824 newnp->next = array.ht[h];
3825 newnp->data = oldnp->data;
3826 newnp->from = &(array.ht[h]);
3829 free(x1a->tbl);
3833 h = ph & (x1a->size-1);
3834 np = &(x1a->tbl[x1a->count++]);
3835 np->data = data;
3836 if( x1a->ht[h] ) x1a->ht[h]->from = &(np->next);
3837 np->next = x1a->ht[h];
3838 x1a->ht[h] = np;
3839 np->from = &(x1a->ht[h]);
3852 h = strhash(key) & (x1a->size-1);
3853 np = x1a->ht[h];
3855 if( strcmp(np->data,key)==0 ) break;
3856 np = np->next;
3858 return np ? np->data : 0;
3873 sp->name = Strsafe(x);
3874 sp->type = isupper(*x) ? TERMINAL : NONTERMINAL;
3875 sp->rule = 0;
3876 sp->fallback = 0;
3877 sp->prec = -1;
3878 sp->assoc = UNK;
3879 sp->firstset = 0;
3880 sp->lambda = B_FALSE;
3881 sp->destructor = 0;
3882 sp->datatype = 0;
3883 Symbol_insert(sp,sp->name);
3892 ** (non-terminals). Other than that, the order does not matter.
3901 return i1-i2; in Symbolcmpp()
3934 x2a->size = 128; in Symbol_init()
3935 x2a->count = 0; in Symbol_init()
3936 x2a->tbl = (x2node*)malloc( in Symbol_init()
3938 if( x2a->tbl==0 ){ in Symbol_init()
3943 x2a->ht = (x2node**)&(x2a->tbl[128]); in Symbol_init()
3944 for(i=0; i<128; i++) x2a->ht[i] = 0; in Symbol_init()
3960 h = ph & (x2a->size-1);
3961 np = x2a->ht[h];
3963 if( strcmp(np->key,key)==0 ){
3968 np = np->next;
3970 if( x2a->count>=x2a->size ){
3974 array.size = size = x2a->size*2;
3975 array.count = x2a->count;
3981 for(i=0; i<x2a->count; i++){
3983 oldnp = &(x2a->tbl[i]);
3984 h = strhash(oldnp->key) & (size-1);
3986 if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
3987 newnp->next = array.ht[h];
3988 newnp->key = oldnp->key;
3989 newnp->data = oldnp->data;
3990 newnp->from = &(array.ht[h]);
3993 free(x2a->tbl);
3997 h = ph & (x2a->size-1);
3998 np = &(x2a->tbl[x2a->count++]);
3999 np->key = key;
4000 np->data = data;
4001 if( x2a->ht[h] ) x2a->ht[h]->from = &(np->next);
4002 np->next = x2a->ht[h];
4003 x2a->ht[h] = np;
4004 np->from = &(x2a->ht[h]);
4017 h = strhash(key) & (x2a->size-1);
4018 np = x2a->ht[h];
4020 if( strcmp(np->key,key)==0 ) break;
4021 np = np->next;
4023 return np ? np->data : 0;
4026 /* Return the n-th data. Return NULL if n is out of range. */
4031 if( x2a && n>0 && n<=x2a->count ){
4032 data = x2a->tbl[n-1].data;
4042 return x2a ? x2a->count : 0; in Symbol_count()
4053 size = x2a->count; in Symbol_arrayof()
4056 for(i=0; i<size; i++) array[i] = x2a->tbl[i].data; in Symbol_arrayof()
4067 x = a->rp->index - b->rp->index;
4068 if( x==0 ) x = a->dot - b->dot;
4078 for(rc=0; rc==0 && a && b; a=a->bp, b=b->bp){
4079 rc = a->rp->index - b->rp->index;
4080 if( rc==0 ) rc = a->dot - b->dot;
4084 if( b ) rc = -1;
4095 h = h*571 + a->rp->index*37 + a->dot;
4096 a = a->bp;
4140 x3a->size = 128; in State_init()
4141 x3a->count = 0; in State_init()
4142 x3a->tbl = (x3node*)malloc( in State_init()
4144 if( x3a->tbl==0 ){ in State_init()
4149 x3a->ht = (x3node**)&(x3a->tbl[128]); in State_init()
4150 for(i=0; i<128; i++) x3a->ht[i] = 0; in State_init()
4166 h = ph & (x3a->size-1);
4167 np = x3a->ht[h];
4169 if( statecmp(np->key,key)==0 ){
4174 np = np->next;
4176 if( x3a->count>=x3a->size ){
4180 array.size = size = x3a->size*2;
4181 array.count = x3a->count;
4187 for(i=0; i<x3a->count; i++){
4189 oldnp = &(x3a->tbl[i]);
4190 h = statehash(oldnp->key) & (size-1);
4192 if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
4193 newnp->next = array.ht[h];
4194 newnp->key = oldnp->key;
4195 newnp->data = oldnp->data;
4196 newnp->from = &(array.ht[h]);
4199 free(x3a->tbl);
4203 h = ph & (x3a->size-1);
4204 np = &(x3a->tbl[x3a->count++]);
4205 np->key = key;
4206 np->data = data;
4207 if( x3a->ht[h] ) x3a->ht[h]->from = &(np->next);
4208 np->next = x3a->ht[h];
4209 x3a->ht[h] = np;
4210 np->from = &(x3a->ht[h]);
4223 h = statehash(key) & (x3a->size-1);
4224 np = x3a->ht[h];
4226 if( statecmp(np->key,key)==0 ) break;
4227 np = np->next;
4229 return np ? np->data : 0;
4240 size = x3a->count; in State_arrayof()
4243 for(i=0; i<size; i++) array[i] = x3a->tbl[i].data; in State_arrayof()
4253 h = h*571 + a->rp->index*37 + a->dot;
4286 x4a->size = 64; in Configtable_init()
4287 x4a->count = 0; in Configtable_init()
4288 x4a->tbl = (x4node*)malloc( in Configtable_init()
4290 if( x4a->tbl==0 ){ in Configtable_init()
4295 x4a->ht = (x4node**)&(x4a->tbl[64]); in Configtable_init()
4296 for(i=0; i<64; i++) x4a->ht[i] = 0; in Configtable_init()
4311 h = ph & (x4a->size-1);
4312 np = x4a->ht[h];
4314 if( Configcmp(np->data,data)==0 ){
4319 np = np->next;
4321 if( x4a->count>=x4a->size ){
4325 array.size = size = x4a->size*2;
4326 array.count = x4a->count;
4332 for(i=0; i<x4a->count; i++){
4334 oldnp = &(x4a->tbl[i]);
4335 h = confighash(oldnp->data) & (size-1);
4337 if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
4338 newnp->next = array.ht[h];
4339 newnp->data = oldnp->data;
4340 newnp->from = &(array.ht[h]);
4343 free(x4a->tbl);
4347 h = ph & (x4a->size-1);
4348 np = &(x4a->tbl[x4a->count++]);
4349 np->data = data;
4350 if( x4a->ht[h] ) x4a->ht[h]->from = &(np->next);
4351 np->next = x4a->ht[h];
4352 x4a->ht[h] = np;
4353 np->from = &(x4a->ht[h]);
4366 h = confighash(key) & (x4a->size-1);
4367 np = x4a->ht[h];
4369 if( Configcmp(np->data,key)==0 ) break;
4370 np = np->next;
4372 return np ? np->data : 0;
4381 if( x4a==0 || x4a->count==0 ) return;
4382 if( f ) for(i=0; i<x4a->count; i++) (*f)(x4a->tbl[i].data);
4383 for(i=0; i<x4a->size; i++) x4a->ht[i] = 0;
4384 x4a->count = 0;