Lines Matching refs:rp
319 struct rule *rp; /* The rule upon which the configuration is based */ member
350 struct rule *rp; /* The rule, if a reduce */ member
525 rc = ap1->x.rp->index - ap2->x.rp->index; in actioncmp()
558 newaction->x.rp = (struct rule *)arg; in Action_add()
813 struct rule *rp; in FindRulePrecedences() local
814 for(rp=xp->rule; rp; rp=rp->next){ in FindRulePrecedences()
815 if( rp->precsym==0 ){ in FindRulePrecedences()
817 for(i=0; i<rp->nrhs && rp->precsym==0; i++){ in FindRulePrecedences()
818 struct symbol *sp = rp->rhs[i]; in FindRulePrecedences()
822 rp->precsym = sp->subsym[j]; in FindRulePrecedences()
827 rp->precsym = rp->rhs[i]; in FindRulePrecedences()
843 struct rule *rp; in FindFirstSets() local
856 for(rp=lemp->rule; rp; rp=rp->next){ in FindFirstSets()
857 if( rp->lhs->lambda ) continue; in FindFirstSets()
858 for(i=0; i<rp->nrhs; i++){ in FindFirstSets()
859 struct symbol *sp = rp->rhs[i]; in FindFirstSets()
863 if( i==rp->nrhs ){ in FindFirstSets()
864 rp->lhs->lambda = LEMON_TRUE; in FindFirstSets()
874 for(rp=lemp->rule; rp; rp=rp->next){ in FindFirstSets()
875 s1 = rp->lhs; in FindFirstSets()
876 for(i=0; i<rp->nrhs; i++){ in FindFirstSets()
877 s2 = rp->rhs[i]; in FindFirstSets()
906 struct rule *rp; in FindStates() local
931 for(rp=lemp->rule; rp; rp=rp->next){ in FindStates()
933 for(i=0; i<rp->nrhs; i++){ in FindStates()
934 if( rp->rhs[i]==sp ){ /* FIX ME: Deal with multiterminals */ in FindStates()
947 for(rp=sp->rule; rp; rp=rp->nextlhs){ in FindStates()
949 rp->lhsStart = 1; in FindStates()
950 newcfp = Configlist_addbasis(rp,0); in FindStates()
1041 if( cfp->dot>=cfp->rp->nrhs ) continue; /* Can't shift this config */ in buildshifts()
1043 sp = cfp->rp->rhs[cfp->dot]; /* Symbol after the dot */ in buildshifts()
1050 if( bcfp->dot>=bcfp->rp->nrhs ) continue; /* Can't shift this one */ in buildshifts()
1051 bsp = bcfp->rp->rhs[bcfp->dot]; /* Get symbol after dot */ in buildshifts()
1054 newcfg = Configlist_addbasis(bcfp->rp,bcfp->dot+1); in buildshifts()
1157 struct rule *rp; in FindActions() local
1166 if( cfp->rp->nrhs==cfp->dot ){ /* Is dot at extreme right? */ in FindActions()
1171 Action_add(&stp->ap,REDUCE,lemp->symbols[j],(char *)cfp->rp); in FindActions()
1213 for(rp=lemp->rule; rp; rp=rp->next) rp->canReduce = LEMON_FALSE; in FindActions()
1217 if( ap->type==REDUCE ) ap->x.rp->canReduce = LEMON_TRUE; in FindActions()
1220 for(rp=lemp->rule; rp; rp=rp->next){ in FindActions()
1221 if( rp->canReduce ) continue; in FindActions()
1222 ErrorMsg(lemp->filename,rp->ruleline,"This rule can not be reduced.\n"); in FindActions()
1253 spy = apy->x.rp->precsym; in resolve_conflict()
1271 spx = apx->x.rp->precsym; in resolve_conflict()
1272 spy = apy->x.rp->precsym; in resolve_conflict()
1347 struct rule *rp, /* The rule */ in Configlist_add() argument
1353 model.rp = rp; in Configlist_add()
1358 cfp->rp = rp; in Configlist_add()
1373 struct config *Configlist_addbasis(struct rule *rp, int dot) in Configlist_addbasis() argument
1379 model.rp = rp; in Configlist_addbasis()
1384 cfp->rp = rp; in Configlist_addbasis()
1404 struct rule *rp, *newrp; in Configlist_closure() local
1410 rp = cfp->rp; in Configlist_closure()
1412 if( dot>=rp->nrhs ) continue; in Configlist_closure()
1413 sp = rp->rhs[dot]; in Configlist_closure()
1416 ErrorMsg(lemp->filename,rp->line,"Nonterminal \"%s\" has no rules.", in Configlist_closure()
1422 for(i=dot+1; i<rp->nrhs; i++){ in Configlist_closure()
1423 xsp = rp->rhs[i]; in Configlist_closure()
1438 if( i==rp->nrhs ) Plink_add(&cfp->fplp,newcfp); in Configlist_closure()
1592 static struct rule *Rule_sort(struct rule *rp){ in Rule_sort() argument
1597 while( rp ){ in Rule_sort()
1598 pNext = rp->next; in Rule_sort()
1599 rp->next = 0; in Rule_sort()
1601 rp = Rule_merge(x[i], rp); in Rule_sort()
1604 x[i] = rp; in Rule_sort()
1605 rp = pNext; in Rule_sort()
1607 rp = 0; in Rule_sort()
1609 rp = Rule_merge(x[i], rp); in Rule_sort()
1611 return rp; in Rule_sort()
1668 struct rule *rp; in main() local
1720 for(i=0, rp=lem.rule; rp; rp=rp->next){ in main()
1721 rp->iRule = rp->code ? i++ : -1; in main()
1724 for(rp=lem.rule; rp; rp=rp->next){ in main()
1725 if( rp->iRule<0 ) rp->iRule = i++; in main()
2383 struct rule *rp; in parseonetoken() local
2384 rp = (struct rule *)calloc( sizeof(struct rule) + in parseonetoken()
2386 if( rp==0 ){ in parseonetoken()
2393 rp->ruleline = psp->tokenlineno; in parseonetoken()
2394 rp->rhs = (struct symbol**)&rp[1]; in parseonetoken()
2395 rp->rhsalias = (const char**)&(rp->rhs[psp->nrhs]); in parseonetoken()
2397 rp->rhs[i] = psp->rhs[i]; in parseonetoken()
2398 rp->rhsalias[i] = psp->alias[i]; in parseonetoken()
2399 if( rp->rhsalias[i]!=0 ){ rp->rhs[i]->bContent = 1; } in parseonetoken()
2401 rp->lhs = psp->lhs; in parseonetoken()
2402 rp->lhsalias = psp->lhsalias; in parseonetoken()
2403 rp->nrhs = psp->nrhs; in parseonetoken()
2404 rp->code = 0; in parseonetoken()
2405 rp->noCode = 1; in parseonetoken()
2406 rp->precsym = 0; in parseonetoken()
2407 rp->index = psp->gp->nrule++; in parseonetoken()
2408 rp->nextlhs = rp->lhs->rule; in parseonetoken()
2409 rp->lhs->rule = rp; in parseonetoken()
2410 rp->next = 0; in parseonetoken()
2412 psp->firstrule = psp->lastrule = rp; in parseonetoken()
2414 psp->lastrule->next = rp; in parseonetoken()
2415 psp->lastrule = rp; in parseonetoken()
2417 psp->prevrule = rp; in parseonetoken()
3234 void rule_print(FILE *out, struct rule *rp){ in rule_print() argument
3236 fprintf(out, "%s",rp->lhs->name); in rule_print()
3239 for(i=0; i<rp->nrhs; i++){ in rule_print()
3240 struct symbol *sp = rp->rhs[i]; in rule_print()
3257 struct rule *rp; in Reprint() local
3279 for(rp=lemp->rule; rp; rp=rp->next){ in Reprint()
3280 rule_print(stdout, rp); in Reprint()
3282 if( rp->precsym ) printf(" [%s]",rp->precsym->name); in Reprint()
3290 void RulePrint(FILE *fp, struct rule *rp, int iCursor){ in RulePrint() argument
3293 fprintf(fp,"%s ::=",rp->lhs->name); in RulePrint()
3294 for(i=0; i<=rp->nrhs; i++){ in RulePrint()
3296 if( i==rp->nrhs ) break; in RulePrint()
3297 sp = rp->rhs[i]; in RulePrint()
3312 RulePrint(fp, cfp->rp, cfp->dot); in ConfigPrint()
3367 struct rule *rp = ap->x.rp; in PrintAction() local
3368 fprintf(fp,"%*s reduce %-7d",indent,ap->sp->name,rp->iRule); in PrintAction()
3369 RulePrint(fp, rp, -1); in PrintAction()
3373 struct rule *rp = ap->x.rp; in PrintAction() local
3374 fprintf(fp,"%*s shift-reduce %-7d",indent,ap->sp->name,rp->iRule); in PrintAction()
3375 RulePrint(fp, rp, -1); in PrintAction()
3387 indent,ap->sp->name,ap->x.rp->iRule); in PrintAction()
3404 indent,ap->sp->name,ap->x.rp->iRule); in PrintAction()
3426 struct rule *rp; in ReportOutput() local
3438 if( cfp->dot==cfp->rp->nrhs ){ in ReportOutput()
3439 lemon_sprintf(buf,"(%d)",cfp->rp->iRule); in ReportOutput()
3505 for(rp=lemp->rule; rp; rp=rp->next){ in ReportOutput()
3506 fprintf(fp, "%4d: ", rp->iRule); in ReportOutput()
3507 rule_print(fp, rp); in ReportOutput()
3509 if( rp->precsym ){ in ReportOutput()
3511 rp->precsym->name, rp->precsym->prec); in ReportOutput()
3580 act = lemp->minReduce + ap->x.rp->iRule; in compute_action()
3582 act = lemp->minShiftReduce + ap->x.rp->iRule; in compute_action()
3586 case REDUCE: act = lemp->minReduce + ap->x.rp->iRule; break; in compute_action()
3846 PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){ in translate_code() argument
3858 for(i=0; i<rp->nrhs; i++) used[i] = 0; in translate_code()
3861 if( rp->code==0 ){ in translate_code()
3863 rp->code = newlinestr; in translate_code()
3864 rp->line = rp->ruleline; in translate_code()
3865 rp->noCode = 1; in translate_code()
3867 rp->noCode = 0; in translate_code()
3871 if( rp->nrhs==0 ){ in translate_code()
3874 }else if( rp->rhsalias[0]==0 ){ in translate_code()
3878 if( has_destructor(rp->rhs[0],lemp) ){ in translate_code()
3881 rp->rhs[0]->index,1-rp->nrhs); in translate_code()
3882 rp->codePrefix = Strsafe(append_str(0,0,0,0)); in translate_code()
3883 rp->noCode = 0; in translate_code()
3885 }else if( rp->lhsalias==0 ){ in translate_code()
3888 }else if( strcmp(rp->lhsalias,rp->rhsalias[0])==0 ){ in translate_code()
3894 if( rp->lhs->dtnum!=rp->rhs[0]->dtnum ){ in translate_code()
3895 ErrorMsg(lemp->filename,rp->ruleline, in translate_code()
3898 rp->lhs->name, rp->lhsalias, rp->rhs[0]->name, rp->rhsalias[0]); in translate_code()
3903 rp->lhsalias, rp->rhsalias[0]); in translate_code()
3904 zSkip = strstr(rp->code, zOvwrt); in translate_code()
3914 sprintf(zLhs, "yymsp[%d].minor.yy%d",1-rp->nrhs,rp->lhs->dtnum); in translate_code()
3917 sprintf(zLhs, "yylhsminor.yy%d",rp->lhs->dtnum); in translate_code()
3923 for(cp=(char *)rp->code; *cp; cp++){ in translate_code()
3930 if( ISALPHA(*cp) && (cp==rp->code || (!ISALNUM(cp[-1]) && cp[-1]!='_')) ){ in translate_code()
3935 if( rp->lhsalias && strcmp(cp,rp->lhsalias)==0 ){ in translate_code()
3940 for(i=0; i<rp->nrhs; i++){ in translate_code()
3941 if( rp->rhsalias[i] && strcmp(cp,rp->rhsalias[i])==0 ){ in translate_code()
3943 ErrorMsg(lemp->filename,rp->ruleline, in translate_code()
3945 rp->rhsalias[0], zOvwrt); in translate_code()
3947 }else if( cp!=rp->code && cp[-1]=='@' ){ in translate_code()
3950 append_str("yymsp[%d].major",-1,i-rp->nrhs+1,0); in translate_code()
3952 struct symbol *sp = rp->rhs[i]; in translate_code()
3959 append_str("yymsp[%d].minor.yy%d",0,i-rp->nrhs+1, dtnum); in translate_code()
3974 if( cp && cp[0] ) rp->code = Strsafe(cp); in translate_code()
3978 if( rp->lhsalias && !lhsused ){ in translate_code()
3979 ErrorMsg(lemp->filename,rp->ruleline, in translate_code()
3981 rp->lhsalias,rp->lhs->name,rp->lhsalias); in translate_code()
3988 for(i=0; i<rp->nrhs; i++){ in translate_code()
3989 if( rp->rhsalias[i] ){ in translate_code()
3992 if( rp->lhsalias && strcmp(rp->lhsalias,rp->rhsalias[i])==0 ){ in translate_code()
3993 ErrorMsg(lemp->filename,rp->ruleline, in translate_code()
3996 rp->rhs[i]->name, rp->rhsalias[i]); in translate_code()
4000 if( rp->rhsalias[j] && strcmp(rp->rhsalias[j],rp->rhsalias[i])==0 ){ in translate_code()
4001 ErrorMsg(lemp->filename,rp->ruleline, in translate_code()
4003 rp->rhsalias[i]); in translate_code()
4010 ErrorMsg(lemp->filename,rp->ruleline, in translate_code()
4012 rp->rhsalias[i],rp->rhs[i]->name,rp->rhsalias[i]); in translate_code()
4015 }else if( i>0 && has_destructor(rp->rhs[i],lemp) ){ in translate_code()
4017 rp->rhs[i]->index,i-rp->nrhs+1); in translate_code()
4024 append_str(" yymsp[%d].minor.yy%d = ", 0, 1-rp->nrhs, rp->lhs->dtnum); in translate_code()
4032 rp->codeSuffix = Strsafe(cp); in translate_code()
4033 rp->noCode = 0; in translate_code()
4045 struct rule *rp, in emit_code() argument
4052 if( rp->codePrefix && rp->codePrefix[0] ){ in emit_code()
4053 fprintf(out, "{%s", rp->codePrefix); in emit_code()
4054 for(cp=rp->codePrefix; *cp; cp++){ if( *cp=='\n' ) (*lineno)++; } in emit_code()
4058 if( rp->code ){ in emit_code()
4061 tplt_linedir(out,rp->line,lemp->filename); in emit_code()
4063 fprintf(out,"{%s",rp->code); in emit_code()
4064 for(cp=rp->code; *cp; cp++){ if( *cp=='\n' ) (*lineno)++; } in emit_code()
4073 if( rp->codeSuffix && rp->codeSuffix[0] ){ in emit_code()
4074 fprintf(out, "%s", rp->codeSuffix); in emit_code()
4075 for(cp=rp->codeSuffix; *cp; cp++){ if( *cp=='\n' ) (*lineno)++; } in emit_code()
4078 if( rp->codePrefix ){ in emit_code()
4269 static void writeRuleText(FILE *out, struct rule *rp){ in writeRuleText() argument
4271 fprintf(out,"%s ::=", rp->lhs->name); in writeRuleText()
4272 for(j=0; j<rp->nrhs; j++){ in writeRuleText()
4273 struct symbol *sp = rp->rhs[j]; in writeRuleText()
4297 struct rule *rp; in ReportTable() local
4367 for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){ in ReportTable()
4368 assert( i==rp->iRule ); in ReportTable()
4371 rp->iRule, rp->lhs->index in ReportTable()
4373 writeRuleText(sql, rp); in ReportTable()
4375 for(j=0; j<rp->nrhs; j++){ in ReportTable()
4376 struct symbol *sp = rp->rhs[j]; in ReportTable()
4577 for(rp=lemp->rule; rp; rp=rp->next) rp->doesReduce = LEMON_FALSE; in ReportTable()
4581 ap->x.rp->doesReduce = 1; in ReportTable()
4776 for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){ in ReportTable()
4777 assert( rp->iRule==i ); in ReportTable()
4779 writeRuleText(out, rp); in ReportTable()
4857 for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){ in ReportTable()
4858 fprintf(out," %4d, /* (%d) ", rp->lhs->index, i); in ReportTable()
4859 rule_print(out, rp); in ReportTable()
4863 for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){ in ReportTable()
4864 fprintf(out," %3d, /* (%d) ", -rp->nrhs, i); in ReportTable()
4865 rule_print(out, rp); in ReportTable()
4872 for(rp=lemp->rule; rp; rp=rp->next){ in ReportTable()
4873 i += translate_code(lemp, rp); in ReportTable()
4879 for(rp=lemp->rule; rp; rp=rp->next){ in ReportTable()
4881 if( rp->codeEmitted ) continue; in ReportTable()
4882 if( rp->noCode ){ in ReportTable()
4886 fprintf(out," case %d: /* ", rp->iRule); in ReportTable()
4887 writeRuleText(out, rp); in ReportTable()
4889 for(rp2=rp->next; rp2; rp2=rp2->next){ in ReportTable()
4890 if( rp2->code==rp->code && rp2->codePrefix==rp->codePrefix in ReportTable()
4891 && rp2->codeSuffix==rp->codeSuffix ){ in ReportTable()
4898 emit_code(out,rp,lemp,&lineno); in ReportTable()
4900 rp->codeEmitted = 1; in ReportTable()
4905 for(rp=lemp->rule; rp; rp=rp->next){ in ReportTable()
4906 if( rp->codeEmitted ) continue; in ReportTable()
4907 assert( rp->noCode ); in ReportTable()
4908 fprintf(out," /* (%d) ", rp->iRule); in ReportTable()
4909 writeRuleText(out, rp); in ReportTable()
4910 if( rp->neverReduce ){ in ReportTable()
4912 rp->iRule); lineno++; in ReportTable()
4913 }else if( rp->doesReduce ){ in ReportTable()
4914 fprintf(out, " */ yytestcase(yyruleno==%d);\n", rp->iRule); lineno++; in ReportTable()
4917 rp->iRule); lineno++; in ReportTable()
4992 struct rule *rp, *rp2, *rbest; in CompressTables() local
5008 rp = ap->x.rp; in CompressTables()
5009 if( rp->lhsStart ) continue; in CompressTables()
5010 if( rp==rbest ) continue; in CompressTables()
5014 rp2 = ap2->x.rp; in CompressTables()
5016 if( rp2==rp ) n++; in CompressTables()
5020 rbest = rp; in CompressTables()
5033 if( ap->type==REDUCE && ap->x.rp==rbest ) break; in CompressTables()
5038 if( ap->type==REDUCE && ap->x.rp==rbest ) ap->type = NOT_USED; in CompressTables()
5044 if( ap->type==REDUCE && ap->x.rp!=rbest ) break; in CompressTables()
5064 ap->x.rp = pNextState->pDfltReduce; in CompressTables()
5080 rp = ap->x.rp; in CompressTables()
5081 if( rp->noCode==0 ) continue; in CompressTables()
5082 if( rp->nrhs!=1 ) continue; in CompressTables()
5091 for(ap2=stp->ap; ap2 && (ap2==ap || ap2->sp!=rp->lhs); ap2=ap2->next){} in CompressTables()
5148 assert( stp->autoReduce==0 || stp->pDfltReduce==ap->x.rp ); in ResortStates()
5586 x = a->rp->index - b->rp->index; in Configcmp()
5596 rc = a->rp->index - b->rp->index; in statecmp()
5611 h = h*571 + a->rp->index*37 + a->dot; in statehash()
5763 h = h*571 + a->rp->index*37 + a->dot; in confighash()