235/235 .

This commit is contained in:
Nicolas PENELOUX 2023-10-24 22:51:13 +02:00
parent 885f2e0790
commit ec792fd40d

View file

@ -18,6 +18,7 @@
%start<HopixAST.t> program %start<HopixAST.t> program
/* TODO: Résoudre tout les shift/reduce conflits */ /* TODO: Résoudre tout les shift/reduce conflits */
%right lparen1
%left LPAREN %left LPAREN
%left let1 %left let1
@ -44,6 +45,7 @@
%left PLUS MINUS %left PLUS MINUS
%left SLASH STAR %left SLASH STAR
%left local_def1
%left ref1 %left ref1
%left fun1 %left fun1
%left app1 %left app1
@ -118,17 +120,28 @@ label_with_type:
l, t l, t
} }
/*
vdefinition et vdefinition_local font sensiblement la même chose, seulement l'ordre de priorité est différent
*/
vdefinition: vdefinition:
/* Valeur simple */ /* Valeur simple */
| LET i=located(var_identifier) ts=option(colon_type_scheme) | LET i=located(var_identifier) ts=option(colon_type_scheme)
EQUAL e=located(expression) %prec let1 { EQUAL e=located(expression) {
SimpleValue(i, ts, e) SimpleValue(i, ts, e)
} }
/* Fonction(s) /* Fonction(s) */
* Exemple :
* - fun : int f a = 1 | FUN fl=separated_nonempty_list(AND_KW, fundef) {
* - fun f a = 1 and : int g a = 2 */ RecFunctions(fl)
}
vdefinition_local:
/* Valeur simple */
| LET i=located(var_identifier) ts=option(colon_type_scheme)
EQUAL e=located(expression) %prec local_def1 {
SimpleValue(i, ts, e)
}
/* Fonction(s) */
| FUN fl=separated_nonempty_list(AND_KW, fundef) { | FUN fl=separated_nonempty_list(AND_KW, fundef) {
RecFunctions(fl) RecFunctions(fl)
} }
@ -224,6 +237,8 @@ pattern_list:
* ty -> ty STAR separated_nonempty_list(STAR, located(ty)) * ty -> ty STAR separated_nonempty_list(STAR, located(ty))
* ty -> ty * [ ty ] * ty -> ty * [ ty ]
*/ */
simple_ty: simple_ty:
/* Application d'un constructeur de type */ /* Application d'un constructeur de type */
| tc=type_constructor { | tc=type_constructor {
@ -287,15 +302,12 @@ simple_expression:
| i=located(var_identifier) tl=option(type_list) { | i=located(var_identifier) tl=option(type_list) {
Variable(i, tl) Variable(i, tl)
} }
/* Annotation de type
* ( expr : type ) */
| LPAREN e=located(expression) COLON t=located(ty) RPAREN { | LPAREN e=located(expression) COLON t=located(ty) RPAREN {
TypeAnnotation(e, t) TypeAnnotation(e, t)
} }
/* Tagged Value - Construction d'une donnée */
/*
| const=located(constructor) tl=option(type_list) el=optionlist(expr_list) {
Tagged(const, tl, el)
}
*/
/* Tuple n = 0 - Construction d'un 0-uplet */ /* Tuple n = 0 - Construction d'un 0-uplet */
| LPAREN RPAREN { | LPAREN RPAREN {
@ -319,6 +331,7 @@ simple_expression:
Read(e) Read(e)
} }
type_list: type_list:
| INFERIOR tl=separated_list(COMMA, located(ty)) SUPERIOR { | INFERIOR tl=separated_list(COMMA, located(ty)) SUPERIOR {
tl tl
@ -329,6 +342,7 @@ expr_list:
el el
} }
mid_expression: mid_expression:
|e=simple_expression{ |e=simple_expression{
e e
@ -343,52 +357,36 @@ mid_expression:
Field(e, l, tl) Field(e, l, tl)
} }
/* Application */ /* Tagged Value - Construction d'une donnée */
| const=located(constructor) tl=option(type_list) el=optionlist(expr_list) {
Tagged(const, tl, el)
}
/* Application */
| e1=located(mid_expression) e2=located(mid_expression) %prec app1 { | e1=located(mid_expression) e2=located(mid_expression) %prec app1 {
Apply(e1, e2) Apply(e1, e2)
} }
| const=located(constructor) tl=option(type_list) el=optionlist(expr_list) {
Tagged(const, tl, el)
}
expression: expression:
| e=mid_expression { | e=mid_expression {
e e
} }
/* Field - Projection dun champ */
/*
| e=located(expression) DOT l=located(label_identifier) tl=option(type_list) {
Field(e, l, tl)
}
/* Sequence - Séquencement *
* Pas sûr, voir s'il ne faut pas une troisième couche d'expression */
/* /* Sequence - Séquencement */
| e=located(mid_expression) | e=located(expression) SEMICOLON e2=located(expression) {
SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(mid_expression)) {
Sequence(e :: e_list)
}*/
| e=located(expression) SEMICOLON e2=located(expression){
Sequence([e;e2]) Sequence([e;e2])
} }
/* | e1=located(expression) SEMICOLON e2=located(expression) {
Sequence([e1; e2])
} */
/* Definition locale */ /* Definition locale */
| vd=vdefinition SEMICOLON e=located(expression) { | vd=vdefinition_local SEMICOLON e=located(expression) {
Define(vd, e) Define(vd, e)
} }
/* Fonction anonyme */ /* Fonction anonyme */
| BACKSLASH p=located(pattern) ARROW e=located(expression) { | BACKSLASH p=located(pattern) ARROW e=located(expression) {
Fun(FunctionDefinition(p, e)) Fun(FunctionDefinition(p, e))
} }
/* Application */
/*
| e1=located(expression) e2=located(expression) %prec app1 {
Apply(e1, e2)
}
/* Operateurs binaires - Application infixe */ /* Operateurs binaires - Application infixe */
| e1=located(expression) b=binop e2=located(expression) { | e1=located(expression) b=binop e2=located(expression) {
@ -405,16 +403,8 @@ expression:
e2 e2
) )
} }
// Je met en commentaire parce que donner la location passe pas
// plus de tests et ça rajoute plein de trucs relou donc jsp
/* | e1=located(expression) b=var_binop(binop) e2=located(expression) {
Apply(
Position.with_pos (
(Position.position b))
(Apply(b, e1))
, e2
)
} */
/* Analyse de motifs /* Analyse de motifs
* match (exp) {| ...| ... | ...} */ * match (exp) {| ...| ... | ...} */
| MATCH LPAREN e=located(expression) RPAREN LBRACE b=branches RBRACE { | MATCH LPAREN e=located(expression) RPAREN LBRACE b=branches RBRACE {
@ -434,11 +424,7 @@ expression:
ELSE LBRACE e3=located(expression) RBRACE { ELSE LBRACE e3=located(expression) RBRACE {
IfThenElse(e1, e2, e3) IfThenElse(e1, e2, e3)
} }
/* Reference - Allocation
* ref expr */
| REF e=located(simple_expression) {
Ref(e)
}
/* Affectation /* Affectation
* expr := expr */ * expr := expr */
| e1=located(expression) ASSIGN e2=located(expression) { | e1=located(expression) ASSIGN e2=located(expression) {
@ -464,21 +450,15 @@ expression:
LBRACE e3=located(expression) RBRACE { LBRACE e3=located(expression) RBRACE {
For(var, e1, e2, e3) For(var, e1, e2, e3)
} }
/* Parenthésage
* Pas sûr mais je vois pas sinon */
/* /* allocation
| LPAREN e=expression RPAREN { * ref expr */
e | REF e=located(mid_expression) {
}*/ Ref(e)
/* Annotation de type
* (e : ty) */
/*
| LPAREN e=located(expression) COLON t=located(ty) RPAREN {
TypeAnnotation(e, t)
} }
/******************************** BASIC TYPES *********************************/ /******************************** BASIC TYPES *********************************/
var_identifier: var_identifier:
| var_id=ID { | var_id=ID {