Re: buggy 4.0 program
- Posted by kinz Dec 15, 2008
- 1568 views
My question, why the error handling system can not separate the non-declared things and other things of the "referencing error" series?
Please define the difference between the two from the parser's perspective. The answer is that there isn't any. It can't know what you were thinking about, to know that you "meant to" declare something, or whether you just typed something incorrectly.
Non-declared exactly:
- the EOF is reached and
- there is no the declaration of the symbol in the whole program.
(The current parser's perspective is zero, so to say. It has nothing to do any more.)
But if it sees a different error (a syntax error of the missing operator type for example) then the parser stops. The parser stops.
Yes, I know that now, so I say 'the EOF (End Of File) is reached'. The parser can only reach EOF if there is no the different error. So, if parser sees EOF then all detected errors are of the "referencing error" series. And if there is no daclaration of some of them in the whole program then these ones are non-declared. Who cares why do they look as non-declared from the point of view of the correct program? So "Please declare ... properly: [list]".
It does not continue to parse the rest of the program to see if the symbol is ever declared or not, so at the point where the syntax error is reported, it is too soon for the parser to know about undeclared variables/unresolved forward references.
Ok, I know now that it does not continue to parse the rest of the program. And my question is why? Why it can not collect the different errors in same manner as "referencing error" series?
The only way to fix this (without getting rid of forward referencing altogether) is to add an extra pass to the parser, with the variable reference resolving occuring on the first pass and the syntax error check on the second pass.
Why not to collect all at all errors to EOF and then generate complete error message after single pass?
I'm not sure if there is a difference between undeclared variables and unresolved forward references (that and conflicting references - variable declared twice - are the only reference errors that I know of).
The difference seems to be very clear, if EOF is reached.
Regards,
Igor Kachan
kinz@peterlink.ru