diff options
Diffstat (limited to 'compilador/automatas/automata_enteros.py')
-rw-r--r-- | compilador/automatas/automata_enteros.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/compilador/automatas/automata_enteros.py b/compilador/automatas/automata_enteros.py new file mode 100644 index 0000000..c97659e --- /dev/null +++ b/compilador/automatas/automata_enteros.py @@ -0,0 +1,58 @@ +class automata_ent: + stateN = 0 + + def isAccepted(self, _str): + i = len(_str) + _len = len(_str) + + for i in range(len): + if self.stateN == 0: + self.start(_str[i]) + if self.stateN == 1: + self.state1(_str[i]) + if self.stateN == 2: + self.state2(_str[i]) + if self.stateN == 3: + self.state3(_str[i]) + else: + return 0 + if self.stateN == 2 or self.stateN == 3: + return 1 + else: + return 0 + + + def start(self,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'): + self.stateN = 3 + else if (c == '0'): + self.stateN = 2 + else if (c == '-'): + self.stateN = 1 + else + self.stateN = -1 + + def state1(self,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'): + self.stateN = 3 + else: + self.stateN = -1 + + def state2(self,c): + self.stateN = -1 + + def state3(self,c) + { + if c.isdigit(): + self.stateN = 3 + else: + self.stateN = -1 + } + + def verified(self,token) + { + if isAccepted(token): + return true + else: + return false + }
\ No newline at end of file |