Using Lex (and Yacc) on a string.
George Bogatko
bogatko at lzga.ATT.COM
Sat Aug 11 02:42:20 AEST 1990
In article <1990Aug10.012927.5558 at basho.uucp>, john at basho.uucp (John Lacey) writes:
> Has anyone done this, or see a way to do it, or know a way to do it, or ....
Put these lines in your lex file after the #include lines
%{
#include <stdio.h>
#include <y.tab.h>
extern char *mis_ptr;
#undef input
#undef unput
# define input() (*mis_ptr=='\n'?0:*mis_ptr++)
# define unput(c) (*--mis_ptr=(c) )
%}
Now have a char buff called myinputstring
char myinputstring[100];
do the following in main:
char *mis_ptr;
main()
{
for(;;)
{
gets(buf);
mis_ptr = buf;
yylex();
}
}
I think you get the picture now?
GB
More information about the Comp.unix.questions
mailing list