help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: calling yyparse repeatedly


From: Tim Van Holder
Subject: Re: calling yyparse repeatedly
Date: 25 Jan 2002 08:07:22 +0100

On Fri, 2002-01-25 at 05:25, Prabhu M.K wrote:
> 
> Yes I am using states in the flex.. what should i do for the scanner  to
> come to INITIAL state after calling yyparse().
> 
> > Are you using states in flex? If so, you have to return to
> > INITIAL yourself. To quote the manpage:
> >
> >         Note  that  yyrestart() does not reset the start condition
> >         to INITIAL (see Start Conditions, below).
> 
> Thanks Very Much
> 
> Regards
> Prabhu M.K

Well, you could, for example, have some flag variable set to 1 if it's a
new file.  Then put at the top of your flex file's rules section:


...

%%

        { /* This code is run whenever yylex() is called */
          if (my_flag_indicating_new_file == 1) {
            ...
            BEGIN(INITIAL);
            ...
            my_flag_indicating_new_file = 0;
          }
        }

....


And then simply make sure that that flag is true whenever you call
yyrestart().  For example, you could create your own restart_scanner()
function:


void
restart_scanner(FILE* f)
{
  my_flag_indicating_new_file = 1;
  yyrestart (f);
}

and then call this instead of yyrestart().





reply via email to

[Prev in Thread] Current Thread [Next in Thread]