LEX

Michael Gwilliam michael at nyit.UUCP
Tue Feb 2 08:32:53 AEST 1988





I'm writting a C like language to discribe data structures.  When I
was writting the tokenizer using LEX and I got intrigued by a little
problem.  Is it possible to write a regular expression that will
transform a /* comment */ into nothing?

I tried something like  

\/\*[^(\/\*)]*\*\/ ;  

which works pretty good, but won't handle cases like

/*  comment /* more comment */

which is legal in C.  Then somebody came up with something like...

\/\*(.\*)\*\/ ;  

which works pretty good, but it doesn't reject

/* /* nested comment */ */ 

which are illlegal.  So my question is, to all you experienced lex
users and compiler writers, can this be done?  Or do I need to
use input() and other lex functions.  I imagine that the lex code
would be similar in pascal.

Thanks for the help or at least reading this far.

michael

P.S. If reponses are mailed instead of posted, I will be happy to
summerize the results and post them myself, giving proper credit
where it is due.

              nyit!michael
      philabs!nyit!michael
ihnp4!philabs!nyit!michael



More information about the Comp.lang.c mailing list