Commit 0df691c9 authored by POTTIER Francois's avatar POTTIER Francois

Instead of computing just a set of "futures" (the second part of an item's

right-hand side), compute a set of items (possibly coming from different
states).
parent b5cb07e8
...@@ -138,7 +138,7 @@ let items_current env = ...@@ -138,7 +138,7 @@ let items_current env =
would require wrapping it in an existential type. *) would require wrapping it in an existential type. *)
items current items current
let shift_item (prod, index) t = let shift_item ((prod, index) as item) t =
let rhs = rhs prod in let rhs = rhs prod in
let length = List.length rhs in let length = List.length rhs in
assert (0 < index && index <= length); assert (0 < index && index <= length);
...@@ -149,20 +149,17 @@ let shift_item (prod, index) t = ...@@ -149,20 +149,17 @@ let shift_item (prod, index) t =
let symbol = List.nth rhs index in let symbol = List.nth rhs index in
if xfirst symbol t then if xfirst symbol t then
(* This item can justify a shift transition along [t]. *) (* This item can justify a shift transition along [t]. *)
[ drop index rhs ] [ item ]
else else
(* This item cannot justify a shift transition along [t]. *) (* This item cannot justify a shift transition along [t]. *)
[] []
let shift_items items t futures =
List.fold_left (fun futures item ->
shift_item item t @ futures
) futures items
let rec investigate_terminal checkpoint t futures = let rec investigate_terminal checkpoint t futures =
match checkpoint with match checkpoint with
| Shifting (env, _, _) -> | Shifting (env, _, _) ->
shift_items (items_current env) t futures List.fold_left (fun futures item ->
shift_item item t @ futures
) futures (items_current env)
| AboutToReduce (_, prod) -> | AboutToReduce (_, prod) ->
investigate_terminal (resume checkpoint) t futures investigate_terminal (resume checkpoint) t futures
| HandlingError _ -> | HandlingError _ ->
...@@ -173,11 +170,7 @@ let rec investigate_terminal checkpoint t futures = ...@@ -173,11 +170,7 @@ let rec investigate_terminal checkpoint t futures =
assert false (* cannot happen *) assert false (* cannot happen *)
let investigate checkpoint = let investigate checkpoint =
(* Print what we have recognized so far. *) let () = match checkpoint with InputNeeded env -> P.print_env env | _ -> assert false in
Printf.fprintf stderr "Past:\n%!";
let env = match checkpoint with InputNeeded env -> env | _ -> assert false in
P.print_symbols (List.rev (past (items_current env)));
Printf.fprintf stderr "\n%!";
(* Let us analyse which tokens are accepted in this state. *) (* Let us analyse which tokens are accepted in this state. *)
let futures = let futures =
foreach_terminal_but_error (fun symbol futures -> foreach_terminal_but_error (fun symbol futures ->
...@@ -191,12 +184,9 @@ let investigate checkpoint = ...@@ -191,12 +184,9 @@ let investigate checkpoint =
investigate_terminal checkpoint t futures investigate_terminal checkpoint t futures
) [] ) []
in in
let futures = uniq compare_words (List.sort compare_words futures) in let futures = uniq compare_items (List.sort compare_items futures) in
Printf.fprintf stderr "Futures:\n%!"; Printf.fprintf stderr "Futures:\n%!";
List.iter (fun future -> List.iter P.print_item futures
P.print_symbols future;
Printf.fprintf stderr "\n%!"
) futures
(* The loop which drives the parser. At each iteration, we analyze a (* The loop which drives the parser. At each iteration, we analyze a
result produced by the parser, and act in an appropriate manner. *) result produced by the parser, and act in an appropriate manner. *)
...@@ -226,6 +216,7 @@ let rec loop lexbuf (checkpoint : int result) (result : int result) = ...@@ -226,6 +216,7 @@ let rec loop lexbuf (checkpoint : int result) (result : int result) =
Printf.fprintf stderr Printf.fprintf stderr
"At offset %d: syntax error.\n%!" "At offset %d: syntax error.\n%!"
(Lexing.lexeme_start lexbuf); (Lexing.lexeme_start lexbuf);
P.print_env env;
investigate checkpoint investigate checkpoint
| Accepted v -> | Accepted v ->
(* The parser has succeeded and produced a semantic value. Print it. *) (* The parser has succeeded and produced a semantic value. Print it. *)
......
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