More questions abou YACC and LEX (Bison/Flex)

John T. Nelson jtn at potomac.ads.com
Fri Sep 14 00:32:51 AEST 1990


First I'd like to thank everyone for your comments concerning my
problem with YACC grammars.  It looks like there is an ambiguity in
the grammar because YACC implements an LALR(1) parser.  Only one
character lookahead so I'll have to find another way to represent the
grammar.

I do have a question about running YACC/Bison in programs though.  I
have a program that looks sort of like the following:

main()
{

openInputFile();

if ( yyparse() )
	errorRoutine1();

closeInputFIle();

openInputFile();

if ( yyparse() )
	errorRoutine2();

closeInputFile();
}

The parser works fine on the first pass through yyparse() however upon
entering the parser a second time, I get a YACC parser error.
Apparently, the parser still thinks it's in one of the old states it
was in back in the first call to yyparse and bombs because it has an
inappropriate token.  Indeed it almost looks like the first token it
reads fromthe grammar file the second time around is the LAST token it
read fromthe file the first time around.

Now that's wierd.

How can I reset the state of the parser?  Shouldn't all the state
variables be properly initialized upon entry to yyparse?  Tracing
through the code it looks like they ARE being set properly, yet for
some reason the first token is wrong and the state is wrong too.

Oh.... once again I'm actually using GNU Bison and Flex, YACC and LEX
lookalikes.  Pretty good packages.  Thanks in advance!


-- 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ORGANIZATION:  Advanced Decision Systems   GEOGRAPHIC: Arlington, VA
UUCP:          kzin!speaker at mimsy.umd.edu  INTERNET:   jtn at potomac.ads.com
SPOKEN:        Yo... John!                 PHONE:      (703) 243-1611
PROJECT:       The Conrail Locomotive/Harpsichord Fusion Program
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



More information about the Comp.unix.questions mailing list