Commit 193ce7a7 authored by POTTIER Francois's avatar POTTIER Francois

Modified LRijkstra to produce a .messages file. Verbose (includes closure).

parent 5da0686b
......@@ -1135,19 +1135,21 @@ let data : (Nonterminal.t * W.word * Lr1.node) list ref =
let reachable =
ref Lr1.NodeSet.empty
(* [display] displays one data item. *)
(* [display] displays one data item. The format is that of a [.messages]
file, which the user can then edit to customize the error messages. *)
let display (nt, w, s') =
let display (nt, w, s') : unit =
(* Print the sentence, followed with a few comments, followed with a
blank line, followed with a proposed error message, followed with
another blank line. *)
Printf.printf
"An error in state %d can be obtained as follows.\n\
Start symbol: %s\n\
Input length: %d\n\
Input sentence:\n\
%s\n\n%!"
(Lr1.number s')
"%s: %s\n# Length: %d\n# Leads to an error in state: %d.\n%s\n%s\n\n"
(Nonterminal.print false nt)
(W.length w)
(W.print w)
(W.length w)
(Lr1.number s')
(Lr0.print_closure "# " (Lr1.state s'))
"Syntax error."
(* Perform the forward search. *)
......
......@@ -244,21 +244,24 @@ let export (k, toksr) =
(* Displaying a concrete state. *)
let print_concrete (state : concretelr1state) =
let print_concrete leading (state : concretelr1state) =
let buffer = Buffer.create 1024 in
Item.Map.iter (fun item toks ->
Printf.bprintf buffer "%s[ %s ]\n" (Item.print item) (TerminalSet.print toks)
Printf.bprintf buffer "%s%s[ %s ]\n"
leading
(Item.print item)
(TerminalSet.print toks)
) state;
Buffer.contents buffer
(* Displaying a state. By default, only the kernel is displayed, not
the closure. *)
let print state =
print_concrete (export state)
let print leading state =
print_concrete leading (export state)
let print_closure state =
print_concrete (closure (export state))
let print_closure leading state =
print_concrete leading (closure (export state))
(* The core of an LR(1) state is the underlying LR(0) state. *)
......
......@@ -107,13 +107,12 @@ val union: lr1state -> lr1state -> lr1state
val restrict: TerminalSet.t -> lr1state -> lr1state
(* Displaying a concrete state. *)
val print_concrete: concretelr1state -> string
(* Displaying a state. By default, only the kernel is displayed, not
the closure. *)
val print: lr1state -> string
val print_closure: lr1state -> string
(* The following functions display: 1- a concrete state; 2- a state
(only the kernel, not the closure); 3- the closure of a state.
The first parameter is a fixed string that is added at the
beginning of every line. *)
val print_concrete: string -> concretelr1state -> string
val print: string -> lr1state -> string
val print_closure: string -> lr1state -> string
......@@ -75,7 +75,7 @@ let follow_transition (again : bool) (source : node) (symbol : Symbol.t) (state
(if again then "Re-examining" else "Examining")
source.raw_number
(Symbol.print symbol)
(Lr0.print_closure state)
(Lr0.print_closure "" state)
let follow_state (msg : string) (node : node) (print : bool) =
if Settings.follow then
......@@ -83,7 +83,7 @@ let follow_state (msg : string) (node : node) (print : bool) =
"%s: r%d.\n%s\n"
msg
node.raw_number
(if print then Lr0.print_closure node.state else "")
(if print then Lr0.print_closure "" node.state else "")
(* ------------------------------------------------------------------------ *)
......@@ -714,34 +714,34 @@ let out =
(* ------------------------------------------------------------------------ *)
(* If requested, dump a verbose description of the automaton. *)
let describe out node =
Printf.fprintf out "State %d%s:\n%s"
node.number
(if Settings.follow then Printf.sprintf " (r%d)" node.raw_number else "")
(Lr0.print "" node.state);
SymbolMap.iter (fun symbol node ->
Printf.fprintf out "-- On %s shift to state %d\n"
(Symbol.print symbol) node.number
) node.transitions;
TerminalMap.iter (fun tok prods ->
List.iter (fun prod ->
(* TEMPORARY factoriser les symboles qui conduisent a reduire une meme production *)
Printf.fprintf out "-- On %s " (Terminal.print tok);
match Production.classify prod with
| Some nt ->
Printf.fprintf out "accept %s\n" (Nonterminal.print false nt)
| None ->
Printf.fprintf out "reduce production %s\n" (Production.print prod)
) prods
) node.reductions;
if not (TerminalSet.is_empty node.conflict_tokens) then
Printf.fprintf out "** Conflict on %s\n" (TerminalSet.print node.conflict_tokens);
Printf.fprintf out "\n%!"
let () =
Time.tick "Construction of the LR(1) automaton";
if Settings.dump then begin
fold (fun () node ->
let out = Lazy.force out in
Printf.fprintf out "State %d%s:\n%s"
node.number
(if Settings.follow then Printf.sprintf " (r%d)" node.raw_number else "")
(Lr0.print node.state);
SymbolMap.iter (fun symbol node ->
Printf.fprintf out "-- On %s shift to state %d\n"
(Symbol.print symbol) node.number
) node.transitions;
TerminalMap.iter (fun tok prods ->
List.iter (fun prod ->
(* TEMPORARY factoriser les symboles qui conduisent a reduire une meme production *)
Printf.fprintf out "-- On %s " (Terminal.print tok);
match Production.classify prod with
| Some nt ->
Printf.fprintf out "accept %s\n" (Nonterminal.print false nt)
| None ->
Printf.fprintf out "reduce production %s\n" (Production.print prod)
) prods
) node.reductions;
if not (TerminalSet.is_empty node.conflict_tokens) then
Printf.fprintf out "** Conflict on %s\n" (TerminalSet.print node.conflict_tokens);
Printf.fprintf out "\n%!"
) ();
iter (describe (Lazy.force out));
Time.tick "Dumping the LR(1) automaton"
end
......
......@@ -139,7 +139,7 @@ let count_slr_violations () : int =
Printf.fprintf
stderr
"The following SLR(1) state has a conflict:\n%s"
(Lr0.print_concrete s)
(Lr0.print_concrete "" s)
end
done;
......
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