Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
POTTIER Francois
menhir
Commits
3e1c3a22
Commit
3e1c3a22
authored
Nov 20, 2020
by
POTTIER Francois
Browse files
Improve [Lr0.union] to return its second argument unchanged when possible.
parent
366249e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
src/lr0.ml
src/lr0.ml
+15
-4
src/lr0.mli
src/lr0.mli
+3
-0
No files found.
src/lr0.ml
View file @
3e1c3a22
...
...
@@ -635,11 +635,22 @@ let error_compatible (k1, toksr1) (k2, toksr2) =
(* Union of two states. The two states must have the same core. The
new state is obtained by pointwise union of the lookahead sets. *)
let
union
(
k1
,
toksr1
)
(
k2
,
toksr2
)
=
let
union
(
k1
,
toksr1
)
(
(
k2
,
toksr2
)
as
s2
)
=
assert
(
k1
=
k2
);
k1
,
Array
.
init
(
Array
.
length
toksr1
)
(
fun
i
->
TerminalSet
.
union
toksr1
.
(
i
)
toksr2
.
(
i
)
)
let
k
=
k1
in
let
toksr
=
Array
.
init
(
Array
.
length
toksr1
)
(
fun
i
->
TerminalSet
.
union
toksr1
.
(
i
)
toksr2
.
(
i
)
)
in
(* If the fresh array [toksr] has the same content as [toksr2],
then we must return the state [s2], unchanged. We could be
even more ambitious and try to not even allocate the array
[toksr] in that case, but that seems more trouble than it
is worth. *)
if
Misc
.
array_for_all2
(
==
)
toksr2
toksr
then
s2
else
k
,
toksr
(* Restriction of a state to a set of tokens of interest. Every
lookahead set is intersected with that set. *)
...
...
src/lr0.mli
View file @
3e1c3a22
...
...
@@ -134,6 +134,9 @@ val error_compatible: lr1state -> lr1state -> bool
(* Union of two states. The two states must have the same core. The
new state is obtained by pointwise union of the lookahead sets. *)
(* If [s'] is a subset of [s], then [union s' s] is physically equal
to [s]. *)
val
union
:
lr1state
->
lr1state
->
lr1state
(* Restriction of a state to a set of tokens of interest. Every
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment