[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Compiler error handling
How are folks handling errors during the compile phase?
I have the system walking the tree and generating code. But when I encounter
an error, I can't throw an exception (as outXXX doesn't allow it).
Do folks just note the errors in a log someplace, and then set flags?
So, say I discover SYMBOL NOT FOUND, should I just set a flag, note the
error?
So, for example, I can reset the error flag as I'm going into a high level
construct (statement, expression, whatever).
Also, from an idiomatic point of view, I wonder if I'm doing things the
"correct" way.
I've got my DFA class, and it's overriding a bunch of outXXX methods.
In each out method, I generate a bunch of node information using
setOut(node, info).
So, something like this would happen (contrived code follows):
public void outAddExpr(AAddExpr node)
{
NodeInfo rhs = (NodeInfo)getOut(node.getRHS());
NodeInfo lhs = (NodeInfo)getOut(node.getLHS());
if (rhs.getDataType() != lhs.getDataType()) {
error("can't add different datatypes")
} else {
NodeInfo ni = new NodeInfo();
ni.type = rhs.getDataType();
setOut(node, ni);
}
}
So, in this case, we're bubbling up expression type infomation.
But I also get a lot of these for "fill in" parts of the grammar, where it's
mostly syntactic sugar.
So, I do this:
public void outSugar(ASugar node)
{
NodeInfo ni = (NodeInfo)getOut(node.getThing());
setOut(node, ni);
}
It's working fine, I'm just curious if this is "the way it's done" or am I
missing something. In the Thesis, there was a section where Etienne talked
about having a bunch of nested AnalysisAdapter anonymous classes. I admit
that it wasn't particularly clear what he was doing here to me.
So, it's mostly an idiomatic question that I'm doing this the "right way".
Thanx!
Will Hartung
(willh@msoft.com)