Vadim Zaytsev aka @grammarware

GraSs: A Taxonomy of Grammar Smells


Organisation
global problems
Navigation
problems with navigating through the grammar
Structure
harmful relationships among grammar components

Proxy
indirect uses
Dependency
antipatterns in use
Complexity
metric-based smells

TooWide
the width (right hand side length) is too big
TooRamose
too much branching
TooRecursive
too much recursion
TooNested
groups are too deeply nested
TooTall
the height (distance from the root) is too big
Lonely
large non-modular grammar
TooModular
too many modules
Greedy
one module that does too much
Lazy
one module that does not do much
TooCoupled
low cohesion and/or high coupling

TooRamose Edit!

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.


The GraSs taxonomy is a joint effort maintained by Dr. Vadim Zaytsev a.k.a. @grammarware. Page last updated in March 2021.
XHTML 1.1 CSS 3