You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement error recovery for the Kipper compiler, which allows it to attempt recovery from an error and continue the semantic analysis if possible. This will make it be able to throw multiple compile errors and provide more insight into the errors of a program.
Example
Code:
varx: typ=5+"str";
Errors:
[ERROR]: Traceback:
File 'anonymous-script', line 1, col 7:
var x: typ = 5 + "5";
^^^
TypeError: Unknown type'typ'.
[ERROR]: Traceback:
File 'anonymous-script', line 1, col 13:
var x: typ = 5 + "5";
^^^^^^^
InvalidArithmeticOperationError: Invalid arithmetic operation between types 'num' and 'str'.
Exact behaviour / changes you want
Add compile config field recover, which is per default true.
Add new CLI flags -r/--recover and --no-recover.
Implement the recover algorithm, which follows the following procedure (Lexing and Parsing does not apply to these rules):
Run semantic analysis for an AST node.
If the semantic analysis fails due to an error, try to determine whether the semantic data is present:
If not, then recovering for this AST node and its primary parent (statement or definition) is impossible, and as such, the whole statement/definition is discarded and the analysis should continue with the next statement or definition.
If it is present, then recover from this error and continue the analysis for the statement/definition.
Afterwards, the error should be added to a list of errors and then thrown using a single error at the end of the semantic analysis. (KipperCompileResult should contain an errors field, which provides a list of all errors).
Continue with the next expression, statement or definition.
Note
The recover algorithm can result in semantic data being missing. For example, if a variable can not be created/registered due to an error, recovering from that error will mean that any reference to it afterwards will cause more errors as the compiler does not know about the variable. This is bad behaviour, as it results in errors that are wrong and provide invalid insight into what went wrong. Such behaviour should therefore be avoided at all costs and the semantic analysis should be structured as robust as possible to make sure semantic data that is valid is registered, and as such "invalid errors" are avoided.
The text was updated successfully, but these errors were encountered:
Basic error recovery implementation implemented with 79f94a4. Development and tests will continue on the branch, and then later be merged into dev for the next release v0.10.0.
Is there an existing proposal for this?
This feature does not exist in the latest version
Proposal
Implement error recovery for the Kipper compiler, which allows it to attempt recovery from an error and continue the semantic analysis if possible. This will make it be able to throw multiple compile errors and provide more insight into the errors of a program.
Example
Exact behaviour / changes you want
recover
, which is per defaulttrue
.-r/--recover
and--no-recover
.KipperCompileResult
should contain anerrors
field, which provides a list of all errors).Note
The recover algorithm can result in semantic data being missing. For example, if a variable can not be created/registered due to an error, recovering from that error will mean that any reference to it afterwards will cause more errors as the compiler does not know about the variable. This is bad behaviour, as it results in errors that are wrong and provide invalid insight into what went wrong. Such behaviour should therefore be avoided at all costs and the semantic analysis should be structured as robust as possible to make sure semantic data that is valid is registered, and as such "invalid errors" are avoided.
The text was updated successfully, but these errors were encountered: