Skip to content
Regular expressions matching to illustrate lexical analysis in MiniJava transpiler
OCaml
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
regenerate
.gitignore
README.md
dune
dune-project
grammar.txt
regex.ml
test_re.ml

README.md

Regex

This repository contains the code to illustrate regular expressions and automata for the lexical analysis part of the MiniJava transpiler, which is documented on www.mrcoder.org.

To use the code in the ocaml interpreter do the following.

utop # #use "regex.ml";;

You can create a regular expression with the following code.

utop # let re = RE.regex_from_string "0*(100*)*1?";;

You can now create a non-deterministic finite automata equivalent to this regular expression with

utop # let nfa = NFA.init re;;

And now, you can test if a string is matched by the regular expression with

utop # NFA.full_match nfa "101010";;
- : bool = true

If you want to launch the test suite, you will need dune, you can install it with opam by executing the following command.

opam install dune

You can now launch the test suite with

dune exec ./test_re.exe
You can’t perform that action at this time.