Noeud « Next »: , Noeud « Previous »: Invoking tc, Noeud « Up »: Implementation



3.2 Errors

Compile errors must be reported on the standard error flow with precise error location. Examples include:

     $ echo "1 + + 2" | ./tc -
     error-->standard input:1.4: syntax error, unexpected "+"
     error-->Parsing Failed

and

     $ echo "1 + () + 2" | ./tc -T -
     error-->standard input:1.0-5: type mismatch
     error-->  right operand type: void
     error-->  expected type: int

Note that the symbol error--> is not part of the actual output. It is only used in this document to highlight that the message is produced on the standard error flow. Do not include it as part of the compiler's messages.


The compiler exit value should reflect faithfully the compilation status. The possible values are:
0
Everything is all right.
1
Some error which does not fall into the other categories occurred. For instance, malloc or fopen failed, a file is missing etc.

Note that an optional option (such as --hir-use-ix) must cause tc to exit 1 if it does not support it. If you don't, be sure that your compiler will be exercised on these optional features, and it will most probably have 0.

2
Error detected during the scanning, e.g., invalid character.
3
Parse error.
4
Semantical error such as type incompatibility.
64 (EX_USAGE)
The command was used incorrectly, e.g., with the wrong number of arguments, a bad flag, a bad syntax in a parameter, or whatever. This is the value used by argp.

When several errors have occurred, the least value should be issued, not the earliest. For instance:

     (let error in end; %)

should exit 2, not 3, although the parse error was first detected.


In addition to compiler errors, the compiled programs may have to raise a runtime error, for instance when runtime functions received improper arguments. In that case use the exit code 120, and issue a clear diagnostic. Note that because of the basic MIPS model we target which does not provide the standard error output, the message is to be output onto the standard output.