Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (45 sloc) 2 KB
This is a study project for regular expression implementation.
Only the most basic regular expression syntax is supported, i.e.,
the closure (*) operator, the alternation (|) operator, and the
concatenation operator.
make -f
perl Makefile.PL
* As an NFA generator:
perl -Ilib script/ '(a|b)*(aa|bb)(a|b)*'
It will generate one image file, NFA.png:
* As a DFA generator:
perl -Ilib script/ '(a|b)*(aa|bb)(a|b)*'
It will generate two image files, DFA.png and DFA.min.png,
showing the DFA automata and the minimized DFA automata:
* As a regular expression compiler:
perl -Ilib script/ '(a|b)*(aa|bb)(a|b)*'
will generate a Perl subroutine's source code to implement
the corresponding minized DFA automata:
On the other hand, we can also compile regular expressions
down to C code:
perl -Ilib script/ '(a|b)*(aa|bb)(a|b)*'
The generated C code can be seen here:
* As a regular expression parser:
perl -Ilib script/ '(a|b)*(aa|bb)(a|b)*'
It will output the XML representation for the parsed regular
expression's AST (Abstract Syntax Tree) structure:
* As a regular expression interpreter:
perl -Ilib script/ -c '(a|b)*(aa|bb)(a|b)*' "abbbf"
This command will run the regular expression against the text "abbbf"
using the C backend (specified by the -c option). It will output
match: 'abbb'
The script uses the Inline::C Perl module to run the C code
generated by the regular expression compiler with the C backend.
Also, it's possible to use the Perl backend to run the regular expression,
by specifying the -p option:
perl -Ilib script/ -p '(a|b)*(aa|bb)(a|b)*' "abbbf"