Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!mnetor!seismo!mcvax!diku!scabel From: scabel@diku.UUCP Newsgroups: comp.unix.questions,comp.unix.wizards,comp.lang.c Subject: Re: argv ==> stdin (fast) Message-ID: <2800@diku.UUCP> Date: Fri, 21-Nov-86 06:52:38 EST Article-I.D.: diku.2800 Posted: Fri Nov 21 06:52:38 1986 Date-Received: Sat, 22-Nov-86 06:47:23 EST References: <2972@rsch.WISC.EDU> Organization: DIKU, U of Copenhagen, DK Lines: 45 Keywords: make the commandline look like a file? Xref: watmath comp.unix.questions:143 comp.unix.wizards:144 comp.lang.c:145 In article <2972@rsch.WISC.EDU> mcvoy@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@diku.uucp / ...!seismo!mcvax!diku!scabel