# 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:
~~~bash
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:
~~~bash
./re_parser "a(b|c)+d*"
~~~
Will produce the two files `nfa.dot` and `dfa.dot`.
These can be directly viwed with `xdot`:
~~~bash
xdot nfa.dot
xdot dfa.dot
~~~
Or translated to png images with `dot`:
~~~bash
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:
~~~bash
./re_app --host localhost --port 3000
~~~
The server will be available at <a href='http://localhost:3000'>http://localhost:3000</a>.
## RE parser as a library
You can also use RE parser as a library by importing `re_parser`.
~~~nit
import re_parser
var re = "a(b|c)+d*"
# Parse the expression
var l = new Lexer_re_parser(re)
var p = new Parser_re_parser
p.tokens.add_all l.lex
var node = p.parse
# Check errors
if not node isa NProd then
print "Error parsing the regular expression"
abort
end
# Get NFA and DFA
var v = new REVisitor
v.start(node)
print v.nfa.to_dot
print v.nfa.to_dfa.to_dot
~~~
Web app demo: http://re.moz-code.org/
Pull-Request: #2373
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Jean-Christophe Beaupré <jcbrinfo.public@gmail.com>