Commit 92fd60c4 authored by POTTIER Francois's avatar POTTIER Francois

Enrich the signature [TABLE] so the Engine has access to [goto_nt] and [goto_prod]

instead of just [goto_prod] (which previously was named [goto]).
At this point, [goto_nt] is unused by the Engine (which knows nothing about nonterminal
symbols anyway). It could be used in the future to implement functions that force
transitions and reductions to take place.
parent bdf78ec6
......@@ -253,7 +253,7 @@ module Make (T : TABLE) = struct
by consulting the goto table at the return state and at
production [prod]. *)
let current = T.goto stack.state prod in
let current = T.goto_prod stack.state prod in
let env = { env with stack; current } in
run env false
......
......@@ -113,6 +113,10 @@ module type TABLE = sig
type terminal
(* The type of nonterminal symbols. *)
type nonterminal
(* The type of semantic values. *)
type semantic_value
......@@ -198,13 +202,15 @@ module type TABLE = sig
('env -> 'answer) ->
'env -> 'answer
(* This is the automaton's goto table. It maps a pair of a state and a
production to a new state.
(* This is the automaton's goto table. This table maps a pair of a state
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 convention is slightly different from the textbook approach. The
goto table is usually indexed by a state and a non-terminal symbol. *)
(* 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: state -> production -> state
val goto_nt : state -> nonterminal -> state
val goto_prod: state -> production -> state
(* [is_start prod] tells whether the production [prod] is a start production. *)
......@@ -370,4 +376,3 @@ module type ENGINE = sig
and type 'a checkpoint := 'a checkpoint
end
......@@ -26,6 +26,9 @@ module Make (T : TableFormat.TABLES)
type terminal =
int
type nonterminal =
int
type semantic_value =
Obj.t
......@@ -86,11 +89,14 @@ module Make (T : TableFormat.TABLES)
assert (c = 0);
fail env
let goto state prod =
let code = unmarshal2 T.goto state (PackedIntArray.get T.lhs prod) in
let goto_nt state nt =
let code = unmarshal2 T.goto state nt in
(* code = 1 + state *)
code - 1
let goto_prod state prod =
goto_nt state (PackedIntArray.get T.lhs prod)
exception Error =
T.Error
......@@ -167,4 +173,3 @@ module Make (T : TableFormat.TABLES)
end
end)
......@@ -33,6 +33,9 @@ module T = struct
type terminal =
Terminal.t
type nonterminal =
Nonterminal.t
type semantic_value =
cst
......@@ -89,12 +92,15 @@ module T = struct
with Not_found ->
fail env
let goto (s : state) (prod : production) : state =
let goto_nt (s : state) (nt : nonterminal) : state =
try
SymbolMap.find (Symbol.N (Production.nt prod)) (Lr1.transitions s)
SymbolMap.find (Symbol.N nt) (Lr1.transitions s)
with Not_found ->
assert false
let goto_prod (s : state) (prod : production) : state =
goto_nt s (Production.nt prod)
open MenhirLib.EngineTypes
exception Error
......@@ -369,4 +375,3 @@ let check_error_path log nt input =
in
loop (E.start entry Lexing.dummy_pos) []
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