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

NoDefault Edit!

Related smells: Missing Default Case, Assertion Roulette

Parser generators are great for everything, except for one aspect: error handling. There are many methods that use heuristics in an attempt to improve the situation, but error detection, localisation and reporting in manually written parsers is always incomparably better than in generated ones. However, there are certain tricks experienced grammar engineers use to improve the situation. For example, consider a DSL where each statement starts with a keyword and ends with a period. An obvious improvement to the naïve approach would be to, for instance, once a keyword MAP is recognised, have a panic mode setup or some other semiparsing [CSMR-WCRE-2014-Zaytsev] machinery to fail locally and report on an “error in a map statement” rather than pointlessly try to backtrack and fail at the general statement level. To do this, one has to have a special default case among the rules for each particular statement kind. This recipe is more often observed in grammars written for frameworks where ordered choice is more natural (TXL, PEGs, etc).


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