Commit aea80b11 authored by POTTIER Francois's avatar POTTIER Francois

New functions [transition_tokens] and [reduction_tokens] in Lr0.

parent 5580435d
......@@ -371,6 +371,16 @@ let transition
in
(k, Array.map (interpret state) sr)
(* [transition_tokens transitions] returns the set of tokens (terminal symbols)
that are labels of outgoing transitions in the table [transitions]. *)
let transition_tokens transitions =
SymbolMap.fold (fun symbol _target toks ->
match symbol with
| Symbol.T tok -> TerminalSet.add tok toks
| Symbol.N _ -> toks
) transitions TerminalSet.empty
(* Equality of states. *)
let equal ((k1, toksr1) as state1) ((k2, toksr2) as state2) =
......@@ -636,6 +646,14 @@ let reductions_table state =
add_reductions prod toks reductions
) TerminalMap.empty (reductions state)
(* [reduction_tokens reductions] returns the domain of the reductions table
[table], in the form of a set of tokens. *)
let reduction_tokens reductions =
TerminalMap.fold (fun tok _prods toks ->
TerminalSet.add tok toks
) reductions TerminalSet.empty
(* This inverts a mapping of tokens to productions into a mapping of
productions to sets of tokens. *)
......
......@@ -85,6 +85,11 @@ val start: node -> lr1state
val transitions: lr1state -> lr1state SymbolMap.t
val transition: Symbol.t -> lr1state -> lr1state
(* [transition_tokens transitions] returns the set of tokens (terminal symbols)
that are labels of outgoing transitions in the table [transitions]. *)
val transition_tokens: 'target SymbolMap.t -> TerminalSet.t
(* Information about the reductions at a state. *)
(* See also [reductions_table] further on. *)
......@@ -169,6 +174,11 @@ val reductions_table: lr1state -> reductions
val invert : reductions -> TerminalSet.t ProductionMap.t
(* [reduction_tokens reductions] returns the domain of the reductions table
[table], in the form of a set of tokens. *)
val reduction_tokens: reductions -> TerminalSet.t
(* [has_eos_conflict transitions reductions] tells whether a state has
an end-of-stream conflict, that is, a reduction action on [#] and
at least one other (shift or reduce) action. *)
......
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