diff options
Diffstat (limited to 'compilador/automatas')
-rw-r--r-- | compilador/automatas/automata_cadenas.py | 43 | ||||
-rw-r--r-- | compilador/automatas/automata_caracteres.py | 51 | ||||
-rw-r--r-- | compilador/automatas/automata_enteros.py | 58 | ||||
-rw-r--r-- | compilador/automatas/automata_flotantes.py | 78 | ||||
-rw-r--r-- | compilador/automatas/automata_identificadores.py | 36 | ||||
-rw-r--r-- | compilador/automatas/automata_operadores.py | 96 |
6 files changed, 362 insertions, 0 deletions
diff --git a/compilador/automatas/automata_cadenas.py b/compilador/automatas/automata_cadenas.py new file mode 100644 index 0000000..dc15a98 --- /dev/null +++ b/compilador/automatas/automata_cadenas.py @@ -0,0 +1,43 @@ +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/compilador/automatas/automata_caracteres.py b/compilador/automatas/automata_caracteres.py new file mode 100644 index 0000000..139f86b --- /dev/null +++ b/compilador/automatas/automata_caracteres.py @@ -0,0 +1,51 @@ +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/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 diff --git a/compilador/automatas/automata_flotantes.py b/compilador/automatas/automata_flotantes.py new file mode 100644 index 0000000..b7be7d8 --- /dev/null +++ b/compilador/automatas/automata_flotantes.py @@ -0,0 +1,78 @@ +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/compilador/automatas/automata_identificadores.py b/compilador/automatas/automata_identificadores.py new file mode 100644 index 0000000..c26adfb --- /dev/null +++ b/compilador/automatas/automata_identificadores.py @@ -0,0 +1,36 @@ +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/compilador/automatas/automata_operadores.py b/compilador/automatas/automata_operadores.py new file mode 100644 index 0000000..af10e61 --- /dev/null +++ b/compilador/automatas/automata_operadores.py @@ -0,0 +1,96 @@ + +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 |