argv ==> stdin (fast)
scabel at diku.UUCP
scabel at diku.UUCP
Fri Nov 21 21:52:38 AEST 1986
In article <2972 at rsch.WISC.EDU> mcvoy at rsch.WISC.EDU (Lawrence W. McVoy) writes:
>Hi there. I'm using lex & yacc to do some work for me and I can't
>quite get it. The scanner & parser part works, but only if it's
>getting input from stdin. I diddled lex.yy.c to change the getc(yyin)
>call in the input() define to call my routine which feed sit characters
>from argv. This works if I call yylex() from main, but if yyparse calls
>it then I get a "syntax error". The same program works if I don't
>diddle the input() routine. And I can't figure out what's wrong
>with my diddling.....
I have made a program using lex and yacc, which either reads from a
argument to the program, or from stdin.
Here is the important parts from the lex file..
%C
%{
#ifdef input
#undef input
#endif
# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):nextchar())==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
extern int ARGEXPR;
extern char *argexpr;
%}
%%
/* The lex program */
%%
int nextchar()
{
static int i = 0;
if (ARGEXPR) {
if (*argexpr == '\0')
return(i++ == 0?'\n':EOF);
return(*argexpr++);
} else
return(getc(yyin));
}
--
Niels Schachtschabel,
Institute of Datalogy, University of Copenhagen
E-mail: scabel at diku.uucp / ...!seismo!mcvax!diku!scabel
More information about the Comp.unix.wizards
mailing list