This commit is contained in:
Mylloon 2023-10-21 12:44:40 +02:00
parent 4d08e97bd8
commit 48a9b8b23d
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -6,7 +6,7 @@
%}
%token EOF LET TYPE WILDCARD ARROW COLON EXTERN FUN COMMA AND EQUAL LPAREN
%token RPAREN LBRACK RBRACK LBRACE RBRACE INFERIOR SUPERIOR BINOP DO ELSE FOR
%token RPAREN LBRACK RBRACK LBRACE RBRACE INFERIOR SUPERIOR DO ELSE FOR
%token FROM IF MATCH PIPE REF THEN TO UNTIL WHILE AND_KW DOT SEMICOLON BACKSLASH
%token ASSIGN EXCLA
%token PLUS MINUS STAR SLASH D_AND D_OR EQUAL_OP INF_EQUAL_OP SUP_EQUAL_OP INF_OP SUP_OP
@ -17,7 +17,7 @@
%start<HopixAST.t> program
%right PIPE
/* TODO: Résoudre tout les shift/reduce conflits */
%%
@ -316,8 +316,29 @@ expression:
Apply(e1, e2)
}
/* Operateurs binaires - Application infixe */
/* | e1=located(expression) b=binop e2=located(expression) {
Apply(Apply(b, e1), e2)
| e1=located(expression) b=binop e2=located(expression) {
Apply(
Position.unknown_pos (Apply(
Position.unknown_pos (
Variable (
Position.unknown_pos (Id b),
None
)
),
e1
)),
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) {| ...| ... | ...} */
@ -427,18 +448,43 @@ identifier:
%inline binop:
/* | loc=located(PLUS) { ("`+`",loc) } */
| MINUS { "`-`" }
| STAR { "`*`" }
| SLASH { "`/`" }
| D_AND { "`&&`" }
| D_OR { "`||`" }
| EQUAL_OP { "`=?`" }
| PLUS { "`+`" }
| MINUS { "`-`" }
| STAR { "`*`" }
| SLASH { "`/`" }
| D_AND { "`&&`" }
| D_OR { "`||`" }
| EQUAL_OP { "`=?`" }
| INF_EQUAL_OP { "`<=?`" }
| SUP_EQUAL_OP { "`>=?`" }
| INF_OP { "`<?`" }
| SUP_OP { "`>?`" }
| 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