Re: Statement at a time parsing with yacc

bliss@sp64.csrd.uiuc.edu (Brian Bliss)
Tue, 10 Dec 91 21:59:09 GMT

          From comp.compilers

Related articles
Statement at a time parsing with yacc przemek@viewlogic.com (1991-12-06)
Re: Statement at a time parsing with yacc bart@cs.uoregon.edu (1991-12-10)
Re: Statement at a time parsing with yacc bliss@sp64.csrd.uiuc.edu (1991-12-10)
Re: Statement at a time parsing with yacc chris@mks.com.ca (1991-12-11)
Statement at a time parsing with yacc compres!chris@crackers.clearpoint.com (1991-12-12)
Re: Statement at a time parsing with yacc d87-jse@nada.kth.se (1991-12-17)
| List of all articles for this month |
Newsgroups: comp.compilers
From: bliss@sp64.csrd.uiuc.edu (Brian Bliss)
Keywords: yacc, parse
Organization: UIUC Center for Supercomputing Research and Development
References: 91-12-036
Date: Tue, 10 Dec 91 21:59:09 GMT

>I have a nifty parser for a C-like language. I can run it on a file or a
>string containing one statement and everything is cool. What I want it to
>do is to point to a file and ask it to parse *one* statement only, even if
>there are many statements in sequence in the file.


I assume what you mean is "parse a statment, then return. when called
again, parse the next statment, then return. etc..."


1) try using a threads package to divide your process into two threads.
      the main thread fork the parser in a dirrerent thread, when a
      statement is parsed, it time out, and returns a result to the main
        thread using an appropriate synchronization mechanism.


      You might be able to do something similar with setjmp().


2) modify yaccpar, the skeleton parser file. globalize any local vars.
      i.e. change the following first part of yyparse():


--------
YYSTYPE yyv[YYMAXDEPTH];
int yychar = -1;
int yynerrs = 0;
short yyerrflag = 0;


yyparse() {


                short yys[YYMAXDEPTH];
                short yyj, yym;
                register YYSTYPE *yypvt;
                register short yystate, *yyps, yyn;
                register YYSTYPE *yypv;
                register short *yyxi;


                yystate = 0;
                yychar = -1;
                yynerrs = 0;
                yyerrflag = 0;
                yyps= &yys[-1];
                yypv= &yyv[-1];
--------
to
--------
YYSTYPE yyv[YYMAXDEPTH];
int yychar = -1;
int yynerrs = 0;
short yyerrflag = 0;


short yys[YYMAXDEPTH];
short yyj, yym;
YYSTYPE *yypvt;
short yystate = 0, *yyps = &yys[-1], yyn;
YYSTYPE *yypv = &yyv[-1];
short *yyxi;


yyparse() {


--------


when you re-enter yacc, it will be in the same state as when you
returned from it last time (using a return statement).
just define a macro:


#define yyrestart \
                yystate = 0;\
                yychar = -1;\
                yynerrs = 0;\
                yyerrflag = 0;\
                yyps= &yys[-1];


to reset the parser to the start mode.
(alternatively, you could make the var static, but then
you'ld have to re-enter start mode from within the parser
itself, presumabley just before you exited previously).


bb
--


Post a followup to this message

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