comments in lex

Steve Hammond hammond at steinmetz.UUCP
Tue Jul 23 08:24:47 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.
> 

I get around #1 it by switching modes when I encounter a /*
and switching back when I encounter a */.  To date I
have not overflowed the yytext buffer (I hope).
-- 
  Steve Hammond   arpa: hammond at GE   uucp: {...edison!}steinmetz!hammond



More information about the Comp.unix mailing list