NoDefault

There are certain tricks experienced grammar engineers use to improve the error handling. 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 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), and could take the form of Stmt := "MAP" MapStmt "." / "IF" IfStmt "." /··· / Id (!".")* ".". The lack of the last alternative in this example would be an indication of a NoDefault 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.