aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--automata_cadenas.py86
-rw-r--r--automata_caracteres.py103
-rw-r--r--automata_enteros.py119
-rw-r--r--automata_flotantes.py165
-rw-r--r--automata_identificadores.py73
-rw-r--r--automata_operadores.py205
6 files changed, 362 insertions, 389 deletions
diff --git a/automata_cadenas.py b/automata_cadenas.py
index 4f8a99b..7170d4b 100644
--- a/automata_cadenas.py
+++ b/automata_cadenas.py
@@ -1,43 +1,43 @@
-class automata_cadena:
- 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:
- return 0
-
- if (stateN == 2):
- return 1
- else:
- return 0
-
- def start(char c):
- if (c == '\"'):
- stateN = 1
- else:
- stateN = -1
-
- def state1(char c):
- if (c != '\"'):
- stateN = 1
- else:
- stateN = 2
-
- def state2(char c):
- stateN = -1
-
- bool verified(char* token):
- if (isAccepted(token)):
- return true
- else:
- return false
+class automata_cad:
+ 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])
+ else:
+ return 0
+ if self.stateN == 2
+ return 1
+ else:
+ return 0
+
+ def start(self, c):
+ if (c == '\"'):
+ self.stateN = 1
+ else:
+ self.stateN = -1
+
+ def state1(self,c):
+ if (c != '\"'):
+ self.stateN = 1
+ else:
+ self.stateN = 2
+
+ def state2(self,c):
+ self.stateN = -1
+
+ def verified(self,token)
+ {
+ if isAccepted(token):
+ return true
+ else:
+ return false
+ } \ No newline at end of file
diff --git a/automata_caracteres.py b/automata_caracteres.py
index 0173467..341100a 100644
--- a/automata_caracteres.py
+++ b/automata_caracteres.py
@@ -1,52 +1,51 @@
-class automata_caracter:
- 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 == 3):
- return 1
- else:
- return 0
-
- def start(char c):
- if (c == '\''):
- stateN = 1
- else:
- stateN = -1
-
- def state1(char c):
- if (c != '\''):
- stateN = 2
- else:
- stateN = 3
-
- def state2(char c):
- if (c == '\''):
- stateN = 3
- else:
- stateN = -1
-
- def state3(char c):
- stateN = -1
-
- bool verified(char* token):
- if (isAccepted(token)):
- return true
- else:
- return false
+class automata_car:
+ 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 == 3:
+ return 1
+ else:
+ return 0
+
+ def start(self,c):
+ if (c == '\''):
+ self.stateN = 1
+ else:
+ self.stateN = -1
+
+ def state1(self,c):
+ if (c != '\''):
+ self.stateN = 2
+ else:
+ self.stateN = 3
+
+ def state2(self,c):
+ if (c == '\''):
+ self.stateN = 3
+ else:
+ self.stateN = -1
+
+ def state3(self,c):
+ self.stateN = -1
+
+ def verified(self,token){
+ if isAccepted(token):
+ return true
+ else:
+ return false
+ }
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
diff --git a/automata_flotantes.py b/automata_flotantes.py
index 222f977..5ba2b7d 100644
--- a/automata_flotantes.py
+++ b/automata_flotantes.py
@@ -1,87 +1,78 @@
-class automata_flotante:
- 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
- return 0
-
- if (stateN == 5):
- return 1
- else:
- return 0
-
- def start(char c):
- if (c == '0'):
- stateN = 1
- else:
- if(c == '-'):
- stateN = 2
- else:
- 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 state1(char c):
- if (c == '.'):
- stateN = 4
- else:
- stateN = -1
-
- def state2(char c):
- if(c == '0'):
- stateN = 1
- else:
- 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 state3(char c):
- if(c == '.'):
- stateN = 4
- else:
- if(isdigit(c)):
- stateN = 3
- else:
- stateN = -1
-
- def state4(char c):
- if(isdigit(c)):
- stateN = 5
- else:
- stateN = -1
-
- def state5(char c):
- if(isdigit(c)):
- stateN = 5
- else:
- stateN = -1
-
- bool verified(char* token):
- if (isAccepted(token)):
- return true
- else:
- return false
+class automata_flot:
+ 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])
+ if self.stateN == 4:
+ self.state4(_str[i])
+ if self.stateN == 5:
+ self.state5(_str[i])
+ else:
+ return 0
+
+ if self.stateN == 5:
+ return 1
+ else:
+ return 0
+
+ def start(self, c):
+ if (c == '0'):
+ self.stateN = 1
+ else if(c == '-'):
+ self.stateN = 2
+ else 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 state1(self,c):
+ if (c == '.'):
+ self.stateN = 4
+ else:
+ self.stateN = -1
+
+ def state2(self,c):
+ if(c == '0'):
+ self.stateN = 1
+ else 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 state3(self,c):
+ if(c == '.'):
+ self.stateN = 4
+ else if c.isdigit():
+ stateN = 3
+ else:
+ self.stateN = -1
+
+ def state4(self,c):
+ if c.isdigit():
+ self.stateN = 5
+ else:
+ self.stateN = -1
+
+ def state5(self,c):
+ if c.isdigit():
+ self.stateN = 5
+ else:
+ self.stateN = -1
+
+ def verified(self,token):
+ if isAccepted(token)
+ return true
+ else:
+ return false \ No newline at end of file
diff --git a/automata_identificadores.py b/automata_identificadores.py
index 5e95429..7955616 100644
--- a/automata_identificadores.py
+++ b/automata_identificadores.py
@@ -1,37 +1,36 @@
-class automata_identificadores:
- 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:
- return 0
-
- if (stateN == 1):
- return 1
- else:
- return 0
-
- def start(char c):
- if (isalpha(c) or c == '_'):
- stateN = 1
- else:
- stateN = -1
-
- def state1(char c):
- if (isalpha(c) or c == '_' or isdigit(c)):
- stateN = 1
- else:
- stateN = -1
-
- bool no_es_main(char* token):
- if (isAccepted(token))
- return true
- else:
- return false
+class automata_ident:
+ 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])
+ else:
+ return 0
+ if self.stateN == 1:
+ return 1
+ else:
+ return 0
+
+ def start(self, c):
+ if (c.isalpha() or c == '_'):
+ self.stateN = 1
+ else:
+ self.stateN = -1
+
+ def state1(self, c):
+ if (c.isalpha() or c == '_' or c.isdigit()):
+ self.stateN = 1
+ else:
+ self.stateN = -1
+
+ def no_es_main(self,token):
+ if isAccepted(token):
+ return true
+ else:
+ return false \ No newline at end of file
diff --git a/automata_operadores.py b/automata_operadores.py
index 02d0ff9..354bfe8 100644
--- a/automata_operadores.py
+++ b/automata_operadores.py
@@ -1,109 +1,96 @@
-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
+
+class automata_ope:
+ 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])
+ if self.stateN == 4:
+ self.start4(_str[i])
+ if self.stateN == 5:
+ self.state5(_str[i])
+ if self.stateN == 6:
+ self.state6(_str[i])
+ if self.stateN == 7:
+ self.state7(_str[i])
+ if self.stateN == 8:
+ self.state8(_str[i])
+ else:
+ return 0
+ if (self.stateN == 1 or self.stateN == 7 or self.stateN == 8 or self.stateN == 2 or self.stateN == 3 or self.stateN == 6):
+ return 1
+ else:
+ return 0
+
+ def start(self,c):
+ if(c == '=' or c == '>' or c == '<' or c == '/' or c == '*' or c == '%' or c == '!'):
+ self.stateN = 1
+ else if(c == '&'):
+ self.stateN = 4
+ else if(c == '|'):
+ self.stateN = 5
+ else if(c == '-'):
+ selfstateN = 6
+ else if(c == '+'):
+ selfstateN = 3
+ else:
+ self.stateN = -1
+
+ def state1(self,c):
+ if(c == '='):
+ self.stateN = 2
+ else:
+ self.stateN = -1
+
+ def state2(self,c):
+ self.stateN = -1
+
+ def state3(self,c):
+ if(c == '+'):
+ self.stateN = 7
+ else if(c == '='):
+ self.stateN = 2
+ else:
+ self.stateN = -1
+
+ def state4(self,c):
+ if(c == '&'):
+ self.stateN = 2
+ else:
+ self.stateN = -1
+
+ def state5(self,c):
+ if(c == '|'):
+ self.stateN = 2
+ else:
+ self.stateN = -1
+
+ def state6(self,c):
+ if(c == '-'):
+ self.stateN = 8
+ else if(c == '='):
+ self.stateN = 2
+ else:
+ self.stateN = -1
+
+ def state7(self,c):
+ self.stateN = -1
+
+ def state8(self,c):
+ self.stateN = -1
+
+ def verified(self,token):
+ if isAccepted(token):
+ return true
+ else:
+ return false \ No newline at end of file