aboutsummaryrefslogtreecommitdiff
path: root/automata_enteros.py
blob: cdf5879afd92a433c3ac02e7c87b95ca9e6ce2a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class automata_enteros:
        int stateN = 0
        int isAccepted(char str[]):

            int len = len(str)
            
            for i in len:
                if (stateN == 0):
                    start(str[i])
                else:
                    if (stateN == 1):
                        state1(str[i])
                    else: 
                        if(stateN == 2):
                            state2(str[i])
                        else:
                            if(stateN == 3):
                                state3(str[i])
                            else
                                return 0

            if (stateN == 2 or stateN == 3):
                return 1
            else:
                return 0
			
			def start(char c):
			        
				if (c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or 
				    c == '6' or c == '7' or c == '8' or c == '9'):
			        stateN = 3
			    else: 
                    if (c == '0'):
			            stateN = 2
			        else: 
                        if(c == '-'):
			    	        stateN = 1
			            else:
			    	        stateN = -1
		
			def state1(char c):
			    if (c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or 
				    c == '6' or c == '7' or c == '8' or c == '9'):
			        stateN = 3
			    else:
			    	stateN = -1
			
			def state2(char c):
			    stateN = -1
			
			def state3(char c):
			    if (isdigit(c)):
			        stateN = 3
			    else:
			    	stateN = -1
			
			bool verified(char* token):
			    if (isAccepted(token)):
			        return true
			    else:
			        return false