bison's yyparse() several times

hanss@stud.cs.uit.no (Hans Sundsfjord)
Thu, 19 May 1994 13:59:05 GMT

          From comp.compilers

Related articles
bison's yyparse() several times hanss@stud.cs.uit.no (1994-05-19)
Re: bison's yyparse() several times Wilfred.Hansen@cs.cmu.edu (1994-05-20)
Re: bison's yyparse() several times hanss@stud.cs.uit.no (1994-05-30)
| List of all articles for this month |
Newsgroups: comp.compilers
From: hanss@stud.cs.uit.no (Hans Sundsfjord)
Keywords: yacc, parse, comment
Organization: University of Tromsoe
Date: Thu, 19 May 1994 13:59:05 GMT

Hi,


I'm building an interpreter using GNU Bison (1.19). I have a problem with
invoking the parser more than once from a program. It always works fine
the first time I call yyparse(), but it always gets a "parse error" when I
call it again.


Have I missed some initialization or buffer flushing or .... something else?


(I have run the same thing with yacc-made yyparse() before, without
problems.)


Well, it looks like this....




FILE *infd;
FILE *outfd;


translate(char *in, char *out)
{


        if ((infd = fopen(in, "r")) == NULL)
        {
            fprintf(stderr, "could not open input file: %s\n", in);
            return (-1);
        }


        yyin = infd;


        if ((outfd = fopen(out, "w")) == NULL)
        {
            fprintf(stderr, "could not open output file: %s\n", out);
            return (-1);
        }


        yyout = outfd;


        yyparse();


        close((int)infd);
        fflush(outfd);
        close((int)outfd);
}
[I'd suspect a smashed pointer somewhere. If you don't need any of Bison's
unique features, you're probably better off with the smaller and faster
Berkeley Yacc anyway. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.