diff --git a/p2a/Makefile b/p2a/Makefile deleted file mode 100644 index c85da39..0000000 --- a/p2a/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -OCAMLBUILD = ocamlbuild - -SOURCES = basics.mli basics.ml testUtils.ml -PUBLIC_SOURCES = public.ml - -PUBLIC_RESULT = public.native - -OCAMLLDFLAGS = -g -PACKS = oUnit - -all: $(PUBLIC_RESULT) - -$(PUBLIC_RESULT): $(SOURCES) $(PUBLIC_SOURCES) - $(OCAMLBUILD) $(PUBLIC_RESULT) -pkgs $(PACKS) - -clean: - rm -f *.cmi - rm -f *.cmo - $(OCAMLBUILD) -clean diff --git a/p2a/dune-project b/p2a/dune-project new file mode 100644 index 0000000..de4fc20 --- /dev/null +++ b/p2a/dune-project @@ -0,0 +1 @@ +(lang dune 1.0) diff --git a/p2a/dune-workspace b/p2a/dune-workspace new file mode 100644 index 0000000..a9a16f2 --- /dev/null +++ b/p2a/dune-workspace @@ -0,0 +1,3 @@ +(lang dune 1.0) +(context default) +(profile release) diff --git a/p2a/basics.ml b/p2a/src/basics.ml similarity index 100% rename from p2a/basics.ml rename to p2a/src/basics.ml diff --git a/p2a/basics.mli b/p2a/src/basics.mli similarity index 100% rename from p2a/basics.mli rename to p2a/src/basics.mli diff --git a/p2a/src/dune b/p2a/src/dune new file mode 100644 index 0000000..714be4b --- /dev/null +++ b/p2a/src/dune @@ -0,0 +1,3 @@ +(library + (name basics) + (public_name basics)) diff --git a/p2a/test/dune b/p2a/test/dune new file mode 100644 index 0000000..7525118 --- /dev/null +++ b/p2a/test/dune @@ -0,0 +1,3 @@ +(test + (name public) + (libraries basics ounit)) diff --git a/p2a/public.ml b/p2a/test/public.ml similarity index 100% rename from p2a/public.ml rename to p2a/test/public.ml diff --git a/p2a/testUtils.ml b/p2a/test/testUtils.ml similarity index 100% rename from p2a/testUtils.ml rename to p2a/test/testUtils.ml diff --git a/p4/Makefile b/p4/Makefile deleted file mode 100644 index ec87602..0000000 --- a/p4/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -CC = ocamlc -CMO_DEPENDS = sets.cmo nfa.cmo regexp.cmo testUtils.cmo -PACKS=oUnit,str - -PUBLIC_RESULT = public.native -VISUALIZE_RESULT = viz.native -PROGS=$(PUBLIC_RESULT) $(VISUALIZE_RESULT) - -all: public viz - -public: $(PUBLIC_RESULT) -viz: $(VISUALIZE_RESULT) - -$(PUBLIC_RESULT): $(CMO_DEPENDS) public.ml - ocamlfind $(CC) -o $@ -linkpkg -package $(PACKS) -g $(CMO_DEPENDS) public.ml - -$(VISUALIZE_RESULT): $(CMO_DEPENDS) viz.ml - ocamlfind $(CC) -o $@ -linkpkg -package $(PACKS) -g $(CMO_DEPENDS) viz.ml - -nfa.cmo: nfa.ml nfa.cmi - $(CC) -o $@ -c nfa.ml - -nfa.cmi: nfa.mli - $(CC) -o $@ -c nfa.mli - -regexp.cmo: regexp.ml regexp.cmi nfa.cmo nfa.cmi - $(CC) -o $@ -c regexp.ml - -regexp.cmi: regexp.mli nfa.cmo nfa.cmi - $(CC) -o $@ -c regexp.mli - -testUtils.cmo testUtils.mli: nfa.cmo regexp.cmo testUtils.ml - ocamlfind $(CC) -o testUtils -linkpkg -package oUnit -c testUtils.ml - -clean: - @echo "Cleaning object files and executables" - -@rm -f $(PROGS) public.cm[oi] viz.cm[oi] nfa.cm[oi] regexp.cm[oi] testUtils.cm[oi] oUnit*.log oUnit*.cache diff --git a/p4/viz.ml b/p4/bin/viz.ml similarity index 100% rename from p4/viz.ml rename to p4/bin/viz.ml diff --git a/p4/dep/sets/META b/p4/dep/sets/META new file mode 100644 index 0000000..287ae87 --- /dev/null +++ b/p4/dep/sets/META @@ -0,0 +1,5 @@ +description = "" +version = "1.0.0" + +archive(byte) = "sets.cma" +archive(native) = "sets.cmxa" \ No newline at end of file diff --git a/p4/dep/sets/Makefile b/p4/dep/sets/Makefile new file mode 100644 index 0000000..6746fd8 --- /dev/null +++ b/p4/dep/sets/Makefile @@ -0,0 +1,14 @@ +BYTECC = ocamlc +NATIVECC = ocamlopt +CMO_DEPENDS = sets.cmo +PACKS=str + +all: sets_pkg + +sets_pkg: sets.cma META + ocamlfind install sets META sets.cmi sets.cma + +sets.cma: $(CMO_DEPENDS) + ocamlfind $(BYTECC) -a -o $@ -linkpkg -package $(PACKS) -g $(CMO_DEPENDS) + +# Need to also include the cmxa for running tests... not sure how to build those yet diff --git a/p4/dep/sets/sets.cma b/p4/dep/sets/sets.cma new file mode 100644 index 0000000..5839b7d Binary files /dev/null and b/p4/dep/sets/sets.cma differ diff --git a/p4/sets.cmi b/p4/dep/sets/sets.cmi similarity index 100% rename from p4/sets.cmi rename to p4/dep/sets/sets.cmi diff --git a/p4/sets.cmo b/p4/dep/sets/sets.cmo similarity index 100% rename from p4/sets.cmo rename to p4/dep/sets/sets.cmo diff --git a/p4/dep/sets/sets.opam b/p4/dep/sets/sets.opam new file mode 100644 index 0000000..104e897 --- /dev/null +++ b/p4/dep/sets/sets.opam @@ -0,0 +1,7 @@ +opam-version: "1.2" +name: "sets" +version: "1.0.0" +build: [ + ["make"] +] +descr: "test" \ No newline at end of file diff --git a/p4/dune-project b/p4/dune-project new file mode 100644 index 0000000..de4fc20 --- /dev/null +++ b/p4/dune-project @@ -0,0 +1 @@ +(lang dune 1.0) diff --git a/p4/dune-workspace b/p4/dune-workspace new file mode 100644 index 0000000..a9a16f2 --- /dev/null +++ b/p4/dune-workspace @@ -0,0 +1,3 @@ +(lang dune 1.0) +(context default) +(profile release) diff --git a/p4/src/dune b/p4/src/dune new file mode 100644 index 0000000..0d4a4be --- /dev/null +++ b/p4/src/dune @@ -0,0 +1,3 @@ +(library + (name regexpi) + (libraries sets)) \ No newline at end of file diff --git a/p4/nfa.ml b/p4/src/nfa.ml similarity index 92% rename from p4/nfa.ml rename to p4/src/nfa.ml index 3c427f7..4bb8d62 100644 --- a/p4/nfa.ml +++ b/p4/src/nfa.ml @@ -34,6 +34,6 @@ let move m qs s = failwith "unimplemented" let e_closure m qs = failwith "unimplemented" -let accept m str = failwith "unimplemented" +let accept m str = if elem "x" [ "y" ] then true else false let nfa_to_dfa m = failwith "unimplemented" diff --git a/p4/nfa.mli b/p4/src/nfa.mli similarity index 100% rename from p4/nfa.mli rename to p4/src/nfa.mli diff --git a/p4/regexp.ml b/p4/src/regexp.ml similarity index 100% rename from p4/regexp.ml rename to p4/src/regexp.ml diff --git a/p4/regexp.mli b/p4/src/regexp.mli similarity index 100% rename from p4/regexp.mli rename to p4/src/regexp.mli diff --git a/p4/test/dune b/p4/test/dune new file mode 100644 index 0000000..7a390d7 --- /dev/null +++ b/p4/test/dune @@ -0,0 +1,7 @@ +(test + (name public) + (libraries regexpi ounit)) + +(alias + (name runtest) + (action (run ./public.bc))) diff --git a/p4/public.ml b/p4/test/public.ml similarity index 99% rename from p4/public.ml rename to p4/test/public.ml index 27c99d3..ea666a7 100644 --- a/p4/public.ml +++ b/p4/test/public.ml @@ -1,6 +1,6 @@ open OUnit2 -open Nfa -open Regexp +open Regexpi.Nfa +open Regexpi.Regexp open TestUtils let test_nfa_accept ctxt = diff --git a/p4/testUtils.ml b/p4/test/testUtils.ml similarity index 81% rename from p4/testUtils.ml rename to p4/test/testUtils.ml index 02d6005..2620c62 100644 --- a/p4/testUtils.ml +++ b/p4/test/testUtils.ml @@ -1,4 +1,5 @@ -open Nfa +open Regexpi.Nfa +open Regexpi.Regexp open OUnit2 let assert_true x = assert_equal true x;; @@ -17,23 +18,23 @@ let assert_dfa m = (* Helpers for clearly testing the accept function *) let assert_nfa_accept nfa input = - if not @@ Nfa.accept nfa input then + if not @@ accept nfa input then assert_failure @@ Printf.sprintf "NFA should have accept string '%s', but did not" input let assert_nfa_deny nfa input = - if Nfa.accept nfa input then + if accept nfa input then assert_failure @@ Printf.sprintf "NFA should not have accepted string '%s', but did" input let assert_nfa_closure nfa ss es = let es = List.sort compare es in - let rcv = List.sort compare @@ Nfa.e_closure nfa ss in + let rcv = List.sort compare @@ e_closure nfa ss in if not (es = rcv) then assert_failure @@ Printf.sprintf "Closure failure: Expected %s, received %s" (string_of_int_list es) (string_of_int_list rcv) let assert_nfa_move nfa ss mc es = let es = List.sort compare es in - let rcv = List.sort compare @@ Nfa.move nfa ss mc in + let rcv = List.sort compare @@ move nfa ss mc in if not (es = rcv) then assert_failure @@ Printf.sprintf "Move failure: Expected %s, received %s" (string_of_int_list es) (string_of_int_list rcv) -let assert_regex_string_equiv rxp = assert_equal rxp @@ Regexp.string_to_regexp @@ Regexp.regexp_to_string rxp +let assert_regex_string_equiv rxp = assert_equal rxp @@ string_to_regexp @@ regexp_to_string rxp