using lex with strings, not files

shap shap at shasta.Stanford.EDU
Tue May 7 04:43:37 AEST 1991


In article <5384 at lectroid.sw.stratus.com> leavitt at mordor.hw.stratus.com (Will Leavitt) writes:
>
>   I'd like to use lex & yacc to parse strings within an application, but they
>seem to be hardwired to take their input from stdin.  What is the cannonical 
>way to get them to work on a string?  Thanks!

Yacc doesn't read the input directly, so there's no work there.  My
recollection is that lex uses two macros: GET() and UNGET() to
obtain/pushback characters.  If you take a look at the lex-generated C
code you will spot them. 

What you need to do is supply your own version of these macros at teh
top of your file.

Jonathan



More information about the Comp.lang.c mailing list