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
fix
Commits
75a08d51
Commit
75a08d51
authored
Nov 30, 2018
by
POTTIER Francois
Browse files
Introduce [accepting_state_can_have_successors].
parent
8fa7e1f1
Changes
1
Show 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 = {
...
@@ -392,6 +392,18 @@ type dfa = {
expressions. Then, we construct a DFA whose states are the reachable
expressions. Then, we construct a DFA whose states are the reachable
expressions and whose transitions correspond to derivation. *)
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
=
let
dfa
(
e
:
regexp
)
:
dfa
=
(* Discover and number the nonempty reachable expressions. The most
(* Discover and number the nonempty reachable expressions. The most
nontrivial aspect of this phase is termination. The fact that expressions
nontrivial aspect of this phase is termination. The fact that expressions
...
@@ -401,9 +413,10 @@ let dfa (e : regexp) : dfa =
...
@@ -401,9 +413,10 @@ let dfa (e : regexp) : dfa =
more expressions being identified, therefore smaller automata. *)
more expressions being identified, therefore smaller automata. *)
let
module
G
=
struct
let
module
G
=
struct
type
t
=
regexp
type
t
=
regexp
(* The successors of [e] are its derivatives along every character [a],
provided they are nonempty. *)
let
foreach_successor
e
f
=
let
foreach_successor
e
f
=
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
->
Char
.
foreach
(
fun
a
->
let
e'
=
delta
a
e
in
let
e'
=
delta
a
e
in
if
nonempty
e'
then
if
nonempty
e'
then
...
@@ -425,7 +438,12 @@ let dfa (e : regexp) : dfa =
...
@@ -425,7 +438,12 @@ let dfa (e : regexp) : dfa =
(* The initial state is the encoding of [e]. *)
(* The initial state is the encoding of [e]. *)
let
init
=
encode
e
in
let
init
=
encode
e
in
(* The transition function is as follows. *)
(* 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. *)
(* We are done. *)
{
n
;
init
;
decode
;
transition
}
{
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