module Lex where import IO whitespace :: String whitespace = ['\n','\t',' '] getWord :: String -> String getWord [] = [] getWord (x:xs) | elem x whitespace = [] | otherwise = x : getWord xs dropWord :: String -> String dropWord [] = [] dropWord (x:xs) | elem x whitespace = (x:xs) | otherwise = dropWord xs dropSpace :: String -> String dropSpace [] = [] dropSpace (x:xs) | elem x whitespace = dropSpace xs | otherwise = (x:xs) splitWords :: String -> [String] splitWords st = split (dropSpace st) split :: String -> [String] split [] = [] split st = (getWord st) : split (dropSpace (dropWord st)) testReadFile :: IO [String] testReadFile = do s <- readFile "c:/lexemes.txt" g <- return(splitWords s) return(findToken g) findName :: [String] -> [String] findName (x:y) | x == "" = (y) | otherwise = ["not found"] findToken :: [String] -> [String] findToken st = do (x:y) <- findName st [y]