Related articles |
---|
Error recovery in byacc derek@knosof.co.uk (1995-11-03) |
Error recovery in byacc grosch@cocolab.sub.com (1995-11-16) |
Error recovery in byacc derek@knosof.co.uk (1995-11-16) |
Newsgroups: | comp.compilers |
From: | derek@knosof.co.uk (Derek M Jones) |
Keywords: | yacc, errors |
Organization: | Compilers Central |
Date: | Fri, 3 Nov 1995 17:20:33 GMT |
All,
I have been trying to add some reasonable syntax error recovery
to the parser generated by byacc. As a starting point I used the
error recovery contained in our C parser based on the yacc
skeleton.
Syntax error recovery is never perfect and sometimes not even close,
but I would like the 'new' parser to be 'as good as' the existing one.
Problems arise because the handling of default actions is different.
So the two parsers are not in the same state when an error is detected.
Quite good error recovery in C is possible by inserting a semicolon
prior to the input token that caused the problem. Our existing parser
is a little cleverer, it builds a set of expected tokens (if semicolon
is in that set it is choosen). Because byacc does not reduce rules the
same way as yacc I find that in many error states a semicolon is not
yet regarded as a legal expected input token. So some other token gets
inserted and this is invariably the wrong choice.
I know how to solve the problem. The error recovery code needs to
do some analysis to find out what other tokens might be acceptable if
more reductions take place. This is hard, thinking work.
I have looked at what gcc does (very little).
Can anybody give me pointers to parsers containing error recovery that
are based on the byacc generated tables?
Thanks
derek
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.