Commit db8f8d4a authored by POTTIER Francois's avatar POTTIER Francois

Modified the table [semantic_action] so that it no longer has entries

  for the start productions.
parent c5708e8c
......@@ -587,6 +587,9 @@ module Production = struct
let foldx f accu =
Misc.foldij start n f accu
let mapx f =
Misc.mapij start n f
(* Printing a production. *)
let print prod =
......
......@@ -300,6 +300,7 @@ module Production : sig
val iterx: (index -> unit) -> unit
val foldx: (index -> 'a -> 'a) -> 'a -> 'a
val mapx: (index -> 'a) -> 'a list
(* This maps a (user) non-terminal start symbol to the corresponding
start production. *)
......
......@@ -228,53 +228,39 @@ let reducebody prod =
) :: []
in
(* Is this is one of the start productions? *)
(* This cannot be one of the start productions. *)
assert (not (Production.is_start prod));
match Production.classify prod with
| Some nt ->
(* This is a start production. Raise [Accept]. *)
EComment (
sprintf "Accepting %s" (Nonterminal.print false nt),
blet (
[ pat, EVar stack ],
ERaise (EData ("Not_found", [])) (* TEMPORARY *)
)
)
| None ->
(* This is a regular production. Perform a reduction. *)
(* This is a regular production. Perform a reduction. *)
let action =
Production.action prod
in
let act =
EAnnot (Action.to_il_expr action, type2scheme (semvtypent nt))
in
let action =
Production.action prod
in
let act =
EAnnot (Action.to_il_expr action, type2scheme (semvtypent nt))
in
EComment (
Production.print prod,
blet (
(pat, EVar stack) :: (* destructure the stack *)
casts @ (* perform type casts *)
posbindings @ (* bind [startp] and [endp] *)
extrabindings action @ (* add bindings for the weird keywords *)
[ PVar semv, act ], (* run the user's code and bind [semv] *)
(* Return a new stack, onto which we have pushed a new stack cell. *)
ERecord [ (* the new stack cell *)
fstate, EVar state; (* the current state after popping; it will be updated by [goto] *)
fsemv, ERepr (EVar semv); (* the newly computed semantic value *)
fstartp, EVar startp; (* the newly computed start and end positions *)
fendp, EVar endp;
fnext, EVar stack; (* this is the stack after popping *)
]
EComment (
Production.print prod,
blet (
(pat, EVar stack) :: (* destructure the stack *)
casts @ (* perform type casts *)
posbindings @ (* bind [startp] and [endp] *)
extrabindings action @ (* add bindings for the weird keywords *)
[ PVar semv, act ], (* run the user's code and bind [semv] *)
(* Return a new stack, onto which we have pushed a new stack cell. *)
ERecord [ (* the new stack cell *)
fstate, EVar state; (* the current state after popping; it will be updated by [goto] *)
fsemv, ERepr (EVar semv); (* the newly computed semantic value *)
fstartp, EVar startp; (* the newly computed start and end positions *)
fendp, EVar endp;
fnext, EVar stack; (* this is the stack after popping *)
]
)
)
)
)
let semantic_action prod =
EFun (
......@@ -620,7 +606,8 @@ let lhs =
let semantic_action =
define (
"semantic_action",
EArray (Production.map semantic_action)
(* Non-start productions only. *)
EArray (Production.mapx semantic_action)
)
(* ------------------------------------------------------------------------ *)
......
......@@ -101,7 +101,8 @@ module type TABLES = sig
(* A one-dimensional semantic action table maps productions to semantic
actions. The calling convention for semantic actions is described in
[EngineTypes]. *)
[EngineTypes]. This table contains ONLY NON-START PRODUCTIONS, so the
indexing is off by [start]. Be careful. *)
val semantic_action: ((int, Obj.t, token) EngineTypes.env ->
(int, Obj.t) EngineTypes.stack) array
......
......@@ -98,7 +98,9 @@ module Make (T : TableFormat.TABLES)
(state, semantic_value) EngineTypes.stack
let semantic_action prod =
T.semantic_action.(prod)
(* Indexing into the array [T.semantic_action] is off by [T.start],
because the start productions do not have entries in this array. *)
T.semantic_action.(prod - T.start)
(* If [T.trace] is [None], then the logging functions do nothing. *)
......
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