The tool YACC can generate a parser with the ability to automatically recover from the errors. Major nonterminals , such as those for program blocks or statements, are identified; and then error productions of the form A ’ error ± are added to the grammar, where ± is usually ˆˆ .
When YACC-generated parser encounters an error, it finds the top-most state on its stack, whose underlying set of items includes an item of the form A ’ .error. Therefore, the parser shifts the token error, and a reduction to A is immediately possible. The parser then invokes a semantic action associated with production A ’ error, and this semantic action takes care of recovering from the error.