Path: utzoo!mnetor!uunet!edsews!peter From: peter@edsews.EDS.COM (Peter Zadrozny) Newsgroups: comp.lang.c Subject: Re: LEX Message-ID: <421@edsews.EDS.COM> Date: 5 Feb 88 19:06:21 GMT References: <260@nyit.UUCP> Organization: EDS - Bloomfield Hills, MI Lines: 46 Keywords: LEX, comments, C, regular expression nyit.uucp is unknown... In article <260@nyit.UUCP>, michael@nyit.UUCP (Michael Gwilliam) writes: > Is it possible to write a regular expression that will > transform a /* comment */ into nothing? A while ago I had to do something similar for a PL/1 preprocessor (PL/1 also uses /* ... */ as comment delimiter). After toying a while trying to get the perfect lex syntax, I remembered that I had to do more stuff than just skip the comment such as line counting, error trapping and more, therefore my final solution was to recognize "/*" and send it to a comment eater routine similar to: #define EOF_MESSAGE "Unexpected EOF in comment" void skip_comm () { register int c; for (;;) { if ((c = input ()) == '\n') line_counter++; else { if (c == 0) lex_error (EOF_MESSAGE, UNRECOVERABLE); if (c == '*') { if ((c = input ()) == '/') break; else if (c == 0) lex_error (EOF_MESSAGE, UNRECOVERABLE); else unput (c); } } } input () and unput () are lex routines, and lex_error is my error handler which uses line_counter to output a decent error message. -------------------------------------------------------------------- Peter Zadrozny peter@edsews.eds.com Oh my god, he can speak!!! uunet!edsews!peter Yeah, but don't tell anyone, he'll get fired (313) 645-4725 --------------------------------------------------------------------