This commit is contained in:
Nicolas PENELOUX 2023-10-20 20:48:23 +02:00
commit 8ed2b0c51f
5 changed files with 141 additions and 113 deletions

View file

@ -110,7 +110,7 @@ and branch =
| Branch of pattern located * expression located
and ty =
(** An instantiated type constructor [t <ty₁, .., tyₙ>]. *)
(** An instantiated type constructor [t <ty₁, ..., tyₙ>]. *)
| TyCon of type_constructor * ty located list
(** A function type [ty₁ → ty₂]. *)
| TyArrow of ty located * ty located

View file

@ -71,7 +71,9 @@ list_ty: LPAREN l=separated_nonempty_list(COMMA,located(ty)) RPAREN {
label_with_type:
| l=located(label) COLON t=located(ty) { l, t }
| l=located(label) COLON t=located(ty) {
l, t
}
vdefinition:
@ -352,13 +354,18 @@ simple_expression:
Apply(e1, e2)
}
<<<<<<< HEAD
=======
/* TODO operation binaire mais j'ai pas très bien compris encore */
>>>>>>> 726daf228d20fae695ecf903491c8b62d9e6a673
/* Match (exp) {| ...| ... | ...} */
| MATCH LPAREN e=located(expression) RPAREN
LBRACE b=branches RBRACE {
| MATCH LPAREN e=located(expression) RPAREN LBRACE b=branches RBRACE {
Case(e, b)
}
<<<<<<< HEAD
/* TODO if ( exp ) then { expr } j'ai RIEN COMPRIS */
/*
@ -375,14 +382,28 @@ simple_expression:
}
/* Reference ref expr */
=======
/* TODO if ( exp ) then { expr } j'ai RIEN COMPRIS */
/* | IF LPAREN e=located(expression) RPAREN
THEN LBRACE e2=located(expression) RBRACE {
IfThenElse(e, e2, None)
} */
>>>>>>> 726daf228d20fae695ecf903491c8b62d9e6a673
/* if ( expr ) then { expr } else { expr } */
| IF LPAREN e=located(expression) RPAREN
THEN LBRACE e2=located(expression) RBRACE
ELSE LBRACE e3=located(expression) RBRACE {
IfThenElse(e, e2, e3)
}
/* Reference ref expr */
| REF e=located(expression) {
Ref(e)
}
/* Affectation */
/* expr := expr */
/* Affectation
* expr := expr */
| e1=located(expression) ASSIGN e2=located(expression) {
Assign(e1, e2)
}
@ -394,27 +415,36 @@ simple_expression:
While(e, e2)
}
/* Do while TODO */
/* do { expr } until ( expr ) */
/* Do while
* do { expr } until ( expr ) */
/* TODO */
/* boucle for */
/* for x in (e1 to e2) { expr } */
/* boucle for
* for x in (e1 to e2) { expr } */
| FOR x=located(identifier)
FROM LPAREN e1=located(expression) RPAREN TO LPAREN e2=located(expression) RPAREN
LBRACE e3=located(expression) RBRACE
{ For(x,e1,e2,e3)}
LBRACE e3=located(expression) RBRACE {
For(x, e1, e2, e3)
}
/* Parenthésage pas sûr mais je vois pas sinon */
| LPAREN e=expression RPAREN {
e
}
<<<<<<< HEAD
/* Annotation de type */
/* (e : ty) */
| LPAREN e=located(expression) COLON t=located(ty) RPAREN {
TypeAnnotation(e,t)
=======
/* Annotation de type
* (e : ty) */
| LPAREN e=located(expression) COLON t=located(ty) RPAREN {
TypeAnnotation(e, t)
>>>>>>> 726daf228d20fae695ecf903491c8b62d9e6a673
}

View file

@ -32,11 +32,12 @@ let rec program p =
and definition = function
| DefineType (t, ts, tdef) ->
let eq = match tdef with Abstract -> empty | _ -> string "=" in
nest 2 (
group (group (string "type"
++ located type_constructor t
^^ group (type_parameters_angles ts))
++ string "=")
++ eq)
++ type_definition tdef)
| DeclareExtern (x, t) ->
group (string "extern" ++ located identifier x

View file

@ -2,11 +2,8 @@ open HopixAST
(** Abstract syntax for types.
The following internal syntax for types is the same as the one for
the types [ty] defined in {!HopixAST} except that all positions
have been erased.
*)
The following internal syntax for types is the same as the one for the types
[ty] defined in {!HopixAST} except that all positions have been erased. *)
type aty =
| ATyVar of type_variable
| ATyCon of type_constructor * aty list

Binary file not shown.