Skip to content
Snippets Groups Projects
Commit 80a4e0c7 authored by Wilke Pierre's avatar Wilke Pierre
Browse files

Sujet parser + commentaires dans ast.ml

parent cc84f605
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -9,6 +9,7 @@ let id = letter (digit|letter|'_')*
rule token = parse
| [' ' '\t'] { token lexbuf }
| "//" { comment lexbuf }
| "/*" { comment_multiline lexbuf }
| '\n' { Lexing.new_line lexbuf; EOL }
| '{' { action 0 "" lexbuf }
| "->" { ARROW }
......@@ -29,3 +30,7 @@ and action level s = parse
and comment = parse
| '\n' { Lexing.new_line lexbuf; token lexbuf }
| _ { comment lexbuf }
and comment_multiline = parse
| '\n' { Lexing.new_line lexbuf; comment_multiline lexbuf }
| "*/" { token lexbuf }
| _ { comment_multiline lexbuf }
......@@ -19,7 +19,8 @@ let rec make_list l =
(* Return the list of elements of the rule. *)
let default_action (pl: string list) : string =
make_list (List.mapi (fun i e -> i) pl)
(* make_list (List.mapi (fun i e -> i) pl) *)
"()"
let resolve_vars s =
Str.global_replace (Str.regexp "\\$\\([0-9]+\\)") "p\\1" s
......
......@@ -29,11 +29,4 @@ axiom S
}
rules
S -> GLOBDEF SYM_EOF { Node (Tlistglobdef, [$1]) }
IDENTIFIER -> SYM_IDENTIFIER { StringLeaf ($1) }
INTEGER -> SYM_INTEGER { IntLeaf ($1) }
GLOBDEF -> IDENTIFIER SYM_LPARENTHESIS LPARAMS SYM_RPARENTHESIS INSTR {
let fargs = $3 in
let instr = $5 in
Node (Tfundef, [$1; Node (Tfunargs, fargs) ; instr ])
}
S -> GLOBDEF SYM_EOF { Node (Tlistglobdef, []) }
open Batteries
open BatPrintf
(* Les AST sont des arbres, du type [tree], étiquetés par des [tag].
Un arbre [tree] est soit un nœud [Node(t, children)] où [t] est un tag et
[children] une liste de sous-arbres ; soit une feuille qui contient une
chaîne de caractères ([StringLeaf]), un entier ([IntLeaf]), un caractère
([CharLeaf]), ou rien du tout ([NullLeaf]).
La signification des différents tags :
- importe peu : vous pouvez définir de nouveaux types de tags si ça vous
semble nécessaire / profitable, pour peu de compléter la fonction
[string_of_tag] ci-dessous.
- devrait être assez claire d'après le nom du tag ou l'utilisation qui en est
faite dans l'exemple donné dans le sujet.
- peut être demandée à votre encadrant de TP favori (ou celui présent en
séance, à défaut)
*)
type tag = Tassign | Tif | Twhile | Tblock | Treturn | Tprint
| Tint
| Tadd | Tmul | Tdiv | Tmod | Txor | Tsub
......@@ -9,7 +31,7 @@ type tag = Tassign | Tif | Twhile | Tblock | Treturn | Tprint
| Tlistglobdef
| Tfundef | Tfunname | Tfunargs | Tfunbody
| Tassignvar
| Targ | Targs
| Targ
type tree = | Node of tag * tree list
| StringLeaf of string
......@@ -52,9 +74,9 @@ let string_of_tag = function
| Tfunbody -> "Tfunbody"
| Tassignvar -> "Tassignvar"
| Targ -> "Targ"
| Targs -> "Targs"
(* return (node, nextnode, dotcode) *)
(* Écrit un fichier .dot qui correspond à un AST *)
let rec draw_ast a next =
match a with
| Node (t, l) ->
......
......@@ -335,7 +335,9 @@ let _ =
run "LTL" !ltl_run (exec_ltl_prog) ltl;
(if !ltl_debug then debug_ltl_prog input ltl !heapsize !params);
dump !riscv_dump dump_riscv_prog ltl (fun file () -> ignore (compile_rv basename file ()));
dump !riscv_dump dump_riscv_prog ltl (fun file () ->
add_to_report "riscv" "RISC-V" (Code (file_contents file));
ignore (compile_rv basename file ()));
if not !Options.nostart then begin
run "Risc-V" !riscv_run (exec_rv_prog ltl basename) !riscv_dump
end;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment