Lines Matching refs:lemp
607 void FindFirstSets(lemp) in FindFirstSets() argument
608 struct lemon *lemp; in FindFirstSets()
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){
640 for(rp=lemp->rule; rp; rp=rp->next){
664 void FindStates(lemp) in FindStates() argument
665 struct lemon *lemp; in FindStates()
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;
690 for(rp=lemp->rule; rp; rp=rp->next){
694 ErrorMsg(lemp->filename,0,
698 lemp->errorcnt++;
715 (void)getstate(lemp);
723 PRIVATE struct state *getstate(lemp) in getstate() argument
724 struct lemon *lemp; in getstate()
750 Configlist_closure(lemp); /* Compute the configuration closure */
757 stp->index = lemp->nstate++; /* Every state gets a sequence number */
760 buildshifts(lemp,stp); /* Recursively compute successor states */
768 PRIVATE void buildshifts(lemp,stp) in buildshifts() argument
769 struct lemon *lemp; in buildshifts()
805 newstp = getstate(lemp);
816 void FindLinks(lemp) in FindLinks() argument
817 struct lemon *lemp; in FindLinks()
827 for(i=0; i<lemp->nstate; i++){
828 stp = lemp->sorted[i];
836 for(i=0; i<lemp->nstate; i++){
837 stp = lemp->sorted[i];
852 void FindFollowSets(lemp) in FindFollowSets() argument
853 struct lemon *lemp; in FindFollowSets()
861 for(i=0; i<lemp->nstate; i++){
862 for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){
869 for(i=0; i<lemp->nstate; i++){
870 for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){
889 void FindActions(lemp) in FindActions() argument
890 struct lemon *lemp; in FindActions()
902 for(i=0; i<lemp->nstate; i++){ /* Loop over all states */
903 stp = lemp->sorted[i];
906 for(j=0; j<lemp->nterminal; 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];
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){
953 for(rp=lemp->rule; rp; rp=rp->next){
955 ErrorMsg(lemp->filename,rp->ruleline,"This rule can not be reduced.\n");
956 lemp->errorcnt++;
1145 void Configlist_closure(lemp) in Configlist_closure() argument
1146 struct lemon *lemp; in Configlist_closure()
1160 if( sp->rule==0 && sp!=lemp->errsym ){
1161 ErrorMsg(lemp->filename,rp->line,"Nonterminal \"%s\" has no rules.",
1163 lemp->errorcnt++;
2496 PRIVATE char *file_makename(lemp,suffix) in file_makename() argument
2497 struct lemon *lemp; in file_makename()
2503 name = malloc( strlen(lemp->filename) + strlen(suffix) + 5 );
2508 strcpy(name,lemp->filename);
2518 PRIVATE FILE *file_open(lemp,suffix,mode) in file_open() argument
2519 struct lemon *lemp; in file_open()
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++;
2538 void Reprint(lemp) in Reprint() argument
2539 struct lemon *lemp; in Reprint()
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];
2553 skip = (lemp->nsymbol + ncolumns - 1)/ncolumns;
2556 for(j=i; j<lemp->nsymbol; j+=skip){
2557 sp = lemp->symbols[j];
2563 for(rp=lemp->rule; rp; rp=rp->next){
2596 PRIVATE void SetPrint(out,set,lemp) in SetPrint() argument
2599 struct lemon *lemp;
2605 for(i=0; i<lemp->nterminal; i++){
2607 fprintf(out,"%s%s",spacer,lemp->symbols[i]->name);
2661 void ReportOutput(lemp) in ReportOutput() argument
2662 struct lemon *lemp; in ReportOutput()
2670 fp = file_open(lemp,".out","w");
2673 for(i=0; i<lemp->nstate; i++){
2674 stp = lemp->sorted[i];
2676 if( lemp->basisflag ) cfp=stp->bp;
2689 SetPrint(fp,cfp->fws,lemp);
2693 if( lemp->basisflag ) cfp=cfp->bp;
2755 PRIVATE int compute_action(lemp,ap) in compute_action() argument
2756 struct lemon *lemp; in compute_action()
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;
2809 PRIVATE FILE *tplt_open(lemp) in tplt_open() argument
2810 struct lemon *lemp; in tplt_open()
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++;
2847 PRIVATE void tplt_print(out,lemp,str,strln,lineno) in tplt_print() argument
2849 struct lemon *lemp;
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;
2869 void emit_destructor_code(out,sp,lemp,lineno) in emit_destructor_code() argument
2872 struct lemon *lemp;
2879 cp = lemp->tokendest;
2881 fprintf(out,"#line %d \"%s\"\n{",lemp->tokendestln,lemp->filename);
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);
2902 fprintf(out,"}\n#line %d \"%s\"\n",*lineno,lemp->outname);
2909 int has_destructor(sp, lemp) in has_destructor() argument
2911 struct lemon *lemp;
2915 ret = lemp->tokendest!=0;
2917 ret = lemp->vardest!=0 || sp->destructor!=0;
2926 PRIVATE void emit_code(out,rp,lemp,lineno) in emit_code() argument
2929 struct lemon *lemp;
2943 fprintf(out,"#line %d \"%s\"\n{",rp->line,lemp->filename);
2970 fprintf(out,"}\n#line %d \"%s\"\n",*lineno,lemp->outname);
2975 ErrorMsg(lemp->filename,rp->ruleline,
2978 lemp->errorcnt++;
2985 ErrorMsg(lemp->filename,rp->ruleline,
2988 lemp->errorcnt++;
2990 if( has_destructor(rp->rhs[i],lemp) ){
3010 void print_stack_union(out,lemp,plineno,mhflag) in print_stack_union() argument
3012 struct lemon *lemp; /* The main info structure for this parser */
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];
3052 for(i=0; i<lemp->nsymbol; i++){
3053 struct symbol *sp = lemp->symbols[i];
3055 if( sp==lemp->errsym ){
3059 if( sp->type!=NONTERMINAL || (sp->datatype==0 && lemp->vartype==0) ){
3064 if( cp==0 ) cp = lemp->vartype;
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++;
3159 void ReportTable(lemp, mhflag) in ReportTable() argument
3160 struct lemon *lemp; in ReportTable()
3176 in = tplt_open(lemp);
3178 out = file_open(lemp,".c","w");
3184 tplt_xfer(lemp->name,in,out,&lineno);
3187 tplt_print(out,lemp,lemp->include,lemp->includeln,&lineno);
3189 char *name = file_makename(lemp, ".h");
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++;
3216 print_stack_union(out,lemp,&lineno,mhflag);
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++;
3241 name,lemp->arg,&lemp->arg[i]); lineno++;
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);
3275 ax = malloc( sizeof(ax[0])*lemp->nstate*2 );
3280 for(i=0; i<lemp->nstate; i++){
3281 stp = lemp->sorted[i];
3283 stp->iDflt = lemp->nstate + lemp->nrule;
3287 if( compute_action(lemp,ap)>=0 ){
3288 if( ap->sp->index<lemp->nterminal ){
3290 }else if( ap->sp->index<lemp->nsymbol ){
3293 stp->iDflt = compute_action(lemp, ap);
3311 qsort(ax, lemp->nstate*2, sizeof(ax[0]), axset_compare);
3313 for(i=0; i<lemp->nstate*2 && ax[i].nAction>0; i++){
3318 if( ap->sp->index>=lemp->nterminal ) continue;
3319 action = compute_action(lemp, ap);
3329 if( ap->sp->index<lemp->nterminal ) continue;
3330 if( ap->sp->index==lemp->nsymbol ) continue;
3331 action = compute_action(lemp, ap);
3347 if( action<0 ) action = lemp->nsymbol + lemp->nrule + 2;
3363 if( la<0 ) la = lemp->nsymbol;
3379 n = lemp->nstate;
3382 stp = lemp->sorted[i];
3400 n = lemp->nstate;
3403 stp = lemp->sorted[i];
3419 n = lemp->nstate;
3421 stp = lemp->sorted[i];
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];
3448 tplt_xfer(lemp->name, in, out, &lineno);
3452 for(i=0; i<lemp->nsymbol; i++){
3453 sprintf(line,"\"%s\",",lemp->symbols[i]->name);
3458 tplt_xfer(lemp->name,in,out,&lineno);
3464 for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){
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];
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];
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];
3505 emit_destructor_code(out,dflt_sp,lemp,&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){
3523 tplt_xfer(lemp->name,in,out,&lineno);
3526 for(rp=lemp->rule; rp; rp=rp->next){
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);
3554 void ReportHeader(lemp) in ReportHeader() argument
3555 struct lemon *lemp; in ReportHeader()
3563 if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
3565 in = file_open(lemp,".h","r");
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 ){
3577 out = file_open(lemp,".h","w");
3579 for(i=1; i<lemp->nterminal; i++){
3580 fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
3593 void CompressTables(lemp) in CompressTables() argument
3594 struct lemon *lemp; in CompressTables()
3602 for(i=0; i<lemp->nstate; i++){
3603 stp = lemp->sorted[i];