Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!noao!arizona!rupley From: rupley@arizona.edu (John Rupley) Newsgroups: comp.lang.c Subject: Re: Want a way to strip comments from a Summary: Lex script still fails (and crashes) Message-ID: <9888@megaron.arizona.edu> Date: 26 Mar 89 02:51:19 GMT References: <7150@siemens.UUCP> <9900010@bradley> <890@m10ux.UUCP> <893@m10ux.UUCP> Organization: U of Arizona CS Dept, Tucson Lines: 31 In article <893@m10ux.UUCP>, mnc@m10ux.UUCP (Michael Condict) writes: > Oops, the previous lex script I posted for deleting comments from > C source code is incorrect -- it doesn't recognize: /***...**/ > Here is a better one (simpler, too): > > %% > \"([^\\"]*\\(.|\n))*[^\\"]*\" ECHO; > "/*"([^*]|"*"+[^/*])*"*"*"*/" ; > . ECHO; You indeed fixed the /***/ error, but two errors remain. First, no handling of single-quoted double quotes: main() {printf("%c\n", '"');/*gotcha*/printf("%c\n", '"');} Second, your program crashes when uncommenting a real source file, with a sizeable change history or whatever inside a comment. You need at least one state change, so a comment can be matched line-by-line, and so not overflow a Lex buffer. Both previous Lex postings did it right. A third state, to handle quoted strings line-by-line, is perhaps optional, and the previous postings differ here. Apparently you missed the previous Lex postings, which I will be happy to email you on request. My argument, that it's difficult to make a logical error in coding this problem in Lex, has now been demonstrated wrong (sob :-). But at least Lex is still outscoring straight C (faint praise :-?). John Rupley rupley!local@megaron.arizona.edu