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

Factoring Edit!

Related smells: Missing Hierarchy, Repeated Conditionals

In classic by-the-book [PT-GJ] non-memoising parsing, if alternative production rules from the same nonterminal start from the same symbols, these would have to be reparsed in each of the branches. As a real example (Doug Cooper, Scott Moore, Pascal grammar in Yacc format, fetched):


open_if_statement
 : IF boolean_expression THEN statement
 | IF boolean_expression THEN closed_statement
                         ELSE open_statement;

Interestingly, this example is a false positive: factoring the first three symbols into a separate nonterminal will clutter the grammar without bringing any noticeable benefits (and will introduce the Weak smell). In other cases, this smell has been avoided/removed (The Dart Team, Dart Programming Language Specification, extracted):


ifStatement ::= "if" "(" expression ")" statement
               ("else" statement)?


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