Commit 5238c909 authored by POTTIER Francois's avatar POTTIER Francois

Construct the forward reference graph only if [--graph] was given.

parent 1091e03c
......@@ -709,13 +709,21 @@ module ProductionMap = struct
end
(* ------------------------------------------------------------------------ *)
(* Build the grammar's forward reference graph. This graph is unused, but
can be printed on demand. *)
(* If requested, build and print the forward reference graph of the grammar.
There is an edge of a nonterminal symbol [nt1] to every nonterminal symbol
[nt2] that occurs in the definition of [nt1]. *)
let forward : NonterminalSet.t array =
let () =
if Settings.graph then begin
(* Allocate. *)
let forward : NonterminalSet.t array =
Array.make Nonterminal.n NonterminalSet.empty
in
(* Populate. *)
let () =
Array.iter (fun (nt1, rhs) ->
Array.iter (function
| Symbol.T _ ->
......@@ -723,13 +731,10 @@ let () =
| Symbol.N nt2 ->
forward.(nt1) <- NonterminalSet.add nt2 forward.(nt1)
) rhs
) Production.table
) Production.table;
(* ------------------------------------------------------------------------ *)
(* If requested, dump the forward reference graph. *)
(* Print. *)
let () =
if Settings.graph then
let module P = Dot.Print (struct
type vertex = Nonterminal.t
let name nt =
......@@ -747,6 +752,8 @@ let () =
P.print f;
close_out f
end
(* ------------------------------------------------------------------------ *)
(* Support for analyses of the grammar, expressed as fixed point computations.
We exploit the generic fixed point algorithm in [Fix]. *)
......
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