From 48a9b8b23d2525c521f2cb61b09ce2200d519ea5 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 21 Oct 2023 12:44:40 +0200 Subject: [PATCH] opbin? --- flap/src/hopix/hopixParser.mly | 74 +++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/flap/src/hopix/hopixParser.mly b/flap/src/hopix/hopixParser.mly index 631b752..38df860 100644 --- a/flap/src/hopix/hopixParser.mly +++ b/flap/src/hopix/hopixParser.mly @@ -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 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 { "`?`" } +| INF_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) } + +// /* 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