Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
POTTIER Francois
menhir
Commits
95145679
Commit
95145679
authored
Sep 19, 2019
by
POTTIER Francois
Browse files
Remove the duplicate function [addl] in [Slr] and [Lr1]. Replace it with [Lr0.add_reductions].
parent
1dd3480c
Pipeline
#94460
passed with stages
in 26 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/lr0.ml
View file @
95145679
...
...
@@ -606,3 +606,27 @@ let restrict toks (k, toksr) =
k
,
Array
.
map
(
fun
toksri
->
TerminalSet
.
inter
toksri
toks
)
toksr
(* A (state-local, possibly nondeterministic) reduction table maps
terminal symbols to lists of productions. *)
type
reductions
=
Production
.
index
list
TerminalMap
.
t
(* [add_reduction prod tok reductions] adds a reduction of [prod] on [tok]
to the table [reductions]. *)
let
add_reduction
prod
tok
reductions
=
let
prods
=
try
TerminalMap
.
lookup
tok
reductions
with
Not_found
->
[]
in
TerminalMap
.
add
tok
(
prod
::
prods
)
reductions
(* [add_reductions prod toks reductions] adds a reduction of [prod] on every
token in the set [toks] to the table [reductions]. *)
let
add_reductions
prod
toks
reductions
=
TerminalSet
.
fold
(
add_reduction
prod
)
toks
reductions
src/lr0.mli
View file @
95145679
...
...
@@ -139,3 +139,19 @@ val restrict: TerminalSet.t -> lr1state -> lr1state
val
print_concrete
:
string
->
concretelr1state
->
string
val
print
:
string
->
lr1state
->
string
val
print_closure
:
string
->
lr1state
->
string
(* A (state-local, possibly nondeterministic) reduction table maps
terminal symbols to lists of productions. *)
type
reductions
=
Production
.
index
list
TerminalMap
.
t
(* [add_reduction prod tok reductions] adds a reduction of [prod] on [tok]
to the table [reductions]. *)
val
add_reduction
:
Production
.
index
->
Terminal
.
t
->
reductions
->
reductions
(* [add_reductions prod toks reductions] adds a reduction of [prod] on every
token in the set [toks] to the table [reductions]. *)
val
add_reductions
:
Production
.
index
->
TerminalSet
.
t
->
reductions
->
reductions
src/lr1.ml
View file @
95145679
...
...
@@ -509,18 +509,6 @@ let () =
num
:=
number
+
1
;
node
.
number
<-
number
;
(* Insertion of a new reduce action into the table of reductions. *)
let
addl
prod
tok
reductions
=
let
prods
=
try
TerminalMap
.
lookup
tok
reductions
with
Not_found
->
[]
in
TerminalMap
.
add
tok
(
prod
::
prods
)
reductions
in
(* Build the reduction table. Here, we gather all potential
reductions, without attempting to solve shift/reduce
conflicts on the fly, because that would potentially hide
...
...
@@ -529,7 +517,7 @@ let () =
let
reductions
=
List
.
fold_left
(
fun
reductions
(
toks
,
prod
)
->
TerminalSet
.
fold
(
addl
prod
)
toks
reductions
Lr0
.
add_reductions
prod
toks
reductions
)
TerminalMap
.
empty
(
Lr0
.
reductions
node
.
state
)
in
...
...
src/slr.ml
View file @
95145679
...
...
@@ -64,23 +64,6 @@ let make_slr_state (s : Lr0.node) : Lr0.concretelr1state =
Item
.
Map
.
add
item
follow_nt
accu
)
s
Item
.
Map
.
empty
(* Insertion of a new reduce action into the table of reductions. Copied
from [Lr1] (boo, hiss). *)
let
addl
prod
tok
reductions
=
let
prods
=
try
TerminalMap
.
lookup
tok
reductions
with
Not_found
->
[]
in
TerminalMap
.
add
tok
(
prod
::
prods
)
reductions
(* Same thing, for a set of tokens. *)
let
addl
prod
toks
reductions
=
TerminalSet
.
fold
(
addl
prod
)
toks
reductions
(* The following function turns a closed LR(1) state into a map of terminal
symbols to reduction actions. Copied from a related function in [Lr0]. *)
...
...
@@ -88,7 +71,7 @@ let reductions (s : Lr0.concretelr1state) : Production.index list TerminalMap.t
Item
.
Map
.
fold
(
fun
item
toks
reductions
->
match
Item
.
classify
item
with
|
Item
.
Reduce
prod
->
addl
prod
toks
reductions
Lr0
.
add_reductions
prod
toks
reductions
|
Item
.
Shift
_
->
reductions
)
s
TerminalMap
.
empty
...
...
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