Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!stanford.edu!shap@shasta.Stanford.EDU From: shap@shasta.Stanford.EDU (shap) Newsgroups: comp.lang.c Subject: Re: using lex with strings, not files Keywords: lex, yacc, strings Message-ID: <187@shasta.Stanford.EDU> Date: 6 May 91 18:43:37 GMT References: <5384@lectroid.sw.stratus.com> Organization: Stanford University Computer Systems Laboratory Lines: 15 In article <5384@lectroid.sw.stratus.com> leavitt@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