🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Andrew Thomas Thu, 19 Oct 1989 02:23
flex and multiple inputs
#512
Author: Andrew Thomas
Date: Thu, 19 Oct 1989 02:23
20 lines
1420 bytes
I have recently tried to write a parser using bison and flex.  It
worked fine on a single input file, but I wanted to read mulitple
files and parse them in the same way.  The program always aborted from
the parser on the second file saying that EOF had been reached.  I
tried setting yyin to a new file pointer before calling yyparse but it
did not help.  Eventually I changed the skeleton file to remove the
'static' definitions from the function 'yyrestart'.  Now from the
routine which calls yyparse, I set yyin to stdin (so yyrestart won't
try to close some other file), then call yyrestart with a pointer to
the file I want to read.  This has the desired effect, but now the
line number counting I have put in the .l file is off by the number of
lines in the previous file.   Is there a correct way to read multiple
input files with one parser run?

--

Andrew Thomas
andrewt@watsnew.waterloo.edu	Systems Design Eng.	University of Waterloo
"If a million people do a stupid thing, it's still a stupid thing." - Opus
Re: flex and multiple inputs
#518
Author: Vern Paxson
Date: Fri, 20 Oct 1989 15:41
34 lines
1553 bytes
In article <ANDREWT.89Oct18222337@watsnew.waterloo.edu> andrewt@watsnew.waterloo.edu (Andrew Thomas) writes:
> I have recently tried to write a parser using bison and flex.  It
> worked fine on a single input file, but I wanted to read mulitple
> files and parse them in the same way....
> Eventually I changed the skeleton file to remove the
> 'static' definitions from the function 'yyrestart'....
> This has the desired effect, but now the
> line number counting I have put in the .l file is off by the number of
> lines in the previous file.   Is there a correct way to read multiple
> input files with one parser run?

Yes.  What you want to do is add a rule like:

	<<EOF>>	{
		if there's another input file
			{
			fclose( yyin );
			yyin = fopen( file, "r" );
			reset line number counter
			YY_NEW_FILE;
			}
		else
			return;
		}

This is a new feature so it may be somewhat buggy.  If you have
problems with it, send me mail.

		Vern


	Vern Paxson			      vern@cs.cornell.edu
	Computer Science Dept.		      decvax!cornell!vern
	Cornell University		      vern@LBL (bitnet)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads