9.6 PREDICTIVE PARSING ERROR RECOVERY


9.5 AUTOMATIC ERROR RECOVERY IN YACC

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.




Algorithms for Compiler Design
Algorithms for Compiler Design (Electrical and Computer Engineering Series)
ISBN: 1584501006
EAN: 2147483647
Year: 2005
Pages: 108
Authors: O G Kakde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net