Hello,

I want to code an application that calculates a program's complexity. I may have put this the wrong way: I want to count the operators, variables, function calls etc. in a C/C++ program.

At first I thought about reading the .C file as a .txt file, looping through each character and counting a symbol's appearance: ";" 10 times, "." 2 times, "^" 1 time, printf 3 times etc.

However, if someone uses #include <math.h>, I need to count the number of calls to math functions and so on.

What I need to do is obtain the names of functions included in a header and check for their calls. How to do that? Or any other ideas ?


LE: I'd also have to check for user defined functions. This might not be so doable as I originally thought. :D

You'll need to perform a Lexical analysis of the code. Your software will need to 'understand' that something like // This is a test of the sprintf() function ... doesn't have a function call, isn't using . operators, etc.

This might help.

Thanks for the reply.

I am going to postpone this until my "Designing Compilers" class next year.

I've recently learned about regular expressions. Seems promising and suitable for my case.

If anyone has experience with this, please post; I'll update my progress.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.