lex: how to restart a lexer with string input
Posted on 1999-01-20
(note: I'm using AT&T lex)
I'm writing a shared library that lexs string input sent by external programs. Problem is, when the function is called consecutively by any instance of an external program, the lexer -- yylex() -- does not get reset. Thus, subsequent return values are null (the first call works great though!). Below is part of this program:
Part of the header file:
#define input() (*instring++)
#define unput(c) ( *--instring = c)
and later I define the main function:
char * lexfunction(char *yourstring)
THEN an external script which loads in this library
can call "lexfunction(somestring)".
QUESTION: how do I reset the lexer. I know it's something with either yywrap() or yylex() but I don't know how to do it!
Any suggestions would be GREATLY appreciated.