Using Lex (and Yacc) on a string.
John Lacey
john at basho.uucp
Fri Aug 10 11:29:27 AEST 1990
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 at 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
More information about the Comp.unix.questions
mailing list