Merge branch 'anri' of gaufre.informatique.univ-paris-diderot.fr:Anri/compilation-m1-2023 into anri
This commit is contained in:
commit
cd04e3c0fc
2 changed files with 38 additions and 52 deletions
|
@ -19,29 +19,26 @@
|
||||||
error msg (lex_join lexbuf.lex_start_p lexbuf.lex_curr_p)
|
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.
|
(* Fonction qui convertie une chaîne de caractère ascii en vrai caractère.
|
||||||
On en a besoin pour certains test *)
|
* Notamment les escapes : "\n" ou "\000" *)
|
||||||
(*)
|
let recup_char charac lexbuf =
|
||||||
let recup_char charac lexbuf =
|
let taille = String.length charac in
|
||||||
let taille = String.length charac in
|
match charac with
|
||||||
match charac with
|
| "\\n" -> Some '\n'
|
||||||
| "\\n" -> '\n'
|
| "\\r" -> Some '\r'
|
||||||
| "\\r" -> '\r'
|
| "\\t" -> Some '\t'
|
||||||
| "\\t" -> '\t'
|
| "\\\'" -> Some '\''
|
||||||
| "\\\'" -> '\''
|
| "\\\\" -> Some '\\'
|
||||||
| "\\\\" -> '\\'
|
| _ -> (
|
||||||
| _ ->
|
let s2 = String.get charac 1 in
|
||||||
(let s2 = String.get charac 1 in
|
if s2 = '0' || s2 = '1' || s2 = '2' then (
|
||||||
if s2 = '0' || s2 = '1' || s2 = '2' then
|
let s = String.sub charac 1 (taille - 1) in
|
||||||
(let s=String.sub charac 1 (taille - 1) in
|
let i = int_of_string s in
|
||||||
let i = int_of_string s in
|
Some (Char.chr i))
|
||||||
Char.chr i)
|
else None )
|
||||||
else error lexbuf )
|
|
||||||
*)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let newline = ('\010' | '\013' | "\013\010")
|
let newline = ('\010' | '\013' | "\013\010")
|
||||||
let blank = [' ' '\009' '\012']
|
let blank = [' ' '\009' '\012']
|
||||||
|
|
||||||
|
@ -141,9 +138,9 @@ rule token = parse
|
||||||
| ">?" { SUP_OP }
|
| ">?" { SUP_OP }
|
||||||
|
|
||||||
(** Identificateurs *)
|
(** Identificateurs *)
|
||||||
| ident as s { ID s }
|
| ident as s { ID s }
|
||||||
| type_variable as s { TID s }
|
| type_variable as s { TID s }
|
||||||
| constr_id as s { CID s }
|
| constr_id as s { CID s }
|
||||||
|
|
||||||
(* Integers *)
|
(* Integers *)
|
||||||
| int as i { INT (Mint.of_string i) }
|
| int as i { INT (Mint.of_string i) }
|
||||||
|
@ -152,17 +149,16 @@ rule token = parse
|
||||||
| '"' { read_string (Buffer.create 16) lexbuf }
|
| '"' { read_string (Buffer.create 16) lexbuf }
|
||||||
|
|
||||||
(* Characters *)
|
(* Characters *)
|
||||||
| "'" (letter as c) "'" { CHAR c }
|
| "'" (letter as c) "'" { CHAR c }
|
||||||
(*| "'" (atom as c) "'" {CHAR (recup_char c lexbuf )} (* On retire le \ du début
|
| "'" (atom as a) "'" { match recup_char a lexbuf with
|
||||||
* TODO: fix *)
|
| Some c -> CHAR c
|
||||||
(*)
|
| None -> error lexbuf None "" }
|
||||||
let code = int_of_string (String.sub c 1 ((String.length c) - 2))
|
|
||||||
in CHAR (Char.chr (code)) } *) *)
|
|
||||||
|
|
||||||
(** Lexing error *)
|
(** 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 "" }
|
| "'" 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 *)
|
(* TODO: Gérer les imbrications de commentaires *)
|
||||||
and commentary = parse
|
and commentary = parse
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
%{ (* -*- tuareg -*- *)
|
%{ (* -*- tuareg -*- *)
|
||||||
|
|
||||||
open HopixAST
|
open HopixAST
|
||||||
(* open Position *)
|
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
@ -16,12 +15,9 @@
|
||||||
%token<char> CHAR
|
%token<char> CHAR
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%start<HopixAST.t> program
|
%start<HopixAST.t> program
|
||||||
|
|
||||||
/* TODO: Résoudre tout les shift/reduce conflits */
|
/* TODO: Résoudre tout les shift/reduce conflits */
|
||||||
|
|
||||||
%left FUN
|
%left FUN
|
||||||
%left STRING
|
%left STRING
|
||||||
%left INT
|
%left INT
|
||||||
|
@ -33,12 +29,9 @@
|
||||||
%left LPAREN
|
%left LPAREN
|
||||||
%left BACKSLASH
|
%left BACKSLASH
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%left EXCLA COLON
|
%left EXCLA COLON
|
||||||
|
|
||||||
/* priorités binop */
|
/* Priorités binop */
|
||||||
|
|
||||||
%left D_OR
|
%left D_OR
|
||||||
%left D_AND
|
%left D_AND
|
||||||
%left EQUAL_OP INF_EQUAL_OP INF_OP SUP_EQUAL_OP SUP_OP
|
%left EQUAL_OP INF_EQUAL_OP INF_OP SUP_EQUAL_OP SUP_OP
|
||||||
|
@ -338,16 +331,13 @@ expression:
|
||||||
}
|
}
|
||||||
/* Sequence - Séquencement *
|
/* Sequence - Séquencement *
|
||||||
* Pas sûr, voir s'il ne faut pas une troisième couche d'expression */
|
* Pas sûr, voir s'il ne faut pas une troisième couche d'expression */
|
||||||
|
|
||||||
| e=located(simple_expression)
|
| e=located(simple_expression)
|
||||||
SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(simple_expression)) {
|
SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(simple_expression)) {
|
||||||
Sequence(e :: e_list)
|
Sequence(e :: e_list)
|
||||||
}
|
}
|
||||||
/*
|
/* | e1=located(expression) SEMICOLON e2=located(expression) {
|
||||||
|e1=located(expression) SEMICOLON e2=located(expression){
|
Sequence([e1; e2])
|
||||||
Sequence([e1;e2])
|
} */
|
||||||
}*/
|
|
||||||
|
|
||||||
/* Definition locale */
|
/* Definition locale */
|
||||||
| vd=vdefinition SEMICOLON e=located(expression) {
|
| vd=vdefinition SEMICOLON e=located(expression) {
|
||||||
Define(vd, e)
|
Define(vd, e)
|
||||||
|
|
Reference in a new issue