Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: LEX Question Message-ID: <1989Feb24.165832.9921@utzoo.uucp> Organization: U of Toronto Zoology References: <32240@auc.UUCP> <9580001@hpcuhb.HP.COM> <1989Feb15.200741.15963@utzoo.uucp> <412@chem.ucsd.EDU> <1989Feb23.164129.8672@utzoo.uucp> <416@chem.ucsd.EDU> Date: Fri, 24 Feb 89 16:58:32 GMT In article <416@chem.ucsd.EDU> tps@chem.ucsd.edu (Tom Stockfisch) writes: >>Re-defining "input" is in the documentation as the way to alter input; any >>version of lex that follows the manual (and hence deserves to be called >>"lex") will permit it and have it work as documented. "yyin" is not >>documented at all... > >I must be missing something. Looking at lex.yy.c on my machine shows that >input() is defined as > ># define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10? \ > (yylineno++,yytchar):yytchar)==EOF?0:yytchar) > >so if I re-#define input(), don't I have to use yytchar,yysptr, and yysbuf? No; they are lex's buffered-input system. If you redefine input(), you have to provide your own buffering scheme, or have it provided for you by a library. You need not, and should not, use lex's own internal variables to do it with. The input interface to lex is fully defined in the documentation: input() should yield the next character, unput(c) should push c back into the input stream. Meet those specs (and a few more details that are in the documentation) and it works fine; I've done it on occasion. Messing with mysterious and undocumented variables whose names start with "yy" is neither necessary nor desirable. I have, on occasion, just assigned a stdio file pointer to yyin... but I've never claimed it was portable or good practice, and I've always documented it as a bug. If you define your own input stuff, the variables lex uses for its input system just go unused. This is a minor waste of space. It could undoubtedly be eliminated by some cleverness in lex, if anyone felt it worth bothering about. -- The Earth is our mother; | Henry Spencer at U of Toronto Zoology our nine months are up. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu