Add regex input to regex_to_nfa.py and regex_to_regex.py
This commit is contained in:
parent
1409400cc8
commit
3a843fb07f
|
@ -1,5 +1,8 @@
|
||||||
from regex import Literal, Concatenation, Alternation, Star, lit, concat, bar, star
|
import sys
|
||||||
|
|
||||||
|
from regex import Literal, Concatenation, Alternation, Star, lit
|
||||||
from nfa import NFA, prettyprint
|
from nfa import NFA, prettyprint
|
||||||
|
from parse_regex import parse, ParseError
|
||||||
|
|
||||||
def to_nfa(regex):
|
def to_nfa(regex):
|
||||||
def new_state():
|
def new_state():
|
||||||
|
@ -94,9 +97,13 @@ def to_nfa(regex):
|
||||||
return NFA(start_state, [end_state], transitions)
|
return NFA(start_state, [end_state], transitions)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
regex = concat(lit('x'), star(bar(lit('a'), lit('b'))), lit('y'))
|
try:
|
||||||
print(regex)
|
regex = parse(input('regex> '))
|
||||||
|
|
||||||
|
except ParseError as err:
|
||||||
|
print('%s: Error: %s' % (sys.argv[0], str(err)), file=sys.stderr)
|
||||||
|
|
||||||
|
else:
|
||||||
nfa = to_nfa(regex)
|
nfa = to_nfa(regex)
|
||||||
|
|
||||||
prettyprint(nfa)
|
prettyprint(nfa)
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
from regex import lit, concat, bar, star
|
import sys
|
||||||
|
|
||||||
from regex_to_nfa import to_nfa
|
from regex_to_nfa import to_nfa
|
||||||
from nfa_to_regex import to_regex
|
from nfa_to_regex import to_regex
|
||||||
|
from parse_regex import parse, ParseError
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
regex = concat(bar(lit('foo'), lit('bar')), bar(lit('baz'), lit('qux')))
|
try:
|
||||||
print(regex)
|
regex = parse(input('regex> '))
|
||||||
|
|
||||||
|
except ParseError as err:
|
||||||
|
print('%s: Error: %s' % (sys.argv[0], str(err)), file=sys.stderr)
|
||||||
|
|
||||||
|
else:
|
||||||
nfa = to_nfa(regex)
|
nfa = to_nfa(regex)
|
||||||
regex_prime = to_regex(nfa)
|
regex_prime = to_regex(nfa)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue