Xref: utzoo comp.lang.c:30978 comp.unix.questions:24502 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!usenet.ins.cwru.edu!tut.cis.ohio-state.edu!n8emr!uncle!basho!john From: john@basho.uucp (John Lacey) Newsgroups: comp.lang.c,comp.unix.questions Subject: Using Lex (and Yacc) on a string. Message-ID: <1990Aug10.012927.5558@basho.uucp> Date: 10 Aug 90 01:29:27 GMT Organization: Sportsware Lines: 41 Normally, of course, one wants a scanner (and a parser) to work from a file, perhaps stdin. Sigh. Well, I want one that works from a string. I am using Flex 2.3, and Bison 1.11. I tried the following few #define's: #undef YY_INPUT #define YY_INPUT(buf,result,max_size) \ { \ for ( result = 0; *ch_this && result < max_size; result ++ ) \ buf[result] = *ch_this++; \ } #define YY_USER_INIT \ if ( scan_init ) { \ if ( yy_flex_debug ) \ printf ( "-- initializing for scan %d\n", scan_init ); \ ch_this = inbuffer; \ scan_init = 0; } with the following couple of definitions and declarations in the scanner: static char * ch_this; extern char * inbuffer; extern int scan_init; and with inbuffer and scan_init defined in the code that calls yyparse(). This didn't work. Well, actually, it works the first time yyparse() is called, but not again. Now, YY_USER_INIT is used inside an if statement that checks yy_init, so I moved it out of there in the scanner skeleton so that YY_USER_INIT is seen every time the scanner is called. Still no go. Has anyone done this, or see a way to do it, or know a way to do it, or .... Thanks. -- John Lacey, E-mail: ...!osu-cis!n8emr!uncle!basho!john (coming soon: john@basho.uucp) V-mail: (614) 436--3773, or 487--8570 "What was the name of the dog on Rin-tin-tin?" --Mickey Rivers, ex-Yankee CF