Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!novavax!twwells!bill From: bill@twwells.uucp (T. William Wells) Newsgroups: comp.lang.c Subject: Re: LEX Question Message-ID: <384@twwells.uucp> Date: 15 Feb 89 19:30:01 GMT References: <32240@auc.UUCP> <9580001@hpcuhb.HP.COM> Reply-To: bill@twwells.UUCP (T. William Wells) Organization: None, Ft. Lauderdale Lines: 39 Summary: Expires: Sender: Followup-To: Distribution: Keywords: I have this at the top of one of my .l files: %{ #undef input #undef unput # define input() (((yytchar=yysptr>yysbuf?U(*--yysptr): \ nextchar())==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar) # define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--; \ *yysptr++=yytchar;} %} [These ugly macros are made from the ones that are created by lex.] And one of my source files contains this bit of code: int nextchar() { if (*Bufptr == 0) { return ('\n'); } else { return (*Bufptr++); } } Replace nextchar with whatever function you need for returning characters. It does work, I use the program containing it all the time. I don't recall any of the design decisions I made when doing this; what it is used for is lexing out of a buffer. I do not know if the details will be applicable to your system. (It works on a Sun and on my Microport V/386 3.0e). Consider it as a clue as to what to do. --- Bill { uunet!proxftl | novavax } !twwells!bill