This repository has been archived on 2022-12-27. You can view files and clone it, but cannot push or open issues or pull requests.
compilateurMIPS/errors.ml
Mylloon 828a780f9c
WIP Function implementation
* Add basic support of function
* move debug function to test file
* add a test who need to pass to end the implementation
2022-12-10 01:55:15 +01:00

44 lines
925 B
OCaml

open Ast
open Lexing
exception LexerError of char
exception SemanticsError of string * Lexing.position
let err msg pos =
Printf.eprintf
"Error on line %d col %d: %s.\n"
pos.pos_lnum
(pos.pos_cnum - pos.pos_bol)
msg;
exit 1
;;
let rec string_of_type_t = function
| Void_t -> "void"
| Int_t -> "int"
| Bool_t -> "bool"
| Func_t (r, a) ->
(if List.length a > 1 then "(" else "")
^ String.concat ", " (List.map string_of_type_t a)
^ (if List.length a > 1 then ")" else "")
^ " -> "
^ string_of_type_t r
;;
let errt expected given pos =
raise
(SemanticsError
( Printf.sprintf
"Expected %s but given %s"
(string_of_type_t expected)
(string_of_type_t given)
, pos ))
;;
let warn msg (pos : Lexing.position) =
Printf.eprintf
"Warning on line %d col %d: %s.\n"
pos.pos_lnum
(pos.pos_cnum - pos.pos_bol)
msg
;;