Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fix
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
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 = {
...
@@ -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,14 +413,15 @@ let dfa (e : regexp) : dfa =
...
@@ -401,14 +413,15 @@ 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
=
Char
.
foreach
(
fun
a
->
if
may_have_successors
e
then
let
e'
=
delta
a
e
in
(* The successors of [e] are its derivatives along every character
if
nonempty
e'
then
[a], provided they are nonempty. *)
f
e'
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. *)
(* The single root is [e], if it is nonempty. *)
let
foreach_root
f
=
let
foreach_root
f
=
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