Factoring

In classic by-the-book 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:

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).

Reference

Mats Stijlaart and Vadim Zaytsev. 2017. Towards a taxonomy of grammar smells. In Proceedings of the 10th ACM SIGPLAN International Conference on Software Language Engineering (SLE 2017). ACM, New York, NY, USA, 43-54.


Parsing Smells

Home

All rights reserved (c) Tushar Sharma 2017-23.