Index: branches/apertium-separable/testing/acceptor.py =================================================================== --- branches/apertium-separable/testing/acceptor.py (nonexistent) +++ branches/apertium-separable/testing/acceptor.py (revision 79827) @@ -0,0 +1,40 @@ +import sys, re + +def next_token(): + token = sys.stdin.read(1) + if token == '<': + c = '' + while c != '>': + c = sys.stdin.read(1) + token += c + # print token + return token + +def main(): + states = ['^', 't', 'a', 'k', 'e', '', '$', ' ', '^', 'ANY_CHAR', '', '$', ' ', '^', 'o', 'u', 't', '$'] + #states = ['^', 't', 'a', 'k', 'e', '', '', '$', ' ', '^', 'ANY_CHAR', '', '', '$', ' ', '^', 'o', 'u', 't', '$'] + current_state = 0 + + print('input a string:') + c = next_token() + +#^take$ ^the$ ^thing$ ^out$ + + while c: + if current_state == len(states): #end of input + print('Yes') + sys.exit(0) + elif c == states[current_state]: #ok + print c, current_state + current_state += 1 + elif re.match('[a-zA-Z]', c): + print c, current_state + elif re.match('\<(.+?)\>', c): + print c, current_state + else: #error + print('No') + sys.exit(1) + c = next_token() + +if __name__ == '__main__': + main() \ No newline at end of file Index: branches/apertium-separable/testing/transducer.py =================================================================== --- branches/apertium-separable/testing/transducer.py (nonexistent) +++ branches/apertium-separable/testing/transducer.py (revision 79827) @@ -0,0 +1,100 @@ +import sys, re + +transitions = { + (-1,'^') : 0, + (0,'t') : 1, + (1,'a') : 2, + (2,'k') : 3, + (3,'e') : 4, + (4,'') : 5, + (5,'') : 6, + (6,'') : 11, + (10,'') : 12, + (10,'') : 13, + (10,'') : 14, + (11,'') : 15, + (12,'') : 15, + (13,'') : 15, + (14,'') : 15, + (15,'') : 15, + (15,'$') : 16, + (16,' ') : 17, + (17,'^') : 18, + (18,'c') : 10, + (18,'o') : 19, + (19,'u') : 20, + (20,'t') : 21, + (21,'') : 22, + (21,'') : 23, + (22,'$') : 24, + (23,'$') : 24, + (24,'\n') : 25 +} + +states = { + -1 : '?', + 0 : '^', + 1 : 't', + 2 : 'a', + 3 : 'k', + 4 : 'e', + 5 : '', + 6 : '', # + 7 : '$', + 8 : ' ', + 9 : '^', + 10 : 'c', #'ANY_CHAR', # + 11 : '', + 12 : '', + 13 : '', + 14 : '', + 15 : '', + 16 : '$', + 17 : ' ', + 18 : '^', + 19 : 'o', + 20 : 'u', + 21 : 't', + 22 : '', + 23 : '', + 24 : '$', + 25 : '' +} + +def next_token(): + token = sys.stdin.read(1) + if token == '<': + c = '' + while c != '>': + c = sys.stdin.read(1) + token += c + # print token + return token + +def step(state, symbol): + print(states[state]) + return transitions.get((state,symbol)) #return the next state, or None if it doesn't exist + +print('input a string:') +current_state = -1 +c = next_token() +while states.get(current_state) != None: + current_state = step(current_state, c) #c is peeking; get next state + if current_state == None: + print('error: next state not found for ' (current_state,c) ) + exit(1) + c = next_token() +exit(0) + +#^take$ ^ccccc$ ^ccccc$ ^out$ +#^take$ ^the$ ^thing$ ^out$ + + +# if __name__ == '__main__': +# main() \ No newline at end of file