mirror of
https://github.com/LucasVbr/croissant.git
synced 2026-07-09 15:07:48 +00:00
feat: Add Literals and operator of comparison
This commit is contained in:
+21
-3
@@ -8,13 +8,31 @@ let string_of_binary_operator = function
|
||||
| Substract -> "Substract"
|
||||
| Multiply -> "Multiply"
|
||||
| Divide -> "Divide"
|
||||
| AmpersandAmpersand -> "AmpersandAmpersand"
|
||||
| BarBar -> "BarBar"
|
||||
| EqualsEquals -> "EqualsEquals"
|
||||
| ExclamationEquals -> "ExclamationEquals"
|
||||
| LessThan -> "LessThan"
|
||||
| LessThanEquals -> "LessThanEquals"
|
||||
| GreaterThan -> "GreaterThan"
|
||||
| GreaterThanEquals -> "GreaterThanEquals"
|
||||
|
||||
(** [string_of_unary_operator op] returns a string representation of the unary operator [op]. *)
|
||||
let string_of_unary_operator = function Negate -> "Negate"
|
||||
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
|
||||
| IntegerLiteral i -> "IntegerLiteral(" ^ string_of_int i ^ ")"
|
||||
| Literal l -> "Literal(" ^ string_of_literal l ^ ")"
|
||||
| Identifier i -> "Identifier(\"" ^ i ^ "\")"
|
||||
| UnaryExpression (op, e) ->
|
||||
"UnaryExpression("
|
||||
^ string_of_unary_operator op
|
||||
@@ -33,4 +51,4 @@ let string_of_statement = function
|
||||
let string_of_source_file = function
|
||||
| SourceFile stmts ->
|
||||
let stmt_strings = List.map string_of_statement stmts in
|
||||
"SourceFile([" ^ String.concat ", " stmt_strings ^ "])"
|
||||
"SourceFile([" ^ String.concat ", " stmt_strings ^ "])"
|
||||
+26
-4
@@ -1,12 +1,34 @@
|
||||
(* lib/ast/syntax.ml *)
|
||||
|
||||
type binary_operator = Add | Substract | Multiply | Divide
|
||||
type unary_operator = Negate
|
||||
type literal =
|
||||
| Integer of int
|
||||
| Float of float
|
||||
| Character of char
|
||||
| String of string
|
||||
| Boolean of bool
|
||||
| Null
|
||||
|
||||
type binary_operator =
|
||||
| Add
|
||||
| Substract
|
||||
| Multiply
|
||||
| Divide
|
||||
| AmpersandAmpersand
|
||||
| BarBar
|
||||
| EqualsEquals
|
||||
| ExclamationEquals
|
||||
| LessThan
|
||||
| LessThanEquals
|
||||
| GreaterThan
|
||||
| GreaterThanEquals
|
||||
|
||||
type unary_operator = Negate | Not
|
||||
|
||||
type expression =
|
||||
| IntegerLiteral of int
|
||||
| Literal of literal
|
||||
| Identifier of string
|
||||
| UnaryExpression of unary_operator * expression
|
||||
| BinaryExpression of binary_operator * expression * expression
|
||||
|
||||
type statement = ExpressionStatement of expression
|
||||
type source_file = SourceFile of statement list
|
||||
type source_file = SourceFile of statement list
|
||||
Reference in New Issue
Block a user