home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.compilers
- Path: sparky!uunet!news.gtech.com!noc.near.net!news.Brown.EDU!qt.cs.utexas.edu!yale.edu!jvnc.net!newsserver.jvnc.net!darwin.sura.net!paladin.american.edu!howland.reston.ans.net!sol.ctr.columbia.edu!eff!world!iecc!compilers-sender
- From: richw@sol.camb.inmet.com (Richard Wagner)
- Subject: Re: Input buffer overflow in lex...
- Reply-To: richw@sol.camb.inmet.com (Richard Wagner)
- Organization: Intermetrics, Inc.
- Date: Wed, 6 Jan 1993 19:57:37 GMT
- Approved: compilers@iecc.cambridge.ma.us
- Message-ID: <93-01-024@comp.compilers>
- References: <93-01-009@comp.compilers> <93-01-013@comp.compilers>
- Keywords: lex, comment
- Sender: compilers-sender@iecc.cambridge.ma.us
- Lines: 40
-
- In the version of "lex" I use, the generated lexer gets its input via an
- "input" macro. One solution, which may be viewed as a "kludge" or "hack",
- is to "#undef" the default macro and "#define" another with the same
- functionality, but which also checks for overflow (and possibly takes some
- recovery action, like copy what's in the buffer to an "infinitely" long
- linked-list of buffers).
-
- For example:
-
- %{
- #undef input
-
- #define usual_input_macro() (...text of default "input" definition...)
-
- #define input() ( \
- ('\0' != *(yytext + YYLMAX - 1)) \
- ? (token_too_long()) \
- : usual_input_macro() \
- )
-
- #define token_too_long() (...recovery action...)
-
- :
-
-
- Disclaimer: I've never tried this.
-
- Lets hope I'm not being blind to some reason this can't work. I
- personally prefer this than just bumping YYLMAX, which may be fine,
- practically speaking, but still nags in that it just begs the question.
-
- Hope this helps,
-
- Rich Wagner
- Intermetrics, Inc.
- [I still think you're better off writing your lexer so you don't get
- enormous tokens. -John]
- --
- Send compilers articles to compilers@iecc.cambridge.ma.us or
- {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.
-