Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
POTTIER Francois
fix
Commits
75a08d51
Commit
75a08d51
authored
Nov 30, 2018
by
POTTIER Francois
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce [accepting_state_can_have_successors].
parent
8fa7e1f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
8 deletions
+26
-8
demos/brz/Brzozowski.ml
demos/brz/Brzozowski.ml
+26
-8
No files found.
demos/brz/Brzozowski.ml
View file @
75a08d51
...
...
@@ -392,6 +392,18 @@ type dfa = {
expressions. Then, we construct a DFA whose states are the reachable
expressions and whose transitions correspond to derivation. *)
(* If one wishes to stop as soon as an accepting state is encountered, then a
final state need not have any outgoing transitions; that would be
pointless. However, in some applications, one might wish to record that an
accepting state was reached and nevertheless continue reading the input. In
that case, the following flag should be set to true]. *)
let
accepting_state_can_have_successors
=
false
let
may_have_successors
(
e
:
regexp
)
:
bool
=
accepting_state_can_have_successors
||
not
(
nullable
e
)
let
dfa
(
e
:
regexp
)
:
dfa
=
(* Discover and number the nonempty reachable expressions. The most
nontrivial aspect of this phase is termination. The fact that expressions
...
...
@@ -401,14 +413,15 @@ let dfa (e : regexp) : dfa =
more expressions being identified, therefore smaller automata. *)
let
module
G
=
struct
type
t
=
regexp
(* The successors of [e] are its derivatives along every character [a],
provided they are nonempty. *)
let
foreach_successor
e
f
=
Char
.
foreach
(
fun
a
->
let
e'
=
delta
a
e
in
if
nonempty
e'
then
f
e'
)
if
may_have_successors
e
then
(* The successors of [e] are its derivatives along every character
[a], provided they are nonempty. *)
Char
.
foreach
(
fun
a
->
let
e'
=
delta
a
e
in
if
nonempty
e'
then
f
e'
)
(* The single root is [e], if it is nonempty. *)
let
foreach_root
f
=
if
nonempty
e
then
...
...
@@ -425,7 +438,12 @@ let dfa (e : regexp) : dfa =
(* The initial state is the encoding of [e]. *)
let
init
=
encode
e
in
(* The transition function is as follows. *)
let
transition
q
a
=
encode
(
delta
a
(
decode
q
))
in
let
transition
q
a
=
if
may_have_successors
(
decode
q
)
then
encode
(
delta
a
(
decode
q
))
else
None
in
(* We are done. *)
{
n
;
init
;
decode
;
transition
}
...
...
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