Xref: utzoo comp.sources.wanted:15697 comp.software-eng:5028 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!news.cs.indiana.edu!arizona.edu!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.sources.wanted,comp.software-eng Subject: Re: WANTED: "C" code line counter program Message-ID: <1142@caslon.cs.arizona.edu> Date: 12 Mar 91 15:42:26 GMT References: <1991Mar6.214157.18633@ntpal.uucp> <1991Mar11.182848.26693@comm.wang.com> <2969@inews.intel.com> Followup-To: comp.software-eng Organization: U of Arizona CS Dept, Tucson Lines: 89 (had to trim alt.sources.wanted since we don't get it here...) In article <2969@inews.intel.com> bhoughto@pima.intel.com (Blair P. Houghton) writes: |In article <1991Mar11.182848.26693@comm.wang.com> lws@comm.wang.com (Lyle Seaman) writes: |>Counting semi-colons is a pretty good approach, as that counts C |>statements. Lines is kind of less meaningful. Counting '{' is |>an interesting one, too. | |{{{{{{{{printf("Oh, if I were a rich man... ;;;;;;;;;;;;;;;;;;;;;;;\n");}}}}}}}} I think I'd have to call this a pathalogical case. Bidee bidee bum. I think the trouble caused by this problem is that we have no clear cut definition of what a "line of code" is. So what we really need is to define what we mean by "# of statements" by setting up some rules like o declaration/assignment/function call is 1 statement o rules for counting constructs like if/while/for a good idea might just count the # of statements it groups, so if( foo ) S would have the same statement count as S (perhaps +1) o a rule for do S while() - perhaps the same as above, but you may want to treat this seperately. o { S } has the same statement count as S o rules for macros, comments, function headers, etc. This scheme seems to be workable to me, and has lots of room for fine-tuning the results to your personal taste. And it should be a simple matter to hack together a fairly simple yacc grammar to parse the code. Note that with this scheme (assuming strings are parsed correctly), the above "pathalogical" case now has a statement count of 1, as we might expect. -- Dave Schaumann | dave@cs.arizona.edu | Short .sig's rule! Newsgroups: alt.sources.wanted,comp.sources.wanted,comp.software-eng Subject: Re: WANTED: "C" code line counter program Summary: Expires: References: <1991Mar6.214157.18633@ntpal.uucp> <1991Mar11.182848.26693@comm.wang.com> <2969@inews.intel.com> Sender: Followup-To: Distribution: Organization: U of Arizona CS Dept, Tucson Keywords: In article <2969@inews.intel.com> bhoughto@pima.intel.com (Blair P. Houghton) writes: |In article <1991Mar11.182848.26693@comm.wang.com> lws@comm.wang.com (Lyle Seaman) writes: |>Counting semi-colons is a pretty good approach, as that counts C |>statements. Lines is kind of less meaningful. Counting '{' is |>an interesting one, too. | |{{{{{{{{printf("Oh, if I were a rich man... ;;;;;;;;;;;;;;;;;;;;;;;\n");}}}}}}}} I think I'd have to call this a pathalogical case. Bidee bidee bum. I think the trouble caused by this problem is that we have no clear cut definition of what a "line of code" is. So what we really need is to define what we mean by "# of statements" by setting up some rules like o declaration/assignment/function call is 1 statement o rules for counting constructs like if/while/for a good idea might just count the # of statements it groups, so if( foo ) S would have the same statement count as S (perhaps +1) o a rule for do S while() - perhaps the same as above, but you may want to treat this seperately. o { S } has the same statement count as S o rules for macros, comments, function headers, etc. This scheme seems to be workable to me, and has lots of room for fine-tuning the results to your personal taste. And it should be a simple matter to hack together a fairly simple yacc grammar to parse the code. Note that with this scheme (assuming strings are parsed correctly), the above "pathalogical" case now has a statement count of 1, as we might expect. -- Dave Schaumann | dave@cs.arizona.edu | Short .sig's rule!