aboutsummaryrefslogtreecommitdiff
path: root/automata_operadores.py
blob: 02d0ff9cb4feb04a19a5d71d76d9051975de5b07 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
class automata_operador:
    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: 
                            if (stateN == 4):
                                state4(str[i])
                            else: 
                                if (stateN == 5):
                                    state5(str[i])
                                else: 
                                    if (stateN == 6):
                                        state6(str[i])
                                    else: 
                                        if (stateN == 7):
                                            state7(str[i])
                                        else: 
                                            if (stateN == 8):
                                                state8(str[i])
                                            else:
                                                return 0

        if (stateN == 1 or stateN == 7 or stateN == 8 or stateN == 2 or stateN == 3 or stateN == 6):
            return 1
        else:
            return 0
    
    def start(char c):
        if(c == '=' or c == '>' or c == '<' or c == '/' or c == '*' or c == '%' or c == '!'):
            stateN = 1
        else: 
            if(c == '&'):
                stateN = 4
            else: 
                if(c == '|'):
                    stateN = 5
                else: 
                    if(c == '-'):
                        stateN = 6
                    else: 
                        if(c == '+'):
                            stateN = 3
                        else
                            stateN = -1
        
    def state1(char c):
        if(c == '='):
            stateN = 2
        else:
            stateN = -1
    
    def state2(char c):
        stateN = -1
    
    def state3(char c):
        if(c == '+'):
            stateN = 7
        else: 
            if(c == '=')
                stateN = 2
            else:
                stateN = -1
    
    def state4(char c):
        if(c == '&'):
            stateN = 2
        else:
            stateN = -1
    
    def state5(char c):
        if(c == '|'):
            stateN = 2
        else:
            stateN = -1
    
    def state6(char c):
        if(c == '-'):
            stateN = 8
        else: 
            if(c == '=')
                stateN = 2
            else
            stateN = -1
    
    def state7(char c):
        stateN = -1
    
    def state8(char c):
        stateN = -1
    
    bool verified(char* token):
        if (isAccepted(token)):
            return true
        else:
            return false