My problem is probably a format error but i can't find what error it is, when i use readFile and then I try to read that string into a data type, i receive that error.
I'm implementing a simple interpreter of a programming language in Haskell like this post:
Implementing a language interpreter in haskell
Then, I am trying to read from a file some datatype from user and files, when it is from user, it correctrly works, but not for the types read from file. My datatypes are the following:
infixr 1 :=
infix 4 :<, :>, :==, :>=, :<=
infixl 6 :+, :-
infixl 7 :*, :/
data Valuable = I Int --Entero
| V Variable --Variable
| Valuable :+ Valuable
| Valuable :- Valuable
| Valuable :* Valuable
| Valuable :/ Valuable
deriving (Read, Show);
data Boolval = B Bool --Dato booleano
| Valuable :>= Valuable
| Valuable :<= Valuable
| Valuable :== Valuable
| Valuable :> Valuable
| Valuable :< Valuable
deriving (Read, Show);
data Instruccion = Valuable := Valuable
| While Boolval Instruccion
| Cond Boolval Instruccion
| Varias [Instruccion]
deriving (Read, Show);
And when I'm trying to get the input with this procedure:
mst::[VarVal]->String -- Varval is [String, int]
mst [] = ""
mst[(a,b)] = "('" ++ a ++"', "++ (show b) ++ ")"
mst((a,b):xs) = "('" ++ a ++"', "++ (show b) ++ "), " ++ mst xs
main = do
putStrLn "Introduce el nombre del programa a cargar (Por ejemplo arch.txt)"
file <- getLine --Se toma el nombre de archivo
putStrLn "Introduce el estado de las variables con comillas dobles, (ej [(`X`,3)])"
user_state <- getLine --Se toma la entrada
arch <- readFile file
let real_state = read user_state
let my_program_file = read arch
putStrLn arch
let lst = ejecutar my_program_file real_state --problemas
putStrLn (mst lst)
The problem comes when is used the "read file" instruction, because the input format is not correct(I'm not sure) and i get the message: *** Exception: Prelude.read: no parse
. this is the input format
Varias [(V "Y" := (V "X"),
(V "R" := I 1),
(While (I 0 :< V "Y") (Varias [
(V "R" := (V "R" :* V "Y")),
(V "Y" := (V "Y" :- I 1))
])
)
]
What am I doing wrong?