Path: utzoo!news-server.csri.toronto.edu!rutgers!sun-barr!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!dkuug!iesd!iesd.auc.dk!richard From: richard@iesd.auc.dk (Richard Flamsholt S0rensen) Newsgroups: comp.software-eng Subject: Counting semicolons (was: Re: WANTED: "C" code line counter program) Message-ID: Date: 12 Mar 91 18:44:39 GMT References: <1991Mar6.214157.18633@ntpal.uucp> <9082@suns6.crosfield.co.uk> Sender: news@iesd.auc.dk Followup-To: comp.software-eng Organization: Mathematics and Computer Science, University of Aalborg Lines: 45 In-reply-to: raj@crosfield.co.uk's message of 11 Mar 91 09:06:47 GMT >>>>> On 11 Mar 91 09:06:47 GMT, raj@crosfield.co.uk (Ray Jones) said: Ray> In article <1991Mar6.214157.18633@ntpal.uucp> dcavasso@ntpal.uucp (Dana Cavasso) writes: > > I need a "C" code line counter program, preferably written in >"C". It will be used on several platforms, so solutions involving >shell scripts and other UNIX utilities won't work. I'm not very >picky (although I'd like something that did a little more than count >newlines :-) Ray> So how about one that counts semi-colons :-) Doesn't sound that silly after all. The only thing (somebody correct me if I'm wrong) that "terminates" statements, are semicolons and right braces. (Surely I know, that right braces doesn't terminate a statement in the sense, that you can write x = 1} y = 3; . What I mean is, that when you encounter a }, you can be at the end of a compound statement, the only statement that's *not* terminated by a semicolon.) The problem is, that if (x == 7) { y = 1; } - would count as two statements, thought that's actually quite correct; a compound statement is a statement in itself and need not include any statements at all inside it; here, it does include one so all in all we have two statements. In a line counting program, however, you probably wouldn't want the {}'s themselfes to count as a statement, would you? Furthermore, if we count }'s as statements this also makes function definitions, structs, unions, enums and initializers - who all ends with a } - look like statements. Therefore, I think the idea of dismissing the compound statements and only counting semicolons is allright (as long as you stay out of comments, character constants and strings, of course ...) - and if I'm wrong, somebody'll probably tell me so ;-) Richard -- /Richard Flamsholt richard@iesd.auc.dk