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

  1. Newsgroups: comp.compilers
  2. Path: sparky!uunet!world!iecc!compilers-sender
  3. From: John R. Levine <johnl@iecc.cambridge.ma.us>
  4. Subject: Re: Input buffer overflow in lex...
  5. Reply-To: John R. Levine <johnl@iecc.cambridge.ma.us>
  6. Organization: Compilers Central
  7. Date: Tue, 5 Jan 1993 00:10:47 GMT
  8. Approved: compilers@iecc.cambridge.ma.us
  9. Message-ID: <93-01-010@comp.compilers>
  10. Keywords: lex
  11. References: <93-01-009@comp.compilers>
  12. Sender: compilers-sender@iecc.cambridge.ma.us
  13. Lines: 37
  14.  
  15. |    \"(\\.|[^\\"])*\"                       {some_action_here ();}
  16. |
  17. |The input string is "aaaa..." with 2000 `a' in it [and the token buffer
  18. |overflows]
  19.  
  20. Well, the short answer is that you lose.  No version of lex checks for
  21. token buffer overflow, although it is less destructive in flex than it is
  22. in lex.  This can be called a lex design error, though it's hard to
  23. check for overflow without making the lexer a lot slower.  The solution
  24. is not to use tokens that can be arbitrarily long.
  25.  
  26. If you switch to flex (highly recommended) it can handle up to 8K per
  27. token with no trouble.  In AT&T lex, you can redefine YYLMAX, the size of
  28. the token buffer, yourself at the front of the lex file.
  29.  
  30. The other possibility is to use start states to build the string
  31. yourself:
  32.  
  33. %s STRING
  34.  
  35. <INITIAL>\"        { BEGIN STRING; init_string_buf(); }
  36. <STRING>\\.|[^\\"]    { add_to_string(yytext); }
  37. <STRING>\"        { end_string_buf(); BEGIN INITIAL; }
  38.  
  39. This topic is discussed at some length in the reference part of:
  40.  
  41. John R. Levine, Tony Mason, and Doug Brown, ``Lex & Yacc,'' 2nd Edition,
  42. O'Reilly and Associates, 1992, ISBN 1-56592-000-7, $29.95.
  43.  
  44. I think it's a swell book but since I wrote a lot of it my opinion may be
  45. a wee bit biased.
  46. -- 
  47. Regards,
  48. John Levine
  49. -- 
  50. Send compilers articles to compilers@iecc.cambridge.ma.us or
  51. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  52.