Path: utzoo!attcan!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!cornell!batcomputer!sun.soe.clarkson.edu!cline From: cline@sunshine.ece.clarkson.edu (Marshall Cline) Newsgroups: comp.lang.c++ Subject: Re: C++ Comments Message-ID: Date: 24 May 89 19:52:16 GMT References: <6957@brunix.UUCP> <7636@saturn.ucsc.edu> Sender: news@sun.soe.clarkson.edu Reply-To: cline@sun.soe.clarkson.edu (Marshall Cline) Organization: Clarkson University, Postdam NY Lines: 35 In-reply-to: easterb@ucscb.UCSC.EDU's message of 24 May 89 07:52:09 GMT In article <7636@saturn.ucsc.edu> easterb@ucscb.UCSC.EDU (William K. Karwin) writes: >Summary: one of many possible fixes >Some students ran into this problem, and the "macros-expanded-even- >though-they're-in-comments" problem this school term, in a class >using C++. We think one way to solve it is to have in a makefile: >.c.o: @sed s/\\/\\/.\*// $< > $*.C > CC $(CFLAGS) -c $*.C > @/bin/rm -f $*.C >The sed command strips // comments and all characters following on a >line. We are using the .c suffix for our C++ code files. >William Karwin, ...ucbvax!ucscc!ucscb!easterb As you said, this is _one_ of _many_ fixes. But it should be pointed out that "sed" is ignorant of the appropriate language constructs. Thus a printf which is supposed to print the string constant "double slash (//) starts a C++ comment" would be bashed into "double slash ( which would undoubtedly cause numerous syntax errors. Any regular expression parser (like "sed") is limited to regular languages. Even a push-down-automata (recognizing _context_free_languages_) is insufficient. The only correct "fix" is then a context *sensitive* language recognizer, which is nearly as complex as a Turing Machine. In other words, somebody's gonna have to buckle down and write a "c++pp" (like Gnu apparently has done). Marshall -- ________________________________________________________________ Marshall P. Cline ARPA: cline@sun.soe.clarkson.edu ECE Department UseNet: uunet!sun.soe.clarkson.edu!cline Clarkson University BitNet: BH0W@CLUTX Potsdam, NY 13676 AT&T: (315) 268-6591