Semantic error recovery

whatis@gni.ai.mit.edu (Steve Boswell)
Tue, 2 Nov 1993 18:00:30 GMT

          From comp.compilers

Related articles
Semantic error recovery whatis@gni.ai.mit.edu (1993-11-02)
Re: Semantic error recovery isckbk@leonis.nus.sg (1993-11-10)
Re: Semantic error recovery mauney@adm.csc.ncsu.edu (1993-11-10)
Re: Semantic error recovery wjw@eb.ele.tue.nl (1993-11-11)
Re: Semantic error recovery sasghm@unx.sas.com (1993-11-11)
Re: Semantic error recovery strohm@mksol.dseg.ti.com (1993-11-12)
Re: Semantic error recovery olsen@verdix.com (1993-11-12)
[11 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: whatis@gni.ai.mit.edu (Steve Boswell)
Keywords: errors, semantics, comment
Organization: Universal Media Netweb
Date: Tue, 2 Nov 1993 18:00:30 GMT

On every compiler that I've ever seen, one semantic error leads to a
cascade of semantic errors based on it. Here are some error messages
produced by my C++ compiler, just because my 2 case labels,
COMPARE_ENTITIES and COMPARE_ENTITIES_BY_NAME were not defined:


>error: COMPARE_ENTITIES undefined
>error: bad case label: cannot evaluate constant
>error: COMPARE_ENTITIES_BY_NAME undefined
>error: bad case label: cannot evaluate constant
>warning: theCheckType not used
>warning: notEnoughInfoList not used
>warning: unresolvedList not used


Now, there's no point in saying that the case labels are bad, or that
certain variables are unused, because the error isn't there. (It turns
out that they were used in the body of the switch statement.)


I'm currently writing a compiler for a different language, and I want to
avoid this cascading of error messages. I've designed a solution, but I
haven't implemented it yet, and I don't know if it's going to work. More
to the point, I can't figure out why someone has done something like this
yet.


In my solution, every node in the syntax tree has an attribute I call
"status". "status" is either correct or semanticError. "correct" means
that all immediate sub-nodes are correct, and their results can be
combined successfully to produce the current node. "semanticError" means
that either one of the immediate sub-nodes is semanticError, or they're
all correct but their results cannot be combined successfully.


The idea is, only when all immediate sub-nodes are correct but their
results can't be combined successfully is an error message printed. If
any immediate sub-nodes are semanticError, then any error message would
just be a "cascaded" error, so it's not printed.


Are there compilers that recover from semantic errors without a cascade of
meaningless error messages? How do they do it?


Steve Boswell
whatis@gnu.ai.mit.edu
[I can't say that I know of many compilers that recover usefully from any
but the most trivial errors. I usually just give up after the third message
or so. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.