Related smells: Wide Hierarchy, Clone Tables, Conditional Complexity, Broken Modularization
McCabe's cyclomatic complexity has received a lot of critique over the years, but nevertheless is present in many code analysis tools either directly or conceptually through improvements like cognitive complexity [IWPC-2003-RillingK] or control flow patterns [SCAM-2012-VinjuG]. In grammars cyclomatic complexity is easy to estimate if we think of the parsing semantics, and it will be rather close for any other concrete application of the grammar. Alternatives and all kinds of disjunction obviously contribute to its increase, as well as repetition metasymbols. Conjunction, if present, also contributes to the branching since a construct like A & B
means that both the parser and the grammar engineer will have to explore both branches related to A
as well as to B
.
It is interesting to consider how this smell can be eliminated: a similar “Wide Hierarchy” code smell suggests to introduce intermediate hubs for groups of nonterminals, but others blame such a solution from other points of view because there is a chance of those nonterminals to be Weak.