re_parser -
RE Parser
RE parser provides a simple API to regular expression parsing. It is also able to convert a regular expression into a NFA or a DFA and produce dot files from it.
Building RE parser
From the re_parser
directory:
make all
RE parser in command line
RE parser can be used as a command line tool to generate NFA and DFA dot files from a regular expression:
./re_parser "a(b|c)+d*"
Will produce the two files nfa.dot
and dfa.dot
.
These can be directly viwed with xdot
:
xdot nfa.dot
xdot dfa.dot
Or translated to png images with dot
:
dot -Tpng -onfa.png nfa.dot
dot -Tpng -odfa.png dfa.dot
See man dot
for available formats.
RE parser as a web app
RE parser comes with a web app that allow users to submit regular expression and see the resulting NFA and DFA.
To run the web app server:
./re_app --host localhost --port 3000
The server will be available at http://localhost:3000.
RE parser as a library
You can also use RE parser as a library by importing re_parser
.
import re_parser
var re = "a(b|c)+d*"
# Parse re
var re_parser = new REParser
var node = re_parser.parse_re(re)
if node == null then
print re_parser.last_error.as(not null)
exit 1
abort
end
# Build NFA and DFA
var nfa = re_parser.make_nfa(node)
print nfa.to_dot(false)
print nfa.to_dfa.to_dot(false)
Use to_dot(true)
to merge transitions on characters.
Content
- re_parser: RE Parser (contrib/re_parser)
- src (contrib/re_parser/src)
- re_app (contrib/re_parser/src/re_app.nit)
- re_parser (contrib/re_parser/src/re_parser.nit)
- re_parser_lexer: Lexer generated by nitcc for the grammar re_parser (contrib/re_parser/src/re_parser_lexer.nit)
- re_parser_parser: Parser generated by nitcc for the grammar re_parser (contrib/re_parser/src/re_parser_parser.nit)
- re_parser_test_parser: Standalone parser tester for the language re_parser (contrib/re_parser/src/re_parser_test_parser.nit)
- src (contrib/re_parser/src)