File tree Expand file tree Collapse file tree 5 files changed +21
-13
lines changed Expand file tree Collapse file tree 5 files changed +21
-13
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,9 @@ module type NFAType = sig
147
147
val from_dfa : dfa -> nfa
148
148
val to_dfa : nfa -> dfa
149
149
(*
150
- val reachable : nfa -> nfa
150
+ * TODO
151
+ val accessible : nfa -> nfa
152
+ val co_accessible : nfa -> nfa
151
153
val remove_epsilon : nfa -> nfa
152
154
*)
153
155
end
Original file line number Diff line number Diff line change 2
2
open Parser
3
3
4
4
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 )
5
6
let get_index s = String. sub s 3 ((String. length s) - 3 )
6
7
let get_state_index s = String. sub s 1 ((String. length s) - 1 )
7
8
}
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* '"'
10
13
let reg = " REG" [ '0' - '9' ]+
11
14
let dfa = " DFA" [ '0' - '9' ]+
12
15
let nfa = " NFA" [ '0' - '9' ]+
@@ -24,7 +27,8 @@ rule token = parse
24
27
| '*' { STAR }
25
28
| '0' { ZERO }
26
29
| '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 ]) }
28
32
29
33
| ',' { COMMA }
30
34
| str { STR (get_string (Lexing. lexeme lexbuf)) }
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ let concat_n s n =
4
4
5
5
let main () =
6
6
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
8
8
print_endline cmd;
9
9
let lexbuf = Lexing. from_string (cmd^ " \n " ) in
10
10
Parser. toplevel Lexer. token lexbuf
Original file line number Diff line number Diff line change @@ -33,7 +33,10 @@ type regexp =
33
33
let rec string_of_regexp (r :regexp ) : string = match r with
34
34
| Zero -> " 0"
35
35
| 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
37
40
| Star (Zero as r ) | Star (One as r ) | Star (Symb(_ ) as r ) ->
38
41
(string_of_regexp r) ^ " *"
39
42
| Star (r ) -> " (" ^ (string_of_regexp r) ^ " )*"
Original file line number Diff line number Diff line change 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 -}
3
2
4
3
NFA1 :=
5
- | _ o l
4
+ | _ `0 `1
6
5
---------------------------
7
6
-> s1 -> | ! s1 s2
8
7
s2 | ! s3 s1
9
8
s3 | ! s2 s3
10
9
11
10
REG1 := < NFA1 >
12
11
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
17
16
You can’t perform that action at this time.
0 commit comments