Beruflich Dokumente
Kultur Dokumente
currentSymbol
Error Recovery in a LL(1) Parser The ‘kind’ of token currently being processed
Equal to the Yytoken ‘symbol’ instance variable
Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 1 Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 2
Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 3 Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 4
Scheme 1 Scheme 1
We modify our lexer interface mustbe We also need to supress extraneous error messages (we really only
want to see the first one).
This technique is outlined in the paper: “Error
Easy: our error reporting method (we'll call it syntaxError() ) does not
Diagnosis and Recovery in One Pass Compilers" by issue an error message when a flag called “recovering” is set to true.
D.A. Turner. syntaxError() sets this flag...
This approach makes the mustbe interface throw Code for syntaxError():
input tokens away when we detect an error.
We stop throwing input away until we reach a plausible public void syntaxError (String errMsg) {
symbol... if (!recovering) {
// call to error routine to
Note // print/record the error message.
This is the basis of every sensible error recovery error(currentToken, errMsg);
strategy – throw erroneous input away recovering = true;
}
Error recovery strategies differ in how much input they }
discard
The less input you discard, the better!
Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 5 Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 6
Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 9 Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 10
Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 13 Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 14
Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 17 Compiler Construction & Project © 2004 Kevin J. Maciunas, Rob Esser Slide 18