Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. C ounting Source Lines of Code (SLOC) One common, very crude, measure of software complexity and programmer productivity is Source Lines of Code (SLOC).

1. C ounting Source Lines of Code (SLOC) One common, very crude, measure of software complexity and programmer productivity is Source Lines of Code (SLOC). This is a measure of the number of lines of code in the source code for a given program. A typical program often includes many tens (or even 100s) of files, so it is helpful to have an automated mechanism that computes this. To get a fairly accurate count, you want to count only those lines that are actual code, not empty or blank lines, and not lines that are just comments. The approach we will take is to focus on identifying the lines we dont want to count, eliminating them from the source file and counting what is left. Of course, the original source file will remain unchanged , we will delete line s from output that is written to stdout and eventually piped to wc l for counting the remaining lines. Rather than ask you to simply write the filter from scratch, we will do this step by step to help you see how complex filters are constructed. The fil e we will use for testing is c_comments ; this is not a real C program, but it has a mix of simple C code and comments. Some of the statements are not necessarily typical, but all are legal C statements. We start by identifying a set of statements that we know we do NOT want to count ; these are statements we want to eliminate. To ensure that we have the first step in the filter correct, we write to stdout just these statements for verification . It then will be a simple matter to convert the command from writing these statements out to deleting them instead.

a) Using a single sed statement, what is the command to display only the following lines from the file c_comments: lines that contain only single line C - style comments /* ... */

lines that contain only C++ style comments //

lines that are blank or empty HINT: This can be done using a single sed invocation with multiple commands ( - e option) or put the commands in a separate file.

b) When you have verified that the above command generates the correct output , modify it to instead display c_comments with those lines removed. Give the command to do this.

c) You should observe that the output produced by (b) still has the C - style multiple line comments. One may suggest that using the sed regul ar expression addressing with the first address to match /* and second address to match */ would find the multiple line comments. This will work, but not quite as simply as you might think. To understand the problem, pipe the output from step (b) int o a second sed statement that uses the suggestion to delete the multiple line comments. Give the command you used (the complete pipe command) and explain what you observe. Why doesnt this work?

d) You can fix this by eliminating /* ...*/ on the lines produ ced by (b). This can be added to the command in (b) as anot her command using the e option (or add it to a command file). Then add one more sed command using e again that contains the delete command you tried in (c). Give the complete pipe command you used to do this. Verify that the output is exactly only those lines with C code and no other lines.

e) Finally, pipe into wc to count the lines. Give the final command you used and the resulting number of lines.

Please help. Here is the input file:

// File with various examples of C and C++ style comments

/* simple C style comment on one line with no code */

x = 5*3; /* Example comment following code */

/* comments do not have to begin at the line beginning */ /* And you can have empty comments like the next one */ /**/ /* comments with code following the comment (not possible with C++ style) */ x = w * u/y/z; // As shown below you can have what appear to comments embedded in a string // The line below should be counted as code printf(" This output string looks like a /* comment */ doesn't it? "); /* ---- Example of a multiline C style comment */ c++; // C ++ style comment following code c=a/b*c; /* comment between two pieces of code */ w = a*b/e; /* This is a multiline c style comment. This comment covers several lines. ------*/ a = b / c * d; /* -----------End of the file ---------------*/

And yes this is one question, just a cruel one

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

1. Identify the sources for this conflict.

Answered: 1 week ago