Commit 17305d1a authored by POTTIER Francois's avatar POTTIER Francois

Extend [TABLE] so that the Engine has access to [maybe_goto_nt],

which allows testing for the existence of an outgoing transition
in the goto table.
parent 7e56637d
......@@ -206,11 +206,16 @@ module type TABLE = sig
and a nonterminal symbol to a new state. By extension, it also maps a
pair of a state and a production to a new state. *)
(* This function can be applied to [s] and [nt] ONLY if the state [s] has
an outgoing transition labeled [nt]. Otherwise, its result is undefined. *)
val goto_nt : state -> nonterminal -> state
val goto_prod: state -> production -> state
(* The function [goto_nt] can be applied to [s] and [nt] ONLY if the state
[s] has an outgoing transition labeled [nt]. Otherwise, its result is
undefined. Similarly, the call [goto_prod prod s] is permitted ONLY if
the state [s] has an outgoing transition labeled with the nonterminal
symbol [lhs prod]. The function [maybe_goto_nt] involves an additional
dynamic check and CAN be called even if there is no outgoing transition. *)
val goto_nt : state -> nonterminal -> state
val goto_prod: state -> production -> state
val maybe_goto_nt: state -> nonterminal -> state option
(* [is_start prod] tells whether the production [prod] is a start production. *)
......
......@@ -97,6 +97,13 @@ module Make (T : TableFormat.TABLES)
let goto_prod state prod =
goto_nt state (PackedIntArray.get T.lhs prod)
let maybe_goto_nt state nt =
let code = unmarshal2 T.goto state nt in
(* If [code] is 0, there is no outgoing transition.
If [code] is [1 + state], there is a transition towards [state]. *)
assert (0 <= code);
if code = 0 then None else Some (code - 1)
exception Error =
T.Error
......
......@@ -101,6 +101,12 @@ module T = struct
let goto_prod (s : state) (prod : production) : state =
goto_nt s (Production.nt prod)
let maybe_goto_nt (s : state) (nt : nonterminal) : state option =
try
Some (SymbolMap.find (Symbol.N nt) (Lr1.transitions s))
with Not_found ->
None
open MenhirLib.EngineTypes
exception Error
......
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