Skip to content

Commit

Permalink
Fixed a Bug and modified printnfa function
Browse files Browse the repository at this point in the history
  • Loading branch information
dejavudwh committed Sep 20, 2019
1 parent 56a2d0e commit 7fb0e29
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lex/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def advance(self):
pos = self.pos
pattern = self.pattern
if pos > len(pattern) - 1:
self.current_token = Token.EOS
return Token.EOS

text = self.lexeme = pattern[pos]
Expand Down Expand Up @@ -73,5 +74,4 @@ def handle_hex(self):
return 1

def match(self, token):
return self.current_token == token

return self.current_token == token
4 changes: 1 addition & 3 deletions nfa/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def is_conn(token):
Token.CCL_END,
Token.AT_BOL,
]
print(lexer.current_token, token not in nc)
return token not in nc


Expand Down Expand Up @@ -172,7 +171,6 @@ def nfa_option_closure(pair_out):

pair_out.start_node = start
pair_out.end_node = end
print(lexer.current_token, '****')

lexer.advance()
print(lexer.current_token, '****')
return True
13 changes: 11 additions & 2 deletions nfa/nfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,21 @@ def __init__(self):

def log_nfa(start_node):
log('NFA: ******** ')
if start_node.next_1 is not None:
next_1 = start_node.next_1 is not None
next_2 = start_node.next_2 is not None
if next_1:
log('from: ', start_node.status_num)
log('to: ', start_node.next_1.status_num)
log('in: ', start_node.edge)
else:

if next_2:
log('from: ', start_node.status_num)
log('to: ', start_node.next_2.status_num)
log('in: ', start_node.edge)

if not next_1 and not next_2:
log('accept: ', start_node.status_num)

start_node.visited = True
if hasattr(start_node, 'input_set'):
log('input set: ', start_node.input_set)
Expand Down
10 changes: 9 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from nfa.nfa import (
log_nfa,
)
from lex.lexer import Lexer


nfa_pair = NfaPair()
Expand All @@ -22,4 +23,11 @@
# debugNfa(nfa_pair.start_node)
# factor(nfa_pair)
factor_conn(nfa_pair)
log_nfa(nfa_pair.start_node)
log_nfa(nfa_pair.start_node)

# lexer = Lexer('*asd[]')
# print('len ', len('*asd[]'))
# for i in range(10):
# lexer.advance()
# print(lexer.pos)
# print(lexer.current_token)

0 comments on commit 7fb0e29

Please sign in to comment.