home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / compiler / 2101 < prev    next >
Encoding:
Text File  |  1993-01-07  |  1.9 KB  |  55 lines

  1. Newsgroups: comp.compilers
  2. 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
  3. From: richw@sol.camb.inmet.com (Richard Wagner)
  4. Subject: Re: Input buffer overflow in lex...
  5. Reply-To: richw@sol.camb.inmet.com (Richard Wagner)
  6. Organization: Intermetrics, Inc.
  7. Date: Wed, 6 Jan 1993 19:57:37 GMT
  8. Approved: compilers@iecc.cambridge.ma.us
  9. Message-ID: <93-01-024@comp.compilers>
  10. References: <93-01-009@comp.compilers> <93-01-013@comp.compilers>
  11. Keywords: lex, comment
  12. Sender: compilers-sender@iecc.cambridge.ma.us
  13. Lines: 40
  14.  
  15. In the version of "lex" I use, the generated lexer gets its input via an
  16. "input" macro.  One solution, which may be viewed as a "kludge" or "hack",
  17. is to "#undef" the default macro and "#define" another with the same
  18. functionality, but which also checks for overflow (and possibly takes some
  19. recovery action, like copy what's in the buffer to an "infinitely" long
  20. linked-list of buffers).
  21.  
  22. For example:
  23.  
  24.     %{
  25.     #undef input
  26.  
  27.     #define usual_input_macro()    (...text of default "input" definition...)
  28.  
  29.     #define input()         ( \
  30.     ('\0' != *(yytext + YYLMAX - 1)) \
  31.         ? (token_too_long()) \
  32.         : usual_input_macro() \
  33.     )
  34.  
  35.     #define token_too_long()    (...recovery action...)
  36.  
  37.     :
  38.  
  39.  
  40. Disclaimer:  I've never tried this.
  41.  
  42. Lets hope I'm not being blind to some reason this can't work.  I
  43. personally prefer this than just bumping YYLMAX, which may be fine,
  44. practically speaking, but still nags in that it just begs the question.
  45.  
  46. Hope this helps,
  47.  
  48. Rich Wagner
  49. Intermetrics, Inc.
  50. [I still think you're better off writing your lexer so you don't get
  51. enormous tokens. -John]
  52. -- 
  53. Send compilers articles to compilers@iecc.cambridge.ma.us or
  54. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  55.