Calculate cyclical complexity at runtime for generated program tree

I am running an evolutionary algorithm that automatically generates S-expressions that represent an abstract syntax tree. From there I generate C code to create a compiled program.

For each generated expression, I need to calculate the cyclical complexity that will be used in calculating the fitness. I noticed that there are tools for this (such as the metrics Eclipse plugin ), but I was hoping for something that could analyze a more representation of the overall program.

I could see the call to an external tool, however, I think it would significantly increase the execution time. Is there an easy way to calculate cyclical complexity with some kind of formula that takes S-expressions or abstract syntax trees into account?

+3


source to share


1 answer


If your generated programs are not available (for example, "structured" programs), you can calculate cyclical complexity using a simple rule:

CC(p) =  #conditionals +1

      



This is a fact for structured programs. You only need a complete definition if your programs are spaghetti control confusion.

0


source







All Articles