diff --git a/sources/zweic/Report.scala b/sources/zweic/Report.scala new file mode 100755 index 0000000..895769d --- /dev/null +++ b/sources/zweic/Report.scala @@ -0,0 +1,51 @@ +/* zweic -- a compiler for zwei + * + * Stephane Micheloud & LAMP + * + * $Id$ + */ + +package zweic; + + +/** This class provides functionality for printing error messages. + */ +object Report { + + /** Number of errors. + */ + var errors: Int = 0; + + /** Prints out an error message. + */ + def error(message: String): Unit = { + errors = errors + 1; + System.err.println(message); + } + + /** Prints out an error message. + */ + def error(position: Int, message: String): Unit = { + errors = errors + 1; + print(position, message); + } + + /** Prints out an error message and stops the program execution. + */ + def fail(message: String): Unit = { + error(message); + System.exit(-1); + } + + /** Prints out an error message and stops the program execution. + */ + def fail(position: Int, message: String): Unit = { + error(position, message); + System.exit(-1); + } + + /** Imprime la position et le message passés en argument. */ + private def print(pos: Int, message: String): Unit = + System.err.println(Position.toString(pos) + ": " + message); + +}