feat: Add typecheck to the AST

This commit is contained in:
Lucàs
2024-07-05 00:06:32 +02:00
parent 0a42fbe3dc
commit d81b96779a
17 changed files with 234 additions and 39 deletions
+10 -10
View File
@@ -11,10 +11,19 @@ let string_of_type = function
| BooleanType -> "BooleanType"
| VoidType -> "VoidType"
(** [string_of_literal l] returns a string representation of the literal [l]. *)
let string_of_literal = function
| Integer i -> "Integer(" ^ string_of_int i ^ ")"
| Float f -> "Float(" ^ string_of_float f ^ ")"
| Character c -> "Character('" ^ Char.escaped c ^ "')"
| String s -> "String(\"" ^ s ^ "\")"
| Boolean b -> "Boolean(" ^ string_of_bool b ^ ")"
| Null -> "Null"
(** [string_of_binary_operator op] returns a string representation of the binary operator [op]. *)
let string_of_binary_operator = function
| Add -> "Add"
| Substract -> "Substract"
| Subtract -> "Subtract"
| Multiply -> "Multiply"
| Divide -> "Divide"
| AmpersandAmpersand -> "AmpersandAmpersand"
@@ -30,15 +39,6 @@ let string_of_binary_operator = function
(** [string_of_unary_operator op] returns a string representation of the unary operator [op]. *)
let string_of_unary_operator = function Negate -> "Negate" | Not -> "Not"
(** [string_of_literal l] returns a string representation of the literal [l]. *)
let string_of_literal = function
| Integer i -> "Integer(" ^ string_of_int i ^ ")"
| Float f -> "Float(" ^ string_of_float f ^ ")"
| Character c -> "Character('" ^ Char.escaped c ^ "')"
| String s -> "String(\"" ^ s ^ "\")"
| Boolean b -> "Boolean(" ^ string_of_bool b ^ ")"
| Null -> "Null"
(** [string_of_expression e] returns a string representation of the expression [e]. *)
let rec string_of_expression = function
| Literal l -> "Literal(" ^ string_of_literal l ^ ")"