This commit is contained in:
Mylloon 2023-10-24 23:09:45 +02:00
parent f596c5c64d
commit 88efc86649
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -17,24 +17,16 @@
%start<HopixAST.t> program
/* TODO: Résoudre tout les shift/reduce conflits */
%right lparen1
%left LPAREN
%left let1
/* %left FUN */
%left STRING
%left INT CID CHAR /* WHILE */
%left INT CID CHAR
%left ID
/* %right REF DO */
/* %left LET MATCH IF FOR */
%right ARROW
%right SEMICOLON
%left DOT
%left ASSIGN
%left LBRACE
/* %left BACKSLASH */
%left EXCLA COLON
@ -46,8 +38,6 @@
%left SLASH STAR
%left local_def1
%left ref1
/* %left ref1 */
%left fun1
%left app1
@ -74,7 +64,6 @@ definition:
DefineType (tc, tvl, td)
}
// La tdefinition peut être optionnel, dans ce cas on utilise c'est abstrait
| TYPE tc=located(type_constructor) tvl=optionlist(definition_typevariablelist) {
DefineType (tc, tvl, Abstract)
}
@ -121,17 +110,15 @@ label_with_type:
l, t
}
/*
vdefinition et vdefinition_local font sensiblement la même chose, seulement l'ordre de priorité est différent
*/
/* vdefinition et vdefinition_local font sensiblement la même chose,
* seulement l'ordre de priorité est différent */
vdefinition:
/* Valeur simple */
| LET i=located(var_identifier) ts=option(colon_type_scheme)
EQUAL e=located(expression) {
EQUAL e=located(expression) {
SimpleValue(i, ts, e)
}
/* Fonction(s) */
| FUN fl=separated_nonempty_list(AND_KW, fundef) {
RecFunctions(fl)
}
@ -156,10 +143,6 @@ fundef:
/********************************** PATTERN ***********************************/
/* à revoir éventuellement : PTaggedValue (et PRecord) est réécrite 4 fois, mais
* peut être qu'en utilisant des option, on pourrait diminuer le nombre de répétition.
* TODO : y'a environ 50 warnings ici, surtout au niveau du POr et PAnd */
branches:
| option(PIPE) b=separated_nonempty_list(PIPE, located(branch)) {
b
@ -180,14 +163,14 @@ simple_pattern:
| WILDCARD {
PWildcard
}
/* N-uplets ou parenthésage */
/* Parenthésage */
| LPAREN RPAREN {
PTuple([])
}
/* N-uplets */
| l=pattern_list {
match l with | [alone] -> Position.value alone | _ -> PTuple(l)
}
/* Annotation de type */
| p=located(simple_pattern) COLON ty=located(ty) {
PTypeAnnotation(p, ty)
@ -239,7 +222,6 @@ pattern_list:
* ty -> ty * [ ty ]
*/
simple_ty:
/* Application d'un constructeur de type */
| tc=type_constructor {
@ -303,13 +285,11 @@ simple_expression:
| i=located(var_identifier) tl=option(type_list) {
Variable(i, tl)
}
/* Annotation de type
* ( expr : type ) */
/* Annotation de type
* ( expr : type ) */
| LPAREN e=located(expression) COLON t=located(ty) RPAREN {
TypeAnnotation(e, t)
}
/* Tuple n = 0 - Construction d'un 0-uplet */
| LPAREN RPAREN {
Tuple([])
@ -345,20 +325,17 @@ expr_list:
mid_expression:
|e=simple_expression{
e
}
| e=simple_expression {
e
}
/* Field record */
| e=located(mid_expression) DOT l=located(label_identifier) tl=option(type_list) {
Field(e, l, tl)
}
/* 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 {
Apply(e1, e2)
@ -370,12 +347,10 @@ expression:
| e=mid_expression {
e
}
/* Sequence - Séquencement */
| e=located(expression) SEMICOLON e2=located(expression) {
Sequence([e;e2])
}
Sequence([e; e2])
}
/* Definition locale */
| vd=vdefinition_local SEMICOLON e=located(expression) {
Define(vd, e)
@ -384,7 +359,6 @@ expression:
| BACKSLASH p=located(pattern) ARROW e=located(expression) {
Fun(FunctionDefinition(p, e))
}
/* Operateurs binaires - Application infixe */
| e1=located(expression) b=binop e2=located(expression) {
Apply(
@ -400,8 +374,6 @@ expression:
e2
)
}
/* Analyse de motifs
* match (exp) {| ...| ... | ...} */
| MATCH LPAREN e=located(expression) RPAREN LBRACE b=branches RBRACE {
@ -421,7 +393,6 @@ expression:
ELSE LBRACE e3=located(expression) RBRACE {
IfThenElse(e1, e2, e3)
}
/* Affectation
* expr := expr */
| e1=located(expression) ASSIGN e2=located(expression) {
@ -447,7 +418,6 @@ expression:
LBRACE e3=located(expression) RBRACE {
For(var, e1, e2, e3)
}
/* Allocation
* ref expr */
| REF e=located(mid_expression) {
@ -472,7 +442,6 @@ constructor:
KId constr_id
}
type_constructor:
| type_con=ID {
TCon type_con
@ -483,7 +452,6 @@ label_identifier:
LId label
}
literal:
/* Entier positif */
| i=INT {
@ -499,6 +467,7 @@ literal:
}
/****************************** INLINE FUNCTIONS ******************************/
%inline binop:
| PLUS { "`+`" }
| MINUS { "`-`" }
@ -512,32 +481,6 @@ literal:
| INF_OP { "`<?`" }
| SUP_OP { "`>?`" }
// Utile pour le binop avec location :
// %inline binop:
// | loc=location(PLUS) { ("`+`", loc) }
// | loc=location(MINUS) { ("`-`", loc) }
// | loc=location(STAR) { ("`*`", loc) }
// | loc=location(SLASH) { ("`/`", loc) }
// | loc=location(D_AND) { ("`&&`", loc) }
// | loc=location(D_OR) { ("`||`", loc) }
// | loc=location(EQUAL_OP) { ("`=?`", loc) }
// | loc=location(INF_EQUAL_OP) { ("`<=?`", loc) }
// | loc=location(SUP_EQUAL_OP) { ("`>=?`", loc) }
// | loc=location(INF_OP) { ("`<?`", loc) }
// | loc=location(SUP_OP) { ("`>?`", loc) }
// /* On récupère juste la position de X */
// %inline location(X): X {
// Position.position (Position.with_poss $startpos $endpos None)
// }
// /* On transforme notre binop en variable located */
// %inline var_binop(X): x=X {
// Position.with_pos
// (snd x)
// (Variable (Position.with_pos (snd x) (Id (fst x)), None))
// }
%inline located(X): x=X {
Position.with_poss $startpos $endpos x
}