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.
All rights reserved (c) Tushar Sharma 2017-23.