Commit 53f9ac83 authored by POTTIER Francois's avatar POTTIER Francois

Updated [Dot] to support node shapes. Updated [AutomatonGraph] to...

Updated [Dot] to support node shapes. Updated [AutomatonGraph] to double-circle nodes with a reduction.
parent 923c1828
......@@ -9,7 +9,7 @@ module G = struct
Lr1.node
let number s : string =
string_of_int (Lr1.number s)
Printf.sprintf "%02d" (Lr1.number s)
let name s =
Printf.sprintf "s%s" (number s)
......@@ -19,9 +19,19 @@ module G = struct
action ~label:(Symbol.print symbol) s'
)
let iter (action: ?style:Dot.style -> label:string -> vertex -> unit) : unit =
let iter (action: ?shape:Dot.shape -> ?style:Dot.style -> label:string -> vertex -> unit) : unit =
Lr1.iter (fun s ->
action ~label:(number s) s
let has_reduction =
match Invariant.has_default_reduction s with
| Some _ ->
true
| None ->
not (TerminalMap.is_empty (Lr1.reductions s))
in
let shape =
if has_reduction then Dot.DoubleCircle else Dot.Circle
in
action ~shape ~label:(number s) s
)
end
......@@ -32,6 +42,6 @@ let filename =
let () =
let c = open_out filename in
let module P = Dot.Print(G) in
P.print ~orientation:Dot.Portrait ~size:(8.,5.) c;
P.print ~orientation:Dot.Portrait ~ratio:Dot.Compress ~size:(5.,5.) c;
close_out c
......@@ -36,6 +36,13 @@ type style =
| Diagonals
| Rounded
type shape =
| Box
| Oval
| Circle
| DoubleCircle
(* there are many others, let's stop here *)
(* ------------------------------------------------------------------------- *)
(* Basic printers. *)
......@@ -65,6 +72,23 @@ let print_style = function
in
sprintf ", style = %s" style
let print_shape = function
| None ->
""
| Some shape ->
let shape =
match shape with
| Box ->
"box"
| Oval ->
"oval"
| Circle ->
"circle"
| DoubleCircle ->
"doublecircle"
in
sprintf ", shape = %s" shape
(* ------------------------------------------------------------------------- *)
(* The graph printer. *)
......@@ -77,7 +101,7 @@ module Print (G : sig
val successors: (?style:style -> label:string -> vertex -> unit) -> vertex -> unit
val iter: (?style:style -> label:string -> vertex -> unit) -> unit
val iter: (?shape:shape -> ?style:style -> label:string -> vertex -> unit) -> unit
end) = struct
......@@ -115,15 +139,17 @@ end) = struct
fprintf f "ratio = auto;\n"
end;
G.iter (fun ?style ~label vertex ->
fprintf f "%s [ label=\"%s\"%s ] ;\n"
G.iter (fun ?shape ?style ~label vertex ->
fprintf f "%s [ label=\"%s\"%s%s ] ;\n"
(G.name vertex)
label
(print_style style)
(print_shape shape)
);
G.iter (fun ?style ~label source ->
ignore style; (* avoid unused variable warnings *)
G.iter (fun ?shape ?style ~label source ->
ignore shape; (* avoid unused variable warnings *)
ignore style;
ignore label;
G.successors (fun ?style ~label destination ->
fprintf f "%s %s %s [ label=\"%s\"%s ] ;\n"
......
......@@ -38,6 +38,13 @@ type style =
| Diagonals
| Rounded
type shape =
| Box
| Oval
| Circle
| DoubleCircle
(* there are many others, let's stop here *)
(* ------------------------------------------------------------------------- *)
(* The graph printer. *)
......@@ -50,7 +57,7 @@ module Print (G : sig
val successors: (?style:style -> label:string -> vertex -> unit) -> vertex -> unit
val iter: (?style:style -> label:string -> vertex -> unit) -> unit
val iter: (?shape:shape -> ?style:style -> label:string -> vertex -> unit) -> unit
end) : sig
......
......@@ -837,7 +837,7 @@ let () =
NonterminalSet.iter (fun successor ->
f ~label:"" successor
) forward.(nt)
let iter (f : ?style:Dot.style -> label:string -> vertex -> unit) =
let iter (f : ?shape:Dot.shape -> ?style:Dot.style -> label:string -> vertex -> unit) =
Nonterminal.iter (fun nt ->
f ~label:(Nonterminal.print false nt) nt
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment