[Haskell-beginners] University project - weird problem

Renato dos Santos Leal renatodossantosleal at gmail.com
Wed Apr 21 20:30:06 EDT 2010


Right now, my program is ike this
listO = ['+', '-', '*', '/', '%', '^', '=', '>', '<', '.', '|', '&', '!',
'~']
listS = [';', '{', '(', ')', '}', '[', ']', ',']
listC = ['0','1'..'9']
listCF = listC ++ ['.']
listA = listO ++ listS ++ [' ']
listPC =
["auto","double","int","struct","break","else","long","switch","case",

"enum","register","typedef","char","extern","return","union","const",

"float","short","unsigned","continue","for","signed","void","default",
          "goto","sizeof","volatile","do","if","static","while"]

verifica :: IO ()
verifica = do
   putStr ("Favor visualizar o codigo para ver os bugs e erros do
programa\n")
   putStr ("Digite o nome do arquivo de entrada: ")
   arqent <- getLine
   texto <- readFile arqent
   le_bloco texto

le_bloco :: String -> IO ()
le_bloco (x:xs)
   | x `elem` listO = do operador (x:xs)
   | x `elem` listC = do cnum (x:xs)
   | x `elem` listS = do separador (x:xs)
   | x == '\n' = le_bloco xs
   | x == '"' = litstr (xs)
   | x /= ' ' = pchave (x:xs) []
   | x == ' ' = le_bloco xs
   | otherwise    = do { putStr "Outro\n" ; le_bloco xs }

le_bloco [] = return ()

separador :: String -> IO ()
separador (x:xs)
   | x `elem` listS = do{ putStr [x] ; putStr " <separador>\n" ; le_bloco
xs}

cnum :: String -> IO ()
cnum (x:xs)
   | x `elem` listCF = do{ putChar x ; cnum xs}
   | otherwise = do{ putStr " <cte. numerica>\n" ; le_bloco (x:xs)}

operador :: String -> IO ()
operador (x:xs)
   | x `elem` listO = do{ putChar x ; operador xs}
   | otherwise = do{ putStr " <operador>\n" ; le_bloco (x:xs)}

litstr :: String -> IO ()
litstr (x:xs)
   | x /= '"' = do{ putChar x ; litstr xs}
   | otherwise = do{ putStr " <literal string>\n" ; le_bloco xs}

pchave :: String -> String -> IO ()
pchave (x:xs) ys
   | x `notElem` listA = pchave xs (ys++[x])
   | otherwise = pPCouI (x:xs) ys

pPCouI :: String -> String -> IO ()
pPCouI (x:xs) z
   | membroPC z = do{ putStr (z ++ " <palavra chave>\n") ; le_bloco (x:xs)}
   | otherwise = do{putStr z ; putStr " <identificador>\n" ; le_bloco
(x:xs)}

membroPC :: String -> Bool
membroPC x
   | x `elem` listPC = True
   | otherwise = False


But there is still one problem that I haven't corrected:
printing the tag when there is only one keyword or identifier in the line
the case of beign the last one of the line is corrected but this one I don't
know how to do
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100421/203879ca/attachment.html


More information about the Beginners mailing list