Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Armillon Damien
infosec-ecomp
Commits
bde85892
Commit
bde85892
authored
Mar 02, 2021
by
Armillon Damien
Browse files
fix lexer
parent
4c8b73f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lexer_generator.ml
View file @
bde85892
...
@@ -361,23 +361,27 @@ type lexer_result =
...
@@ -361,23 +361,27 @@ type lexer_result =
*)
*)
let
to_lexer_result
(
d
:
dfa
)
(
q
:
dfa_state
)
(
w
:
char
list
)
:
lexer_result
=
let
to_lexer_result
(
d
:
dfa
)
(
q
:
dfa_state
)
(
w
:
char
list
)
:
lexer_result
=
let
(
_
,
f
)
=
List
.
find
(
fun
(
state
,_
)
->
Set
.
equal
q
state
)
d
.
dfa_final
in
let
result
=
List
.
find_opt
(
fun
(
state
,_
)
->
Set
.
equal
q
state
)
d
.
dfa_final
in
match
f
(
string_of_char_list
w
)
with
match
result
with
|
None
->
LRskip
|
None
->
LRerror
|
Some
token
->
LRtoken
token
|
Some
(
_
,
f
)
->
match
f
(
string_of_char_list
w
)
with
|
None
->
LRskip
|
Some
token
->
LRtoken
token
let
tokenize_one
(
d
:
dfa
)
(
w
:
char
list
)
:
lexer_result
*
char
list
=
let
tokenize_one
(
d
:
dfa
)
(
w
:
char
list
)
:
lexer_result
*
char
list
=
let
rec
recognize
(
q
:
dfa_state
)
(
w
:
char
list
)
let
rec
recognize
(
q
:
dfa_state
)
(
w
:
char
list
)
(
current_word
:
char
list
)
(
last_accepted
:
lexer_result
*
char
list
)
(
current_word
:
char
list
)
(
last_accepted
:
lexer_result
*
char
list
)
:
lexer_result
*
char
list
=
:
lexer_result
*
char
list
=
let
last_accepted'
=
(
to_lexer_result
d
q
current_word
,
w
)
in
let
last_accepted'
=
(
to_lexer_result
d
q
current_word
,
w
)
in
match
w
with
match
w
with
|
[]
->
last_accepted'
|
[]
->
last_accepted'
|
lettre
::
r
->
|
lettre
::
r
->
match
d
.
dfa_step
q
lettre
with
match
d
.
dfa_step
q
lettre
with
|
None
->
last_accepted'
|
None
->
last_accepted'
|
Some
q'
->
let
new_current_word
=
current_word
@
[
lettre
]
in
match
to_lexer_result
d
q'
new_current_word
with
|
Some
q'
->
let
new_current_word
=
current_word
@
[
lettre
]
in
match
to_lexer_result
d
q'
new_current_word
with
|
LRerror
->
recognize
q'
r
(
new_current_word
)
last_accepted'
|
lr
->
recognize
q'
r
(
new_current_word
)
last_accepted'
|
lr
->
recognize
q'
r
(
new_current_word
)
last_accepted'
in
in
recognize
d
.
dfa_initial
w
[]
(
LRerror
,
w
)
recognize
d
.
dfa_initial
w
[]
(
LRerror
,
w
)
...
@@ -524,6 +528,9 @@ let nfa_of_list_regexp l =
...
@@ -524,6 +528,9 @@ let nfa_of_list_regexp l =
let
dfa_of_list_regexp
l
=
let
dfa_of_list_regexp
l
=
let
n
=
nfa_of_list_regexp
l
in
let
n
=
nfa_of_list_regexp
l
in
let
oc
=
open_out
"/tmp/nfa.dot"
in
nfa_to_dot
oc
n
;
close_out
oc
;
dfa_of_nfa
n
dfa_of_nfa
n
let
tokenize_list_regexp
l
s
=
let
tokenize_list_regexp
l
s
=
...
...
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