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 parse_regex import parse, ParseError
|
||||
|
||||
def to_nfa(regex):
|
||||
def new_state():
|
||||
|
@ -94,9 +97,13 @@ def to_nfa(regex):
|
|||
return NFA(start_state, [end_state], transitions)
|
||||
|
||||
def main():
|
||||
regex = concat(lit('x'), star(bar(lit('a'), lit('b'))), lit('y'))
|
||||
print(regex)
|
||||
try:
|
||||
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)
|
||||
|
||||
prettyprint(nfa)
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
from regex import lit, concat, bar, star
|
||||
import sys
|
||||
|
||||
from regex_to_nfa import to_nfa
|
||||
from nfa_to_regex import to_regex
|
||||
from parse_regex import parse, ParseError
|
||||
|
||||
def main():
|
||||
regex = concat(bar(lit('foo'), lit('bar')), bar(lit('baz'), lit('qux')))
|
||||
print(regex)
|
||||
try:
|
||||
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)
|
||||
regex_prime = to_regex(nfa)
|
||||
|
||||
|
|
Loading…
Reference in New Issue