Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.wizards,comp.lang.c,comp.unix.questions Subject: Re: Lex Macros Message-ID: <9390@mimsy.UUCP> Date: Mon, 16-Nov-87 06:58:49 EST Article-I.D.: mimsy.9390 Posted: Mon Nov 16 06:58:49 1987 Date-Received: Tue, 17-Nov-87 06:38:08 EST References: <48@wvucswv.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 42 Keywords: Lex C Macros Xref: mnetor comp.unix.wizards:5480 comp.lang.c:5439 comp.unix.questions:4928 In article <48@wvucswv.UUCP> dymm@wvucswv.UUCP asks what the `input' and `unput' macros lex generates do. Try considering them as functions: /* * Retrieve an input character. */ int input() { int c; /* retrieve pushback, if any, else next char */ if (yysptr > yysbuf) c = *--yysptr; else c = getc(yyin); /* increment input line number if newline */ if (c == '\n') yylineno++; /* return 0 for eof, anything else as is */ return (c == EOF ? 0 : c); } unput(c) int c; { /* if pushing back a newline, back the line number down */ if (c == '\n') yylineno--; *yysptr++ = c; } The nonsense with the global `yytchar' is to avoid referring to macro arguments or using `getc' more than once. It would be nice if lex used EOF for EOF rather than 0, but not many people need to scan NULs. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris