Restarting lex portably

Michael A Copenhafer <mcopenha@cs.ucsd.edu>
21 Aug 2000 00:02:17 -0400

          From comp.compilers

Related articles
Restarting lex portably mcopenha@cs.ucsd.edu (Michael A Copenhafer) (2000-08-21)
Re: Restarting lex portably jksoutter@my-deja.com (2000-09-08)
| List of all articles for this month |
From: Michael A Copenhafer <mcopenha@cs.ucsd.edu>
Newsgroups: comp.compilers
Date: 21 Aug 2000 00:02:17 -0400
Organization: CSE Dept., UC San Diego
Keywords: lex, question

Hi -- I want to restart lex after an error occurs in parsing. It isn't
obvious to me how to do this in a portable manner. Flex offers the
function yyrestart(), pclex has the macro YY_INIT, MKS lex has the
function yy_reset(). Is there a more portable method of restarting lex?
Page 171 of Levine's 'Lex and Yacc' (2nd ed.) says the following:


              ...you cannot restart a lexer just by calling yylex(). you have
to reset it into the default state using
                BEGIN(INITIAL), discard any input text buffered up by unput(),
and otherwise arrange so that the
                next call to input() will start reading the new input.


Could someone explain what code is necessary to accomplish this?


thanks,
Mike C.
[You can't really do it portably in lex. I'd suggest deciding that your
favorite version of lex is flex, and shipping the lex.yy.c along with
your C routines if you want to move the code to another system. -John]







Post a followup to this message

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