Commit 3ffb877e authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Comment, explaining the constraints that must be imposed by [Invariant].

The old comment was wrong, I think.
parent 6c6982b4
...@@ -596,32 +596,41 @@ let rewind node : instruction = ...@@ -596,32 +596,41 @@ let rewind node : instruction =
rewind w rewind w
(* ------------------------------------------------------------------------ *) (* ------------------------------------------------------------------------ *)
(* We now determine which positions must be kept track of. For
simplicity, we do this on a per symbol basis. That is, for each (* We now determine which positions must be kept track of. For simplicity, we
symbol, either we never keep track of position information, or we do this on a per-symbol basis. That is, for each symbol, either we never
always do. In fact, we do distinguish start and end positions. keep track of position information, or we always do. In fact, we do
This leads to computing two sets of symbols -- those that keep distinguish start and end positions. This leads to computing two sets of
track of their start position and those that keep track of their symbols -- those that keep track of their start position and those that
end position. keep track of their end position.
A symbol on the right-hand side of a production must keep track of A symbol on the right-hand side of a production must keep track of its
its (start or end) position if that position is explicitly (start or end) position if that position is explicitly requested by a
requested by a semantic action. semantic action.
Furthermore, if the left-hand symbol of a production must keep Furthermore, if the left-hand symbol of a production must keep track of its
track of its start (resp. end) position, then the first start (resp. end) position, then the first (resp. last) symbol of its
(resp. last) symbol of its right-hand side (if there is one) must right-hand side (if there is one) must do so as well. That is, unless the
do so as well. That is, unless the right-hand side is empty. *) right-hand side is empty. *)
(* 2015/11/04. When an epsilon production is reduced, the top stack cell is (* 2015/11/04. When an epsilon production [prod] is reduced, the top stack cell
consulted for its end position. This implies that this cell must exist and may be consulted for its end position. This implies that this cell must exist
must store an end position! Thus, we have the following constraint: if some and must store an end position! Now, when does this happen?
state whose incoming symbol is [sym] can reduce an epsilon production, then
[sym] must keep track of its end position. (Furthermore, if some initial 1- This happens if the left-hand symbol of the production, [nt prod], keeps
state can reduce an epsilon production, then the sentinel cell at the bottom track of its start or end position.
of the stack must contain a position. This does not concern us here.) 2- This happens if the semantic action explicitly mentions the keyword
Similarly, if some state whose incoming symbol is [sym] uses [$endpos($0)], [$endpos($0)].
then [sym] must keep track of its end position. *)
Now, if this happens, what should we do?
a- If this happens in a state [s] whose incoming symbol is [sym], then [sym]
must keep track of its end position.
b- If this happens in an initial state, where the stack may be empty, then
the sentinel cell at the bottom of the stack must contain an end position.
Point (b) doesn't concern us here, but point (a) does. We must implement the
constraint (1) \/ (2) -> (a). *)
open Keyword open Keyword
......
Supports Markdown
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