class AFD:

uno
def __init__(self):
self.estado_actual = 'Inicio'
self.estados_finales = ['Final']
def transicion(self, caracter):
"""
Definir las transiciones del AFD basado en el estado actual y el carácter de entrada.
"""
if self.estado_actual == 'Inicio':
if caracter.isalpha() or caracter == '_':
self.estado_actual = 'Usuario_Letra_o_GuionBajo'
else:
self.estado_actual = 'Error'
elif self.estado_actual == 'Usuario_Letra_o_GuionBajo':
if caracter.isalnum() or caracter == '.' or caracter == '_':
self.estado_actual = 'Usuario_CaracterValido'
else:
self.estado_actual = 'Error'
elif self.estado_actual == 'Usuario_CaracterValido':
if caracter.isalnum() or caracter == '_':
pass # Permanece en el mismo estado
elif caracter == '@':
self.estado_actual = 'Esperando_Arroba'
else:
self.estado_actual = 'Error'
elif self.estado_actual == 'Esperando_Arroba':
if caracter.isalnum():
self.estado_actual = 'Subdominio'
else:
self.estado_actual = 'Error'
elif self.estado_actual == 'Subdominio':
if caracter.isalnum():
pass # Permanece en el mismo estado
elif caracter == '.':
self.estado_actual = 'Esperando_DominioPunto'
else:
self.estado_actual = 'Error'
elif self.estado_actual == 'Esperando_DominioPunto':
if caracter.isalnum():
self.estado_actual = 'Subdominio'
elif len(caracter) == 2 and caracter.isalpha(): # Supone subdominio de 2 letras
self.estado_actual = 'Dominio_AltoNivel'
else:
self.estado_actual = 'Error'
elif self.estado_actual == 'Dominio_AltoNivel':
self.estado_actual = 'Final'
else:
self.estado_actual = 'Error'
def evaluar_cadena(self, cadena):
"""
Evalúa si la cadena es aceptada por el AFD.
"""
for caracter in cadena:
self.transicion(caracter)
if self.estado_actual == 'Error':
return False
# Verifica si terminó en un estado final
return self.estado_actual in self.estados_finales
# Crear una instancia del AFD
afd = AFD()
# Cadena de prueba
cadena = "dmercadol@cuc.edu.co"
# Evaluar la cadena
if afd.evaluar_cadena(cadena):
print("Cadena aceptada")
else:
print("Cadena rechazada")uno
Welcome to JFLAP

JFLAP Logo and last release date
Please help add content here, especially if you're working with or working on JFLAP. Thanks!!!!!!!
17 articles since (Month) (Year)
Contents (view all pages)
|
|
What's new on JFLAP
Check out the Rankophilia Wikia
- JFLAP Wiki Born!
- July 2008 - JFLAP now has two listservs. To join, go to lists.duke.edu You do not need to be a member of Duke to join the listserv.
- jflap-announce@duke.edu - for announcements on new releases of JFLAP or new info on the JFLAP web page
- jflap-discuss@duke.edu - for anyone to have discussions about JFLAP
- July 27, 2018 - JFLAP 7.1 now available. We have updated JFLAP 7 to Java 8 and made some changes to Turing machines.
- We recommend using JFLAP 7.1 and NOT JFLAP 8 Beta as the Beta version was never finished and doesn't cover as many topics.
Helping out
To write a new article, just enter the article title in the box below.
<createbox> width=24 break=no buttonlabel=Create new article </createbox>
- Not sure where to start?
- Find out more about the wiki on the About page.
- If you are new to wikis, check out the tutorial.
- Check out Help:Starting this wiki if you're setting up the wiki.
- Adding content
- Every wiki has two list of articles that need help called "Stubs" and "Wanted Articles". Don't be shy, get in there.
- Uploading images is another really easy way to help out - see the Special:Upload page!
- You can find a list of useful templates on Category:Templates, some of which are documented on the templates project page.
- Talk and more...
- Check out the community portal to see what the community is working on, to give feedback or just to say hi.
- Other Resources