(/home/sate/Testcases/c/cve/wireshark-1.2.0/tools/lemon/lemon.c) |
| |
| 3620 | | | void ReportTable( |
| 3621 | | | struct lemon *lemp, |
| 3622 | | | int mhflag) |
| 3623 | | | { |
| 3624 | | | FILE *out, *in; |
| 3625 | | | char line[LINESIZE]; |
| 3626 | | | int lineno; |
| 3627 | | | struct state *stp; |
| 3628 | | | struct action *ap; |
| 3629 | | | struct rule *rp; |
| 3630 | | | struct acttab *pActtab; |
| 3631 | | | int i, j, n; |
| 3632 | | | const char *name; |
| 3633 | | | int mnTknOfst, mxTknOfst; |
| 3634 | | | int mnNtOfst, mxNtOfst; |
| 3635 | | | struct axset *ax; |
| 3636 | | | |
| 3637 | | | in = tplt_open(lemp); |
| 3638 | | | if( in==0 ) return; |
Event 1:
Skipping " if". in == 0 evaluates to false.
hide
|
|
| 3639 | | | out = file_open(lemp,".c","wb"); |
| 3640 | | | if( out==0 ){ |
Event 2:
Skipping " if". out == 0 evaluates to false.
hide
|
|
| 3641 | | | fclose(in); |
| 3642 | | | return; |
| 3643 | | | } |
| 3644 | | | lineno = 1; |
| 3645 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 3646 | | | |
| 3647 | | | |
| 3648 | | | tplt_print(out,lemp,lemp->include,&lineno); |
| 3649 | | | if( mhflag ){ |
Event 3:
Skipping " if". mhflag evaluates to false.
hide
|
|
| 3650 | | | char *name = file_makename_using_basename(lemp, ".h"); |
| 3651 | | | fprintf(out,"#include \"%s\"\n", name); lineno++; |
| 3652 | | | free(name); |
| 3653 | | | } |
| 3654 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 3655 | | | |
| 3656 | | | |
| 3657 | | | if( mhflag ){ |
Event 4:
Skipping " if". mhflag evaluates to false.
hide
|
|
| 3658 | | | const char *prefix; |
| 3659 | | | fprintf(out,"#if INTERFACE\n"); lineno++; |
| 3660 | | | if( lemp->tokenprefix ) prefix = lemp->tokenprefix; |
| 3661 | | | else prefix = ""; |
| 3662 | | | for(i=1; i<lemp->nterminal; i++){ |
| 3663 | | | fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i); |
| 3664 | | | lineno++; |
| 3665 | | | } |
| 3666 | | | fprintf(out,"#endif\n"); lineno++; |
| 3667 | | | } |
| 3668 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 3669 | | | |
| 3670 | | | |
| 3671 | | | fprintf(out,"#define YYCODETYPE %s\n", |
| 3672 | | | minimum_signed_size_type(0, lemp->nsymbol+5)); lineno++; |
| 3673 | | | fprintf(out,"#define YYNOCODE %d\n",lemp->nsymbol+1); lineno++; |
| 3674 | | | fprintf(out,"#define YYACTIONTYPE %s\n", |
| 3675 | | | minimum_signed_size_type(0, lemp->nstate+lemp->nrule+5)); lineno++; |
| 3676 | | | if( lemp->wildcard ){ |
Event 5:
Taking true branch. lemp->wildcard evaluates to true.
hide
|
|
| 3677 | | | fprintf(out,"#define YYWILDCARD %d\n", |
| 3678 | | | lemp->wildcard->index); lineno++; |
| 3679 | | | } |
| 3680 | | | print_stack_union(out,lemp,&lineno,mhflag); |
| 3681 | | | fprintf(out, "#ifndef YYSTACKDEPTH\n"); lineno++; |
| 3682 | | | if( lemp->stacksize ){ |
Event 6:
Taking false branch. lemp->stacksize evaluates to false.
hide
|
|
| 3683 | | | fprintf(out,"#define YYSTACKDEPTH %s\n",lemp->stacksize); lineno++; |
| 3684 | | | }else{ |
| 3685 | | | fprintf(out,"#define YYSTACKDEPTH 100\n"); lineno++; |
| 3686 | | | } |
| 3687 | | | fprintf(out, "#endif\n"); lineno++; |
| 3688 | | | if( mhflag ){ |
Event 7:
Skipping " if". mhflag evaluates to false.
hide
|
|
| 3689 | | | fprintf(out,"#if INTERFACE\n"); lineno++; |
| 3690 | | | } |
| 3691 | | | name = lemp->name ? lemp->name : "Parse"; |
Event 8:
lemp->name evaluates to false.
hide
|
|
| 3692 | | | if( lemp->arg && lemp->arg[0] ){ |
| 3693 | | | int i; |
| 3694 | | | i = (int) strlen(lemp->arg); |
| 3695 | | | while( i>=1 && safe_isspace(lemp->arg[i-1]) ) i--; |
| 3696 | | | while( i>=1 && (safe_isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--; |
| 3697 | | | fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg); lineno++; |
| 3698 | | | fprintf(out,"#define %sARG_PDECL ,%s\n",name,lemp->arg); lineno++; |
| 3699 | | | fprintf(out,"#define %sARG_FETCH %s = yypParser->%s\n", |
| 3700 | | | name,lemp->arg,&lemp->arg[i]); lineno++; |
| 3701 | | | fprintf(out,"#define %sARG_STORE yypParser->%s = %s\n", |
| 3702 | | | name,&lemp->arg[i],&lemp->arg[i]); lineno++; |
| 3703 | | | }else{ |
| 3704 | | | fprintf(out,"#define %sARG_SDECL\n",name); lineno++; |
| 3705 | | | fprintf(out,"#define %sARG_PDECL\n",name); lineno++; |
| 3706 | | | fprintf(out,"#define %sARG_FETCH\n",name); lineno++; |
| 3707 | | | fprintf(out,"#define %sARG_STORE\n",name); lineno++; |
| 3708 | | | } |
| 3709 | | | if( mhflag ){ |
Event 12:
Skipping " if". mhflag evaluates to false.
hide
|
|
| 3710 | | | fprintf(out,"#endif\n"); lineno++; |
| 3711 | | | } |
| 3712 | | | fprintf(out,"#define YYNSTATE %d\n",lemp->nstate); lineno++; |
| 3713 | | | fprintf(out,"#define YYNRULE %d\n",lemp->nrule); lineno++; |
| 3714 | | | if( lemp->errsym->useCnt ){ |
Event 13:
Skipping " if". lemp->errsym->useCnt evaluates to false.
hide
|
|
| 3715 | | | fprintf(out,"#define YYERRORSYMBOL %d\n",lemp->errsym->index); lineno++; |
| 3716 | | | fprintf(out,"#define YYERRSYMDT yy%d\n",lemp->errsym->dtnum); lineno++; |
| 3717 | | | } |
| 3718 | | | if( lemp->has_fallback ){ |
Event 14:
Skipping " if". lemp->has_fallback evaluates to false.
hide
|
|
| 3719 | | | fprintf(out,"#define YYFALLBACK 1\n"); lineno++; |
| 3720 | | | } |
| 3721 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 3722 | | | |
| 3723 | | | |
| 3724 | | | |
| 3725 | | | |
| 3726 | | | |
| 3727 | | | |
| 3728 | | | |
| 3729 | | | |
| 3730 | | | |
| 3731 | | | |
| 3732 | | | |
| 3733 | | | |
| 3734 | | | |
| 3735 | | | |
| 3736 | | | ax = calloc(lemp->nstate*2, sizeof(ax[0])); |
| 3737 | | | if( ax==0 ){ |
Event 15:
Skipping " if". ax == 0 evaluates to false.
hide
|
|
| 3738 | | | fprintf(stderr,"malloc failed\n"); |
| 3739 | | | exit(1); |
| 3740 | | | } |
| 3741 | | | for(i=0; i<lemp->nstate; i++){ |
| 3742 | | | stp = lemp->sorted[i]; |
| 3743 | | | ax[i*2].stp = stp; |
| 3744 | | | ax[i*2].isTkn = 1; |
| 3745 | | | ax[i*2].nAction = stp->nTknAct; |
| 3746 | | | ax[i*2+1].stp = stp; |
| 3747 | | | ax[i*2+1].isTkn = 0; |
| 3748 | | | ax[i*2+1].nAction = stp->nNtAct; |
| 3749 | | | } |
| 3750 | | | mxTknOfst = mnTknOfst = 0; |
| 3751 | | | mxNtOfst = mnNtOfst = 0; |
| 3752 | | | |
| 3753 | | | |
| 3754 | | | |
| 3755 | | | |
| 3756 | | | |
| 3757 | | | qsort(ax, lemp->nstate*2, sizeof(ax[0]), axset_compare); |
| 3758 | | | pActtab = acttab_alloc(); |
| 3759 | | | for(i=0; i<lemp->nstate*2 && ax[i].nAction>0; i++){ |
| 3760 | | | stp = ax[i].stp; |
| 3761 | | | if( ax[i].isTkn ){ |
| 3762 | | | for(ap=stp->ap; ap; ap=ap->next){ |
| 3763 | | | int action; |
| 3764 | | | if( ap->sp->index>=lemp->nterminal ) continue; |
| 3765 | | | action = compute_action(lemp, ap); |
| 3766 | | | if( action<0 ) continue; |
| 3767 | | | acttab_action(pActtab, ap->sp->index, action); |
| 3768 | | | } |
| 3769 | | | stp->iTknOfst = acttab_insert(pActtab); |
| 3770 | | | if( stp->iTknOfst<mnTknOfst ) mnTknOfst = stp->iTknOfst; |
| 3771 | | | if( stp->iTknOfst>mxTknOfst ) mxTknOfst = stp->iTknOfst; |
| 3772 | | | }else{ |
| 3773 | | | for(ap=stp->ap; ap; ap=ap->next){ |
| 3774 | | | int action; |
| 3775 | | | if( ap->sp->index<lemp->nterminal ) continue; |
| 3776 | | | if( ap->sp->index==lemp->nsymbol ) continue; |
| 3777 | | | action = compute_action(lemp, ap); |
| 3778 | | | if( action<0 ) continue; |
| 3779 | | | acttab_action(pActtab, ap->sp->index, action); |
| 3780 | | | } |
| 3781 | | | stp->iNtOfst = acttab_insert(pActtab); |
| 3782 | | | if( stp->iNtOfst<mnNtOfst ) mnNtOfst = stp->iNtOfst; |
| 3783 | | | if( stp->iNtOfst>mxNtOfst ) mxNtOfst = stp->iNtOfst; |
| 3784 | | | } |
| 3785 | | | } |
| 3786 | | | free(ax); |
| 3787 | | | |
| 3788 | | | |
| 3789 | | | fprintf(out,"static const YYACTIONTYPE yy_action[] = {\n"); lineno++; |
| 3790 | | | n = acttab_size(pActtab); |
| 3791 | | | for(i=j=0; i<n; i++){ |
| 3792 | | | int action = acttab_yyaction(pActtab, i); |
| 3793 | | | if( action<0 ) action = lemp->nstate + lemp->nrule + 2; |
| 3794 | | | if( j==0 ) fprintf(out," /* %5d */ ", i); |
| 3795 | | | fprintf(out, " %4d,", action); |
| 3796 | | | if( j==9 || i==n-1 ){ |
| 3797 | | | fprintf(out, "\n"); lineno++; |
| 3798 | | | j = 0; |
| 3799 | | | }else{ |
| 3800 | | | j++; |
| 3801 | | | } |
| 3802 | | | } |
| 3803 | | | fprintf(out, "};\n"); lineno++; |
| 3804 | | | |
| 3805 | | | |
| 3806 | | | fprintf(out,"static const YYCODETYPE yy_lookahead[] = {\n"); lineno++; |
| 3807 | | | for(i=j=0; i<n; i++){ |
| 3808 | | | int la = acttab_yylookahead(pActtab, i); |
| 3809 | | | if( la<0 ) la = lemp->nsymbol; |
| 3810 | | | if( j==0 ) fprintf(out," /* %5d */ ", i); |
| 3811 | | | fprintf(out, " %4d,", la); |
| 3812 | | | if( j==9 || i==n-1 ){ |
| 3813 | | | fprintf(out, "\n"); lineno++; |
| 3814 | | | j = 0; |
| 3815 | | | }else{ |
| 3816 | | | j++; |
| 3817 | | | } |
| 3818 | | | } |
| 3819 | | | fprintf(out, "};\n"); lineno++; |
| 3820 | | | |
| 3821 | | | |
| 3822 | | | fprintf(out, "#define YY_SHIFT_USE_DFLT (%d)\n", mnTknOfst-1); lineno++; |
| 3823 | | | n = lemp->nstate; |
| 3824 | | | while( n>0 && lemp->sorted[n-1]->iTknOfst==NO_OFFSET ) n--; |
| 3825 | | | fprintf(out, "#define YY_SHIFT_MAX %d\n", n-1); lineno++; |
| 3826 | | | fprintf(out, "static const %s yy_shift_ofst[] = {\n", |
| 3827 | | | minimum_size_type(mnTknOfst-1, mxTknOfst)); lineno++; |
| 3828 | | | for(i=j=0; i<n; i++){ |
| 3829 | | | int ofst; |
| 3830 | | | stp = lemp->sorted[i]; |
| 3831 | | | ofst = stp->iTknOfst; |
| 3832 | | | if( ofst==NO_OFFSET ) ofst = mnTknOfst - 1; |
| 3833 | | | if( j==0 ) fprintf(out," /* %5d */ ", i); |
| 3834 | | | fprintf(out, " %4d,", ofst); |
| 3835 | | | if( j==9 || i==n-1 ){ |
| 3836 | | | fprintf(out, "\n"); lineno++; |
| 3837 | | | j = 0; |
| 3838 | | | }else{ |
| 3839 | | | j++; |
| 3840 | | | } |
| 3841 | | | } |
| 3842 | | | fprintf(out, "};\n"); lineno++; |
| 3843 | | | |
| 3844 | | | |
| 3845 | | | fprintf(out, "#define YY_REDUCE_USE_DFLT (%d)\n", mnNtOfst-1); lineno++; |
| 3846 | | | n = lemp->nstate; |
| 3847 | | | while( n>0 && lemp->sorted[n-1]->iNtOfst==NO_OFFSET ) n--; |
| 3848 | | | fprintf(out, "#define YY_REDUCE_MAX %d\n", n-1); lineno++; |
| 3849 | | | fprintf(out, "static const %s yy_reduce_ofst[] = {\n", |
| 3850 | | | minimum_size_type(mnNtOfst-1, mxNtOfst)); lineno++; |
| 3851 | | | for(i=j=0; i<n; i++){ |
Event 23:
Leaving loop. i < n evaluates to false.
hide
|
|
| 3852 | | | int ofst; |
| 3853 | | | stp = lemp->sorted[i]; |
| 3854 | | | ofst = stp->iNtOfst; |
| 3855 | | | if( ofst==NO_OFFSET ) ofst = mnNtOfst - 1; |
| 3856 | | | if( j==0 ) fprintf(out," /* %5d */ ", i); |
| 3857 | | | fprintf(out, " %4d,", ofst); |
| 3858 | | | if( j==9 || i==n-1 ){ |
| 3859 | | | fprintf(out, "\n"); lineno++; |
| 3860 | | | j = 0; |
| 3861 | | | }else{ |
| 3862 | | | j++; |
| 3863 | | | } |
| 3864 | | | } |
| 3865 | | | fprintf(out, "};\n"); lineno++; |
| 3866 | | | |
| 3867 | | | |
| 3868 | | | fprintf(out, "static const YYACTIONTYPE yy_default[] = {\n"); lineno++; |
| 3869 | | | n = lemp->nstate; |
| 3870 | | | for(i=j=0; i<n; i++){ |
| 3871 | | | stp = lemp->sorted[i]; |
| 3872 | | | if( j==0 ) fprintf(out," /* %5d */ ", i); |
| 3873 | | | fprintf(out, " %4d,", stp->iDflt); |
| 3874 | | | if( j==9 || i==n-1 ){ |
| 3875 | | | fprintf(out, "\n"); lineno++; |
| 3876 | | | j = 0; |
| 3877 | | | }else{ |
| 3878 | | | j++; |
| 3879 | | | } |
| 3880 | | | } |
| 3881 | | | fprintf(out, "};\n"); lineno++; |
| 3882 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 3883 | | | |
| 3884 | | | |
| 3885 | | | |
| 3886 | | | if( lemp->has_fallback ){ |
Event 25:
Skipping " if". lemp->has_fallback evaluates to false.
hide
|
|
| 3887 | | | for(i=0; i<lemp->nterminal; i++){ |
| 3888 | | | struct symbol *p = lemp->symbols[i]; |
| 3889 | | | if( p->fallback==0 ){ |
| 3890 | | | fprintf(out, " 0, /* %10s => nothing */\n", p->name); |
| 3891 | | | }else{ |
| 3892 | | | fprintf(out, " %3d, /* %10s => %s */\n", p->fallback->index, |
| 3893 | | | p->name, p->fallback->name); |
| 3894 | | | } |
| 3895 | | | lineno++; |
| 3896 | | | } |
| 3897 | | | } |
| 3898 | | | tplt_xfer(lemp->name, in, out, &lineno); |
| 3899 | | | |
| 3900 | | | |
| 3901 | | | |
| 3902 | | | for(i=0; i<lemp->nsymbol; i++){ |
Event 26:
i is set to 0.
hide
Event 27:
Entering loop body. i < lemp->nsymbol evaluates to true.
hide
Event 30:
Continuing from loop body. Leaving loop. i < lemp->nsymbol evaluates to false.
hide
|
|
| 3903 | | | sprintf(line,"\"%s\",",lemp->symbols[i]->name); |
| 3904 | | | fprintf(out," %-15s",line); |
| 3905 | | | if( (i&3)==3 ){ fprintf(out,"\n"); lineno++; } |
Event 29:
Skipping " if". (i & 3) == 3 evaluates to false.
hide
|
|
| 3906 | | | } |
| 3907 | | | if( (i&3)!=0 ){ fprintf(out,"\n"); lineno++; } |
Event 31:
Taking true branch. (i & 3) != 0 evaluates to true.
hide
|
|
| 3908 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 3909 | | | |
| 3910 | | | |
| 3911 | | | |
| 3912 | | | |
| 3913 | | | |
| 3914 | | | for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){ |
Event 32:
Leaving loop. rp evaluates to false.
hide
|
|
| 3915 | | | assert( rp->index==i );
x /usr/include/assert.h |
| |
91 | # define assert(expr) \ |
92 | ((expr) \ |
93 | ? __ASSERT_VOID_CAST (0) \ |
94 | : __assert_fail (__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION)) |
| |
x /usr/include/assert.h |
| |
42 | # define __ASSERT_VOID_CAST (void) |
| |
x /usr/include/assert.h |
| |
109 | # define __ASSERT_FUNCTION __PRETTY_FUNCTION__ |
| |
|
| 3916 | | | fprintf(out," /* %3d */ \"", i); |
| 3917 | | | writeRuleText(out, rp); |
| 3918 | | | fprintf(out,"\",\n"); lineno++; |
| 3919 | | | } |
| 3920 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 3921 | | | |
| 3922 | | | |
| 3923 | | | |
| 3924 | | | |
| 3925 | | | |
| 3926 | | | if( lemp->tokendest ){ |
Event 33:
Skipping " if". lemp->tokendest evaluates to false.
hide
|
|
| 3927 | | | int once = 1; |
| 3928 | | | for(i=0; i<lemp->nsymbol; i++){ |
| 3929 | | | struct symbol *sp = lemp->symbols[i]; |
| 3930 | | | if( sp==0 || sp->type!=TERMINAL ) continue; |
| 3931 | | | if( once ){ |
| 3932 | | | fprintf(out, " /* TERMINAL Destructor */\n"); lineno++; |
| 3933 | | | once = 0; |
| 3934 | | | } |
| 3935 | | | fprintf(out," case %d: /* %s */\n", |
| 3936 | | | sp->index, sp->name); lineno++; |
| 3937 | | | } |
| 3938 | | | for(i=0; i<lemp->nsymbol && lemp->symbols[i]->type!=TERMINAL; i++); |
| 3939 | | | if( i<lemp->nsymbol ){ |
| 3940 | | | emit_destructor_code(out,lemp->symbols[i],lemp,&lineno); |
| 3941 | | | } |
| 3942 | | | fprintf(out," break;\n"); lineno++; |
| 3943 | | | } |
| 3944 | | | if( lemp->vardest ){ |
Event 34:
Taking true branch. lemp->vardest evaluates to true.
hide
|
|
| 3945 | | | struct symbol *dflt_sp = 0; |
| 3946 | | | int once = 1; |
| 3947 | | | for(i=0; i<lemp->nsymbol; i++){ |
Event 35:
i is set to 0.
hide
Event 36:
Entering loop body. i < lemp->nsymbol evaluates to true.
hide
|
|
| 3948 | | | struct symbol *sp = lemp->symbols[i]; |
| 3949 | | | if( sp==0 || sp->type==TERMINAL || |
Null Test After Dereference
This code tests the nullness of sp, which has already been dereferenced. - If sp were null, there would have been a prior null pointer dereference at lemon.c:3903, and potentially at other locations as well.
- Either this test is redundant, or the earlier dereference(s) should be guarded by a similar test.
The issue can occur if the highlighted code executes. See related event 37. Show: All events | Only primary events |
|
| 3950 | | | sp->index<=0 || sp->destructor!=0 ) continue; |
| 3951 | | | if( once ){ |
| 3952 | | | fprintf(out, " /* Default NON-TERMINAL Destructor */\n"); lineno++; |
| 3953 | | | once = 0; |
| 3954 | | | } |
| 3955 | | | fprintf(out," case %d: /* %s */\n", |
| 3956 | | | sp->index, sp->name); lineno++; |
| 3957 | | | dflt_sp = sp; |
| 3958 | | | } |
| 3959 | | | if( dflt_sp!=0 ){ |
| 3960 | | | emit_destructor_code(out,dflt_sp,lemp,&lineno); |
| 3961 | | | fprintf(out," break;\n"); lineno++; |
| 3962 | | | } |
| 3963 | | | } |
| 3964 | | | for(i=0; i<lemp->nsymbol; i++){ |
| 3965 | | | struct symbol *sp = lemp->symbols[i]; |
| 3966 | | | if( sp==0 || sp->type==TERMINAL || sp->destructor==0 ) continue; |
| 3967 | | | fprintf(out," case %d: /* %s */\n", |
| 3968 | | | sp->index, sp->name); lineno++; |
| 3969 | | | |
| 3970 | | | |
| 3971 | | | for(j=i+1; j<lemp->nsymbol; j++){ |
| 3972 | | | struct symbol *sp2 = lemp->symbols[j]; |
| 3973 | | | if( sp2 && sp2->type!=TERMINAL && sp2->destructor |
| 3974 | | | && sp2->dtnum==sp->dtnum |
| 3975 | | | && strcmp(sp->destructor,sp2->destructor)==0 ){ |
| 3976 | | | fprintf(out," case %d: /* %s */\n", |
| 3977 | | | sp2->index, sp2->name); lineno++; |
| 3978 | | | sp2->destructor = 0; |
| 3979 | | | } |
| 3980 | | | } |
| 3981 | | | |
| 3982 | | | emit_destructor_code(out,lemp->symbols[i],lemp,&lineno); |
| 3983 | | | fprintf(out," break;\n"); lineno++; |
| 3984 | | | } |
| 3985 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 3986 | | | |
| 3987 | | | |
| 3988 | | | tplt_print(out,lemp,lemp->overflow,&lineno); |
| 3989 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 3990 | | | |
| 3991 | | | |
| 3992 | | | |
| 3993 | | | |
| 3994 | | | |
| 3995 | | | |
| 3996 | | | for(rp=lemp->rule; rp; rp=rp->next){ |
| 3997 | | | fprintf(out," { %d, %d },\n",rp->lhs->index,rp->nrhs); lineno++; |
| 3998 | | | } |
| 3999 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 4000 | | | |
| 4001 | | | |
| 4002 | | | for(rp=lemp->rule; rp; rp=rp->next){ |
| 4003 | | | translate_code(lemp, rp); |
| 4004 | | | } |
| 4005 | | | for(rp=lemp->rule; rp; rp=rp->next){ |
| 4006 | | | struct rule *rp2; |
| 4007 | | | if( rp->code==0 ) continue; |
| 4008 | | | fprintf(out," case %d: /* ", rp->index); |
| 4009 | | | writeRuleText(out, rp); |
| 4010 | | | fprintf(out, " */\n"); lineno++; |
| 4011 | | | for(rp2=rp->next; rp2; rp2=rp2->next){ |
| 4012 | | | if( rp2->code==rp->code ){ |
| 4013 | | | fprintf(out," case %d: /* ", rp2->index); |
| 4014 | | | writeRuleText(out, rp2); |
| 4015 | | | fprintf(out," */\n"); lineno++; |
| 4016 | | | rp2->code = 0; |
| 4017 | | | } |
| 4018 | | | } |
| 4019 | | | emit_code(out,rp,lemp,&lineno); |
| 4020 | | | fprintf(out," break;\n"); lineno++; |
| 4021 | | | } |
| 4022 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 4023 | | | |
| 4024 | | | |
| 4025 | | | tplt_print(out,lemp,lemp->failure,&lineno); |
| 4026 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 4027 | | | |
| 4028 | | | |
| 4029 | | | tplt_print(out,lemp,lemp->error,&lineno); |
| 4030 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 4031 | | | |
| 4032 | | | |
| 4033 | | | tplt_print(out,lemp,lemp->accept,&lineno); |
| 4034 | | | tplt_xfer(lemp->name,in,out,&lineno); |
| 4035 | | | |
| 4036 | | | |
| 4037 | | | tplt_print(out,lemp,lemp->,&lineno); |
| 4038 | | | |
| 4039 | | | fclose(in); |
| 4040 | | | fclose(out); |
| 4041 | | | return; |
| 4042 | | | } |
| |