From de272f939f2ae0266a4ee363a854558ace5a59e2 Mon Sep 17 00:00:00 2001 From: Edgar-Alexis-Lopez-Martinez <83847738+Edgar-Alexis-Lopez-Martinez@users.noreply.github.com> Date: Mon, 14 Nov 2022 19:28:48 -0600 Subject: Add Automatas Automatas --- automata_enteros.py | 119 +++++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 61 deletions(-) (limited to 'automata_enteros.py') diff --git a/automata_enteros.py b/automata_enteros.py index cdf5879..1b5fcb8 100644 --- a/automata_enteros.py +++ b/automata_enteros.py @@ -1,61 +1,58 @@ -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 +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 -- cgit v1.2.3