You are on page 1of 4

DESARROLLO LABORATORIO SINTAXIS

concatenarPalabras :: String -> String -> String

concatenarPalabras x y = x ++ y

invertirPalabra :: String -> String

invertirPalabra [] = []

invertirPalabra (x:xs) = invertirPalabra xs ++ [x]

longitud :: String -> Int

longitud [] = 0

longitud (x:xs) = 1 + longitude xs

1. Unión:

unionLenguajes :: [String] -> [String]->[String]


unionLenguajes x y | validarLenguaje x && validarLenguaje y = unionLenguajesSV x y
| otherwise = [“Lenguaje/s No Valido/s”]

unionLenguajesSV :: [String] -> [String]->[String]


unionLenguajesSV x y = eliminarRepetidos ( x ++ y)

eliminarRepetidos :: [String] -> [String]


eliminarRepetidos x = nub x

validarLenguaje :: [String] -> Bool


validarLenguaje [] = True
validarLenguaje (x:xs) | length ( eliminarRepetidos ((x:xs)) ) <= 20 =
(validarPalabra x) && (validarLenguaje xs)
| otherwise = False

validarPalabra :: String - > Bool


validarPalabra [] = True
validarPalabra (x:xs) = ( elem x [`a`..`z`] ) && ( validarPalabra xs )
Diferencia:

diferenciaLenguajes :: [String] -> [String]->[String]


diferenciaLenguajes x y | validarLenguaje x && validarLenguaje y = diferenciaSV x y
| otherwise = [“Lenguaje/s No Valido/s”]

diferenciaSV :: [String] -> [String]->[String]


diferenciaSV x y = eliminarRepetidos ( [ z | z < - x, not ( pertenece z y ) ] )

Intersección:

interseccionLenguajes :: [String] -> [String]->[String]


interseccionLenguajes x y | validarLenguaje x && validarLenguaje y =
interseccionLenguajesSV x y
| otherwise = [“Lenguaje/s No Valido/s”]

interseccionSV :: [String] -> [String]->[String]


interseccionSV x y = eliminarRepetidos ( [ z | z < - x, pertenece z x, pertenece z y ] )

pertenece :: String -> [String] -> Bool


pertenece x [] = False
pertenece x (y:ys) | x == y = True
| otherwise = pertenece x ys

Complemento:

complemento :: [String] -> [String]-> Int -> [String]


complemento a l n | validarLenguajeAlfabeto l a && validarAlfabeto a &&
validarLenguaje l && n<= 20 = take n $ diferenciaSV
(lenguajeUniversal a) l
| otherwise = [“Lenguaje No Valido o Alfabeto No Valido o n>20”]

lenguajeUniversal :: [String] -> [String]


lenguajeUniversal x = potenciaInf x 0

validarAlfabeto :: [String] - > Bool


validarAlfabeto [] = True
validarAlfabeto (x:xs) | length x == 1 = (validarPalabra x ) && (validarAlfabeto xs)
| otherwise = False
Potencia:

potenciaLenguaje :: [String]-> Int -> [String]


potenciaLenguaje x n | validarLenguaje x = potenciaSV x n
| otherwise = [“Lenguaje No Valido”]

potenciaSV :: [String]-> Int -> [String]


potenciaSV x 0 = [””]

potenciaSV x l = x

potenciaSV x n = eliminarRepetidos ( concatenarLenguajesSV x (potenciaSV x (n-1)) )

Concatenar:

concatenarLenguajes :: [String] -> [String]->[String]


concatenarLenguajes x y | validarLenguaje x && validarLenguaje y =
concatenarLenguajesSV x y
| otherwise = [“Lenguaje/s No Valido/s”]

concatenarLenguajesSV :: [String] -> [String]->[String]


concatenarLenguajesSV x y = eliminarRepetidos ( [ concatenarPalabras c d| c< - x, d < -
y])

Estrella Positiva:

estrellaPositiva :: [String]-> Int -> [String]


estrellaPositiva [“”] n = [“”]
estrellaPositiva x n | validarLenguaje x && n < = 20 = take n $ potenciaInf x 1
| otherwise = [“Lenguaje No Valido o n>20”]

potenciaInf :: [String]-> Int -> [String]


potenciaInf x n = unionLenguajesSV ( potenciaSV x n ) ( potenciaInf x (n+1) )

Estrella de Kleane:

estrellaKleene :: [String]-> Int -> [String]


estrellaKleene [“”] n = [“”]
estrellaKleene [] n = [“”]
estrellaKleene x n | validarLenguaje x && n < = 20 = take n $ potenciaInf x 0
| otherwise = [“Lenguaje No Valido o n>20”]

potenciaInf :: [String]-> Int -> [String]


potenciaInf x n = unionLenguajesSV ( potenciaSV x n ) ( potenciaInf x (n+1) )
Inversa:

invertirLenguaje :: [String] -> [String]


invertirLenguaje x | validarLenguaje x = invertirLenguajeSV x
| otherwise = [“Lenguaje No Valido”]

invertirLenguajeSV :: [String] -> [String]


invertirLenguajeSV x = eliminarRepetidos ( [ invertirPalabra y | y < - x ] )

invertirPalabra :: String -> String


invertirPalabra [] = []
invertirPalabra (x:xs) = invertirPalabra xs ++ [x]

You might also like