comments in lex

Andrew Klossner andrew at orca.UUCP
Sun Jul 14 10:52:26 AEST 1985


>> How do you recognise a PL/1 style comment?
>
> "/*"([^*]|"*"[^/])*"*/"

Two problems:

1) This pattern will incorrectly recognize "/***/ */" as a comment.

2) This approach to comment skipping is a bad idea in lex, because the
   generated lexer will try to accumulate the entire comment in the
   "yytext" buffer, which has a fixed size.  (On our system, the size
   is 1024 bytes.)  If ever a comment with more bytes than the buffer
   size is found, the lex driver will merrily overwrite the memory
   following the buffer and blow away your compile.

  -=- Andrew Klossner   (decvax!tektronix!orca!andrew)       [UUCP]
                        (orca!andrew.tektronix at csnet-relay)  [ARPA]



More information about the Comp.unix mailing list