235/235 .
This commit is contained in:
parent
885f2e0790
commit
ec792fd40d
1 changed files with 45 additions and 65 deletions
|
@ -18,6 +18,7 @@
|
|||
%start<HopixAST.t> program
|
||||
|
||||
/* TODO: Résoudre tout les shift/reduce conflits */
|
||||
%right lparen1
|
||||
%left LPAREN
|
||||
%left let1
|
||||
|
||||
|
@ -44,6 +45,7 @@
|
|||
%left PLUS MINUS
|
||||
%left SLASH STAR
|
||||
|
||||
%left local_def1
|
||||
%left ref1
|
||||
%left fun1
|
||||
%left app1
|
||||
|
@ -118,17 +120,28 @@ label_with_type:
|
|||
l, t
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
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) %prec let1 {
|
||||
EQUAL e=located(expression) {
|
||||
SimpleValue(i, ts, e)
|
||||
}
|
||||
/* Fonction(s)
|
||||
* Exemple :
|
||||
* - fun : int f a = 1
|
||||
* - fun f a = 1 and : int g a = 2 */
|
||||
/* Fonction(s) */
|
||||
|
||||
| FUN fl=separated_nonempty_list(AND_KW, fundef) {
|
||||
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) {
|
||||
RecFunctions(fl)
|
||||
}
|
||||
|
@ -224,6 +237,8 @@ pattern_list:
|
|||
* ty -> ty STAR separated_nonempty_list(STAR, located(ty))
|
||||
* ty -> ty * [ ty ]
|
||||
*/
|
||||
|
||||
|
||||
simple_ty:
|
||||
/* Application d'un constructeur de type */
|
||||
| tc=type_constructor {
|
||||
|
@ -287,15 +302,12 @@ simple_expression:
|
|||
| i=located(var_identifier) tl=option(type_list) {
|
||||
Variable(i, tl)
|
||||
}
|
||||
|
||||
/* Annotation de type
|
||||
* ( expr : type ) */
|
||||
| LPAREN e=located(expression) COLON t=located(ty) RPAREN {
|
||||
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 */
|
||||
| LPAREN RPAREN {
|
||||
|
@ -319,6 +331,7 @@ simple_expression:
|
|||
Read(e)
|
||||
}
|
||||
|
||||
|
||||
type_list:
|
||||
| INFERIOR tl=separated_list(COMMA, located(ty)) SUPERIOR {
|
||||
tl
|
||||
|
@ -328,6 +341,7 @@ expr_list:
|
|||
| LPAREN el=separated_nonempty_list(COMMA, located(expression)) RPAREN {
|
||||
el
|
||||
}
|
||||
|
||||
|
||||
mid_expression:
|
||||
|e=simple_expression{
|
||||
|
@ -343,52 +357,36 @@ mid_expression:
|
|||
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 {
|
||||
Apply(e1, e2)
|
||||
}
|
||||
|
||||
| const=located(constructor) tl=option(type_list) el=optionlist(expr_list) {
|
||||
Tagged(const, tl, el)
|
||||
}
|
||||
|
||||
|
||||
expression:
|
||||
| e=mid_expression {
|
||||
e
|
||||
}
|
||||
/* Field - Projection d’un 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 */
|
||||
|
||||
/*
|
||||
| e=located(mid_expression)
|
||||
SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(mid_expression)) {
|
||||
Sequence(e :: e_list)
|
||||
}*/
|
||||
|
||||
| e=located(expression) SEMICOLON e2=located(expression){
|
||||
/* Sequence - Séquencement */
|
||||
| e=located(expression) SEMICOLON e2=located(expression) {
|
||||
Sequence([e;e2])
|
||||
}
|
||||
/* | e1=located(expression) SEMICOLON e2=located(expression) {
|
||||
Sequence([e1; e2])
|
||||
} */
|
||||
|
||||
/* Definition locale */
|
||||
| vd=vdefinition SEMICOLON e=located(expression) {
|
||||
| vd=vdefinition_local SEMICOLON e=located(expression) {
|
||||
Define(vd, e)
|
||||
}
|
||||
/* Fonction anonyme */
|
||||
| BACKSLASH p=located(pattern) ARROW e=located(expression) {
|
||||
Fun(FunctionDefinition(p, e))
|
||||
}
|
||||
/* Application */
|
||||
/*
|
||||
| e1=located(expression) e2=located(expression) %prec app1 {
|
||||
Apply(e1, e2)
|
||||
}
|
||||
|
||||
/* Operateurs binaires - Application infixe */
|
||||
| e1=located(expression) b=binop e2=located(expression) {
|
||||
|
@ -405,16 +403,8 @@ expression:
|
|||
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
|
||||
* match (exp) {| ...| ... | ...} */
|
||||
| MATCH LPAREN e=located(expression) RPAREN LBRACE b=branches RBRACE {
|
||||
|
@ -434,11 +424,7 @@ expression:
|
|||
ELSE LBRACE e3=located(expression) RBRACE {
|
||||
IfThenElse(e1, e2, e3)
|
||||
}
|
||||
/* Reference - Allocation
|
||||
* ref expr */
|
||||
| REF e=located(simple_expression) {
|
||||
Ref(e)
|
||||
}
|
||||
|
||||
/* Affectation
|
||||
* expr := expr */
|
||||
| e1=located(expression) ASSIGN e2=located(expression) {
|
||||
|
@ -464,19 +450,13 @@ expression:
|
|||
LBRACE e3=located(expression) RBRACE {
|
||||
For(var, e1, e2, e3)
|
||||
}
|
||||
/* Parenthésage
|
||||
* Pas sûr mais je vois pas sinon */
|
||||
|
||||
/*
|
||||
| LPAREN e=expression RPAREN {
|
||||
e
|
||||
}*/
|
||||
/* Annotation de type
|
||||
* (e : ty) */
|
||||
/*
|
||||
| LPAREN e=located(expression) COLON t=located(ty) RPAREN {
|
||||
TypeAnnotation(e, t)
|
||||
/* allocation
|
||||
* ref expr */
|
||||
| REF e=located(mid_expression) {
|
||||
Ref(e)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/******************************** BASIC TYPES *********************************/
|
||||
|
|
Reference in a new issue