aboutsummaryrefslogtreecommitdiff
path: root/automata_enteros.py
diff options
context:
space:
mode:
authorEdgar-Alexis-Lopez-Martinez <83847738+Edgar-Alexis-Lopez-Martinez@users.noreply.github.com>2022-11-14 19:28:48 -0600
committerGitHub <noreply@github.com>2022-11-14 19:28:48 -0600
commitde272f939f2ae0266a4ee363a854558ace5a59e2 (patch)
tree2b37b82eb6133f44005dfb18e857eeae42211f80 /automata_enteros.py
parentce60f5d0a018d9cb45d3c04cdbfd1bbfc14ae6b8 (diff)
downloadjavanol-de272f939f2ae0266a4ee363a854558ace5a59e2.tar.gz
javanol-de272f939f2ae0266a4ee363a854558ace5a59e2.tar.bz2
javanol-de272f939f2ae0266a4ee363a854558ace5a59e2.zip
Add Automatas
Automatas
Diffstat (limited to 'automata_enteros.py')
-rw-r--r--automata_enteros.py119
1 files changed, 58 insertions, 61 deletions
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