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

Convention
violations of visual policies
Notation
metalanguage-related
Parsing
parsing techniques related smells
Duplication
the same fragment is repeated

Factoring
improper factoring or distribution
1SidedRecursion
left or right recursive rules
Superset
parser spec is too relaxed
Shotgun
a chunk of input could be parsed in more detail
NoDefault
no error-localising default branch
Action
a code smell in a semantic action

1SidedRecursion Edit!

Related smells: Cyclic Hierarchy, Self Assignment

It is well-known that left-recursive definitions are deadly for by-the-book top-down parsing technologies [PT-GJ], since they create an infinite loop and cause the parser to crash from stack overflow. There are many approaches to solve the problem by grammar refactoring or parser tweaking, available from late 1960s, but most of them, if not all, increase the size and complexity of the grammar significantly. Hence, we can imagine some scenarios when left recursion should be recognised as a smell to be reported to the grammar engineer who will fix the issue manually. This is an example (Vadim Zaytsev, FL.Txl, extracted):


expression ::= expression op expression
             | id expression+

It must be noted here that indirect recursion (when A's right hand side starts with B whose right hand side starts with A) is just as deadly for top-down parsing as direct recursion.

Right recursion in general is less harmful, but it does lead to bottom-up parsers being slower than otherwise [PT-GJ], so it should still be avoided whenever possible.


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