mirror of
https://github.com/LucasVbr/croissant.git
synced 2026-05-13 17:12:10 +00:00
feat: support variable declaration statement
This commit is contained in:
@@ -2,6 +2,15 @@
|
||||
|
||||
open Syntax
|
||||
|
||||
(** [string_of_type t] returns a string representation of the type [t]. *)
|
||||
let string_of_type = function
|
||||
| Type_Integer -> "Type_Integer"
|
||||
| Type_Float -> "Type_Float"
|
||||
| Type_Character -> "Type_Character"
|
||||
| Type_String -> "Type_String"
|
||||
| Type_Boolean -> "Type_Boolean"
|
||||
| Type_Void -> "Type_Void"
|
||||
|
||||
(** [string_of_binary_operator op] returns a string representation of the binary operator [op]. *)
|
||||
let string_of_binary_operator = function
|
||||
| Add -> "Add"
|
||||
@@ -42,10 +51,18 @@ let rec string_of_expression = function
|
||||
^ string_of_binary_operator op
|
||||
^ ", " ^ string_of_expression e1 ^ ", " ^ string_of_expression e2 ^ ")"
|
||||
|
||||
let string_of_variable_declaration = function
|
||||
| VariableDeclaration (t, id, e) ->
|
||||
"VariableDeclaration(" ^ string_of_type t ^ ", " ^ string_of_expression id
|
||||
^ ", " ^ string_of_expression e ^ ")"
|
||||
|
||||
(** [string_of_statement s] returns a string representation of the statement [s]. *)
|
||||
let string_of_statement = function
|
||||
| ExpressionStatement e ->
|
||||
"ExpressionStatement(" ^ string_of_expression e ^ ")"
|
||||
| VariableStatement decls ->
|
||||
let decl_strings = List.map string_of_variable_declaration decls in
|
||||
"VariableStatement([" ^ String.concat ", " decl_strings ^ "])"
|
||||
|
||||
(** [string_of_source_file f] returns a string representation of the source file [f]. *)
|
||||
let string_of_source_file = function
|
||||
|
||||
Reference in New Issue
Block a user