Skip to content

Commit 1004a8f

Browse files
author
pierre.hyvernat
committed
possibility to use other symbols preceded by `
1 parent 8972a13 commit 1004a8f

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

NFA.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ module type NFAType = sig
147147
val from_dfa : dfa -> nfa
148148
val to_dfa : nfa -> dfa
149149
(*
150-
val reachable : nfa -> nfa
150+
* TODO
151+
val accessible : nfa -> nfa
152+
val co_accessible : nfa -> nfa
151153
val remove_epsilon : nfa -> nfa
152154
*)
153155
end

lexer.mll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
open Parser
33

44
let get_string s = String.sub s 1 ((String.length s) - 2)
5+
let get_symbol s = String.sub s 1 ((String.length s) - 1)
56
let get_index s = String.sub s 3 ((String.length s) - 3)
67
let get_state_index s = String.sub s 1 ((String.length s) - 1)
78
}
8-
let symbol = [ 'a'-'z' ]
9-
let str = '"' symbol* '"'
9+
let lower_symbol = [ 'a'-'z' ]
10+
let character = [ 'a'-'z' 'A'-'Z' '0'-'9' '.' ',' ]
11+
let symbol = "`" character
12+
let str = '"' character* '"'
1013
let reg = "REG" [ '0'-'9' ]+
1114
let dfa = "DFA" [ '0'-'9' ]+
1215
let nfa = "NFA" [ '0'-'9' ]+
@@ -24,7 +27,8 @@ rule token = parse
2427
| '*' { STAR }
2528
| '0' { ZERO }
2629
| '1' { ONE }
27-
| symbol { SYMB(Lexing.lexeme_char lexbuf 0) }
30+
| lower_symbol { SYMB(Lexing.lexeme_char lexbuf 0) }
31+
| symbol { SYMB((Lexing.lexeme lexbuf).[1]) }
2832

2933
| ',' { COMMA }
3034
| str { STR(get_string (Lexing.lexeme lexbuf)) }

prof.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let concat_n s n =
44

55
let main () =
66
let n = 64 in
7-
let cmd = "\"" ^ (concat_n "a" n) ^ "\" ~ " ^ (concat_n "(1+a)" n) ^ (concat_n "a" n) in
7+
let cmd = "\"" ^ (concat_n "a" n) ^ "\" < " ^ (concat_n "(1+a)" n) ^ (concat_n "a" n) in
88
print_endline cmd;
99
let lexbuf = Lexing.from_string (cmd^"\n") in
1010
Parser.toplevel Lexer.token lexbuf

regexp.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ type regexp =
3333
let rec string_of_regexp (r:regexp) : string = match r with
3434
| Zero -> "0"
3535
| One -> "1"
36-
| Symb(a) -> String.make 1 a
36+
| Symb(a) ->
37+
if String.contains "abcdefghijklmnopqrstuvwxyz" a
38+
then String.make 1 a
39+
else "`" ^ String.make 1 a
3740
| Star(Zero as r) | Star(One as r) | Star(Symb(_) as r) ->
3841
(string_of_regexp r) ^ "*"
3942
| Star(r) -> "(" ^ (string_of_regexp r) ^ ")*"

tests/binary_three.mlr

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
{- automaton checking if a binary number is divisible by 3,
2-
where o means 0 and l means 1 -}
1+
{- automaton checking if a binary number is divisible by 3 -}
32

43
NFA1 :=
5-
| _ o l
4+
| _ `0 `1
65
---------------------------
76
-> s1 -> | ! s1 s2
87
s2 | ! s3 s1
98
s3 | ! s2 s3
109

1110
REG1 := < NFA1 >
1211

13-
:assert "ll" < REG1
14-
:assert "llo" < REG1
15-
:assert "lool" < REG1
16-
:assert NOT "lolo" < REG1
12+
:assert "11" < REG1
13+
:assert "110" < REG1
14+
:assert "1001" < REG1
15+
:assert NOT "1010" < REG1
1716

0 commit comments

Comments
 (0)