From ca5b578afa6cc1562bb1ec8b246e87f8a16d72a1 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 23 Oct 2023 19:09:56 +0200 Subject: [PATCH 1/2] recup_char should work? --- flap/src/hopix/hopixLexer.mll | 58 ++++++++++++++++------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/flap/src/hopix/hopixLexer.mll b/flap/src/hopix/hopixLexer.mll index ce3a926..3ecb07c 100644 --- a/flap/src/hopix/hopixLexer.mll +++ b/flap/src/hopix/hopixLexer.mll @@ -19,29 +19,26 @@ error msg (lex_join lexbuf.lex_start_p lexbuf.lex_curr_p) - (*Fonction qui va convertir une string de caractère ascii en vrai caractère. -On en a besoin pour certains test *) -(*) -let recup_char charac lexbuf = -let taille = String.length charac in - match charac with - | "\\n" -> '\n' - | "\\r" -> '\r' - | "\\t" -> '\t' - | "\\\'" -> '\'' - | "\\\\" -> '\\' - | _ -> - (let s2 = String.get charac 1 in - if s2 = '0' || s2 = '1' || s2 = '2' then - (let s=String.sub charac 1 (taille - 1) in - let i = int_of_string s in - Char.chr i) - else error lexbuf ) -*) + (* Fonction qui convertie une chaîne de caractère ascii en vrai caractère. + * Notamment les escapes : "\n" ou "\000" *) + let recup_char charac lexbuf = + let taille = String.length charac in + match charac with + | "\\n" -> Some '\n' + | "\\r" -> Some '\r' + | "\\t" -> Some '\t' + | "\\\'" -> Some '\'' + | "\\\\" -> Some '\\' + | _ -> ( + let s2 = String.get charac 1 in + if s2 = '0' || s2 = '1' || s2 = '2' then ( + let s = String.sub charac 1 (taille - 1) in + let i = int_of_string s in + Some (Char.chr i)) + else None ) } - let newline = ('\010' | '\013' | "\013\010") let blank = [' ' '\009' '\012'] @@ -141,9 +138,9 @@ rule token = parse | ">?" { SUP_OP } (** Identificateurs *) - | ident as s { ID s } - | type_variable as s { TID s } - | constr_id as s { CID s } + | ident as s { ID s } + | type_variable as s { TID s } + | constr_id as s { CID s } (* Integers *) | int as i { INT (Mint.of_string i) } @@ -152,17 +149,16 @@ rule token = parse | '"' { read_string (Buffer.create 16) lexbuf } (* Characters *) - | "'" (letter as c) "'" { CHAR c } - (*| "'" (atom as c) "'" {CHAR (recup_char c lexbuf )} (* On retire le \ du début - * TODO: fix *) - (*) - let code = int_of_string (String.sub c 1 ((String.length c) - 2)) - in CHAR (Char.chr (code)) } *) *) + | "'" (letter as c) "'" { CHAR c } + | "'" (atom as a) "'" { match recup_char a lexbuf with + | Some c -> CHAR c + | None -> error lexbuf None "" } (** Lexing error *) - (* erreur qui advient pour le test 22-char-literal, le code renvoie bizarrement que "Error (during lexing) "*) + (* erreur qui advient pour le test 22-char-literal, + * le code renvoie bizarrement que "Error (during lexing)" *) | "'" ascii_trop_grand "'" { error lexbuf None "" } - | _ as _c { error lexbuf None (* (Some _c) *) "unexpected character." } + | _ as _c { error lexbuf None (* (Some _c) *) "unexpected character." } (* TODO: Gérer les imbrications de commentaires *) and commentary = parse From ede3bcd07cdf28722c6fdc9975c3de88a28173b9 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 23 Oct 2023 19:22:02 +0200 Subject: [PATCH 2/2] fmt --- flap/src/hopix/hopixParser.mly | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/flap/src/hopix/hopixParser.mly b/flap/src/hopix/hopixParser.mly index c36d05c..20f3868 100644 --- a/flap/src/hopix/hopixParser.mly +++ b/flap/src/hopix/hopixParser.mly @@ -1,7 +1,6 @@ %{ (* -*- tuareg -*- *) open HopixAST - (* open Position *) %} @@ -16,29 +15,23 @@ %token CHAR - - %start program /* TODO: Résoudre tout les shift/reduce conflits */ - %left FUN -%left STRING +%left STRING %left INT -%right WHILE REF DO +%right WHILE REF DO %left LET MATCH IF FOR -%right ARROW -%right SEMICOLON -%left ASSIGN +%right ARROW +%right SEMICOLON +%left ASSIGN %left LPAREN %left BACKSLASH +%left EXCLA COLON - -%left EXCLA COLON - -/* priorités binop */ - +/* Priorités binop */ %left D_OR %left D_AND %left EQUAL_OP INF_EQUAL_OP INF_OP SUP_EQUAL_OP SUP_OP @@ -123,7 +116,7 @@ vdefinition: /* Valeur simple */ | LET i=located(identifier) ts=option(vdef_type_scheme) EQUAL e=located(expression) %prec let1 { - SimpleValue(i, ts, e) + SimpleValue(i, ts, e) } /* Fonction(s) * Exemple : @@ -332,16 +325,13 @@ expression: } /* Sequence - Séquencement * * Pas sûr, voir s'il ne faut pas une troisième couche d'expression */ - | e=located(simple_expression) SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(simple_expression)) { Sequence(e :: e_list) } - /* - |e1=located(expression) SEMICOLON e2=located(expression){ - Sequence([e1;e2]) - }*/ - +/* | e1=located(expression) SEMICOLON e2=located(expression) { + Sequence([e1; e2]) + } */ /* Definition locale */ | vd=vdefinition SEMICOLON e=located(expression) { Define(vd, e)